Skip to content
Snippets Groups Projects
Commit 074d2f8b authored by J. Gergaud's avatar J. Gergaud
Browse files

foo

parent 1a1b8fe9
Branches
Tags
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Neural Network # Neural Network
Complete the descent with constant rate function Complete the descent with constant rate function
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
function my_descent(f,x0::Vector{<:Real};η=0.1,AbsTol= abs(eps()), RelTol = abs(eps()), ε=0.01, nbit_max = 0)# to complete function my_descent(f,x0::Vector{<:Real};η=0.1,AbsTol= abs(eps()), RelTol = abs(eps()), ε=0.01, nbit_max = 0)# to complete
return xₖ, flag, fₖ, ∇fₖ, k c return xₖ, flag, fₖ, ∇fₖ, k c
end end
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
And apply this code for solving the following problem And apply this code for solving the following problem
$$(P)\left\{\begin{array}{l} $$(P)\left\{\begin{array}{l}
Min\;f(\beta) = \frac{1}{n}\|X\beta - y\|^2\\ Min\;f(\beta) = \frac{1}{n}\|X\beta - y\|^2\\
\beta\in\R^2 \beta\in\R^2
\end{array}\right. \end{array}\right.
$$ $$
with with
$$X = \begin{pmatrix} $$X = \begin{pmatrix}
1 & x_1\\ 1 & x_1\\
\vdots & \vdots\\ \vdots & \vdots\\
1 & x_5 1 & x_5
\end{pmatrix} \end{pmatrix}
\;\;\textrm{and}\;\; \;\;\textrm{and}\;\;
y = \begin{pmatrix} y = \begin{pmatrix}
y_1\\ y_1\\
\vdots\\ \vdots\\
y_5 y_5
\end{pmatrix} \end{pmatrix}
$$ $$
You 'll print the first 7 iterations for the initual guess You 'll print the first 7 iterations for the initual guess
$x0= (n/2)(9,1)$. $x0= (n/2)(9,1)$.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
using Plots using Plots
# n = 5 # n = 5
x1 = 1.; x2 = sqrt(5*9/2-x1^2); x1 = 1.; x2 = sqrt(5*9/2-x1^2);
x = [-x2,-x1,0.,x1,x2] x = [-x2,-x1,0.,x1,x2]
n = length(x) n = length(x)
a₁ = 1; a₀ = 2 a₁ = 1; a₀ = 2
y = a₁*x .+ a₀ # model y = a₁*x .+ a₀ # model
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## ##
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
function descent_backtrac(f,x0::Vector{<:Real};AbsTol= abs(eps()), RelTol = abs(eps()), ε=0.01, nbit_max = 0)
# to complete
return xₖ, flag, fₖ, ∇fₖ, k c
end
```
%% Cell type:code id: tags:
```
using Plots using Plots
x = range(-10*(n/2)-xsol[1],stop=10*(n/2)-xsol[1],length=100) x = range(-10*(n/2)-xsol[1],stop=10*(n/2)-xsol[1],length=100)
y = range(-9*(n/2)-xsol[2],stop=9*(n/2)-xsol[2],length=100) y = range(-9*(n/2)-xsol[2],stop=9*(n/2)-xsol[2],length=100)
f_contour(x,y) = f([x,y]) f_contour(x,y) = f([x,y])
z = @. f_contour(x', y) z = @. f_contour(x', y)
nb_levels = 7 nb_levels = 7
x0 = (n/2)*[9,1] x0 = (n/2)*[9,1]
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment