def error(program: Dag) -> np.array:
    errors = []
    for ndx, (root, filenames) in enumerate(x_train):
        y_true = y_train[ndx]
        n_errors = len(y_true) + 1
        if program is None:
            errors += [penalty] * n_errors
        else:
            try:
                y_pred = program.eval(root=root, filenames=filenames)
            except Exception as e:
                # print(e)
                errors += [penalty] * n_errors
                continue
            # Compare the outputs element-wise and compute absolute errors.
            for ndx, el_pred in enumerate(y_pred[:len(y_true)]):
                el_true = y_true[ndx]
                errors.append(
                    damerau_levenshtein_distance(el_true.path_str,
                                                 el_pred.path_str))
            # If y_pred is shorter than y_true, fill in missing elements with penalties.
            for _ in range(max(0, len(y_true) - len(y_pred))):
                errors.append(penalty)
            # Add the difference in size as an error.
            errors.append(abs(len(y_true) - len(y_pred)))
    return np.array(errors)
Exemplo n.º 2
0
def error(program: Dag) -> np.array:
    errors = []
    for case in x_train:
        y_true = target(case)
        if program is None:
            errors.append(penalty)
        else:
            try:
                y_pred = program.eval(lst=case)
                errors.append(abs(y_true - y_pred))
            except Exception as e:
                # print(e)
                errors.append(penalty)
    return np.array(errors)
Exemplo n.º 3
0
def error(program: Dag) -> np.array:
    errors = []
    for i, dec in x_train:
        if program is None:
            errors.append(penalty)
        else:
            y_true = target(i, dec)
            try:
                y_pred = program.eval(i=i, dec=dec)
                errors.append(abs(y_true - y_pred))
            except Exception as e:
                # print(e)
                errors.append(penalty)
    return np.array(errors)
def error(program: Dag) -> np.array:
    errors = []
    for dt1, dt2, y_true in X_train:
        if program is None:
            errors.append(penalty)
        else:
            try:
                y_pred = program.eval(dt1=dt1, dt2=dt2)
                errors.append(abs(y_pred - y_true))
            except Exception as e:
                # print(e)
                errors.append(penalty)
                continue
    return np.array(errors)
def error(program: Dag) -> np.array:
    errors = []
    for x1, x2 in x_train:
        if program is None:
            errors.append(penalty)
            errors.append(penalty)
        else:
            y_true = target(x1, x2)
            try:
                y_pred = program.eval(x1=float(x1), x2=float(x2))
                errors.append(float(not isinstance(y_pred, float)))
                errors.append(float((y_true - y_pred)**2))
            except Exception as e:
                # print(e)
                errors.append(penalty)
                errors.append(penalty)
    return np.array(errors)
Exemplo n.º 6
0
def error(program: Dag) -> np.array:
    errors = []
    for i in x_train:
        if program is None:
            errors.append(penalty)
            errors.append(penalty)
        else:
            y_true = target(i)
            try:
                y_pred = program.eval(i=i)
                errors.append(float(not isinstance(y_pred, bool)))
                errors.append(float(not (bool(y_pred) == y_true)))
            except Exception as e:
                # print(e)
                errors.append(penalty)
                errors.append(penalty)
    return np.array(errors)
def error(program: Dag) -> np.array:
    errors = []
    for lst, lower, upper, y_true in X_train:
        n_errors = len(y_true) + 1
        if program is None:
            errors += [penalty] * n_errors
        else:
            try:
                y_pred = program.eval(lst=lst, lower=lower, upper=upper)
            except Exception as e:
                # print(e)
                errors += [penalty] * n_errors
                continue
            # Compare the outputs element-wise and compute absolute errors.
            for ndx, el_pred in enumerate(y_pred[:len(y_true)]):
                el_true = y_true[ndx]
                errors.append(int(el_true != el_pred))
            # If y_pred is shorter than y_true, fill in missing elements with penalties.
            for _ in range(max(0, len(y_true) - len(y_pred))):
                errors.append(penalty)
            # Add the difference in size as an error.
            errors.append(abs(len(y_true) - len(y_pred)))
    return np.array(errors)