def train_layer0(sg, generalizers, save_predictions = True): layer0_partition_guess = numpy.array([generalizer.guess_partial(sg) for generalizer in generalizers]) for generalizer_index, generalizer in enumerate(generalizers): if save_predictions: Generalizer.save_partial(generalizer.name(), layer0_partition_guess[generalizer_index]) print("log loss for {} : {}".format( generalizer.name(), log_loss(sg.train_target, layer0_partition_guess[generalizer_index, :, :]) )) layer0_whole_guess = numpy.array([generalizer.guess_whole(sg) for generalizer in generalizers]) for generalizer_index, generalizer in enumerate(generalizers): if save_predictions: Generalizer.save_whole(generalizer.name(), layer0_whole_guess[generalizer_index]) return(layer0_partition_guess, layer0_whole_guess)
def train_layer0(sg, generalizers, save_predictions=True): layer0_partition_guess = numpy.array( [generalizer.guess_partial(sg) for generalizer in generalizers]) for generalizer_index, generalizer in enumerate(generalizers): if save_predictions: Generalizer.save_partial(generalizer.name(), layer0_partition_guess[generalizer_index]) print("log loss for {} : {}".format( generalizer.name(), log_loss(sg.train_target, layer0_partition_guess[generalizer_index, :, :]))) layer0_whole_guess = numpy.array( [generalizer.guess_whole(sg) for generalizer in generalizers]) for generalizer_index, generalizer in enumerate(generalizers): if save_predictions: Generalizer.save_whole(generalizer.name(), layer0_whole_guess[generalizer_index]) return (layer0_partition_guess, layer0_whole_guess)
def test_wp_generalize(tr): x = Int('x') y = Int('y') z = Int('z') c_1 = ConditionStmt(x + y >= 8) c_1_1 = ConditionStmt(x - y >= 8) a_1 = AssignmentStmt(z == x + y) a_1_1 = AssignmentStmt(z == x - y) c_2 = ConditionStmt(x <= y) c_3 = ConditionStmt(z >= 9) a_2 = AssignmentStmt(z == z - 1) c_4 = ConditionStmt(z <= 8) multitrace = BackwardTrace([[c_1, c_1_1], [a_1, a_1_1], [c_2], [c_3], [a_2], [c_4]]) wp_gen_no_simpl = Generalizer(PreciseDomain(False)) wp_gen_with_simpl = Generalizer(PreciseDomain(True)) r = wp_gen_no_simpl.generalize_input(tr, print_annotation=True) print("Final result generalize input from top no simplification: ", r, "\n") simplify(r) print("Final result generalize input from top simplify once at end: ", r, "\n") r = wp_gen_with_simpl.generalize_input(tr, print_annotation=True) print("Final result generalize input from top simplify after each step: ", r, "\n") r = wp_gen_no_simpl.generalize_trace(multitrace, print_annotation=True) print("Final result generalize trace from top no simplification: ", r, "\n") r = wp_gen_with_simpl.generalize_trace(multitrace, print_annotation=True) print("Final result generalize trace from top simplify after each step: ", r, "\n") r = wp_gen_no_simpl.generalize_trace( multitrace, initial_formula=PreciseDomain().get_bottom(), print_annotation=True) print("Final result generalize trace from bottom no simplification: ", r, "\n")
def load_layer0(filenames): layer0_partial_guess = numpy.array([Generalizer.load_partial(filename) for filename in filenames]) layer0_whole_guess = numpy.array([Generalizer.load_whole(filename) for filename in filenames]) return(layer0_partial_guess, layer0_whole_guess)
def load_layer0(filenames): layer0_partial_guess = numpy.array( [Generalizer.load_partial(filename) for filename in filenames]) layer0_whole_guess = numpy.array( [Generalizer.load_whole(filename) for filename in filenames]) return (layer0_partial_guess, layer0_whole_guess)
I_4 = IntervalSet({"x": i_1, "y": i_2, "z": i_4}) I_5 = IntervalSet.get_top() I_6 = IntervalSet.get_bottom() I_7 = IntervalSet({"x": i_10, "y": i_7, "z": i_5}) I_8 = IntervalSet({"x": i_1, "y": i_2, "z": i_8, "w": i_9, "t": i_10}) f_1 = Or(x == 0, y == 1) f_2 = Not(And(x > 0, x < 3)) f_3 = Or(Not(x < 0), And(Not(y > 7), y < 4)) f_4 = Not(Or(Not(x < 0), And(Not(y > 7), y < 4))) f_5 = Implies(x > 0, y < 0) f_6 = If(x > 0, y < 0, y > 0) f_7 = Implies(And(Not(If(x > 0, y < 0, y > 0)), Or(z <= 7, x <= 8)), y == 2) interval_domain = IntervalDomain() interval_generalizer = Generalizer(interval_domain, debug=True) wp_domain = PreciseDomain() wp_generalizer = Generalizer(wp_domain, debug=True) def test_interval(): assert not i_1.is_bottom() assert not i_2.is_bottom() assert not i_3.is_bottom() assert not i_4.is_bottom() assert not i_5.is_bottom() assert i_6.is_bottom() assert i_7.is_bottom() assert not i_1.is_top() assert not i_2.is_top() assert i_3.is_top()
def test_generalization_with_interval(): interval_domain = IntervalDomain(True) model = get_model_from_SSA_trace(tr_TFT) g = Generalizer(interval_domain, True) g.generalize_trace(mt_TFT, model=model, print_annotation=True)