Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
+ demoTree (ok)
Browse files Browse the repository at this point in the history
  • Loading branch information
T. Lienart authored and T. Lienart committed Jun 17, 2015
1 parent 2b9baff commit e6a8405
Showing 1 changed file with 116 additions and 44 deletions.
160 changes: 116 additions & 44 deletions demo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ include("lib_pbp.jl")
include("lib_ep.jl")
include("lib_doSim.jl")
#
demoNames = ["demoGrid","demoChain","demoImg"]
expname = demoNames[1] # choice of demo (reason for this syntax is to show possibilities)
demoNames = ["demoGrid","demoTree","demoImg","demoChain"]
expname = demoNames[2] # choice of demo (reason for this syntax is to show possibilities)
# make directory to store stuff
if ~isdir(expname)
mkdir(expname)
end
#
# ==================================================================================================
if expname == "demoGrid"
Expand Down Expand Up @@ -83,77 +87,72 @@ if expname == "demoGrid"
s_init = 4*obs_var
end
# ==================================================================================================
elseif expname == "demoChain"
elseif expname == "demoTree"
#
# SIMULATIONS TO BE RUN
#
RELOAD = true # re-generate everything
LBPD = true # LBP on deterministic grid
EPBP = true # EPBP
FEPBP = false # Fast-EPBP
PBP = false # PBP with MH sampling
EP = true # straight EP
PBP = true # PBP with MH sampling
EP = false # straight EP
#
# VERBOSITY
NODE_PROGRESS = false
#
# SIMULATION PARAMETERS [!USER!]
#
Nlist = [100,200] # (list) number of particles per node
Clist = [7,10] # (list) number of components for FEPBP, need to be of same dim as NLIST
Nlist = [100] # (list) number of particles per node
Clist = [7] # (list) number of components for FEPBP, need to be of same dim as NLIST
Ninteg = 30 # number of integration points for EP proj
Ngrid = 200 # number of points in the discretization
nloops = 10 # number of loops through scheduling
nEPloops = 25 # number of EP iterations
nruns = 1 # number of time we run the whole thing
#
# EP PROJECTION MODE, default is KL ignoring update if moments not valid.
# EP PROJECTION MODE, default is KL ignoring update if moments not valid
EP_PROJ_MLE = false # use MLE projection instead of KL-EP
#
# Additional parameters for PBP
#
MHIter = 20 # number of MH iterations
MHProposal = Normal(0,.1) # form of the MH proposal
MHProposal = Normal(0,1) # form of the MH proposal
PARACHAINS = true
#
# DECLARE GM
#
T = 5
nnodes,nedges,edge_list = gm_chain(T)
# > declare scheduling
scheduling = gm_chain_scheduling(T,true) # forward only
nnodes,nedges = 8,7
edge_list = [ 1 2; 1 3; # top 1-{2,3}
2 1; 2 4; 2 5; 2 6; 3 1; 3 7; 3 8; # middle 2-{1,4,5,6} and 3-{1,7,8}
4 2; 5 2; 6 2; 7 3; 8 3; ] # leaves 4-2,5-2,6-2,7-3,8-3
sched1 = hcat(1,2,4,5,6,3,7,8)
sched2 = hcat(4,5,6,2,7,8,3,1)
scheduling = vcat(sched1[:],sched2[:])
# > declare edge and node potential
HOMOG_EDGE_POT = false # if edge pot is symmetric & the same everywhere (eg: image)
#
node_noise = Normal(0,2)
node_mult = 0.7
edge_noise = Normal(0,1)
edge_mult = 0.5
#
eval_edge_pot(from,to,xfrom,xto) = pdf(edge_noise,xto-edge_mult*xfrom)
eval_node_pot(node,xnode) = pdf(node_noise,obs_values[node]-node_mult*xnode)
#
# > sampling from MH?
HOMOG_EDGE_POT = true # edge pot is symmetric & same everywhere (eg: image)
# > side functions to define edge/node potential
node_potential = MixtureModel([Normal(-2,1),Gumbel(1,1.5)],[0.7,0.3])
edge_potential = Cauchy(0,1)
# > definition of edge/node potential functions
eval_edge_pot(from,to,xfrom,xto) = pdf(edge_potential,xfrom-xto)
eval_node_pot(node,xnode) = pdf(node_potential,obs_values[node]-xnode)
# > (PBP) sampling from MH?
sampleMHP(old) = old+rand(MHProposal,N)'
LMHCHAIN = 1000
ENDCHUNK = 300
sampleMHP2(old) = old+rand(Normal(0,0.1),1)
# > initial values on the graph
orig_values = zeros(nnodes,1) + 2
#
est_range = (-10,10) # > estimated 1D-range for integration
est_range = (-7,7) # > estimated 1D-range for integration
sigma_thresh = 0.01
# > generate observations
if RELOAD
orig_values = zeros(nnodes,1)
obs_values = zeros(nnodes,1)
#
orig_values[1] = rand(Normal(0,1))
obs_values[1] = rand(Normal(node_mult*orig_values[1],1))
#
for node=2:T
orig_values[node] = rand(Normal(edge_mult*orig_values[node-1],2))
obs_values[node] = rand(Normal(node_mult*orig_values[node],1))
end
# > generate observations
obs_values = orig_values + rand(node_potential,nnodes)
writecsv("$expname/$expname\_orig_values.dat",orig_values)
writecsv("$expname/$expname\_obs_values.dat",obs_values)
#
# > to start
obs_var = sqrt(var(obs_values))
s_init = 4*obs_var
end
Expand All @@ -165,9 +164,9 @@ elseif expname == "demoImg"
RELOAD = false # re-generate everything
LBPD = false # LBP on deterministic grid
EPBP = false # EPBP
FEPBP = true # Fast-EPBP
FEPBP = true # Fast-EPBP
PBP = false # PBP with MH sampling
EP = false # straight EP
EP = false # straight EP
#
# VERBOSITY
NODE_PROGRESS = false
Expand Down Expand Up @@ -236,16 +235,89 @@ elseif expname == "demoImg"
function eval_node_pot(node,xnode)
return pdf(node_potential,obs_values[node]-xnode)
end
# ==================================================================================================
elseif expname == "demoChain"
#
# SIMULATIONS TO BE RUN
#
RELOAD = true # re-generate everything
LBPD = true # LBP on deterministic grid
EPBP = true # EPBP
FEPBP = false # Fast-EPBP
PBP = false # PBP with MH sampling
EP = true # straight EP
#
# VERBOSITY
NODE_PROGRESS = false
#
# SIMULATION PARAMETERS [!USER!]
#
Nlist = [100,200] # (list) number of particles per node
Clist = [7,10] # (list) number of components for FEPBP, need to be of same dim as NLIST
Ninteg = 30 # number of integration points for EP proj
Ngrid = 200 # number of points in the discretization
nloops = 10 # number of loops through scheduling
nEPloops = 25 # number of EP iterations
nruns = 1 # number of time we run the whole thing
#
# EP PROJECTION MODE, default is KL ignoring update if moments not valid.
EP_PROJ_MLE = false # use MLE projection instead of KL-EP
#
# Additional parameters for PBP
#
MHIter = 20 # number of MH iterations
MHProposal = Normal(0,.1) # form of the MH proposal
PARACHAINS = true
#
# DECLARE GM
#
T = 5
nnodes,nedges,edge_list = gm_chain(T)
# > declare scheduling
scheduling = gm_chain_scheduling(T,true) # forward only
# > declare edge and node potential
HOMOG_EDGE_POT = false # if edge pot is symmetric & the same everywhere (eg: image)
#
node_noise = Normal(0,2)
node_mult = 0.7
edge_noise = Normal(0,1)
edge_mult = 0.5
#
eval_edge_pot(from,to,xfrom,xto) = pdf(edge_noise,xto-edge_mult*xfrom)
eval_node_pot(node,xnode) = pdf(node_noise,obs_values[node]-node_mult*xnode)
#
# > (PBP) sampling from MH?
sampleMHP(old) = old+rand(MHProposal,N)'
LMHCHAIN = 1000
ENDCHUNK = 300
sampleMHP2(old) = old+rand(Normal(0,0.1),1)
#
est_range = (-10,10) # > estimated 1D-range for integration
sigma_thresh = 0.01
# > generate observations
if RELOAD
orig_values = zeros(nnodes,1)
obs_values = zeros(nnodes,1)
#
orig_values[1] = rand(Normal(0,1))
obs_values[1] = rand(Normal(node_mult*orig_values[1],1))
#
for node=2:T
orig_values[node] = rand(Normal(edge_mult*orig_values[node-1],2))
obs_values[node] = rand(Normal(node_mult*orig_values[node],1))
end
writecsv("$expname/$expname\_orig_values.dat",orig_values)
writecsv("$expname/$expname\_obs_values.dat",obs_values)
#
# > to start
obs_var = sqrt(var(obs_values))
s_init = 4*obs_var
end
end

#
# ======== RUN SIMULATIONS =========================================================================
#
# make directory to store stuff
if ~isdir(expname)
mkdir(expname)
end
#
integ_pts = linspace(est_range[1],est_range[2],Ninteg)' # ! leave the transpose
grid = linspace(est_range[1],est_range[2],Ngrid)'
# > generate observations
Expand Down

0 comments on commit e6a8405

Please sign in to comment.