From b2234a6f03181b749da0b028800c1c55a3cbabf0 Mon Sep 17 00:00:00 2001
From: baggepinnen <cont-frb@ulund.org>
Date: Thu, 22 Mar 2018 16:01:24 +0100
Subject: [PATCH] updates

---
 flux/bayesian_dropout.jl   | 20 --------------------
 flux/flux_bootstrap.jl     | 26 ++++++++++++--------------
 jump_lin_id/bibtexfile.bib | 28 ++++++++++++++--------------
 3 files changed, 26 insertions(+), 48 deletions(-)

diff --git a/flux/bayesian_dropout.jl b/flux/bayesian_dropout.jl
index cb2ff20..9a22323 100644
--- a/flux/bayesian_dropout.jl
+++ b/flux/bayesian_dropout.jl
@@ -1,24 +1,4 @@
 using Flux, IterTools, ValueHistories, MLDataUtils
-function update_plot(p; max_history = 10, attribute = :markercolor)
-    num_series = length(p.series_list)
-    if num_series > 1
-        if num_series > max_history
-            deleteat!(p.series_list,1:num_series-max_history)
-        end
-
-        for i = 1:min(max_history, length(p.series_list))-1
-            alpha = i/max_history
-            c = p[i][attribute]
-            c = RGBA(
-            alpha*c.r + (1-alpha)*0.5,
-            alpha*c.g + (1-alpha)*0.5,
-            alpha*c.b + (1-alpha)*0.5,
-            c.alpha)
-            p[i][attribute] = c
-        end
-    end
-
-end
 
 iters = 100
 N = 30
diff --git a/flux/flux_bootstrap.jl b/flux/flux_bootstrap.jl
index d55aa93..a93667f 100644
--- a/flux/flux_bootstrap.jl
+++ b/flux/flux_bootstrap.jl
@@ -1,12 +1,13 @@
 isdefined(:time_derivative) || @everywhere include(Pkg.dir("DynamicMovementPrimitives","src","two_link.jl"))
+Base.transpose(x) = x
 @everywhere begin
     # include("/var/tmp/fredrikb/v0.6/DynamicMovementPrimitives/src/two_link.jl")
 
     using TwoLink
 
     using Flux, ValueHistories, IterTools, MLDataUtils, OrdinaryDiffEq
-    using Flux: back!, truncate!, treelike, train!, mse, testmode!, combine, params
-    using Flux.Optimise: weightdecay, Param, optimiser, RMSProp
+    using Flux: back!, truncate!, treelike, train!, mse, testmode!, params
+    using Flux.Optimise: Param, optimiser, RMSProp
 
     N  = 1000
     n  = 2
