rcnl-org / nmsm-core

Neuromusculoskeletal Modeling (NMSM) Pipeline codebase
https://nmsm.rice.edu
Other
15 stars 3 forks source link

[QUESTION] Question about Coefficient Calculation for createMuscleSpecificSurrogateModel.m #281

Closed bfregly closed 7 months ago

bfregly commented 11 months ago

Is your question related to a problem? Please describe. In the last line of createMuscleSpecificSurrogateModel.m within SurrogateModelCreation, the linear regression coefficients are calculated as follows: % Calculate coefficients using linear least squares regression coefficients = matrix \ vector;

This implementation assumes that the system of equations will be overdetermined, meaning that there will be more available equations than unknown coefficients to find.

Will we ever have a situation where the system of equations is underdetermined, meaning that there will be more unknown coefficients to find than available equations?

If so, then we should explore using the following line instead to calculate the unknown coefficients: coefficients = pinv(matrix)*vector; If pinv is used and the system of equations is overdetermined, then pinv will give the least squares solution (see https://www.mathworks.com/help/matlab/math/systems-of-linear-equations.html).

Have you looked for a solution on nmsm.rice.edu?

Describe an answer you'd like We need to decide if we want to allow the user to fit surrogate musculoskeletal geometry models for underdetermined situations.

If so, then we should use pinv instead of . Right now, the backslash \ operator will give a result where redundant coefficients will be set equal to zero. The pinv operator will instead give a result where the coefficient vector has minimum magnitude, with none of the coefficients equal to zero, which is more desirable.

If not, then we may want to issue a warning message telling the user that not enough equations (data points) are available to perform the requested linear least squares regression fitting process.

Describe alternatives you've considered

Additional context

SpencerTWilliams commented 11 months ago

I've used the surrogate model with underdetermined systems before, including the kicking example. Matlab prints a warning, but the model still fits well.

With how helpful small examples like the arm and kicking have been, I think we should definitely let users fit surrogate models for underdetermined systems. From your comment and the documentation, it looks like we can just replace the backslash with pinv(matrix) * without any issues. Is the replacement that direct? If so, I'll just make that change.