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
MocoActivationGoal Class Reference

This goal minimizes the sum of muscle activations to a specified power, optionally allowing custom weights for specific muscles. More...

#include <MocoActivationGoal.h>

Inheritance diagram for MocoActivationGoal:

Public Member Functions

 MocoActivationGoal ()
 Default constructor.
 
 MocoActivationGoal (std::string name)
 Constructor with name.
 
 MocoActivationGoal (std::string name, double weight)
 Constructor with name and weight.
 
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.
 
void setExponent (int ex)
 Set the exponent applied to activation values.
 
bool getExponent () const
 Get the current exponent value.
 
void setCustomWeightNames (const std::vector< std::string > refCoordNames)
 Set the names of states to apply custom weights to.
 
void setCustomWeightValues (const std::vector< double > refWeights)
 Set the custom weight values corresponding to the custom state names.
 
void setDivideByDisplacement (bool tf)
 Set whether to divide the sum of 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
 MocoActivationGoal ()
 Default constructor.
 
 MocoActivationGoal (std::string name)
 Constructor with name.
 
 MocoActivationGoal (std::string name, double weight)
 Constructor with name and weight.
 

Protected Member Functions

Mode getDefaultModeImpl () const override
 
bool getSupportsEndpointConstraintImpl () const override
 
void initializeOnModelImpl (const Model &) const override
 
void calcIntegrandImpl (const IntegrandInput &input, double &integrand) const override
 
void calcGoalImpl (const GoalInput &input, SimTK::Vector &cost) const override
 
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.
 

Private Member Functions

 OpenSim_DECLARE_CONCRETE_OBJECT (MocoActivationGoal, MocoGoal)
 
 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)")
 
void constructProperties ()
 
 OpenSim_DECLARE_CONCRETE_OBJECT (MocoActivationGoal, MocoGoal)
 
void constructProperties ()
 Initialize the goal's properties.
 
Properties
 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

std::vector< std::string > m_state_names
 
std::vector< double > m_custom_weights
 
std::vector< double > m_custom_weights_input
 
std::vector< std::string > m_custom_state_names
 
std::vector< int > m_custom_act_indices
 
Internal working variables
std::vector< int > m_act_indices
 Indices of activation states in the model.
 
std::function< double(const double &)> m_power_function
 

Detailed Description

This goal minimizes the sum of muscle activations to a specified power, optionally allowing custom weights for specific muscles.

Goal that minimizes muscle activation effort in a Moco optimization problem.

The integrand is:

\[
\sum_i w_i |a_i|^p
\]

where $ a_i $ are the activation values, $ w_i $ are the weights (default: 1.0), and $ p $ is the exponent (default: 2).

This goal minimizes the sum of muscle activation values raised to a power, integrated over the phase. The integrand is:

\[
\sum_i |a_i|^p
\]

where $ a_i $ are the activation values and $ p $ is the exponent (default: 2).

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

◆ MocoActivationGoal() [1/6]

MocoActivationGoal ( )
inline

Default constructor.

◆ MocoActivationGoal() [2/6]

MocoActivationGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoActivationGoal() [3/6]

MocoActivationGoal ( 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

◆ MocoActivationGoal() [4/6]

MocoActivationGoal ( )
inline

Default constructor.

◆ MocoActivationGoal() [5/6]

MocoActivationGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoActivationGoal() [6/6]

MocoActivationGoal ( 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

◆ 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

◆ 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

◆ constructProperties() [2/2]

void constructProperties ( )
private

Initialize the goal's properties.

◆ getDefaultModeImpl() [1/2]

Mode getDefaultModeImpl ( ) const
inlineoverrideprotected

◆ 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 constraint target value.

Returns
The target value for endpoint constraint mode

◆ getEndPointGoal() [2/2]

double getEndPointGoal ( ) const
inline

Get the endpoint constraint target value.

Returns
The target value for endpoint constraint mode

◆ getExponent()

bool getExponent ( ) const
inline

Get the current exponent value.

Returns
The exponent applied to activation values

◆ getSupportsEndpointConstraintImpl() [1/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

◆ getSupportsEndpointConstraintImpl() [2/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

Whether this goal supports endpoint constraint mode.

◆ initializeOnModelImpl() [1/2]

void initializeOnModelImpl ( const Model & model) const
overrideprotected

◆ 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 ( MocoActivationGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [2/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoActivationGoal ,
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

◆ setCustomWeightNames()

void setCustomWeightNames ( const std::vector< std::string > refCoordNames)
inline

Set the names of states to apply custom weights to.

Parameters
refCoordNamesVector of state names

◆ setCustomWeightValues()

void setCustomWeightValues ( const std::vector< double > refWeights)
inline

Set the custom weight values corresponding to the custom state names.

Parameters
refWeightsVector of weights matching the order of custom state names

◆ setDivideByDisplacement()

void setDivideByDisplacement ( bool tf)
inline

Set whether to divide the sum of 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 when using this goal as an endpoint constraint.

Parameters
end_point_goalThe target value (default: 0)

◆ 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)

◆ setExponent()

void setExponent ( int ex)
inline

Set the exponent applied to activation values.

Parameters
exThe exponent value. For ex > 1, absolute value is applied first

Member Data Documentation

◆ m_act_indices

std::vector< int > m_act_indices
mutableprivate

Indices of activation states in the model.

◆ m_custom_act_indices

std::vector<int> m_custom_act_indices
mutableprivate

◆ m_custom_state_names

std::vector<std::string> m_custom_state_names
mutableprivate

◆ m_custom_weights

std::vector<double> m_custom_weights
mutableprivate

◆ m_custom_weights_input

std::vector<double> m_custom_weights_input
mutableprivate

◆ m_power_function

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

Function to compute power of activation values

◆ m_state_names

std::vector<std::string> m_state_names
mutableprivate

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