| 1098 | } |
| 1099 | |
| 1100 | bool 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 |
nothing calls this directly
no test coverage detected