This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer