| 25 | } |
| 26 | |
| 27 | void BerkeleyParser::generateQuery( InputQuery &inputQuery ) |
| 28 | { |
| 29 | _berkeleyNeuralNetwork.parseFile(); |
| 30 | |
| 31 | // The total number of variables required for the encoding is computed as follows: |
| 32 | // 1. One for every variable that's part of the query |
| 33 | |
| 34 | unsigned numberOfVariables = _berkeleyNeuralNetwork.getNumVariables(); |
| 35 | |
| 36 | printf( "Total number of Marabou variables: %u\n", numberOfVariables ); |
| 37 | |
| 38 | inputQuery.setNumberOfVariables( numberOfVariables ); |
| 39 | |
| 40 | // Set bounds for inputs. Currently just [0,1] |
| 41 | Set<unsigned> inputVariables = _berkeleyNeuralNetwork.getInputVariables(); |
| 42 | for ( const auto &it : inputVariables ) |
| 43 | { |
| 44 | double min = 0.0; |
| 45 | double max = 1.0; |
| 46 | |
| 47 | inputQuery.setLowerBound( it, min ); |
| 48 | inputQuery.setUpperBound( it, max ); |
| 49 | } |
| 50 | |
| 51 | // Declare relu pairs and set bounds |
| 52 | Map<unsigned, unsigned> fToB = _berkeleyNeuralNetwork.getFToB(); |
| 53 | for ( const auto &it : fToB ) |
| 54 | { |
| 55 | unsigned f = it.first; |
| 56 | unsigned b = it.second; |
| 57 | |
| 58 | PiecewiseLinearConstraint *relu = new ReluConstraint( b, f ); |
| 59 | inputQuery.addPiecewiseLinearConstraint( relu ); |
| 60 | |
| 61 | inputQuery.setLowerBound( f, 0.0 ); |
| 62 | inputQuery.setUpperBound( f, FloatUtils::infinity() ); |
| 63 | |
| 64 | inputQuery.setLowerBound( b, FloatUtils::negativeInfinity() ); |
| 65 | inputQuery.setUpperBound( b, FloatUtils::infinity() ); |
| 66 | } |
| 67 | |
| 68 | // Create the equations |
| 69 | List<BerkeleyNeuralNetwork::Equation> equations = _berkeleyNeuralNetwork.getEquations(); |
| 70 | for ( const auto &berkeleyEquation : equations ) |
| 71 | { |
| 72 | Equation marabouEquation; |
| 73 | |
| 74 | // The Berkeley equation is of the form y = x1 + x2 + x3 + c. |
| 75 | // The Marabou equation is of the form y - x1 - x2 - x3 = c. |
| 76 | unsigned lhs = berkeleyEquation._lhs; |
| 77 | marabouEquation.addAddend( 1.0, lhs ); |
| 78 | |
| 79 | for ( const auto &rhs : berkeleyEquation._rhs ) |
| 80 | { |
| 81 | unsigned var = rhs._var; |
| 82 | double coefficient = rhs._coefficient; |
| 83 | marabouEquation.addAddend( -coefficient, var ); |
| 84 | } |
nothing calls this directly
no test coverage detected