Skip to content

Conversation

@bakpaul
Copy link
Contributor

@bakpaul bakpaul commented Oct 8, 2025

Based on #5666

This PR adds a regularization strategy that uses SVD to explore the NullSpace of the matrix to only add regularization to constraints that have antagonists constraints.

meaningful commit: 30f81e4

Introduced example

The added example shows a beam attached at both sides and which center is constrained in two different positions, meaning that two antagonists constraints are imposed to the center. The idea is that, because the fixations are not faulty, then we want them to be fully solved and we don't want to perturb them while still releasing the constraints on the antagonists ones.

With SVD

Capture d’écran du 2025-10-09 11-45-22 We can see that the attachments are fully solved why in the middle a compromise is found

Without SVD

Capture d’écran du 2025-10-09 11-46-00 Every constraints is regularized so even attachment are not respected.

By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@bakpaul bakpaul added pr: status to review To notify reviewers to review this pull-request pr: new feature Implement a new feature pr: based on previous PR PR based on a previous PR, therefore to be merged ONLY subsequently labels Oct 8, 2025
@hugtalbot hugtalbot changed the title [BuiltConstraintSolver] Add svd based regularization strategy [BuiltConstraintSolver] Add SVD based regularization strategy Oct 9, 2025
Copy link
Contributor

@th-skam th-skam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments and suggestions for this very useful PR

{
if (regularization>std::numeric_limits<SReal>::epsilon())
{
auto * FullW = dynamic_cast<sofa::linearalgebra::LPtrFullMatrix<SReal> * >(&W);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this cast is ensured by how the ComplianceWrapper sets the matrix type in BuiltConstraintSolver. Still, you could add a check for nullptr if anything changes in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do !

int nullSpaceBegin = -1;
for(size_t i=0; i<problemSize; i++)
{
if (fabs(svd.singularValues()(i)) < fabs(svd.singularValues()(0))/100.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to add the 1% criterion as a parameter so that the user can limit/expand the filter.
In a more complex problem, wouldn't it be possible that constraint feasibility is not so clearly separated and you end up with over-regularization. Or on the contrary being too strict with the criterion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is highly probable. But in that case, if no singular value is smaller than the rest, then all the problem should be regularized in my mind.

On the parameter side yes, I also wanted to do that. But I dislike adding new parameters that only apply if another parameter is true. LEt's discuss this in the sofa-dev-meeting

@fredroy
Copy link
Contributor

fredroy commented Oct 26, 2025

[ci-build][with-all-tests]

@bakpaul bakpaul added the pr: status wip Development in the pull-request is still in progress label Oct 30, 2025
@fredroy fredroy removed the pr: status to review To notify reviewers to review this pull-request label Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: based on previous PR PR based on a previous PR, therefore to be merged ONLY subsequently pr: new feature Implement a new feature pr: status wip Development in the pull-request is still in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants