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

Method constructSigmoidLayer

src/engine/InputQuery.cpp:1305–1401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1303}
1304
1305bool InputQuery::constructSigmoidLayer( NLR::NetworkLevelReasoner *nlr,
1306 Map<unsigned, unsigned> &handledVariableToLayer,
1307 unsigned newLayerIndex,
1308 Set<NonlinearConstraint *> &handledNLConstraints )
1309{
1310 INPUT_QUERY_LOG( "Attempting to construct SigmoidLayer..." );
1311 struct NeuronInformation
1312 {
1313 public:
1314 NeuronInformation( unsigned variable, unsigned neuron, unsigned sourceVariable )
1315 : _variable( variable )
1316 , _neuron( neuron )
1317 , _sourceVariable( sourceVariable )
1318 {
1319 }
1320
1321 unsigned _variable;
1322 unsigned _neuron;
1323 unsigned _sourceVariable;
1324 };
1325
1326 List<NeuronInformation> newNeurons;
1327
1328 // Look for Sigmoids where all b variables have already been handled
1329 const List<NonlinearConstraint *> &nlConstraints = getNonlinearConstraints();
1330
1331 unsigned currentSourceLayer = 0;
1332 for ( const auto &nlc : nlConstraints )
1333 {
1334 if ( handledNLConstraints.exists( nlc ) )
1335 continue;
1336
1337 // Only consider Sigmoids
1338 if ( nlc->getType() != SIGMOID )
1339 continue;
1340
1341 const SigmoidConstraint *sigmoid = (const SigmoidConstraint *)nlc;
1342
1343 // Has the b variable been handled?
1344 unsigned b = sigmoid->getB();
1345 if ( !handledVariableToLayer.exists( b ) ||
1346 ( _ensureSameSourceLayerInNLR && !newNeurons.empty() &&
1347 handledVariableToLayer[b] != currentSourceLayer ) )
1348 continue;
1349
1350 // If the f variable has also been handled, ignore this constraint
1351 unsigned f = sigmoid->getF();
1352 if ( handledVariableToLayer.exists( f ) )
1353 continue;
1354
1355 // B has been handled, f hasn't. Add f
1356 if ( _ensureSameSourceLayerInNLR && newNeurons.empty() )
1357 currentSourceLayer = handledVariableToLayer[b];
1358 newNeurons.append( NeuronInformation( f, newNeurons.size(), b ) );
1359
1360 handledNLConstraints.insert( nlc );
1361 }
1362

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
emptyMethod · 0.45

Tested by

no test coverage detected