# This writes a ton of postscript files
# load "READgnu"
# to do all of the ordinary 2d plots
#############################
############ This is a beautiful demo!
#############################
# load "langmc.gnu" 
#
# these are without and with nice arrows: 
# load "langmcps.gnu" 
# load "langmcps.gnu2" 
##################################
# weights in weight space
##################################

# set term X
# set noarrow 1
set xrange [-0.5:3] ; set nologs xy ; set yrange  [-0.5:3] ; set nokey 
set title
#  set xlabel "w1" ; set ylabel "w2" 
set format xy
# set size 0.55,0.7 
# set size 0.336,0.357 
# size small: 
load "gnu/pssquare"
set term post
set output "ps/wl.ps"
plot "wl" u 2:3 w d

set output "ps/wlwlwd01.ps"
plot "wl" u 2:3 w l 1, "wlwd01" u 2:3 w p 3 3

# NOTE that the wdecay 01 does simply stop early. that's all.

set term post
set output "ps/wlwlwd.ps"
plot "wl" u 2:3 w l 1, "wlwd" u 2:3 w p 3 3

# alpha = 1 
set term post
set output "ps/wlwlwd1.ps"
plot "wl" u 2:3 w l 1, "wlwd1" u 2:3 w p 3 3

# Langevin
##################################
# weights in weight space
################################## (uniform contains every 100th

set xrange [-1:4] ; set nologs xy ; set yrange  [-1:4] ; set nokey 
#  set xlabel "w1" ; set ylabel "w2" 
set autos xy
set term post
set output "ps/wlangwlwd01.ps"
# w p 2 2
plot "wlangmc.uniform" u 2:3 w d, "wlwd01" u 2:3 w l 1
# was linesp 3 3
set output "ps/wlanglinewlwd01.ps"
plot "wlangmc.uniform" u 2:3 w linesp 1 2
# , "wlwd01" u 2:3 w linesp 3 3

# hmc
##############
set xrange [0:5.2] ; set nologs xy ; set yrange  [-2:4] ; set nokey 
set term post
set output "ps/whmcwlwd01.ps"
# w p 2 2
plot "whmc" u 2:3 w d, "wlwd01" u 2:3 w l 1
# was linesp 3 3
set output "ps/whmclinewlwd01.ps"
plot "whmc" u 2:3 w linesp 1 2

# hmc up to 10000 only
##############
set xrange [-1:4] ; set nologs xy ; set yrange  [-1:4] ; set nokey 
set autos xy
set term post
set output "ps/whmc10000wlwd01.ps"
# w p 2 2
plot "whmc.1.10000" u 2:3 w d, "wlwd01" u 2:3 w l 1
# was linesp 3 3
set output "ps/whmc10000linewlwd01.ps"
plot "whmc.1.10000" u 2:3 w linesp 1 2

# lang up to 10000 only
##############
set xrange [-1:4] ; set nologs xy ; set yrange  [-1:4] ; set nokey 
set autos xy
set term post
set output "ps/wlang10000wlwd01.ps"
# w p 2 2
plot "wlangmc.uniform" u 2:3 w d, "wlwd01" u 2:3 w l 1
# was linesp 3 3
set output "ps/wlang10000linewlwd01.ps"
plot "wlangmc.uniform" u 2:3 w linesp 1 2


# weights with a Gaussian approximation 
m11 = 0.774308; m12 =   0.057637 ; m21 =   0.057637; m22 =  0.889698
set parametric
set output "ps/wwwgaussian.ps"
plot "wlangmc.uniform" u 2:3 w d, "wlwd01" u 2:3 w l 1,  (1.2283+m11*sin(t)+m12*cos(t)),( 0.84162+m21*sin(t)+m22*cos(t)) w l 2,  (1.2283+2*m11*sin(t)+2*m12*cos(t)),( 0.84162+2*m21*sin(t)+2*m22*cos(t)) w l 2

