def output_func(x):
        return 1 / 5 * x**2

    def complex_noise(x):
        return npr.normal(0, 1, len(x)) * np.abs(np.abs(x + 2) - 2) / 1.5

    def complex_noise2(x):
        return npr.normal(0, 1, len(x)) * 1 / (np.maximum(np.abs(x), 0.3))

    def complex_noise3(x):
        return npr.normal(0, 1, len(x)) * (np.sin((x - 5)) * 0.8)

    n = 500
    trX, trY, teX, teY = generate_data_function(output_func,
                                                complex_noise3,
                                                n,
                                                rate=0.1,
                                                loc=[-3, -2],
                                                yloc=[50, 30])

    x, y = torch.Tensor(trX), torch.Tensor(trY)
    gaussian = Gaussian()
    laplace = Laplace()
    adaptive = Adaptive()

    # # 2-D linear regression
    lr2 = PolyRegression(2)
    fit2 = train_regular(lr2,
                         x,
                         y,
                         gaussian,
                         epoch=1000,
Exemplo n.º 2
0
    noise = [
        indep_noise, linear_noise, exp_noise, unimodal_noise, bimodal_noise,
        trimodal_noise
    ]
    noise = [unimodal_noise]

    Y_name = ['Poly', 'Sin']
    output = [polynomial_outcome, sinusoidal_outcome]
    for i in range(len(Y_name)):
        for j in range(len(n_name)):
            dfs = []
            dfs_o = []
            for r in range(5):
                trX, trY, teX, teY = generate_data_function(output[i],
                                                            noise[j],
                                                            n,
                                                            rate=0.1,
                                                            loc=[-2],
                                                            yloc=[10])
                if i == 0:
                    degree = 2
                else:
                    degree = 5
                df = run_experiment(trX, trY, teX, teY, degree)
                df['rep'] = r
                dfs_o.append(df)

                trX, trY, teX, teY = generate_data_function(output[i],
                                                            noise[j],
                                                            n,
                                                            rate=0.0,
                                                            loc=[-2],
Exemplo n.º 3
0
    return pd.DataFrame(stats)


if __name__ == '__main__':
    output_func = polynomial_outcome
    noise_func = indep_noise
    n_name = ['Indep', 'Linear', 'Exp', 'Uni', 'Bi', 'Tri']
    noise = [indep_noise, linear_noise, exp_noise, unimodal_noise, bimodal_noise, trimodal_noise]
    Y_name = ['Poly']
    output = [polynomial_outcome]
    for d in [1,2,3,4,5,6,7,8,9,10]:
        for i in range(len(Y_name)):
            for j in range(len(n_name)):
                df_b = []
                for r in range(5):
                    trX, trY, _, _ = generate_data_function(output[i], noise[j], 1000, rate=0.1, loc=[-2], yloc=[10])
                    teX, teY, _, _ = generate_data_function(output[i], noise[j], 200, rate=0.1, loc=[-2], yloc=[10])

                    df = run_experiment(trX, trY, teX, teY, degree=d)
                    df['rep'] = r
                    df_b.append(df)
                print(Y_name[i] + n_name[j] + 'base' + str(d))
                pd.concat(df_b).to_csv('results/6_4/' + Y_name[i] + n_name[j] + 'base' + str(d) + 'Outlier.csv')

    for d in [1,2,3,4,5,6,7,8,9,10]:
        for i in range(len(Y_name)):
            for j in range(len(n_name)):
                df_n = []
                for r in range(5):
                    trX, trY, _, _ = generate_data_function(output[i], noise[j], 1000, rate=0.1, loc=[-2], yloc=[10])
                    teX, teY, _, _ = generate_data_function(output[i], noise[j], 200, rate=0.1, loc=[-2], yloc=[10])