@@ -27,8 +27,8 @@ function concentric_sphere(dim, inner_radius_range, outer_radius_range,
2727 push!(data, reshape(random_point_in_sphere(dim, outer_radius_range...), :, 1))
2828 push!(labels, -ones(1, 1))
2929 end
30- data = cat(data..., dims = 2)
31- labels = cat(labels..., dims = 2)
30+ data = cat(data...; dims = 2)
31+ labels = cat(labels...; dims = 2)
3232 DataLoader((data |> Flux.gpu, labels |> Flux.gpu); batchsize = batch_size,
3333 shuffle = true,
3434 partial = false)
@@ -41,7 +41,7 @@ function construct_model(out_dim, input_dim, hidden_dim, augment_dim)
4141 node = NeuralODE(Flux.Chain(Flux.Dense(input_dim, hidden_dim, relu),
4242 Flux.Dense(hidden_dim, hidden_dim, relu),
4343 Flux.Dense(hidden_dim, input_dim)) |> Flux.gpu,
44- (0.0f0, 1.0f0), Tsit5(), save_everystep = false,
44+ (0.0f0, 1.0f0), Tsit5(); save_everystep = false,
4545 reltol = 1.0f-3, abstol = 1.0f-3, save_start = false) |> Flux.gpu
4646 node = augment_dim == 0 ? node : AugmentedNDELayer(node, augment_dim)
4747 return Flux.Chain((x, p = node.p) -> node(x, p),
5454function plot_contour(model, npoints = 300)
5555 grid_points = zeros(Float32, 2, npoints^2)
5656 idx = 1
57- x = range(-4.0f0, 4.0f0, length = npoints)
58- y = range(-4.0f0, 4.0f0, length = npoints)
57+ x = range(-4.0f0, 4.0f0; length = npoints)
58+ y = range(-4.0f0, 4.0f0; length = npoints)
5959 for x1 in x, x2 in y
6060 grid_points[:, idx] .= [x1, x2]
6161 idx += 1
6262 end
6363 sol = reshape(model(grid_points |> Flux.gpu), npoints, npoints) |> Flux.cpu
6464
65- return contour(x, y, sol, fill = true, linewidth = 0.0)
65+ return contour(x, y, sol; fill = true, linewidth = 0.0)
6666end
6767
6868loss_node(x, y) = mean((model(x) .- y) .^ 2)
@@ -91,7 +91,7 @@ opt = Adam(0.005)
9191println("Training Neural ODE")
9292
9393for _ in 1:10
94- Flux.train!(loss_node, Flux.params(parameters, model), dataloader, opt, cb = cb)
94+ Flux.train!(loss_node, Flux.params(parameters, model), dataloader, opt; cb = cb)
9595end
9696
9797plt_node = plot_contour(model)
@@ -103,7 +103,7 @@ println()
103103println("Training Augmented Neural ODE")
104104
105105for _ in 1:10
106- Flux.train!(loss_node, Flux.params(parameters, model), dataloader, opt, cb = cb)
106+ Flux.train!(loss_node, Flux.params(parameters, model), dataloader, opt; cb = cb)
107107end
108108
109109plt_anode = plot_contour(model)
@@ -153,8 +153,8 @@ function concentric_sphere(dim, inner_radius_range, outer_radius_range,
153153 push!(data, reshape(random_point_in_sphere(dim, outer_radius_range...), :, 1))
154154 push!(labels, -ones(1, 1))
155155 end
156- data = cat(data..., dims = 2)
157- labels = cat(labels..., dims = 2)
156+ data = cat(data...; dims = 2)
157+ labels = cat(labels...; dims = 2)
158158 return DataLoader((data |> Flux.gpu, labels |> Flux.gpu); batchsize = batch_size,
159159 shuffle = true,
160160 partial = false)
@@ -181,7 +181,7 @@ function construct_model(out_dim, input_dim, hidden_dim, augment_dim)
181181 node = NeuralODE(Flux.Chain(Flux.Dense(input_dim, hidden_dim, relu),
182182 Flux.Dense(hidden_dim, hidden_dim, relu),
183183 Flux.Dense(hidden_dim, input_dim)) |> Flux.gpu,
184- (0.0f0, 1.0f0), Tsit5(), save_everystep = false,
184+ (0.0f0, 1.0f0), Tsit5(); save_everystep = false,
185185 reltol = 1.0f-3, abstol = 1.0f-3, save_start = false) |> Flux.gpu
186186 node = augment_dim == 0 ? node : (AugmentedNDELayer(node, augment_dim) |> Flux.gpu)
187187 return Flux.Chain((x, p = node.p) -> node(x, p),
@@ -200,15 +200,15 @@ Here, we define a utility to plot our model regression results as a heatmap.
200200function plot_contour(model, npoints = 300)
201201 grid_points = zeros(2, npoints^2)
202202 idx = 1
203- x = range(-4.0f0, 4.0f0, length = npoints)
204- y = range(-4.0f0, 4.0f0, length = npoints)
203+ x = range(-4.0f0, 4.0f0; length = npoints)
204+ y = range(-4.0f0, 4.0f0; length = npoints)
205205 for x1 in x, x2 in y
206206 grid_points[:, idx] .= [x1, x2]
207207 idx += 1
208208 end
209209 sol = reshape(model(grid_points |> Flux.gpu), npoints, npoints) |> Flux.cpu
210210
211- return contour(x, y, sol, fill = true, linewidth = 0.0)
211+ return contour(x, y, sol; fill = true, linewidth = 0.0)
212212end
213213```
214214
@@ -269,7 +269,7 @@ for `20` epochs.
269269model, parameters = construct_model(1, 2, 64, 0)
270270
271271for _ in 1:10
272- Flux.train!(loss_node, Flux.params(model, parameters), dataloader, opt, cb = cb)
272+ Flux.train!(loss_node, Flux.params(model, parameters), dataloader, opt; cb = cb)
273273end
274274```
275275
@@ -288,7 +288,7 @@ a function which can be expressed by the neural ode. For more details and proofs
288288model, parameters = construct_model(1, 2, 64, 1)
289289
290290for _ in 1:10
291- Flux.train!(loss_node, Flux.params(model, parameters), dataloader, opt, cb = cb)
291+ Flux.train!(loss_node, Flux.params(model, parameters), dataloader, opt; cb = cb)
292292end
293293```
294294
0 commit comments