set output "ps/wwgaussian.ps"
plot "wlwd01" u 2:3 w l 1,  (1.2283+m11*sin(t)+m12*cos(t)),( 0.84162+m21*sin(t)+m22*cos(t)) w l 2,  (1.2283+2*m11*sin(t)+2*m12*cos(t)),( 0.84162+2*m21*sin(t)+2*m22*cos(t)) w l 2

set noparametric

##################################
# weights versus time 
##################################

# size medium: 
load "gnu/pssquaremed"
set term post
set output "ps/wltime.ps"
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set key 20,-4
 plot "wl" u 4:1 t "w0" w l, "wl" u 4:2 t "w1" w l, "wl" u 4:3 t "w2" w l 
#
set output "ps/wltimelog.ps"
set logs x
set xlabel ; set ylabel ; set autos xy ;  set key 20,-4 ; set yrange [-12:3]
 plot "wl" u 4:1 t "w0" w l, "wl" u 4:2 t "w1" w l, "wl" u 4:3 t "w2" w l 

# interesting times are: 30 , 80 , 500 , 3000 , 40000

# alpha = 0.1 
set nologs xy ; set autos xy 
set xlabel ; set ylabel ;   set key 20,-2; set yrange [-5:2]
set term post
set output "ps/wlwdtime.ps"
plot "wlwd" u 4:1 t "w0" w l, "wlwd" u 4:2 t "w1" w l, "wlwd" u 4:3 t "w2" w l 
set logs x
set output "ps/wlwdtimelog.ps"
plot "wlwd" u 4:1 t "w0" w l, "wlwd" u 4:2 t "w1" w l, "wlwd" u 4:3 t "w2" w l 
# alpha = 0.01 
set nologs xy
set xlabel ; set ylabel ;   set key 20,-4; set yrange [-12:3]
set term post
set output "ps/wlwd01time.ps"
plot "wlwd01" u 4:1 t "w0" w l, "wlwd01" u 4:2 t "w1" w l, "wlwd01" u 4:3 t "w2" w l 
set logs x
set output "ps/wlwd01timelog.ps"
plot "wlwd01" u 4:1 t "w0" w l, "wlwd01" u 4:2 t "w1" w l, "wlwd01" u 4:3 t "w2" w l 
# alpha = 1
set nologs xy
set xlabel ; set ylabel ;   set key 20,-2; set yrange [-5:2]
set term post
set output "ps/wlwd1time.ps"
plot "wlwd1" u 4:1 t "w0" w l, "wlwd1" u 4:2 t "w1" w l, "wlwd1" u 4:3 t "w2" w l 
set logs x
set output "ps/wlwd1timelog.ps"
plot "wlwd1" u 4:1 t "w0" w l, "wlwd1" u 4:2 t "w1" w l, "wlwd1" u 4:3 t "w2" w l 
#
##################################
# weights versus time  (langevin)
##################################
set term post
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set nokey ;  set xtics 0,10000,40000
set output "ps/wlangtime.ps"
 plot "wlangmc" u 4:1 t "w0" w l 1, "wlangmc" u 4:2 t "w1" w l 1, "wlangmc" u 4:3 t "w2" w l 1
set xtics 
set output "ps/wlangtimelog.ps"
set logs x
# ;  set key 10,-5
replot

set term post
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set nokey ;  set xtics 0,10000,40000
set output "ps/wlangwd01time.ps"
 plot "wlangmc" u 4:1 t "w0" w l 1, "wlangmc" u 4:2 t "w1" w l 1, "wlangmc" u 4:3 t "w2" w l 1 ,"wlwd01" u 4:1 t "w0" w l 2 2, "wlwd01" u 4:2 t "w1" w l 2 2, "wlwd01" u 4:3 t "w2" w l  2 2
set xtics 
set output "ps/wlangwd01timelog.ps"
# ;  set key 10,-5
set logs x
replot

