Пример #1
0
    def evaluate(A, C):
        # accelerator results
        acc = A.predict(X)
        # classification by C and truly
        cls_c = [1 if v[1] > v[0] else 0 for v in C.predict(X)]
        cls_t = [accept(Y[i], acc[i]) for i in range(N)]  # to bool
        # relatvie error for all test data
        if eb_type == 1:
            re = [error.relative_error(Y[i], acc[i]) for i in range(N)]
            re_c = [
                error.relative_error(Y[i], acc[i]) for i in range(N)
                if cls_c[i]
            ]
        else:
            re = [error.absolute_error(Y[i], acc[i]) for i in range(N)]
            re_c = [
                error.absolute_error(Y[i], acc[i]) for i in range(N)
                if cls_c[i]
            ]

        # accuracy of C, recall of C
        accuracy_of_C = sum(
            [1.0 if cls_t[i] == cls_c[i] else 0
             for i in range(N)]) / float(1e-10 + N)
        recall_of_C = sum([
            1.0 if cls_t[i] and cls_c[i] else 0 for i in range(N)
        ]) / float(1e-10 + sum([1 if v else 0 for v in cls_t]))

        # invocation of C, invocation truly
        invocation_of_C = float(sum([1 if v else 0
                                     for v in cls_c])) / float(1e-10 + N)
        invocation_truly = float(sum([1 if v else 0
                                      for v in cls_t])) / float(1e-10 + N)

        # re of A, re of A with C
        mean_relative_error_of_A = sum(re) / float(1e-10 + len(re))
        mean_relative_error_of_A_with_C = sum(re_c) / (1e-10 + len(re_c))

        mean_relative_error_overall = sum(re_c) / float(1e-10 + N)

        return {
            'accuracy_of_C': accuracy_of_C,
            'recall_of_C': recall_of_C,
            'invocation_of_C': invocation_of_C,
            'invocation_truly': invocation_truly,
            'mean_relative_error_of_A': mean_relative_error_of_A,
            'mean_relative_error_of_A_with_C': mean_relative_error_of_A_with_C,
            'mean_relative_error_overall': mean_relative_error_overall
        }
Пример #2
0
import error as e
import application_potential as ap

xs = [x for x, y in ap.pde_data]
ys = [y for x, y in ap.pde_data]


def analytical_function(y):
    return 18*y-8


analytical = [analytical_function(y) for x, y in ap.pde_data]
print('Valor de y: ', list(y for [x, y] in ap.pde_data))

collocation_error = e.absolute_error(analytical, ap.answer)
print('Analitico:', analytical)
print('Aproximado: ', ap.answer)
print('Erro: ', collocation_error)
print(max(collocation_error))
Пример #3
0
 def accept(v0, v1):
     return error.relative_error(
         v0, v1) <= re_bound if eb_type == 1 else error.absolute_error(
             v0, v1) <= re_bound
Пример #4
0
import error as e
import application_elasticity as ae

displacement_y = []
for i in range(len(ae.answer)):
    if (i % 2) != 0 and i != 0:
        displacement_y.append(ae.answer[i])

xs = [x for x, y in ae.pde_data]
ys = [y for x, y in ae.pde_data]


def analytical_function(y):
    return -y / 4


analytical = [analytical_function(y) for x, y in ae.pde_data]
print('Valor de y: ', list(y for [x, y] in ae.pde_data))

collocation_error = e.absolute_error(analytical, displacement_y)
print('Analitico:', analytical)
print('Aproximado: ', displacement_y)
print(collocation_error)
print(max(collocation_error))