@@ -27,9 +28,9 @@ isdefined(:time_derivative) || @everywhere include(Pkg.dir("DynamicMovementPrimi
         srand(seed)
 
         u  = filt(ones(50),[50], 10randn(N+2,n))'
-        t  = h:h:N*h+h
+        t  = 0:h:N*h
         x0 = [-0.4,0,0,0]
-        prob = OrdinaryDiffEq.ODEProblem((t,x)->time_derivative(x, u[:,ceil(Int,t/h)]),x0,(t[[1,end]]...))
+        prob = OrdinaryDiffEq.ODEProblem((x,p,t)->time_derivative(x, u[:,floor(Int,t/h)+1]),x0,(t[[1,end]]...))
         sol = solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8)
         x = hcat(sol(t)...)
         # y = hcat([time_derivative(x[:,t], u[:,t])[3:4] for t in 1:N]...)
@@ -62,10 +63,10 @@ isdefined(:time_derivative) || @everywhere include(Pkg.dir("DynamicMovementPrimi
         function evalcallback()
             iter += 1
             testmode!(m)
-            l = loss(x, y).data[1]
+            l = loss(x, y).tracker.data[1]
             push!(trace,iter,l)
             if iter % 10 == 0
-                push!(vtrace, iter, loss(xv,yv).data[1])
+                push!(vtrace, iter, loss(xv,yv).tracker.data[1])
                 if doplot
                     println("Iter: $iter, Loss: ", l)
                     plot(trace,reuse=true,show=false, lab="Train", layout=3, subplot=1, size=(1400,1000))
@@ -79,7 +80,7 @@ isdefined(:time_derivative) || @everywhere include(Pkg.dir("DynamicMovementPrimi
         end
         train!(loss, dataset, opt, cb = evalcallback)
         results = Dict{Symbol, Any}()
-        results[:num_params]          = num_params
+        # results[:num_params]          = num_params
 
         results[:x]  = x
         results[:u]  = u
@@ -100,9 +101,6 @@ isdefined(:time_derivative) || @everywhere include(Pkg.dir("DynamicMovementPrimi
     function generate_model(;num_params=50, activation=swish)
         np = num_params
         m  = Chain(Dense(ns+n,np, activation), LayerNorm(np), Dense(np, ns))
-        for p in params(m)
-            p.data .*= 6
-        end
         m
     end
 end
@@ -124,7 +122,7 @@ function StatsBase.predict(ms, x)
 end
 
 function Flux.jacobian(ms::Vector, x)
-    jacs = [jacobian(m,x) for m in ms]
+    jacs = [Flux.jacobian(m,x) for m in ms]
     jacmat = cat(3,jacs...)
     squeeze(mean(jacmat, 3), 3), squeeze(std(jacmat, 3), 3)
 end
@@ -157,7 +155,7 @@ results = pmap(1:8) do it
     activation = [swish, relu, Flux.sigmoid, tanh][(it % 4)+1]
     m          = generate_model(num_params=20, activation=activation)
     loss(x,y) = sum((m(x).-y).^2)/size(x,2)
-    opt        = [ADAM(params(m), 0.01, decay=0.001); [weightdecay(Param(p), 0.002) for p in params(m) if isa(p, AbstractMatrix)]]
+    opt        = ADAM(params(m), 0.01, decay=0.001)
     results    = fit_model(opt, loss, m, x, y, u, xv, yv, uv, iters=2000, doplot=false, batch_size = N)
     println("Done: ", it)
     results
@@ -173,7 +171,7 @@ end
 using ForwardDiff
 evalpoint = 400
 J = map(1:N) do evalpoint
-    Jm, Js = jacobian(models(results), x[:,evalpoint])
+    Jm, Js = Flux.jacobian(models(results), x[:,evalpoint])
     Jtrue = true_jacobian(evalpoint)
     Jm[:], Js[:], Jtrue[:]
 end
@@ -193,7 +191,7 @@ for evalpoint = 1:10:N
     scatter!(real.(e), imag.(e), c=:red, show=false)
     scatter!(real.(e+1), imag.(e+1), c=:red, show=false)
 
-    e = eigvals(jacobian(models(results), x[:,evalpoint])[1][1:4,1:4])
+    e = eigvals(Flux.jacobian(models(results), x[:,evalpoint])[1][1:4,1:4])
     scatter!(real.(e), imag.(e), c=:blue, show=false)
     scatter!(real.(e+1), imag.(e+1), c=:blue, show=false)
 end
diff --git a/jump_lin_id/bibtexfile.bib b/jump_lin_id/bibtexfile.bib
index 6f455fc..b1bf7be 100644
--- a/jump_lin_id/bibtexfile.bib
+++ b/jump_lin_id/bibtexfile.bib
@@ -12,7 +12,7 @@
   journal={The Annals of Applied Statistics},
   volume={8},
   number={3},
-  pages={1281--1313},
+  XXpages={1281--1313},
   year={2014},
   publisher={Institute of Mathematical Statistics}
 }
@@ -30,7 +30,7 @@
   journal={Soil Dynamics and Earthquake Engineering},
   volume={24},
   number={8},
-  pages={577--586},
+  XXpages={577--586},
   year={2004},
   publisher={Elsevier}
 }
@@ -42,7 +42,7 @@
   journal={Communications of the ACM},
   volume={4},
   number={6},
-  pages={284},
+  XXpages={284},
   year={1961},
   publisher={ACM}
 }
@@ -60,7 +60,7 @@
   journal={Numerical algorithms},
   volume={6},
   number={1},
-  pages={1--35},
+  XXpages={1--35},
   year={1994},
   publisher={Springer}
 }
@@ -71,7 +71,7 @@
   journal={The Annals of Statistics},
   volume={42},
   number={1},
-  pages={285--323},
+  XXpages={285--323},
   year={2014},
   publisher={Institute of Mathematical Statistics}
 }
@@ -82,7 +82,7 @@
   journal={SIAM review},
   volume={51},
   number={2},
-  pages={339--360},
+  XXpages={339--360},
   year={2009},
   publisher={SIAM}
 }
@@ -100,7 +100,7 @@
   journal={Journal of the American Statistical Association},
   volume={64},
   number={327},
-  pages={1079--1084},
+  XXpages={1079--1084},
   year={1969},
   publisher={Taylor \& Francis}
 }
@@ -109,7 +109,7 @@
   title={Guided policy search},
   author={Levine, Sergey and Koltun, Vladlen},
   booktitle={Int. Conf. Machine Learning (ICML), Atlanta},
-  pages={1--9},
+  XXpages={1--9},
   year={2013}
 }
 
@@ -117,7 +117,7 @@
   title={Learning contact-rich manipulation skills with guided policy search},
   author={Levine, Sergey and Wagener, Nolan and Abbeel, Pieter},
   booktitle={Robotics and Automation (ICRA), IEEE Int. Conf.},
-  pages={156--163},
+  XXpages={156--163},
   year={2015},
   organization={IEEE}
 }
@@ -128,7 +128,7 @@
   journal={IEEE Control Systems},
   volume={26},
   number={3},
-  pages={96--114},
+  XXpages={96--114},
   year={2006},
   publisher={IEEE}
 }
@@ -137,7 +137,7 @@
   title={Trust region policy optimization},
   author={Schulman, John and Levine, Sergey and Abbeel, Pieter and Jordan, Michael and Moritz, Philipp},
   booktitle={Int. Conf. Machine Learning (ICML-15)},
-  pages={1889--1897},
+  XXpages={1889--1897},
   year={2015}
 }
 
@@ -146,7 +146,7 @@
   author={Vidal, Ren{\'e} and Chiuso, Alessandro and Soatto, Stefano},
   booktitle={IEEE Conf. Decision and Control (CDC), Las Vegas},
   volume={4},
-  pages={3614--3619},
+  XXpages={3614--3619},
   year={2002},
   organization={IEEE}
 }
@@ -157,7 +157,7 @@
   journal={Foundations and Trends in Optimization},
   volume={1},
   number={3},
-  pages={127--239},
+  XXpages={127--239},
   year={2014},
   publisher={Now Publishers, Inc.}
 }
@@ -168,6 +168,6 @@
   journal={AIAA journal},
   volume={3},
   number={8},
-  pages={1445--1450},
+  XXpages={1445--1450},
   year={1965}
 }
-- 
GitLab