MCPcopy Create free account
hub / github.com/NeuralNetworkVerification/Marabou / constructSignLayer

Method constructSignLayer

src/engine/InputQuery.cpp:1502–1598  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1500}
1501
1502bool InputQuery::constructSignLayer( NLR::NetworkLevelReasoner *nlr,
1503 Map<unsigned, unsigned> &handledVariableToLayer,
1504 unsigned newLayerIndex,
1505 Set<PiecewiseLinearConstraint *> &handledPLConstraints )
1506{
1507 INPUT_QUERY_LOG( "Attempting to construct SignLayer..." );
1508 struct NeuronInformation
1509 {
1510 public:
1511 NeuronInformation( unsigned variable, unsigned neuron, unsigned sourceVariable )
1512 : _variable( variable )
1513 , _neuron( neuron )
1514 , _sourceVariable( sourceVariable )
1515 {
1516 }
1517
1518 unsigned _variable;
1519 unsigned _neuron;
1520 unsigned _sourceVariable;
1521 };
1522
1523 List<NeuronInformation> newNeurons;
1524
1525 // Look for Signs where the b variables have already been handled
1526 const List<PiecewiseLinearConstraint *> &plConstraints = getPiecewiseLinearConstraints();
1527
1528 unsigned currentSourceLayer = 0;
1529 for ( const auto &plc : plConstraints )
1530 {
1531 if ( handledPLConstraints.exists( plc ) )
1532 continue;
1533
1534 // Only consider Signs
1535 if ( plc->getType() != SIGN )
1536 continue;
1537
1538 const SignConstraint *sign = (const SignConstraint *)plc;
1539
1540 // Has the b variable been handled?
1541 unsigned b = sign->getB();
1542 if ( !handledVariableToLayer.exists( b ) ||
1543 ( _ensureSameSourceLayerInNLR && !newNeurons.empty() &&
1544 handledVariableToLayer[b] != currentSourceLayer ) )
1545 continue;
1546
1547 // If the f variable has also been handled, ignore this constraint
1548 unsigned f = sign->getF();
1549 if ( handledVariableToLayer.exists( f ) )
1550 continue;
1551
1552 // B has been handled, f hasn't. Add f
1553 if ( _ensureSameSourceLayerInNLR && newNeurons.empty() )
1554 currentSourceLayer = handledVariableToLayer[b];
1555 newNeurons.append( NeuronInformation( f, newNeurons.size(), b ) );
1556 nlr->addConstraintInTopologicalOrder( plc );
1557 handledPLConstraints.insert( plc );
1558 }
1559

Callers

nothing calls this directly

Calls 15

NeuronInformationClass · 0.85
addLayerMethod · 0.80
getLayerMethod · 0.80
setLbMethod · 0.80
setUbMethod · 0.80
variableToNeuronMethod · 0.80
addLayerDependencyMethod · 0.80
NeuronIndexClass · 0.50
existsMethod · 0.45
getTypeMethod · 0.45
getBMethod · 0.45

Tested by

no test coverage detected