Skip to content

Instantly share code, notes, and snippets.

dim_input=2 #dim of input, without the intercept
dim_output=1
# Normal noise
d = Normal()
# True parameters
beta = rand(d, dim_input + 1);
# Noise
e = rand(d, n_points);
# Input data:
X = rand(d, (n_points,dim_input));
@JulienPascal
JulienPascal / OLS_ML_4.jl
Created February 28, 2022 14:11
OLS_ML_4
plot(beta_1_grid, beta_2_grid, (x,y) -> obj_function(X, y, [beta[1]; x; y]), st=:contour, colorbar_title=L"|X-y\hat{\beta}|^2")
scatter!([beta[2]], [beta[3]], markershape = :star5)
xlabel!(L"\beta_1")
ylabel!(L"\beta_2")
# refinement loop
beta_hat_sgd = [beta[1]; -9.0; 9.0] #fix the intercept at the true value. Random guess for beta_1 and beta_2
beta_hat = [beta[1]; -9.0; 9.0]
grad_n_sgd = zeros(3) #initialize gradient
grad_n = zeros(3) #initialize gradient