# zoom in on details
#
load "gnu/pslong"
set term post
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set nokey ;  set xtics 
set output "ps/wlangtime.1.10000.ps"
set xrange [0:10000]
 plot "wlangmc.uniform" u 4:1 t "w0" w l 1, "wlangmc.uniform" u 4:2 t "w1" w l 1, "wlangmc.uniform" u 4:3 t "w2" w l 1
set output "ps/wlangtime.10.20000.ps"
set xrange [10000:20000]
replot
load "gnu/pssquaremed"

##################################
# weights versus time  (hmc)
##################################
set term post
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set nokey ;  set xtics 0,10000,40000
set output "ps/whmctime.ps"
set xrange [0:40000]
 plot "whmc" u 10:1 t "w0" w l 1, "whmc" u 10:2 t "w1" w l 1, "whmc" u 10:3 t "w2" w l 1
set xtics 
set output "ps/whmctimelog.ps"
set logs x
# ;  set key 10,-5
set xrange [1:100000]
replot

set term post
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set nokey ;  set xtics 0,10000,40000
set output "ps/whmcwd01time.ps"
set xrange [0:40000]
 plot "whmc" u 10:1 t "w0" w l 1, "whmc" u 10:2 t "w1" w l 1, "whmc" u 10:3 t "w2" w l 1 ,"wlwd01" u 4:1 t "w0" w l 2 2, "wlwd01" u 4:2 t "w1" w l 2 2, "wlwd01" u 4:3 t "w2" w l  2 2
set xtics 
set output "ps/whmcwd01timelog.ps"
# ;  set key 10,-5
set logs x
set xrange [1:100000]
replot

# zoom in on details
#
load "gnu/pslong"
set term post
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set nokey ;  set xtics 
set output "ps/whmctime.1.10000.ps"
set xrange [0:10000]
 plot "whmc" u 10:1 t "w0" w l 1, "whmc" u 10:2 t "w1" w l 1, "whmc" u 10:3 t "w2" w l 1
set output "ps/whmctime.10.20000.ps"
set xrange [10000:20000]
 replot
load "gnu/pssquaremed"

##############################
# G versus time
##############################
#
# new geometry
# set size 0.7,0.6 
set term post
set output "ps/Gtime.ps"
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set key 
set yrange [0:7]
 plot "wl" u 4:5 t "G(w)" w l
set output "ps/Gtimelog.ps"
set logs x
replot

##############################
# EW versus time
##############################
set term post
set output "ps/EWtime.ps"
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set key 30000,200
 plot "wl" u 4:6 t "E_W(w)" w l
set output "ps/EWtimelog.ps"
set logs x ; set key 100,300
replot

##############################
# G and M versus time
##############################
set term post
set output "ps/GMwd01time.ps"
set nologs xy 
set xlabel ; set ylabel ; set autos xy ;  set key ; set yrange [0:7] ; set xtics
 plot "wlwd01" u 4:5 t "G(w)" w l , "wlwd01" u 4:7 t "M(w)" w l
#
set output "ps/GMwd01timelog.ps"
set logs x
replot

# G and M versus time
set term post
set output "ps/GMwdtime.ps"
set nologs xy
set xlabel ; set ylabel ; set autos xy ;  set key ; set yrange [0:7]
 plot "wlwd" u 4:5 t "G(w)" w l , "wlwd" u 4:7 t "M(w)" w l
#
set output "ps/GMwdtimelog.ps"
set logs x
replot

# G and M versus time
set term post
set output "ps/GMwd1time.ps"
set nologs xy 
set xlabel ; set ylabel ; set autos xy ;  set key ; set yrange [0:7]
 plot "wlwd1" u 4:5 t "G(w)" w l , "wlwd1" u 4:7 t "M(w)" w l
#
set output "ps/GMwd1timelog.ps"
set logs x
replot

# langevin
# G and M versus time. I think I want to show G,G and M,M separately
#
set term post ; set xtics 0,10000,40000
set output "ps/Gwlangwd01time.ps"
set nologs xy 
set xlabel ; set ylabel ; set autos xy ;  set key ; set yrange [0:14]
plot  "wlangmc" u 4:5 t "G(w) - Langevin" w l 1 1, "wlwd01" u 4:5 t "G(w) - optimizer" w l 2 2
 set yrange [0:12]
set output "ps/Mwlangwd01time.ps"
plot "wlangmc" u 4:7 t "M(w) - Langevin" w l, "wlwd01" u 4:7 t "M(w) - optimizer" w l 2 2 
#
set output "ps/Mwlangwd01timelog.ps"
set logs x ; set key 200,2 ; set xtics
replot
set output "ps/Gwlangwd01timelog.ps"
 set yrange [0:14]
 set key 200,2 
plot  "wlangmc" u 4:5 t "G(w) - Langevin" w l 1 1, "wlwd01" u 4:5 t "G(w) - optimizer" w l 2 2

# hmc
# G and M versus time. I think I want to show G,G and M,M separately
#
set term post ; set xtics 0,10000,40000
set output "ps/Gwhmcwd01time.ps"
set nologs xy 
set xlabel ; set ylabel ; set autos xy ;  set key ; set yrange [0:14]
set xrange [0:40000]
plot  "whmc" u 10:5 t "G(w) - HMC" w l 1 1, "wlwd01" u 4:5 t "G(w) - optimizer" w l 2 2
 set yrange [0:12]
set output "ps/Mwhmcwd01time.ps"
plot "whmc" u 10:7 t "M(w) - HMC" w l, "wlwd01" u 4:7 t "M(w) - optimizer" w l 2 2 
#
set output "ps/Mwhmcwd01timelog.ps"
set logs x ; set key 200,2 ; set xtics ; set autos x
replot
set output "ps/Gwhmcwd01timelog.ps"
 set yrange [0:14]
 set key 200,2 
plot  "whmc" u 10:5 t "G(w) - HMC" w l 1 1, "wlwd01" u 4:5 t "G(w) - optimizer" w l 2 2

# interesting times are: 30 , 80 , 500 , 3000 , 40000

 set xrange [0:10] ; set yrange [0:10];  set nokey ; set xlabel ; set ylabel ; set nologs xy 
# set size 0.56,0.7
# restore small square geometry ... 
load "gnu/pssquare"
set term post
set output "ps/dat01.ps"
 plot "dat0" u 2:3 w p 3 3, "dat1" u 2:3 w p 6 6

###  functions in x-space
########################################

# after 30 iterations
set output "ps/dw30.ps"
set arrow 1 from   3.1332,  3.7202 to   3.8174,  3.2303
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - (-0.33751) - ( 0.34206) * x )/(-0.24495)  w l 1 , ( (       1) - (-0.33751) - ( 0.34206) * x )/(-0.24495)  w l 2 , ( - (       1) - (-0.33751) - ( 0.34206) * x )/(-0.24495)  w l 2 

# after 80 iterations
set output "ps/dw80.ps"
set arrow 1 from   4.5371,   5.318 to   5.4817,  4.7009
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - (-0.82026) - ( 0.47229) * x )/(-0.30855)  w l 1 , ( (       1) - (-0.82026) - ( 0.47229) * x )/(-0.30855)  w l 2 , ( - (       1) - (-0.82026) - ( 0.47229) * x )/(-0.30855)  w l 2 

# after 500 iterations
set output "ps/dw500.ps"
set arrow 1 from   4.5442,  5.1599 to   5.8277,   5.212
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - ( -3.4631) - ( 0.64175) * x )/(0.026041)  w l 1 , ( (       1) - ( -3.4631) - ( 0.64175) * x )/(0.026041)  w l 2 , ( - (       1) - ( -3.4631) - ( 0.64175) * x )/(0.026041)  w l 2 

# after 3000 iterations
set output "ps/dw3000.ps"
set arrow 1 from   4.0799,  4.4991 to   6.2452,   5.826
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - ( -9.0144) - (  1.0827) * x )/( 0.66345)  w l 1 , ( (       1) - ( -9.0144) - (  1.0827) * x )/( 0.66345)  w l 2 , ( - (       1) - ( -9.0144) - (  1.0827) * x )/( 0.66345)  w l 2 

# after 10000 iterations"
set output "ps/dw10000.ps"
set arrow 1 from   3.5183,   3.835 to   6.7932,  6.4765
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 5 6 , ( - ( -15.252) - (  1.6375) * x )/(  1.3208)  w l 1 , ( (       1) - ( -15.252) - (  1.6375) * x )/(  1.3208)  w l 2 , ( - (       1) - ( -15.252) - (  1.6375) * x )/(  1.3208)  w l 2

# after 40000 iterations
set output "ps/dw40000.ps"
set arrow 1 from   2.4248,  2.5373 to   7.9269,  7.8144
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - ( -27.895) - (   2.751) * x )/(  2.6385)  w l 1 , ( (       1) - ( -27.895) - (   2.751) * x )/(  2.6385)  w l 2 , ( - (       1) - ( -27.895) - (   2.751) * x )/(  2.6385)  w l 2 

# functions performed by weight decay solutions
set term post
# Note this shows a bias:
set output "ps/dwd40000.0.1.ps"
set arrow 1 from   4.5028,  5.0585 to   5.8291,  5.2734
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - ( -3.9809) - ( 0.66313) * x )/( 0.10748)  w l 1 , ( (       1) - ( -3.9809) - ( 0.66313) * x )/( 0.10748)  w l 2 , ( - (       1) - ( -3.9809) - ( 0.66313) * x )/( 0.10748)  w l 2 

#
set output "ps/dwd40000.0.01.ps"
set arrow 1 from   3.9292,  4.3159 to   6.3859,  5.9992
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - ( -10.676) - (  1.2283) * x )/( 0.84162)  w l 1 , ( (       1) - ( -10.676) - (  1.2283) * x )/( 0.84162)  w l 2 , ( - (       1) - ( -10.676) - (  1.2283) * x )/( 0.84162)  w l 2 

set output "ps/dwd40000.1.ps"
set arrow 1 from   4.2267,  4.8409 to   5.0359,  4.4217
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - (-0.90305) - ( 0.40458) * x )/( -0.2096)  w l 1 , ( (       1) - (-0.90305) - ( 0.40458) * x )/( -0.2096)  w l 2 , ( - (       1) - (-0.90305) - ( 0.40458) * x )/( -0.2096)  w l 2 

# add in AB labels
load "gnu/ABon"
set output "ps/dwd40000.0.01.AB.ps"
set arrow 1 from   3.9292,  4.3159 to   6.3859,  5.9992
plot 'dat0' u 2:3 w p 3 3, 'dat1' u 2:3 w p 6 6 , ( - ( -10.676) - (  1.2283) * x )/( 0.84162)  w l 1 , ( (       1) - ( -10.676) - (  1.2283) * x )/( 0.84162)  w l 2 , ( - (       1) - ( -10.676) - (  1.2283) * x )/( 0.84162)  w l 2 
load "gnu/ABoff"

set noarrow 1

set parametric
set contour
set view 0,0,
set nosurface
set cntrparam levels discrete 0.119,0.269,0.5,0.731,0.881 
set nokey 
set size  0.5,0.7 
set xrange [0:10] ; set yrange[0:10]
set autos z
set term post
set output "ps/predlangavg.ps"
 splot "langavg.dat" u 1:2:3 w lines
set output "ps/predmap.ps"
 splot "langavg.dat" u 1:2:4 w lines

# marg using the laplace method / Gaussian approx
set output "ps/predgaussian.ps"
splot "margo" u 1:2:7 w lines



set surface ; set nocontour 
set output "ps/preddata.ps"
splot "dat0" u 2:3:1 w p 3 3,"dat1" u 2:3:1 w p 6 6

# add in A and B
load "gnu/ABon"
set output "ps/preddata.AB.ps"
splot "dat0" u 2:3:1 w p 3 3,"dat1" u 2:3:1 w p 6 6
load "gnu/ABoff"
set noparametric