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

Method constructLeakyReluLayer

src/engine/InputQuery.cpp:1100–1206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1098}
1099
1100bool InputQuery::constructLeakyReluLayer( NLR::NetworkLevelReasoner *nlr,
1101 Map<unsigned, unsigned> &handledVariableToLayer,
1102 unsigned newLayerIndex,
1103 Set<PiecewiseLinearConstraint *> &handledPLConstraints )
1104{
1105 INPUT_QUERY_LOG( "Attempting to construct LeakyReLULayer..." );
1106 struct NeuronInformation
1107 {
1108 public:
1109 NeuronInformation( unsigned variable, unsigned neuron, unsigned sourceVariable )
1110 : _variable( variable )
1111 , _neuron( neuron )
1112 , _sourceVariable( sourceVariable )
1113 {
1114 }
1115
1116 unsigned _variable;
1117 unsigned _neuron;
1118 unsigned _sourceVariable;
1119 };
1120
1121 List<NeuronInformation> newNeurons;
1122
1123 // Look for LeakyReLUs where all b variables have already been handled
1124 const List<PiecewiseLinearConstraint *> &plConstraints = getPiecewiseLinearConstraints();
1125
1126 unsigned currentSourceLayer = 0;
1127 double alpha = -1;
1128 for ( const auto &plc : plConstraints )
1129 {
1130 if ( handledPLConstraints.exists( plc ) )
1131 continue;
1132
1133 // Only consider Leaky ReLUs
1134 if ( plc->getType() != LEAKY_RELU )
1135 continue;
1136
1137 const LeakyReluConstraint *leakyRelu = (const LeakyReluConstraint *)plc;
1138
1139 // Has the b variable been handled?
1140 unsigned b = leakyRelu->getB();
1141 if ( !handledVariableToLayer.exists( b ) ||
1142 ( _ensureSameSourceLayerInNLR && !newNeurons.empty() &&
1143 handledVariableToLayer[b] != currentSourceLayer ) )
1144 continue;
1145
1146 // Is the slope uniform?
1147 double alphaTemp = leakyRelu->getSlope();
1148 if ( alpha != -1 && alpha != alphaTemp )
1149 {
1150 continue;
1151 }
1152
1153 // If the f variable has also been handled, ignore this constraint
1154 unsigned f = leakyRelu->getF();
1155 if ( handledVariableToLayer.exists( f ) )
1156 continue;
1157 // B has been handled, f hasn't. Add f

Callers

nothing calls this directly

Calls 15

NeuronInformationClass · 0.85
getSlopeMethod · 0.80
addLayerMethod · 0.80
getLayerMethod · 0.80
setAlphaMethod · 0.80
setLbMethod · 0.80
setUbMethod · 0.80
variableToNeuronMethod · 0.80
addLayerDependencyMethod · 0.80
NeuronIndexClass · 0.50
existsMethod · 0.45

Tested by

no test coverage detected