├── .gitignore
├── Julia
├── 1dexamples.jl
├── 1dlaplacian.jl
├── comparisons.jl
├── earlystopping.jl
├── iterate.jl
├── laplacian.jl
├── momentum.jl
├── momentum2.jl
├── noisy_gradients.jl
├── pde.jl
├── poly2d.jl
└── tem.jl
├── LICENSE
├── README.md
├── package.json
├── public
├── assets
│ ├── data
│ │ ├── Sigma.json
│ │ ├── U.json
│ │ ├── Urosen.json
│ │ ├── Uval.json
│ │ └── matrix.json
│ ├── eigenfeatures.js
│ ├── eigensum.js
│ ├── flow.js
│ ├── graph.js
│ ├── index.html
│ ├── iterates.js
│ ├── lib
│ │ ├── auto-render.min.js
│ │ ├── contour_plot.js
│ │ ├── contrib
│ │ │ └── auto-render.min.js
│ │ ├── d3-ring-note.js
│ │ ├── fonts
│ │ │ ├── KaTeX_AMS-Regular.eot
│ │ │ ├── KaTeX_AMS-Regular.ttf
│ │ │ ├── KaTeX_AMS-Regular.woff
│ │ │ ├── KaTeX_AMS-Regular.woff2
│ │ │ ├── KaTeX_Caligraphic-Bold.eot
│ │ │ ├── KaTeX_Caligraphic-Bold.ttf
│ │ │ ├── KaTeX_Caligraphic-Bold.woff
│ │ │ ├── KaTeX_Caligraphic-Bold.woff2
│ │ │ ├── KaTeX_Caligraphic-Regular.eot
│ │ │ ├── KaTeX_Caligraphic-Regular.ttf
│ │ │ ├── KaTeX_Caligraphic-Regular.woff
│ │ │ ├── KaTeX_Caligraphic-Regular.woff2
│ │ │ ├── KaTeX_Fraktur-Bold.eot
│ │ │ ├── KaTeX_Fraktur-Bold.ttf
│ │ │ ├── KaTeX_Fraktur-Bold.woff
│ │ │ ├── KaTeX_Fraktur-Bold.woff2
│ │ │ ├── KaTeX_Fraktur-Regular.eot
│ │ │ ├── KaTeX_Fraktur-Regular.ttf
│ │ │ ├── KaTeX_Fraktur-Regular.woff
│ │ │ ├── KaTeX_Fraktur-Regular.woff2
│ │ │ ├── KaTeX_Main-Bold.eot
│ │ │ ├── KaTeX_Main-Bold.ttf
│ │ │ ├── KaTeX_Main-Bold.woff
│ │ │ ├── KaTeX_Main-Bold.woff2
│ │ │ ├── KaTeX_Main-Italic.eot
│ │ │ ├── KaTeX_Main-Italic.ttf
│ │ │ ├── KaTeX_Main-Italic.woff
│ │ │ ├── KaTeX_Main-Italic.woff2
│ │ │ ├── KaTeX_Main-Regular.eot
│ │ │ ├── KaTeX_Main-Regular.ttf
│ │ │ ├── KaTeX_Main-Regular.woff
│ │ │ ├── KaTeX_Main-Regular.woff2
│ │ │ ├── KaTeX_Math-BoldItalic.eot
│ │ │ ├── KaTeX_Math-BoldItalic.ttf
│ │ │ ├── KaTeX_Math-BoldItalic.woff
│ │ │ ├── KaTeX_Math-BoldItalic.woff2
│ │ │ ├── KaTeX_Math-Italic.eot
│ │ │ ├── KaTeX_Math-Italic.ttf
│ │ │ ├── KaTeX_Math-Italic.woff
│ │ │ ├── KaTeX_Math-Italic.woff2
│ │ │ ├── KaTeX_Math-Regular.eot
│ │ │ ├── KaTeX_Math-Regular.ttf
│ │ │ ├── KaTeX_Math-Regular.woff
│ │ │ ├── KaTeX_Math-Regular.woff2
│ │ │ ├── KaTeX_SansSerif-Bold.eot
│ │ │ ├── KaTeX_SansSerif-Bold.ttf
│ │ │ ├── KaTeX_SansSerif-Bold.woff
│ │ │ ├── KaTeX_SansSerif-Bold.woff2
│ │ │ ├── KaTeX_SansSerif-Italic.eot
│ │ │ ├── KaTeX_SansSerif-Italic.ttf
│ │ │ ├── KaTeX_SansSerif-Italic.woff
│ │ │ ├── KaTeX_SansSerif-Italic.woff2
│ │ │ ├── KaTeX_SansSerif-Regular.eot
│ │ │ ├── KaTeX_SansSerif-Regular.ttf
│ │ │ ├── KaTeX_SansSerif-Regular.woff
│ │ │ ├── KaTeX_SansSerif-Regular.woff2
│ │ │ ├── KaTeX_Script-Regular.eot
│ │ │ ├── KaTeX_Script-Regular.ttf
│ │ │ ├── KaTeX_Script-Regular.woff
│ │ │ ├── KaTeX_Script-Regular.woff2
│ │ │ ├── KaTeX_Size1-Regular.eot
│ │ │ ├── KaTeX_Size1-Regular.ttf
│ │ │ ├── KaTeX_Size1-Regular.woff
│ │ │ ├── KaTeX_Size1-Regular.woff2
│ │ │ ├── KaTeX_Size2-Regular.eot
│ │ │ ├── KaTeX_Size2-Regular.ttf
│ │ │ ├── KaTeX_Size2-Regular.woff
│ │ │ ├── KaTeX_Size2-Regular.woff2
│ │ │ ├── KaTeX_Size3-Regular.eot
│ │ │ ├── KaTeX_Size3-Regular.ttf
│ │ │ ├── KaTeX_Size3-Regular.woff
│ │ │ ├── KaTeX_Size3-Regular.woff2
│ │ │ ├── KaTeX_Size4-Regular.eot
│ │ │ ├── KaTeX_Size4-Regular.ttf
│ │ │ ├── KaTeX_Size4-Regular.woff
│ │ │ ├── KaTeX_Size4-Regular.woff2
│ │ │ ├── KaTeX_Typewriter-Regular.eot
│ │ │ ├── KaTeX_Typewriter-Regular.ttf
│ │ │ ├── KaTeX_Typewriter-Regular.woff
│ │ │ └── KaTeX_Typewriter-Regular.woff2
│ │ ├── katex.css
│ │ ├── katex.js
│ │ ├── katex.min.css
│ │ ├── katex.min.js
│ │ ├── lib.js
│ │ └── template.v1.js
│ ├── milestones.js
│ ├── momentum.js
│ ├── numjs.js
│ ├── phasediagram.js
│ ├── phasediagram_description.js
│ ├── poly.js
│ ├── stochastic_milestones.js
│ ├── utils.js
│ └── widgets.css
├── examples
│ ├── 2dslider_widget.html
│ ├── annotate.html
│ ├── annotate_shan.html
│ ├── banana_widget.html
│ ├── change_basis_widget.html
│ ├── eigenfeatures_widget.html
│ ├── eigensum.html
│ ├── eigensum2.html
│ ├── eigensum3.html
│ ├── flow_widget.html
│ ├── force-layout.html
│ ├── hozbar_widget.html
│ ├── linear_transform.html
│ ├── milestones_widget.html
│ ├── milestones_widget_momentum.html
│ ├── momentum_widget.html
│ ├── offline_equation.html
│ ├── phase_diagram.html
│ ├── phase_diagram_description.html
│ ├── poly_widget.html
│ ├── rnn.html
│ ├── rosen_widget.html
│ └── sketch.html
├── index.html
└── thumbnail.jpg
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.log
--------------------------------------------------------------------------------
/Julia/1dexamples.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | # α = 0.076
21 | # β = 0.513
22 |
23 | α = 0.2
24 | β = 0.99
25 | x = 2
26 | y = 0
27 | X = zeros(100)
28 | for i = 1:100
29 | y = β*y - x
30 | x = x - α*y
31 | X[i] = x
32 | end
33 | figure(); plot(X,"k"); plot(X,"k."); xlabel(L"k"); ylabel(L"f(x)")
--------------------------------------------------------------------------------
/Julia/1dlaplacian.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | n = 50
21 | κ = 1000
22 | A = SymTridiagonal(2*ones(n), -ones(n-1))
23 | A = (κ-1)*A/4 + eye(n)
24 | cond(A)
25 | b = zeros(n); b[1] = (κ - 1)/4
26 |
27 | Λ, Q = eig(A)
28 |
29 | κ = Λ[1]/Λ[n]
30 | α = 2/(Λ[1] + Λ[end])
31 | β = 0.98
32 | #β = 0
33 |
34 | # Function from momentum2.jl
35 | Z = cat(2,[ runmomentumcheat(A,b,i)[2] for i = 1:400]...)
36 | heatmap(Z)
37 |
38 | plot(b2)
39 | plot!(A\b)
--------------------------------------------------------------------------------
/Julia/comparisons.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | # f(x) = ((1 + ((x[1]+x[2]+1)^2)*(19 - 14*x[1]+3*x[1]^2-14*x[2]+6*x[1]*x[2]+3*x[2]^2))*
21 | # (30 + ((2*x[1] - 3*x[2])^2)*(18 - 32*x[1] +
22 | # 12*x[1]^2 + 48*x[2] - 36*x[1]*x[2] + 27*x[2]^2)) )
23 | # ∇f(x) = ForwardDiff.gradient(f,x)
24 |
25 | # Beale
26 | # f(x) = ( (1.5 - x[1] + x[1]*x[2])^2
27 | # + (2.25 - x[1] + x[1]*x[2]^2)^2
28 | # + (2.625 - x[1] + x[1]*x[2]^3)^2 )
29 | # ∇f(x) = ForwardDiff.gradient(f,x)
30 |
31 |
32 | # Rosenbrock
33 | # f(x) = 100*(x[2] - x[1]^2)^2 + (x[1] - 1)^2
34 | # ∇f(x) = ForwardDiff.gradient(f,x)
35 |
36 | # Monkey Saddle
37 | # f(x) = x[1]^3 - 3*x[1]*x[2]^2
38 | # ∇f(x) = [3*x[1] - 3*x[2]^2; -6*x[1]*x[2]]
39 |
40 | A = diagm([1; 1])
41 | f(x) = 0.5*vecdot(x,A*x)
42 | ∇f(x) = A*x
43 |
44 | α = 1.5; β = 0.51
45 |
46 | w = [1;1]; z = zeros(2)
47 |
48 | N = 2000
49 | fW = zeros(N)
50 | wp = w
51 | W = zeros(2,N)
52 | for i = 1:N
53 | if i > 2
54 | #if vecdot(∇f(w), w - wp) > 0; println(i); z = zeros(2); end
55 | end
56 | W[:,i] = vecdot(∇f(w), w - wp)
57 | wp = w
58 | z = β*z + ∇f(w)
59 | w = w - α*(∇f(w) + β*z)
60 | println(f(w))
61 | if abs(f(w)) < 100; fW[i] = f(w); else; fW[i] = NaN; end
62 | #W[:,i] = w
63 | end
64 |
65 | plot(fW)
--------------------------------------------------------------------------------
/Julia/earlystopping.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | csize = 5;
21 | y = [-1*ones(csize); 1*ones(csize); -1*ones(csize);1*ones(csize);-1*ones(csize);]
22 | y = y + 0.3*cat(1, [[0,1,0,1,0] for i in 1:5]...)
23 | x = cat(1,[collect(c + linspace(-0.03,0.03, csize)) for c in linspace(-1,1,5)]...)
24 |
25 | pdegree = 25
26 |
27 | # Construct Vander* Matrix
28 | A = zeros(length(y),pdegree+1)
29 | for i = 1:size(A,1), j = 1:size(A,2)
30 | A[i,j] = x[i]^(j-1)
31 | end
32 |
33 | Σ,U = eig(A'A)
34 |
35 | p(w,x) = sum([w[i]*x^(i-1) for i = 1:length(w)])
36 |
37 | Q,R = qr(A)
38 | ws = (R'R)\(A'*y)
39 | plot(r,[p(ws,i) for i in r])
40 | plot!(ylim = [-2,2])
41 | scatter!(x,y)
42 |
43 | r = linspace(x[1]-0.1,1+0.1,500)
44 |
45 | w = 100*randn(size(w))
46 | α = 1/max(eig(A'A)[1]...)
47 |
48 | # for ind = 1:2
49 | # plot!(r,[(U'*ws)[ind]*p(U[:,ind],i) for i in r])
50 | # end
51 | # plot!(ylim = [0,15])
52 | # scatter!(x,y)
53 |
54 | @gif for i = 1:100
55 | println(i)
56 | w = getiterk(A'A, A'y, α)(1.4^i)
57 | println(norm(A'*(A*w - y)))
58 | plot(size = (880,180))
59 | scatter!(x,y)
60 | plot!(r,[p(w,i) for i in r])
61 | plot!(ylim = [-2,2])
62 | end
63 |
--------------------------------------------------------------------------------
/Julia/iterate.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | A = diagm(Float64[i^2 for i = 1:10])
21 | x = ones(10)
22 | y = ones(10)
23 | L = min(eig(A)[1]...)
24 |
25 | β = 0.9999
26 | α = 0.000005
27 | X = zeros(10,10000)
28 | fX = zeros(10000)
29 | fx = vecdot(x,A*x)
30 |
31 | for i = 1:10000
32 | xold = x
33 | fxp = fx
34 | fx = 0.5*vecdot(x,A*x)
35 | x = y - α*(A*y)
36 | fxp < fx ? y = x : y = x + β*(x - xold)
37 | X[:,i] = x
38 | fX[i] = 0.5*vecdot(x,A*x)
39 | end
40 |
41 | plot(fX)
42 |
43 | x = ones(10)
44 | y = ones(10)
45 |
46 | for i = 1:10000
47 | xold = x
48 | fxp = fx
49 | fx = 0.5*vecdot(x,A*x)
50 | x = y - α*(A*y)
51 | y = x + β*(x - xold)
52 | X[:,i] = x
53 | fX[i] = 0.5*vecdot(x,A*x)
54 | end
55 |
56 | plot(fX)
--------------------------------------------------------------------------------
/Julia/laplacian.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | using Plots
21 |
22 | function getiterk(Q,b,α)
23 | Σ,U = eig(Q)
24 | c = U'b
25 | lambdak(k,λ) = (1 - (1 - α*λ).^k)./λ
26 | return k -> U*(lambdak(k,Σ).*c)
27 | end
28 |
29 | Box = zeros(16,16)
30 | Cavity = ones(16,16)
31 | Cavity[8:9,:] = 0
32 | R = [Box Cavity Box Cavity Box Cavity Box]
33 | A = ones(size(R,1)+2, size(R,2) + 2)
34 | A[2:end-1,2:end-1] = R
35 |
36 | n = size(A,1) - 2
37 | m = size(A,2) - 2
38 |
39 | Ind = zeros(Integer, size(A))
40 | IndInv = Tuple{Int64,Int64}[]
41 | count = 1
42 | for i = 1:size(A,1), j = 1:size(A,2)
43 | if A[i,j] == 0
44 | Ind[i,j] = count
45 | push!(IndInv, (i,j))
46 | count = count + 1
47 | end
48 | end
49 |
50 | fp = open("Uval.json","w")
51 | JSON.print(fp, convert(Array{Float16,2},U))
52 | close(fp)
53 |
54 | fp = open("Sigma.json","w")
55 | JSON.print(fp, Σ)
56 | close(fp)
57 | # ==================================================
58 | # Generate Laplacian
59 | # ==================================================
60 |
61 | Q = zeros(length(IndInv), length(IndInv))
62 | for i = 2:(size(A,1)-1), j = 2:(size(A,2)-1)
63 | k = Ind[i,j]
64 | if A[i,j] == 0
65 | A[i,j+1] == 0 ? Q[Ind[i,j+1],k] = 1 : nothing
66 | A[i+1,j] == 0 ? Q[Ind[i+1,j],k] = 1 : nothing
67 | A[i,j-1] == 0 ? Q[Ind[i,j-1],k] = 1 : nothing
68 | A[i-1,j] == 0 ? Q[Ind[i-1,j],k] = 1 : nothing
69 | end
70 | end
71 |
72 | Q = (Q + Q')/2
73 | L = diagm(sum(Q,1)[:]) - Q
74 | L[449,449] = L[449,449] + 0.1
75 | L[561,561] = L[561,561] + 0.1
76 |
77 | Σ,U = eig(L)
78 |
79 | function arrange(x)
80 | A = zeros(n,m)
81 | for ind = 1:length(x)
82 | i,j = IndInv[ind]
83 | A[i-1,j-1] = x[ind]
84 | end
85 | return A
86 | end
87 |
88 | plot(size = (880,140)); heatmap!(arrange(U[:,10]), map = "seismic")
89 |
90 | imshow(arrange(U[:,100]), interpolation = "None", cmap = "spectral"); show()
91 |
92 | pyplot(leg=false, ticks=nothing)
93 |
94 | @gif for i in 2:500
95 | plot(size = (880,140)); heatmap!(reshape(U[:,224*3+i],n,m))
96 | end
97 |
98 | e1 = zeros(length(IndInv))
99 | e1[449] = 1
100 | e1[561] = 1
101 |
102 | α = 1/max(Σ...)
103 |
104 | iterk = getiterk(L,e1,α)
105 |
106 | imshow(arrange(iterk(10000)))
107 | show()
108 |
109 | # α = 1/max(eig(L)[1]...)
110 | # iters = 5000
111 | # X = zeros(n*m,iters)
112 | # x = 10*zeros(n*m)
113 | # for i = 1:iters
114 | # X[:,i] = x
115 | # for i = 1:100
116 | # x = x - (1*α)*(L*x - e1)
117 | # end
118 | # println(norm(L*x - e1))
119 | # end
120 |
121 | # plot(size = (880,140)); heatmap!(reshape(X[:,100],n,m))
122 | # pyplot(leg=false, ticks=nothing)
123 |
124 | # @gif for i in 10:10:2000
125 | # println(i)
126 | # xi = reshape(X[:,i],n,m)
127 | # plot(size = (880,140)); heatmap!(xi)
128 | # end
129 |
130 | # lambdak(k,λ) = α*(1 - (1 - α*λ).^k)./(α*λ)
131 | # c = U'e1
132 |
133 | # @gif for i i guein 10:500:300000
134 | # println(i)
135 | # z = U*(lambdak(i,Σ).*(c)
136 | # plot(size = (880,140)); heatmap!(reshape(z, n, m))
137 | # end
138 |
139 | # A = randn(10,10); A = A*A'
140 |
141 | # b = rand(10)
142 | # x = zeros(10)
143 | # for i = 1:1000
144 | # x = x - 0.01*(A*x - b)
145 | # end
146 | # x - getiterk(A,b,0.01)(1000)
147 |
148 |
--------------------------------------------------------------------------------
/Julia/momentum.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | λ = 1
21 | #M(α,β) = [β λ; -α*β (1-α)]
22 | M(α,β) = [β λ; -α*(β^2) 1-α*λ*(1+β)]
23 | #M(α,β) = [1 αλ; -β-1 -α*β*λ]
24 | S(α,β) = max(abs((eig(M(α,β))[1]))...)
25 |
26 | n = 200
27 | R1 = linspace(0,2,n);
28 | R2 = linspace(-1,1,2*n);
29 | Z = [S(R1[i],R2[j]) for i = 1:n, j = 1:2*n]
30 |
31 | figure(); contour(R1, R2, Z', linspace(0,1,30), cmap = "magma")
32 | contour(R1, R2, Z', [1.,])
33 |
34 | # figure(); imshow(flipdim(Z',1), cmap = "magma")
35 |
36 |
37 | xlabel(L"\alpha\lambda_i")
38 | ylabel(L"\beta")
39 |
40 | figure(); plot(R2, Z[6,:]',"k")
41 | xlabel(L"\beta")
42 | ylabel("Convergence Rate")
--------------------------------------------------------------------------------
/Julia/momentum2.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | srand(1)
21 |
22 | n = 2
23 | U = [1 -1;1 1]/sqrt(2); L = [1 0; 0 2];
24 | A = U*L*inv(U)
25 | b = -ones(n)
26 |
27 | β = 0.4
28 | α = 1/max(eig(A)[1]...)
29 |
30 | function runmomentum(A,b,k)
31 | z = zeros(length(b))
32 | w = zeros(length(b))
33 | for i = 1:k
34 | z = β*z + (A*w - b)
35 | w = w - α*z
36 | end
37 | return (z,w)
38 | end
39 |
40 | function geosumgen(R)
41 | Λ, U = eig(R)
42 | (b,k) -> begin;
43 | Λsum = (1./(1 - Λ)).*(1 - Λ.^k);
44 | real(U*(Λsum.*(U\b)));
45 | end
46 | end
47 |
48 | function runmomentumcheat(A,b,k)
49 | Λ, U = eig(A)
50 | Rmat(i) = [ β Λ[i] ;
51 | -α*β (1- α*Λ[i]) ]
52 | S = inv([ 1 0 ;
53 | α 1 ])
54 | c = -U'b
55 | fcoll = [geosumgen(Rmat(i)) for i = 1:length(b)]
56 | iters = [fcoll[i](S*[c[i];0],k) for i = 1:length(b)]
57 | catiter = cat(2,iters...)
58 | return (U*catiter[1,:], U*catiter[2,:])
59 | end
60 |
61 | (a1,b1) = runmomentum(A,b,4)
62 | (a2,b2) = runmomentumcheat(A,b,4)
63 |
64 | norm(a1)
--------------------------------------------------------------------------------
/Julia/noisy_gradients.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 |
21 | λ = 1
22 | Rf(β, α) = [ β λ;
23 | -α*β (1 - α*λ)]
24 |
25 | α = 0.05
26 | β = 0.4
27 |
28 | ϵ = 8
29 | S = inv([ 1 0 ;
30 | α 1 ])
31 |
32 | function err(k)
33 | R = Rf(β, α)
34 | sum( ( ((R^(k-i))*([ϵ; -α*ϵ]) )[2] )^2 for i = 1:k )
35 | end
36 |
37 | function err2(k, α, β)
38 | R = Rf(β, α)
39 | x = [ϵ; -α*ϵ]
40 | s = 0
41 | z = []
42 | for i = 1:k
43 | s = s + x[2]^2
44 | x = R*x
45 | push!(z, s)
46 | end
47 | return z
48 | end
49 |
50 | err2(100)[50] - err(50)
51 |
52 | function geosumgen(R)
53 | Λ, U = eig(R)
54 | (b,k) -> begin;
55 | Λsum = (1./(1 - Λ)).*(1 - Λ.^k);
56 | real(U*(Λsum.*(U\b)));
57 | end
58 | end
59 |
60 | function runmomentum(A,b,k, ϵ)
61 | z = zeros(length(b))
62 | w = 3*ones(length(b))
63 | for i = 1:k
64 | z = β*z + (A*w - b) + ϵ*randn(1)
65 | w = w - α*z
66 | end
67 | return (z[1],w[1])
68 | end
69 |
70 | function runmomentum2(A,b,k, ϵ)
71 | z = zeros(length(b))
72 | w = 3*ones(length(b))
73 | fx = []
74 | for i = 1:k
75 | z = β*z + (A*w - b) + ϵ*randn(1)
76 | w = w - α*z
77 | push!(fx, w[1]*w[1])
78 | end
79 | return fx
80 | end
81 |
82 | k = 150
83 | d = mean([runmomentum2(1,0, k, ϵ) for i = 1:100])
84 | e = err2(k)
85 | d2 = [runmomentum(1,0, i, 0.)[2]^2 for i = 1:k]
86 |
87 | plot(d,".")
88 | plot(d2+e)
89 | #plot(d2)
90 |
91 | plot(err2(200, 0.01, 0))
92 |
--------------------------------------------------------------------------------
/Julia/pde.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | using Plots
21 |
22 | # A = ones(18,67)
23 |
24 | # A[2:end-1,2:end-1] = 0
25 | # A[1:7,32-5:34+5] = 1
26 | # A[end-7:end,32-5:34+5] = 1
27 |
28 | Box = zeros(16,16)
29 | Cavity = ones(16,16)
30 | Cavity[8:9,:] = 0
31 | R = [Box Cavity Box Cavity Box Cavity Box]
32 | A = ones(size(R,1)+2, size(R,2) + 2)
33 | A[2:end-1,2:end-1] = R
34 |
35 | n = size(A,1) - 2
36 | m = size(A,2) - 2
37 |
38 | R = reshape(1:n*m, n,m)
39 | Id(i,j) = R[i-1,j-1]
40 |
41 | Q = zeros(n*m,n*m)
42 | for i = 2:(size(A,1)-1), j = 2:(size(A,2)-1)
43 | k = Id(i,j)
44 | if A[i,j] == 0
45 | A[i,j+1] == 0 ? Q[Id(i,j+1),k] = 1 : nothing
46 | A[i+1,j] == 0 ? Q[Id(i+1,j),k] = 1 : nothing
47 | A[i,j-1] == 0 ? Q[Id(i,j-1),k] = 1 : nothing
48 | A[i-1,j] == 0 ? Q[Id(i-1,j),k] = 1 : nothing
49 | end
50 | end
51 |
52 | Q = (Q + Q')/2
53 |
54 | v = sum(Q,1)[:]
55 | v[v .== 0] = 1
56 | L = diagm(v) - Q
57 | L[1,1] = 2.1
58 |
59 | Σ,U = eig(L)
60 |
61 | pyplot(leg=false, ticks=nothing)
62 | @gif for i in 2:500
63 | plot(size = (880,140)); heatmap!(reshape(U[:,224*3+i],n,m))
64 | end
65 |
66 | e1 = zeros(n*m)
67 | e1[8:9] = 1
68 |
69 | α = 1/max(eig(L)[1]...)
70 | iters = 5000
71 | X = zeros(n*m,iters)
72 | x = 10*zeros(n*m)
73 | for i = 1:iters
74 | X[:,i] = x
75 | for i = 1:100
76 | x = x - (1*α)*(L*x - e1)
77 | end
78 | println(norm(L*x - e1))
79 | end
80 |
81 | plot(size = (880,140)); heatmap!(reshape(X[:,100],n,m))
82 | pyplot(leg=false, ticks=nothing)
83 |
84 | @gif for i in 10:10:2000
85 | println(i)
86 | xi = reshape(X[:,i],n,m)
87 | plot(size = (880,140)); heatmap!(xi)
88 | end
89 |
90 |
91 | lambdak(k,λ) = α*(1 - (1 - α*λ).^k)./(α*λ)
92 | c = U'e1
93 |
94 |
95 | @gif for i in 10:500:300000
96 | println(i)
97 | z = U*(lambdak(i,Σ).*(c)
98 | plot(size = (880,140)); heatmap!(reshape(z, n, m))
99 | end
100 |
101 | function getiterk(Q,b)
102 | Σ,U = eig(Q)
103 | c = U'b
104 | lambdak(k,λ) = α*(1 - (1 - α*λ).^k)./(α*λ)
105 | return U*(lambdak(k,Σ).*c)
106 | end
107 |
108 |
109 |
--------------------------------------------------------------------------------
/Julia/poly2d.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | gen_rand2(n,x) = [(0.1*randn(n,1) + x[1]) (0.1*randn(n,1) - x[2])]
21 |
22 | X = [gen_rand2(12, [1,0.7]);
23 | gen_rand2(12, [-1,0.7]);
24 | gen_rand2(12, [0,-1])];
25 |
26 | scatter(X[:,1], X[:,2])
27 |
28 | function Φ(x)
29 | o = Float64[]
30 | for i = 0:5, j = 0:5
31 | push!(o, (x[1]^i)*x[2]^j )
32 | end
33 | return o
34 | end
35 |
36 | res = 500
37 | Z = [Φ([i,j])[10] for i = linspace(-1,1,res), j = linspace(-1,1,res)]
38 |
39 | D = cat(2,[Φ(X[i,:]) for i = 1:size(X,1)]...)
40 | S,U = eig(D*D')
41 |
42 | n = 3
43 | Z = [vecdot(Φ([i,j]),U[:,n]) for i = linspace(-2,2,res), j = linspace(-2,2,res)]
44 | c = 0.1*sqrt(S[n])
45 | #heatmap(linspace(-2,2,res),linspace(-2,2,res),min(max(Z,-c),c))
46 | heatmap(linspace(-2,2,res),linspace(-2,2,res),log(abs(Z)))
47 | scatter!(X[:,2], X[:,1])
--------------------------------------------------------------------------------
/Julia/tem.jl:
--------------------------------------------------------------------------------
1 | #=Copyright (c) 2017 Gabriel Goh
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=#
19 |
20 | using ConicIP
21 |
22 | set_default_solver(ConicIPSolver(optTol = 1e-10))
23 |
24 | b = 0.5*ones(10)
25 |
26 | function Ψ(λ)
27 | x = Variable(15)
28 | p = minimize( 0.5*sumsquares(A*x - b) + λ*norm(y,1) )
29 | solve!(p)
30 | s = y.value
31 | s[abs(s) .< 1e-8] = 0
32 | return s
33 | end
34 |
35 | x = 0.5*ones(10)
36 | W = randn(10,15)
37 | I = eye(10)
38 | ϵ = 0.001
39 |
40 | K = !(Ψ(x) .== 0)
41 | ystar = Ψ(x)
42 | inv(W[:,K]'W[:,K])*(W[:,K]'x - sign(ystar[K]))
43 | Ψ(x)
44 |
45 | (Ψ(x + ϵ*I[:,1]) - Ψ(x - ϵ*I[:,1]))/(2ϵ)
46 |
47 | inv(W[:,K]'W[:,K])*(W[:,K]')
48 |
49 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # post--momentum
2 |
3 | run `npm install` to install dependencies.
4 |
5 | run `npm run build` to concat those dependencies into a lib file.
6 |
7 | `npm run serve` will run a server so you can preview the ajax calls.
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "build": "cat node_modules/d3/build/d3.min.js node_modules/numeric/numeric-1.2.6.min.js node_modules/d3-swoopy-drag/swoopy-drag.js node_modules/d3-tip/index.js > public/assets/lib/lib.js",
4 | "serve": "python -m SimpleHTTPServer",
5 | "cache-template": "curl http://distill.pub/template.v1.js > public/assets/lib/template.v1.js"
6 | },
7 | "dependencies": {
8 | "d3": "^4.7.1",
9 | "d3-swoopy-drag": "^0.0.3",
10 | "d3-tip": "^0.7.1",
11 | "distill-template": "^1.0.1",
12 | "numeric": "^1.2.6"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/public/assets/data/matrix.json:
--------------------------------------------------------------------------------
1 | [[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.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1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]]
--------------------------------------------------------------------------------
/public/assets/flow.js:
--------------------------------------------------------------------------------
1 | function renderFlowWidget(divin, FlowSigma, M, FlowU) {
2 |
3 | var jetc = d3.scaleLinear().domain([-100,1.5,2,3,4,5,10,60,200,500]).range(colorbrewer.RdYlBu[10]);
4 |
5 | var colorBar = divin.append("div").style("position", "absolute").style("left","490px").style("top", "5px").style("height","45px")
6 |
7 | colorMap( colorBar,
8 | 180,
9 | jetc,
10 | d3.scaleLinear().domain([0,100]).range([0, 180]) )
11 |
12 | divin.append("figcaption")
13 | .style("position", "absolute")
14 | .style("left", "500px")
15 | .style("width", "300px")
16 | .style("top", "70px")
17 | .html("Each square represents a node, colored by its weight. Edges connect each square to the four neighboring squares.")
18 |
19 | divin.append("figcaption")
20 | .style("position", "absolute")
21 | .style("left", "500px")
22 | .style("width", "100px")
23 | .style("top", "0px")
24 | .attr("class", "figtext")
25 | .html("Weights")
26 |
27 | // sliderGen([320, 130])
28 | // .ticks([0,2/FlowSigma[1119]])
29 | // .cRadius(5)
30 | // .startxval(4)
31 | // .shifty(10)
32 | // .change(changeStep)(divin.append("div").style("position","relative").style("left", "100px"))
33 |
34 | var slider = divin.append("div").style("position","relative").style("left", "112px")
35 | /*
36 | Generate coordinates for 2D Laplacian based on input matrix
37 | V[i] = (x,y) coordinate of node in 2D space.
38 | */
39 | var V = []
40 | for (var i = 0; i < 16; i++) { for (var j = 0; j < 112; j++) {
41 | if (M[i][j] == 0){ V.push([j,i]) }
42 | }}
43 |
44 | /* Generate b in optimization problem x'Ax - b'x */
45 | var b = zeros(FlowU[0].length); b[448] = 10; b[560] = 10
46 | var step = 1.9/(FlowSigma[1119])
47 | //var iter = geniter(FlowU, FlowSigma, b, step)
48 | var Ub = numeric.dot(FlowU, b)
49 |
50 | // We can also run this on momentum.
51 | var iterf = geniterMomentum(FlowU, FlowSigma, b, step, 0.999).iter
52 | var iter = function(k) { return iterf(k)[1] }
53 |
54 | /**************************************************************************
55 | START VISUALIZATION
56 | ***************************************************************************/
57 | divin.style("position", "relative")
58 |
59 | /* Render the 2D grid of pixels, given a div as input
60 | * (appends an svg inside the div)
61 | * Returns a function which allows you to update it */
62 | function renderGrid(s, transition) {
63 |
64 | var sampleSVG = s.style("display", "block")
65 | .style("margin-left","auto")
66 | .style("margin-right","auto")
67 | .style("width", "920px")
68 | .append("svg")
69 | .attr("width", 920)
70 | .attr("height", 150)
71 |
72 | /* Render discretization of 2D Laplacian*/
73 | sampleSVG.selectAll("rect")
74 | .data(V)
75 | .enter().append("rect")
76 | .style("fill", function(d,i) { return "white" })
77 | .attr("height", 7.7)
78 | .attr("width", 7.7)
79 | .attr("x", function(d, i){return d[0]*8+ 10})
80 | .attr("y", function(d, i){return d[1]*8 + 10})
81 |
82 | /* display a function on the laplacian using colormap map*/
83 | var display = function (x, map) {
84 | if (transition === undefined){
85 | sampleSVG.selectAll("rect").style("fill", function(d,i) { return map(x[i]) })
86 | } else {
87 | sampleSVG.transition()
88 | .duration(transition)
89 | .selectAll("rect")
90 | .style("fill", function(d,i) { return map(x[i]) })
91 | }
92 | }
93 |
94 | return display
95 |
96 | }
97 |
98 | var display = renderGrid(divin)
99 | /* Render Control Slider */
100 |
101 | // Callbacks
102 | var showEigen = function (d,i) {
103 | display(FlowU[i], divergent)
104 | }
105 |
106 | var cacheval = -1
107 | var cacheiter = null
108 | var onDragSlider = function (i) {
109 | var i = Math.floor(Math.exp(i-1))
110 | if (cacheval != i) {
111 | cacheiter = iter(i)
112 | cacheval = i
113 | }
114 | display(cacheiter, jetc)
115 | }
116 |
117 | display(iter(100), jetc) // Set it up to a nice looking default
118 |
119 | var barLengths = getStepsConvergence(FlowSigma,step)
120 | .map( function(i) {return Math.abs(Math.log(i+1)) } ).filter( function(d,i) { return (i < 50) || i%20 == 0 } )
121 |
122 | var slideControl = sliderBarGen(barLengths, function(x) { return Math.exp(x-1)} )
123 | .height(281)
124 | .linewidth(1.3)
125 | .maxX(13.3)
126 | .mouseover( function(d,i) { display(FlowU[i], divergent) })
127 | .labelFunc(function (d,i) {
128 | if (i < 50) {
129 | return ((i == 0) ? "Eigenvalue 1" : "") + (( (i+1) % 25 == 0 ) ? (i + 1) : "")
130 | } else {
131 | return (( (i+1) % 25 == 0 ) ? 20*(i + 1) : "")
132 | }
133 | })
134 | .update(onDragSlider)(divin)
135 |
136 | slideControl.slidera.init()
137 |
138 | function changeStep(alpha, beta) {
139 | var iteration = geniterMomentum(FlowU, FlowSigma, b, Math.max(alpha/FlowSigma[1119],0.00000001), Math.min(beta,0.999999))
140 | iterf = iteration.iter
141 | var barLengths = getStepsConvergence(iteration.maxLambda.map(function(i) { return 1- i}), 1)
142 | .map( function(i) {return Math.log(Math.max(i,1))} )
143 | .filter( function(d,i) { return (i < 50) || i%20 == 0 } )
144 | slideControl.update(barLengths)
145 | iter = function(k) { return iterf(k)[1] }
146 | cacheval = -1
147 | slideControl.slidera.init()
148 | }
149 | var reset = slider2D(slider, changeStep, FlowSigma[0], FlowSigma[1119], [1.9,0.00001])
150 |
151 | slider.append("div")
152 | .attr("class","figtext")
153 | .style("left", "155px")
154 | .style("top", "0px")
155 | .style("position","absolute")
156 | .style("pointer-events", "none")
157 | .html("Step-size α =")
158 |
159 | slider.append("div")
160 | .attr("class","figtext")
161 | .style("left", "-87px")
162 | .style("top", "20px")
163 | .style("position","absolute")
164 | .style("pointer-events", "none")
165 | .html("Momentum β = ")
166 |
167 | return reset
168 | }
169 |
170 | //
Step-size α =
171 | //
Momentum β =
172 |
--------------------------------------------------------------------------------
/public/assets/graph.js:
--------------------------------------------------------------------------------
1 | var seed = 17;
2 | function random() {
3 | var x = Math.sin(seed++) * 10000;
4 | return x - Math.floor(x);
5 | }
6 |
7 | function generateGraph(svg, graph, linklength, strength) {
8 |
9 | var width = 300;
10 | var height = 200;
11 |
12 | var simulation = d3.forceSimulation()
13 | .force("link", d3.forceLink().id(function(d) { return d.id; })
14 | .strength(2)
15 | .distance(function() {return linklength}))
16 | .force("charge", d3.forceManyBody().strength(-110))
17 | .force("center", d3.forceCenter(width / 2, height / 2))
18 | .force("x",d3.forceX(1000).strength(strength))
19 | .force("y",d3.forceY(1000).strength(strength))
20 | .stop()
21 | var link = svg.append("g")
22 | .attr("class", "links")
23 | .selectAll("line")
24 | .data(graph.links)
25 | .enter().append("line")
26 | .attr("stroke-width", 1)
27 | .attr("stroke","black")
28 |
29 | var node = svg.append("g")
30 | .attr("class", "nodes")
31 |
32 |
33 | var nodedata = node
34 | .selectAll("circle")
35 | .data(graph.nodes)
36 | .enter().append("circle")
37 | .attr("r", 3)
38 | .attr("fill", "black")
39 |
40 | nodedata.append("title")
41 | .text(function(d) { return d.id; });
42 |
43 | simulation
44 | .nodes(graph.nodes)
45 | .on("tick", ticked);
46 |
47 | simulation.force("link")
48 | .links(graph.links);
49 |
50 | for (var i = 0; i < 200; ++i) {
51 | simulation.tick();
52 | }
53 |
54 | function ticked() {
55 | link.attr("x1", function(d) { return d.source.x; })
56 | .attr("y1", function(d) { return d.source.y; })
57 | .attr("x2", function(d) { return d.target.x; })
58 | .attr("y2", function(d) { return d.target.y; });
59 |
60 | nodedata.attr("cx", function(d) { return d.x; })
61 | .attr("cy", function(d) { return d.y; });
62 | }
63 |
64 | var updateColors = function (update) {
65 | node.selectAll("circle")
66 | .data(update)
67 | .attr("fill", function(d,i) { return d})
68 | }
69 |
70 | ticked()
71 |
72 | return updateColors
73 | };
74 |
75 |
76 | function genGrid(svg) {
77 |
78 | var data = {"nodes": [],"links": []}
79 | var id = {}
80 |
81 | var n = 6
82 | var c = 0
83 | for (var i = 0; i < n; i ++) {
84 | for (var j = 0; j < n; j ++) {
85 | data.nodes.push({"id": i + "," + j})
86 | id[i + "," + j] = c
87 | c++
88 | }
89 | }
90 |
91 | var L = zeros2D(c,c)
92 |
93 | for (var i = 0; i < n; i++) {
94 | for (var j = 0; j < n; j++){
95 | if (j < (n-1)) {
96 | data.links.push({"source":i + "," + j, "target": i + "," + (j + 1)})
97 | L[id[i + "," + j]][id[i + "," + (j+1)]] = -1
98 | L[id[i + "," + (j+1)]][id[i + "," + j]] = -1
99 | }
100 | if (i < (n-1)) {
101 | data.links.push({"source":i + "," + j, "target": (i + 1) + "," + j})
102 | L[id[i + "," + j]][id[(i+1) + "," + j]] = -1
103 | L[id[(i+1) + "," + j]][id[i + "," + j]] = -1
104 | }
105 | }
106 | }
107 |
108 | for (var i = 0; i < c; i++) {
109 | L[i][i] = -numeric.sum(L[i]) + ((i == 0) ? 1 : 0)
110 | }
111 |
112 | colorbrewer.Spectral[3]
113 | var divergent = d3.scaleLinear().domain([-0.1,0,0.1]).range(["#fc8d59", "#e6e600", "#99d594"]);
114 |
115 | var E = eigSym(L)
116 |
117 | var update = generateGraph(svg, data,2,0.2)
118 |
119 | var colors = []
120 | for (var i = 0; i < c; i++) {
121 | colors.push(divergent(E.U[34][i]))
122 | }
123 | update(colors)
124 |
125 |
126 | }
127 |
128 |
129 | function genPath(svg) {
130 | var data = {"nodes": [], "links": []}
131 |
132 | var n = 36
133 | var L = zeros2D(n,n)
134 | for (var i = 0; i < n; i ++) {
135 | data.nodes.push({"id": i})
136 | if (i < (n-1)){
137 | data.links.push({"source":i, "target": i+1})
138 | L[i][i+1] = -1
139 | L[i+1][i] = -1
140 | }
141 | }
142 |
143 | for (var i = 0; i < 3; i++){
144 | var s = Math.floor(random()*36)
145 | var t = Math.floor(random()*36)
146 | data.links.push({"source":s, "target": t})
147 | L[s][t] = -1
148 | L[t][s] = -1
149 | }
150 |
151 | for (var i = 0; i < n; i++) {
152 | L[i][i] = -numeric.sum(L[i]) + ((i == 0) ? 1 : 0)
153 | }
154 |
155 | var divergent = d3.scaleLinear().domain([-0.1,0,0.1]).range(["#fc8d59", "#e6e600", "#99d594"]);
156 |
157 | var E = eigSym(L)
158 |
159 | var update = generateGraph(svg, data, 3, 0.43)
160 | var colors = []
161 | for (var i = 0; i < n; i++) {
162 | colors.push(divergent(E.U[34][i]))
163 | }
164 | update(colors)
165 |
166 |
167 | }
168 |
169 |
170 | function genExpander(svg) {
171 | var data = {"nodes": [], "links": []}
172 | var n = 36
173 | var L = zeros2D(n,n)
174 |
175 | for (var i = 0; i < n; i ++) {
176 | data.nodes.push({"id": i})
177 | }
178 |
179 | for (var i = 0; i < 80; i++){
180 | var s = Math.floor(random()*36);
181 | var t = Math.floor(random()*36)
182 | data.links.push({"source":s, "target": t})
183 | L[s][t] = -1
184 | L[t][s] = -1
185 | }
186 |
187 | for (var i = 0; i < n; i++) {
188 | L[i][i] = -numeric.sum(L[i]) + ((i == 0) ? 1 : 0)
189 | }
190 | var divergent = d3.scaleLinear().domain([-0.1,0,0.1]).range(["#fc8d59", "#e6e600", "#99d594"]);
191 |
192 | var E = eigSym(L)
193 | var update = generateGraph(svg, data, 20, 0.2)
194 | var colors = []
195 | for (var i = 0; i < n; i++) {
196 | colors.push(divergent(E.U[34][i]))
197 | }
198 | update(colors)
199 | }
200 |
201 |
--------------------------------------------------------------------------------
/public/assets/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
When " + MathCache("beta") + " is too small (e.g. in Gradient Descent, " + MathCache("beta-equals-zero") + "), we're over-damping. The particle is immersed in a viscous fluid which saps it of its kinetic energy at every timestep.",
22 | "
Critical Damping
The best value of " + MathCache("beta") + " lies in the middle of the two extremes. This sweet spot happens when the eigenvalues of " + MathCache("r") + " are repeated, when " + MathCache("beta-equals-one-minus") + ".",
23 | "
18 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
19 |
20 |
21 |
22 |
23 |
27 |
28 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
29 |
73 |
74 | The Rosenbrock banana function is famous for its pathological curvature. The landscapes are often described as a valleys, trenches, canals, ravines. In these steep valleys, gradient descent fumbles. But
75 |
76 |
24 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
25 |
26 |
119 |
120 |
366 |
367 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
368 |
17 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
18 |
19 |
20 |
21 |
22 |
23 |
92 |
93 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
94 |
18 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
19 |
20 |
21 |
22 |
23 |
24 |
25 |
91 |
92 |
93 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
94 |
18 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
19 |
20 |
21 |
22 |
23 |
85 |
86 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
87 |
25 | Instead of taking taking a step in the gradient, we move in a geometrically decaying superposition all the previous gradients. When $ \beta = 0 $ , we recover gradient descent. But for $ \beta = 0.99 $ (sometimes $ 0.999$, if things are really bad), the situation improves quite dramatically.
26 |
27 |
28 |
29 |
30 | Small world graphs, like expanders and dense graphs, have excellent conditioning
31 |
32 | The conditioning of grids improves with its dimensionality.
33 |
34 | And long, wiry graphs, like paths, condition poorly.
35 |
36 |
37 |
47 |
48 |
--------------------------------------------------------------------------------
/public/examples/hozbar_widget.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
19 |
20 |
21 |
22 |
23 |
59 |
60 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
61 |
16 | Instead of taking taking a step in the gradient, we move in a geometrically decaying superposition all the previous gradients. When $ \beta = 0 $ , we recover gradient descent. But for $ \beta = 0.99 $ (sometimes $ 0.999$, if things are really bad), the situation improves quite dramatically.
17 |
18 |
19 |
20 |
21 | Optimization can be seen as combination of several component problems, shown here as a b c
22 |
23 |
24 |
25 |
26 |
53 |
54 | Instead of taking taking a step in the gradient, we move in a geometrically decaying superposition all the previous gradients. When $ \beta = 0 $ , we recover gradient descent. But for $ \beta = 0.99 $ (sometimes $ 0.999$, if things are really bad), the situation improves quite dramatically.
55 |
56 |
32 | Instead of taking taking a step in the gradient, we move in a geometrically decaying superposition all the previous gradients. When $ \beta = 0 $ , we recover gradient descent. But for $ \beta = 0.99 $ (sometimes $ 0.999$, if things are really bad), the situation improves quite dramatically.
33 |
34 |
35 |
36 | We decompose the expected value of the objective value $\mathbf{E} f(w) - f(w^*)$ into a deterministic part and a stochastic part . The line depicts the point where the expected errors match.
37 | $\mathbf{E} f(w) - f(w^\star) $
38 |
Step-size α =
39 |
Momentum β =
40 |
41 |
42 |
43 |
44 |
80 |
81 | Instead of taking taking a step in the gradient, we move in a geometrically decaying superposition all the previous gradients. When $ \beta = 0 $ , we recover gradient descent. But for $ \beta = 0.99 $ (sometimes $ 0.999$, if things are really bad), the situation improves quite dramatically.
82 |
83 |
16 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
17 |
18 |
19 |
20 |
21 |
22 |
23 | Convergence Rate
24 |
25 |
26 |
27 |
28 | A plot of $\max{\sigma_1, \sigma_2}$ reveals distinct regions, each with its own style of convergence.
29 |
30 |
31 |
32 |
33 |
34 |
35 |
89 |
90 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
91 |
32 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
33 |
34 | You can resize the bounding box by clicking to place the cursor within the text, then dragging on one of the sizing handles around the perimeter of the bounding box. Shift-dragging a sizing handle will constrain the proportions of the bounding box. Make sure you don’t accidentally drag a sizing handle with the Selection tool, or you’ll scale the text, not its bounding box.
35 |
36 |
37 |
38 |
41 |
42 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
43 |
44 | You can resize the bounding box by clicking to place the cursor within the text, then dragging on one of the sizing handles around the perimeter of the bounding box. Shift-dragging a sizing handle will constrain the proportions of the bounding box. Make sure you don’t accidentally drag a sizing handle with the Selection tool, or you’ll scale the text, not its bounding box.
45 |
25 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
26 |
27 | You can resize the bounding box by clicking to place the cursor within the text, then dragging on one of the sizing handles around the perimeter of the bounding box. Shift-dragging a sizing handle will constrain the proportions of the bounding box. Make sure you don’t accidentally drag a sizing handle with the Selection tool, or you’ll scale the text, not its bounding box.
28 |
29 |
30 |
31 |
32 |
33 |
34 |
37 |
38 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
39 |
40 | You can resize the bounding box by clicking to place the cursor within the text, then dragging on one of the sizing handles around the perimeter of the bounding box. Shift-dragging a sizing handle will constrain the proportions of the bounding box. Make sure you don’t accidentally drag a sizing handle with the Selection tool, or you’ll scale the text, not its bounding box.
41 |
22 | Each row is a single iterate down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
23 |
72 | Hold down the left mouse button and drag in the Comp window to create a paragraph text block. The edge—the text’s bounding box— is defined by how far you dragged the mouse when you created the paragraph text layer. This style of text wraps text to the next line when your type reaches the edge of the current line.
73 |