Skip to content

Commit

Permalink
no more cbrt, no more abs2
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Nov 25, 2022
1 parent 0892dbb commit e4c306b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ Flux is an elegant approach to machine learning. It's a 100% pure-Julia stack, a
Works best with [Julia 1.8](https://julialang.org/downloads/) or later. Here's a very short example to try it out:
```julia
using Flux, Plots
data = [([x], x-cbrt(x)) for x in range(-2, 2, 100)]
data = [([x], 2x-x^3) for x in -2:0.1f0:2]

model = Chain(Dense(1 => 10, tanh), Dense(10 => 1), only)
model = Chain(Dense(1 => 23, tanh), Dense(23 => 1, bias=false), only)

loss(x,y) = abs2(model(x) - y)
loss(x,y) = (model(x) - y)^2
optim = Flux.Adam()
for epoch in 1:1000
Flux.train!(loss, Flux.params(model), data, optim)
end

plot(x -> x-cbrt(x), -2, 2, legend=false)
plot(x -> 2x-x^3, -2, 2, legend=false)
scatter!(-2:0.1:2, [model([x]) for x in -2:0.1:2])
```

Expand Down

0 comments on commit e4c306b

Please sign in to comment.