def test_mapping_precise(self): m = self.ensemble.approximate() m.outputs[0].lower = 0 m.outputs[0].upper = 0 m.outputs[1].lower = 1 m.outputs[1].upper = 1 m.outputs[2].lower = 2 m.outputs[2].upper = 2 for dim in range(3): self.assertTrue(vote.mapping_precise(m)) m.outputs[dim].upper += 1 self.assertFalse(vote.mapping_precise(m)) m.outputs[dim].lower += 1
def add_outputs(self, m): self.outputs.add((m.outputs[0].lower, m.outputs[0].upper)) if vote.mapping_precise(m): return vote.PASS else: return vote.UNSURE
def increment_counter_to_3(self, m): self.assertTrue(vote.mapping_precise(m)) self.count += 1 if self.count < 3: return vote.PASS else: return vote.FAIL
def mapping_cb(self, m): x = [m.inputs[dim] for dim in range(m.nb_inputs)] y = [m.outputs[dim] for dim in range(m.nb_outputs)] if vote.mapping_precise(m): testcase_cb(self, x, y) return vote.PASS else: return vote.UNSURE
def is_valid_probability(mapping): minval = min( [mapping.outputs[dim].lower for dim in range(mapping.nb_outputs)]) maxval = max( [mapping.outputs[dim].upper for dim in range(mapping.nb_outputs)]) if minval >= 0 and maxval <= 1: return vote.PASS elif vote.mapping_precise(mapping): return vote.FAIL else: return vote.UNSURE
def check_mapping(oracle_fn, itype, otype, m, epsilon=0): center = [ m.inputs[dim].lower + (m.inputs[dim].upper - m.inputs[dim].lower) / 2 for dim in range(m.nb_inputs) ] lo = np.array([ itype(m.inputs[dim].lower) if itype(m.inputs[dim].lower) >= m.inputs[dim].lower else np.nextafter( m.inputs[dim].lower, np.inf, dtype=itype) for dim in range(m.nb_inputs) ]) hi = np.array([ itype(m.inputs[dim].upper) if itype(m.inputs[dim].upper) <= m.inputs[dim].upper else np.nextafter( m.inputs[dim].upper, -np.inf, dtype=itype) for dim in range(m.nb_inputs) ]) X = np.array([lo + epsilon, center, hi - epsilon], dtype=itype) Y = oracle_fn(X) lo = [ otype(m.outputs[dim].lower) if otype(m.outputs[dim].lower) >= m.outputs[dim].lower else np.nextafter(m.outputs[dim].lower, np.inf, dtype=otype) for dim in range(m.nb_outputs) ] hi = [ otype(m.outputs[dim].upper) if otype(m.outputs[dim].upper) <= m.outputs[dim].upper else np.nextafter(m.outputs[dim].upper, -np.inf, dtype=otype) for dim in range(m.nb_outputs) ] for xvec, yvec in zip(X, Y): for dim in range(m.nb_outputs): if lo[dim] > yvec[dim] + epsilon: return vote.FAIL if hi[dim] < yvec[dim] - epsilon: return vote.FAIL if vote.mapping_precise(m): return vote.PASS else: return vote.UNSURE
def increment_counter(self, m): self.assertTrue(vote.mapping_precise(m)) self.count += 1 return vote.PASS