In [2]:
using Plots
ENV["MPLBACKEND"] = "Agg"
pyplot()
n = 50
cs = Plots.unzip(Plots.partialcircle(0.5π, 11π/6, 3, 10));
In [3]:
xs = 3randn(n,3)
ys = 3randn(n,3)
for i in 1:3
xs[:,i] += cs[1][i]
ys[:,i] += cs[2][i]
end
In [8]:
colors = [:green,:darkred,:purple]
scatter(xs, ys, grid=false, m=(colors',15,0.7), markerstrokecolor=colors')
Out[8]:
In [34]:
using OnlineAI
net = buildTanhClassificationNet(
2, 1, [5,5,5],
params = NetParams(gradientModel = AdaMaxModel(η=1e-4, ρ1=0.9, ρ2=0.9)),
solverParams = SolverParams(maxiter=1000000,erroriter=500000)
);
In [35]:
dps = DataPoints(hcat(reshape(xs,3n,1),reshape(ys,3n,1)), vcat(-ones(n), zeros(n), ones(n)))
sampler = SimpleSampler(dps)
solve!(net, sampler, sampler)
Out[35]:
In [36]:
x = linspace(-20, 20, 1000)
cmap = ColorGradient(colors, alpha=0.3)
function surf(x,y)
z = predict(net, Float64[x,y])[1]
if z < -0.3
-1.0
elseif z > 0.3
1.0
else
0.0
end
end
# use contours to show the predictions from the neural net
p = plot(x, x, surf, w=2, fill=true, c=cmap, leg=false, grid=false, nlevels=3, size=(400,400))
scatter!(xs, ys, grid=false, m=(colors',15,0.7), markerstrokecolor=colors')
Out[36]:
In [ ]: