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

Method constructMaxLayer

src/engine/InputQuery.cpp:1600–1716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1598}
1599
1600bool InputQuery::constructMaxLayer( NLR::NetworkLevelReasoner *nlr,
1601 Map<unsigned, unsigned> &handledVariableToLayer,
1602 unsigned newLayerIndex,
1603 Set<PiecewiseLinearConstraint *> &handledPLConstraints )
1604{
1605 INPUT_QUERY_LOG( "Attempting to construct MaxLayer..." );
1606 struct NeuronInformation
1607 {
1608 public:
1609 NeuronInformation( unsigned variable,
1610 unsigned neuron,
1611 const List<unsigned> &sourceVariables )
1612 : _variable( variable )
1613 , _neuron( neuron )
1614 , _sourceVariables( sourceVariables )
1615 {
1616 }
1617
1618 unsigned _variable;
1619 unsigned _neuron;
1620 List<unsigned> _sourceVariables;
1621 };
1622
1623 List<NeuronInformation> newNeurons;
1624
1625 // Look for Maxes where all the element variables have already been handled
1626 const List<PiecewiseLinearConstraint *> &plConstraints = getPiecewiseLinearConstraints();
1627
1628 unsigned currentSourceLayer = 0;
1629 for ( const auto &plc : plConstraints )
1630 {
1631 if ( handledPLConstraints.exists( plc ) )
1632 continue;
1633
1634 // Only consider Max
1635 if ( plc->getType() != MAX )
1636 continue;
1637
1638 const MaxConstraint *max = (const MaxConstraint *)plc;
1639
1640 // Have all elements been handled?
1641 // Have all input variables been handled?
1642 bool missingInput = false;
1643 bool sourceLayerDiffers = false;
1644 for ( const auto &input : max->getElements() )
1645 {
1646 if ( !handledVariableToLayer.exists( input ) )
1647 {
1648 missingInput = true;
1649 break;
1650 }
1651 else if ( _ensureSameSourceLayerInNLR && newNeurons.size() &&
1652 handledVariableToLayer[input] != currentSourceLayer )
1653 {
1654 sourceLayerDiffers = true;
1655 break;
1656 }
1657 }

Callers

nothing calls this directly

Calls 15

NeuronInformationClass · 0.85
getElementsMethod · 0.80
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

Tested by

no test coverage detected