Ejemplo n.º 1
0
import lad as lad
import random_dataset_utils as rdu
import plot_utils as pu

n_runs = 10000
n_samples = 500
p_outliers = 0.10

## Let's define some true values for the w vector, which
## later we will try to estimate from the noisy data.
## Note that w_true is a vertical vector

w_true = np.array([[1], \
                   [2]])

(X, Y_true) = rdu.generate_linear_relation_dataset(w_true, n_samples)

w_hat_list = [
]  ## This is where we are going to store all the estimated w_hat's
w_hat_outliers_list = []  ## and this is for the case of outliers
runs_so_far = 0
while (runs_so_far < n_runs):

    ## Add gaussian noise to all points
    Y = rdu.add_gaussian_noise(Y_true, 0, 1, 1)
    ## Add 1% of outliers (gaussian noise with much higher variance!)
    Y_outliers = rdu.add_gaussian_noise(Y, 0, 5, p_outliers)
    w_hat = lad.solve_lad_soft(X, Y, 1000)  ## w_hat is a vertical vector
    w_hat_list.append(w_hat)
    w_hat_outliers = lad.solve_lad_soft(X, Y_outliers,
                                        1000)  ## w_hat is a vertical vector
Ejemplo n.º 2
0
import numpy as np
import sys

sys.path.append('../utils')
import lad as lad
import random_dataset_utils as rdu

n_x_dimensions = 1
n_y_dimensions = 1
n_runs_left = 10000
n_samples = 500

## Let's define some true values for the w vector, which
## later we will try to estimate from the noisy data.
linear_weigths = np.array([[1], [2]])

(X, Y) = rdu.generate_linear_relation_dataset(linear_weigths, n_samples)

## Add a moderate amount of gaussion noise to all points
Y = rdu.add_gaussian_noise(Y, 0, 1, 1)

w_hat = lad.solve_lad_soft(X, Y, 1000000)

print w_hat