Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend ReLU/Max constraint with SoI cost term. #502

Merged
merged 24 commits into from
Jan 24, 2022

Conversation

wu-haoze
Copy link
Collaborator

@wu-haoze wu-haoze commented Jan 17, 2022

Add methods in the ReLU constraints to contribute a cost term in the SoI function. This is a small PR.
The next one is more involved with a SumOfInfeasibilitiesManager class which maintains/update the current heuristic cost (sum of the cost terms from the piecewise linear constraints).

@wu-haoze wu-haoze requested a review from guykatzz January 17, 2022 18:34
Copy link
Collaborator

@guykatzz guykatzz left a comment

Choose a reason for hiding this comment

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

I think it would be cleaner if the PLCs didn't manipulate the cost directly. Let them return their cost, and let someone else manipulate the actual array that stores it.

Compute the error of the current assignment with respect to the cost compoenent
corresponding to the given phase.
*/
virtual double computeCostFunctionComponent( PhaseStatus /* phase */ ) const
Copy link
Collaborator

Choose a reason for hiding this comment

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

Due to their names, it sounds like {add/compute}CostFunctionComponent are doing similar things. But I guess compute is computing not the component, but its value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah exactly. add is adding a "symbolic term" to the cost function, compute returns the values of the term based on the current assignment.

This is done in the SumOfInfeasibilitiesManager class, which maintains/updates the
SoI function.
*/
virtual void removeCostFunctionComponent( Map<unsigned, double> &/* cost */,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of add/remove, why not have a get(), and let the manager do with it as it will?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that makes sense. I'll defer this method to the SoIManager class.

@wu-haoze wu-haoze changed the title Extend ReLU constraint with SoI cost term. Extend ReLU/Max constraint with SoI cost term. Jan 20, 2022
@wu-haoze
Copy link
Collaborator Author

Updates:
I also added support of adding SoI terms from Max constraint.

@@ -512,11 +512,10 @@ List<PiecewiseLinearConstraint::Fix> MaxConstraint::getSmartFixes( ITableau * )

List<PhaseStatus> MaxConstraint::getAllCases() const
{
if ( _phaseStatus != PHASE_NOT_FIXED )
if ( phaseFixed() )
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a quick fix to the issue (#504) resulting from the refactored MaxConstraint. For now this is probably enough for the current master to be sound, because most of the refactored functionality is not in use. A more thorough change in the MaxConstraint is needed for the context dependent stuff to be actually usable.

#define __LinearExpression_h__

#include "Map.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this class different from the Equation class? Can we use the existing one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The difference is that linear expression is the lhs of an equation plus a constant: Ax +b

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay. I believe an equation is Ax = b, so it could also be used, right?
Just trying to reduce code duplication

Copy link
Collaborator

Choose a reason for hiding this comment

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

Never mind, I take my comment back. I think the linear expression has a sufficiently different meaning

@@ -785,3 +832,21 @@ String MaxConstraint::serializeToString() const

return output;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

remove empty line

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whoops will do

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@wu-haoze wu-haoze merged commit bbe8b64 into NeuralNetworkVerification:master Jan 24, 2022
@wu-haoze wu-haoze deleted the marabou-soi-cont branch January 24, 2022 02:44
omriisack pushed a commit to omriisack/Marabou that referenced this pull request Feb 6, 2022
…tion#502)

* change tableau for optimization

* optimize a cost function

* minor

* Cost function manager unit test

* Add unit test

* make optimization code public

* fix numerical issue

* add unit tests for tableau

* Changed {is/not}Optimizing to toggleOptimization.
Moved computeHeuristicCost from Engine to CostFunctionManager

* extend relu constraints with soi

* add unit test

* Update PiecewiseLinearConstraint.h

* change add/removeCostTerm to getCostTerm

* add SoI for Max

* add linear expression struct

* add two more unit tests

* change from HeuristicCost to LinearExpression

* make linear expression a class

* minor

* Update MaxConstraint.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants