Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Godoy, William
jexio
Commits
2208738b
Commit
2208738b
authored
Sep 11, 2020
by
William F Godoy
Browse files
Adding Flux capability
parent
3a66012a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/helper/helperFlux.jl
0 → 100644
View file @
2208738b
import
Flux
import
Statistics
using
Plots
;
pyplot
();
using
LaTeXStrings
function
FluxTrain
(
nepocs
::
Int32
,
X
::
Array
{
Float64
,
1
},
Y
::
Array
{
Float64
,
1
})
W
=
[
500.0
]
b
=
[
10000.0
]
model
=
Flux
.
Dense
(
W
,
b
)
parameters
=
Flux
.
params
(
model
)
println
(
"Initial parameter: "
,
parameters
)
# set up data
Xd
=
reduce
(
hcat
,
X
)
Yd
=
reduce
(
hcat
,
Y
)
data
=
[(
Xd
,
Yd
)]
println
(
"Data"
,
data
)
# optimizer = Flux.Descent(1)
# optimizer = Flux.ADAM()
optimizer
=
Flux
.
ADAM
(
1
,
(
0.99
,
0.999
))
loss
(
x
,
y
)
=
Statistics
.
mean
((
model
(
x
)
.-
y
)
.^
2
)
Yd_0
=
model
(
Xd
)
println
(
"Initial solution: "
,
Yd_0
)
plot
(
X
,
Y
,
st
=
:
scatter
,
label
=
L"y"
)
Yd_nE
=
model
(
Xd
)
for
iter
=
1
:
nepocs
Flux
.
train!
(
loss
,
parameters
,
data
,
optimizer
)
end
println
(
"Module: "
,
model
)
println
(
"Parameters_nE: "
,
parameters
)
println
(
"Final solution: "
,
Yd_nE
)
Yd_nE
=
model
(
Xd
)
plot!
(
Xd
'
,
Yd_0
'
,
lc
=
:
green
,
label
=
L"y_0"
)
plot!
(
Xd
'
,
Yd_nE
'
,
lc
=
:
red
,
label
=
L"y_{n_\mathrm{E}}"
)
plot!
(
xlabel
=
L"x"
,
ylabel
=
L"y"
,
title
=
"Data for linear model"
)
gui
()
end
function
test
()
x
::
Array
{
Float64
,
1
}
=
[
256
,
4096
,
512
,
512
,
8192
]
y
::
Array
{
Float64
,
1
}
=
[
435867
,
2959963
,
1475489
,
1485569
,
4518030
]
nepocs
::
Int32
=
100000
FluxTrain
(
nepocs
,
x
,
y
)
end
test
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment