| 32 | } |
| 33 | |
| 34 | void DeepPolyReLUElement::execute( const Map<unsigned, DeepPolyElement *> &deepPolyElementsBefore ) |
| 35 | { |
| 36 | log( "Executing..." ); |
| 37 | ASSERT( hasPredecessor() ); |
| 38 | allocateMemory(); |
| 39 | |
| 40 | // Update the symbolic and concrete upper- and lower- bounds |
| 41 | // of each neuron |
| 42 | for ( unsigned i = 0; i < _size; ++i ) |
| 43 | { |
| 44 | NeuronIndex sourceIndex = *( _layer->getActivationSources( i ).begin() ); |
| 45 | DeepPolyElement *predecessor = deepPolyElementsBefore[sourceIndex._layer]; |
| 46 | double sourceLb = predecessor->getLowerBound( sourceIndex._neuron ); |
| 47 | double sourceUb = predecessor->getUpperBound( sourceIndex._neuron ); |
| 48 | |
| 49 | if ( !FloatUtils::isNegative( sourceLb ) ) |
| 50 | { |
| 51 | // Phase active |
| 52 | // Symbolic bound: x_b <= x_f <= x_b |
| 53 | // Concrete bound: lb_b <= x_f <= ub_b |
| 54 | _symbolicUb[i] = 1; |
| 55 | _symbolicUpperBias[i] = 0; |
| 56 | _ub[i] = sourceUb; |
| 57 | |
| 58 | _symbolicLb[i] = 1; |
| 59 | _symbolicLowerBias[i] = 0; |
| 60 | _lb[i] = sourceLb; |
| 61 | } |
| 62 | else if ( !FloatUtils::isPositive( sourceUb ) ) |
| 63 | { |
| 64 | // Phase inactive |
| 65 | // Symbolic bound: 0 <= x_f <= 0 |
| 66 | // Concrete bound: 0 <= x_f <= 0 |
| 67 | _symbolicUb[i] = 0; |
| 68 | _symbolicUpperBias[i] = 0; |
| 69 | _ub[i] = 0; |
| 70 | |
| 71 | _symbolicLb[i] = 0; |
| 72 | _symbolicLowerBias[i] = 0; |
| 73 | _lb[i] = 0; |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | // ReLU not fixed |
| 78 | // Symbolic upper bound: x_f <= (x_b - l) * u / ( u - l) |
| 79 | // Concrete upper bound: x_f <= ub_b |
| 80 | double coeff = sourceUb / ( sourceUb - sourceLb ); |
| 81 | _symbolicUb[i] = coeff; |
| 82 | _symbolicUpperBias[i] = -sourceLb * coeff; |
| 83 | _ub[i] = sourceUb; |
| 84 | |
| 85 | // For the lower bound, in general, x_f >= lambda * x_b, where |
| 86 | // 0 <= lambda <= 1, would be a sound lower bound. We |
| 87 | // use the heuristic described in section 4.1 of |
| 88 | // https://files.sri.inf.ethz.ch/website/papers/DeepPoly.pdf |
| 89 | // to set the value of lambda (either 0 or 1 is considered). |
| 90 | if ( sourceUb > -sourceLb ) |
| 91 | { |
no test coverage detected