MocoExtendProblem: Interface Between OpenSim and MATLAB for Rapidly Developing Direct Collocation Goals in Moco 1.1.0
add custom Moco goals to existing matlab scripts
MocoActivationSquaredGoal Class Reference

Goal that minimizes the squared sum of muscle activations. More...

#include <MocoActivationSquaredGoal.h>

Inheritance diagram for MocoActivationSquaredGoal:

Public Member Functions

void setEndPointGoal (double end_point_goal)
 Set the target value for endpoint goal evaluation.
 
double getEndPointGoal () const
 Get the endpoint goal target value.
 
void setDivideByDisplacement (bool tf)
 Set whether to divide the sum of squared activations by displacement.
 
bool getDivideByDisplacement () const
 Get whether the sum is divided by displacement.
 
void setEndPointGoal (double end_point_goal)
 Set the target value when using this goal as an endpoint constraint.
 
double getEndPointGoal () const
 Get the endpoint constraint target value.
 
Constructors
 MocoActivationSquaredGoal ()
 Default constructor.
 
 MocoActivationSquaredGoal (std::string name)
 Constructor with name.
 
 MocoActivationSquaredGoal (std::string name, double weight)
 Constructor with name and weight.
 
 MocoActivationSquaredGoal ()
 Default constructor.
 
 MocoActivationSquaredGoal (std::string name)
 Constructor with name.
 
 MocoActivationSquaredGoal (std::string name, double weight)
 Constructor with name and weight.
 

Protected Member Functions

Required implementations of virtual methods
Mode getDefaultModeImpl () const override
 Get the default mode for this goal.
 
bool getSupportsEndpointConstraintImpl () const override
 Whether this goal supports endpoint constraint mode.
 
void initializeOnModelImpl (const Model &) const override
 Initialize the goal with the model.
 
void calcIntegrandImpl (const IntegrandInput &input, double &integrand) const override
 Calculate the integrand value for the cost function.
 
void calcGoalImpl (const GoalInput &input, SimTK::Vector &cost) const override
 Calculate the goal value.
 
Mode getDefaultModeImpl () const override
 Get the default mode for this goal.
 
bool getSupportsEndpointConstraintImpl () const override
 Whether this goal supports endpoint constraint mode.
 
void initializeOnModelImpl (const Model &) const override
 Initialize the goal with the model.
 
void calcIntegrandImpl (const IntegrandInput &input, double &integrand) const override
 Calculate the integrand value for the cost function.
 
void calcGoalImpl (const GoalInput &input, SimTK::Vector &cost) const override
 Calculate the goal value.
 

Private Member Functions

 OpenSim_DECLARE_CONCRETE_OBJECT (MocoActivationSquaredGoal, MocoGoal)
 
void constructProperties ()
 Initialize the goal's properties.
 
 OpenSim_DECLARE_CONCRETE_OBJECT (MocoActivationSquaredGoal, MocoGoal)
 
void constructProperties ()
 Initialize the goal's properties.
 
Properties
 OpenSim_DECLARE_PROPERTY (exponent, int, "The exponent applied to the output value in the integrand. " "The output can take on negative values in the integrand when the " "exponent is set to 1 (the default value). When the exponent is " "set to a value greater than 1, the absolute value function is " "applied to the output (before the exponent is applied), meaning " "that odd numbered exponents (greater than 1) do not take on " "negative values.")
 
 OpenSim_DECLARE_PROPERTY (end_point_goal, double, "Target value for end-point goal (default: 0)")
 
 OpenSim_DECLARE_PROPERTY (divide_by_displacement, bool, "Divide by the model's displacement over the phase (default: " "false)")
 
 OpenSim_DECLARE_PROPERTY (exponent, int, "The exponent applied to the output value in the integrand. " "The output can take on negative values in the integrand when the " "exponent is set to 1 (the default value). When the exponent is " "set to a value greater than 1, the absolute value function is " "applied to the output (before the exponent is applied), meaning " "that odd numbered exponents (greater than 1) do not take on " "negative values.")
 
 OpenSim_DECLARE_PROPERTY (end_point_goal, double, "Target value for end-point goal (default: 0)")
 

Private Attributes

Internal working variables
std::vector< int > m_act_indices
 Indices of activation states in the model.
 
std::function< double(const double &)> m_power_function
 Function to compute power of activation values.
 

Detailed Description

Goal that minimizes the squared sum of muscle activations.

This goal minimizes the sum of squared muscle activations, integrated over the phase. It is equivalent to using MocoActivationGoal with exponent=2. The squared activation cost is commonly used as a proxy for metabolic cost and effort minimization.

This goal can be useful for:

  • Minimizing muscle effort
  • Finding metabolically efficient motions
  • Generating coordinated movement patterns
  • Reducing co-contraction

The goal can optionally be configured as an endpoint goal, where the squared activations are evaluated only at the final time point instead of being integrated over the phase.

This goal minimizes the sum of squared muscle activation values, integrated over the phase. The integrand is:

\[
\sum_i a_i^2
\]

where $ a_i $ are the activation values. This is equivalent to MocoActivationGoal with exponent=2, but may be more computationally efficient.

This goal can be useful for:

  • Minimizing overall muscle effort
  • Finding metabolically efficient motions
  • Reducing co-contraction

The goal can optionally be divided by the total displacement of the model during the phase to make the cost invariant to the distance traveled.

Constructor & Destructor Documentation

◆ MocoActivationSquaredGoal() [1/6]

Default constructor.

◆ MocoActivationSquaredGoal() [2/6]

MocoActivationSquaredGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoActivationSquaredGoal() [3/6]

MocoActivationSquaredGoal ( std::string name,
double weight )
inline

Constructor with name and weight.

Parameters
nameThe name of the goal
weightWeight for this goal term in the optimization

◆ MocoActivationSquaredGoal() [4/6]

Default constructor.

◆ MocoActivationSquaredGoal() [5/6]

MocoActivationSquaredGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoActivationSquaredGoal() [6/6]

MocoActivationSquaredGoal ( std::string name,
double weight )
inline

Constructor with name and weight.

Parameters
nameThe name of the goal
weightWeight for this goal term in the optimization

Member Function Documentation

◆ calcGoalImpl() [1/2]

void calcGoalImpl ( const GoalInput & input,
SimTK::Vector & cost ) const
overrideprotected

Calculate the goal value.

Parameters
inputInput data containing the integral
costVector to store the calculated cost

◆ calcGoalImpl() [2/2]

void calcGoalImpl ( const GoalInput & input,
SimTK::Vector & cost ) const
overrideprotected

Calculate the goal value.

Parameters
inputInput data containing the integral
costVector to store the calculated cost

◆ calcIntegrandImpl() [1/2]

void calcIntegrandImpl ( const IntegrandInput & input,
double & integrand ) const
overrideprotected

Calculate the integrand value for the cost function.

Parameters
inputInput data for the current state
integrandReference to store the calculated integrand value

◆ calcIntegrandImpl() [2/2]

void calcIntegrandImpl ( const IntegrandInput & input,
double & integrand ) const
overrideprotected

Calculate the integrand value for the cost function.

Parameters
inputInput data for the current state
integrandReference to store the calculated integrand value

◆ constructProperties() [1/2]

void constructProperties ( )
private

Initialize the goal's properties.

◆ constructProperties() [2/2]

void constructProperties ( )
private

Initialize the goal's properties.

◆ getDefaultModeImpl() [1/2]

Mode getDefaultModeImpl ( ) const
inlineoverrideprotected

Get the default mode for this goal.

◆ getDefaultModeImpl() [2/2]

Mode getDefaultModeImpl ( ) const
inlineoverrideprotected

Get the default mode for this goal.

◆ getDivideByDisplacement()

bool getDivideByDisplacement ( ) const
inline

Get whether the sum is divided by displacement.

Returns
True if divided by displacement, false otherwise

◆ getEndPointGoal() [1/2]

double getEndPointGoal ( ) const
inline

Get the endpoint goal target value.

Returns
The target value for endpoint goal evaluation

◆ getEndPointGoal() [2/2]

double getEndPointGoal ( ) const
inline

Get the endpoint constraint target value.

Returns
The target value for endpoint constraint mode

◆ getSupportsEndpointConstraintImpl() [1/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

Whether this goal supports endpoint constraint mode.

◆ getSupportsEndpointConstraintImpl() [2/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

Whether this goal supports endpoint constraint mode.

◆ initializeOnModelImpl() [1/2]

void initializeOnModelImpl ( const Model & model) const
overrideprotected

Initialize the goal with the model.

◆ initializeOnModelImpl() [2/2]

void initializeOnModelImpl ( const Model & ) const
overrideprotected

Initialize the goal with the model.

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [1/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoActivationSquaredGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [2/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoActivationSquaredGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_PROPERTY() [1/5]

OpenSim_DECLARE_PROPERTY ( divide_by_displacement ,
bool ,
"Divide by the model's displacement over the phase (default: " "false)"  )
private

◆ OpenSim_DECLARE_PROPERTY() [2/5]

OpenSim_DECLARE_PROPERTY ( end_point_goal ,
double ,
"Target value for end-point goal (default: 0)"  )
private

◆ OpenSim_DECLARE_PROPERTY() [3/5]

OpenSim_DECLARE_PROPERTY ( end_point_goal ,
double ,
"Target value for end-point goal (default: 0)"  )
private

◆ OpenSim_DECLARE_PROPERTY() [4/5]

OpenSim_DECLARE_PROPERTY ( exponent ,
int ,
"The exponent applied to the output value in the integrand. " "The output can take on negative values in the integrand when the " "exponent is set to 1 (the default value). When the exponent is " "set to a value greater than 1,
the absolute value function is " "applied to the outputbefore the exponent is applied,
meaning " "that odd numbered exponents(greater than 1) do not take on " "negative values."  )
private

◆ OpenSim_DECLARE_PROPERTY() [5/5]

OpenSim_DECLARE_PROPERTY ( exponent ,
int ,
"The exponent applied to the output value in the integrand. " "The output can take on negative values in the integrand when the " "exponent is set to 1 (the default value). When the exponent is " "set to a value greater than 1,
the absolute value function is " "applied to the outputbefore the exponent is applied,
meaning " "that odd numbered exponents(greater than 1) do not take on " "negative values."  )
private

◆ setDivideByDisplacement()

void setDivideByDisplacement ( bool tf)
inline

Set whether to divide the sum of squared activations by displacement.

Parameters
tfTrue to divide by displacement, false otherwise
Here is the caller graph for this function:

◆ setEndPointGoal() [1/2]

void setEndPointGoal ( double end_point_goal)
inline

Set the target value for endpoint goal evaluation.

Parameters
end_point_goalTarget value when used as endpoint goal

◆ setEndPointGoal() [2/2]

void setEndPointGoal ( double end_point_goal)
inline

Set the target value when using this goal as an endpoint constraint.

Parameters
end_point_goalThe target value (default: 0)

Member Data Documentation

◆ m_act_indices

std::vector< int > m_act_indices
mutableprivate

Indices of activation states in the model.

Indices of muscle activation states

◆ m_power_function

std::function< double(const double &)> m_power_function
mutableprivate

Function to compute power of activation values.

Function to compute power of activation values


The documentation for this class was generated from the following files: