Exemplo n.º 1
0
def test_eval_feature():
    print('III. Test evaluate example with given feature')
    print('==================\n')
    print('*******Feature: ')
    f = LL.PlTerm([
        'my_op([1],[1],[1,0])', 'my_op([0],[0],[0])', 'my_op([1],[0],[1])',
        'my_op([0],[1],[1])'
    ])
    print(f)
    print('*******Examples: ')
    ex1 = LL.PlTerm([1, 1, '+', 1, 1, '=', 1, 1])
    ex2 = LL.PlTerm([1, 1, '+', 1, 1, '=', 1, 1, 0])
    ex3 = LL.PlTerm(['A', 'A', 'B', 'A', 'A', 'C', 'A', 'A', 'D'])
    re1 = LL.evalInstFeature(ex1, f)
    re2 = LL.evalInstFeature(ex2, f)
    re3 = LL.evalInstFeature(ex3, f)
    print('****example 1 & result: ')
    print(ex1)
    print(re1)
    print('****example 2 & result: ')
    print(ex2)
    print(re2)
    print('****example 3 & result: ')
    print(ex3)
    print(re3)
    print('----------END------------\n')
Exemplo n.º 2
0
def get_mlp_vector(equation, model, rules, abduced_map, shape=(28, 28, 1)):
    h = shape[0]
    w = shape[1]
    d = shape[2]
    model_output = np.argmax(model.predict(equation.reshape(-1, h, w, d)), axis=1)
    model_labels = []
    for out in model_output:
        model_labels.append(abduced_map[out])
    #print(model_labels)
    vector = []
    for rule in rules:
        ex = LL.PlTerm(model_labels)
        f = LL.PlTerm(rule)
        if LL.evalInstFeature(ex, f):
            vector.append(1)
        else:
            vector.append(0)
    return vector
Exemplo n.º 3
0
	def eval(self, ex):
		# apply mapping
		ex_symbs_n = apply_mapping(ex, self.mapping)
		(ex_symbs, n_pos) = remove_nulls(ex_symbs_n)
		ex_term = LL.PlTerm(ex_symbs)  # LL term
		return LL.evalInstFeature(ex_term, LL.PlTerm(self.rules))