| 1303 | } |
| 1304 | |
| 1305 | bool 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 |
nothing calls this directly
no test coverage detected