////////////////////////////////////////////////////////////////////////////////
//
// Advanced setting.
//
// You probably do not want to change most of these.
//
// Parameters which you are most likely to need to change are marked 
// CHANGE THIS
//
// Note that if a variable is set twice, the last setting takes precedence.
//
// Comments in this section should be read in conjunction with the paper, 
// online methods and supplementary material.
//
// Any line starting with // is a comment and is ignored by the
// plugin.


////////////////////////////////////////////////////////////////////////////////
//
// Things you might want to change are below here
//

//Random seed for the Monte-Carlo process.
//Changing this value will change the random numbers which are generated.
//Please refer to the user manual section "Iterations and run time" for
//further discussion.
seed=0

////////////////////////////////////////////
//
// Spot intensity priors. You can probably leave this as-is unless your
// fluorophores are very much brighter compared to the noise than the ones
// in the paper. See "Modelling the image" in Supplementary Note 1.
//
// See here for definitions of mu and sigma:
// http://en.wikipedia.org/wiki/Log-normal_distribution
//
// Note that these values are for the spot brightness once the image
// has been normalised to have unit standard deviation so these should
// not be changed unless your images are very significantly less noisy
// than the data presented in the paper.
//
intensity.rel_mu=2
intensity.rel_sigma=1


////////////////////////////////////////////
//
// Spot shape priors. CHANGE THIS
//
// This specifies the log-normal distribution for the prior over spot
// radius. This is specified in pixels, not nm.

//Corresponds to 300nm at 100nm per pixel
blur.mu=0.242
blur.sigma=0.1

//Corresponds to 300nm at 160nm per pixel
blur.mu=-0.218
blur.sigma=0.1

//Corresponds to 270nm at 79nm per pixel
//blur.mu=0.37261
//blur.sigma=0.1


//Number of spots. CHANGE THIS
//
//15 is suitable for a small image patch, such as the example in the
//help menu.
//
//If you set this too high, the system will run very slowly.
placement.uniform.num_spots=15



////////////////////////////////////////////////////////////////////////////////
//
// You probably do not want to change anything below here.
//


//Transition matrix and initial probabilities

// Following the notation in [24], A represents the transition
// probabilities of the HMM and pi the initial state. A corresponds
// to Supplementary Figure 4 as:
//    A = [ P1 P2 0; P3 P4 P5; 0 0 1]
// These are used in the inner integral of eq 7.

A=[0.16 0.84 0; 0.495 0.495 0.01; 0 0 1]
pi=[.5 .5 0]



//////////////////////////////////////////////////
//
//General parameters

// All MCMC systems can use mixing samples[28], which are drawn by
// by the sampler but do not take part in further computations. 
// For every mixing_iterations samples drawn 1 is uses, so
// mixing_iterations=1 corresponds to no mixing.

//Number of mixing iterations used by all Gibbs samplers in this algorithm.
gibbs.mixing_iterations=1



//////////////////////////////////////////////////
//
//Specific subsystem parameters


////////////////////////////////////////
//
// Main optimization - step 2 of the algorithm

//maximum l_inf of motion vector during optimization stage.
//See step 2 of the algorithm,
cg.max_motion=0.5

//Scale the maximum step in brightness according to the prior shape
//The reason is that the brightness is a very different scale from
//the spot position and shape, so the optimizer will get stuck
//taking many tiny steps in the direction of brightness.
//
//If this is set to 0 then no scaling is used.
//
//If it is set to 1, then scale by the brighness step by the standard
//deviation of the prior distribution.
max_motion.use_brightness_std=1

//Maximum number of iterations of conjugate gradient optimization
//See [29] for a description of an iteration in this context.
main.cg.max_iterations=5

//Number of samples used for computing gradient using hybrid method.
//This corresponds to S, as applied to step 2 of the algorithm.
main.gibbs.samples=10

//Number of passes of optimization in step 2 to be completed before
//advancing to step 3.
main.passes=4


//Stop the optimization if this many consecutive iterations
//have empty models (no spots). For 0 or less, it never stops
//on this criterion. 1 will stop at the first empty iteration.
main.consecutive_empty_models=0

///This is the minimum size for empty models
///At N or fewer spots, the model is considered to be empty.
main.empty_model.max_size=3


//Which version of the optimization to use:
//1 Version of the code used for NatMeth paper
//2 Bug fixed version.
//There is almost certainly no need to use 1 any more since it is
//substantially less efficient.
main.optimization_version=2

//Allow spots to be at most this far outside the marked region
//Anything further outside will be removed automatically.
position.extra_radius=2.3

////////////////////////////////////////
//
// Add/remove spots - step 3 of the algorithm

//When computing Z, in step 3a and 3c, use a uniform position prior (to
//make spot probability a proper distribution). If this is set to 0, then
//no position prior is used. Do not set to 0 except for debugging.
position.use_prior=1

//Number of samples used to compute the gradient usint the 
//hybrid method, as applied to step 3c.
add_remove.optimizer.samples=20

//The optimizer can get stuck on saddle points. If a saddle point
//is found, the the optimizer will restart in the direction corresponding
//to the worst eigen value. Up to this many restarts will be attempted before
//gving up. Step 3c.
add_remove.optimizer.attempts=10

//There is no efficient algorithm for evaluating the Hessian (equivalent
//to the inner integral in Eq 6, but for second derivatives). The integral 
//is approximated using Monte-Carlo integration (note, not MCMC), with this
//many samples drawn from the Markov chain using FFBS.
//
//The outer summation uses add_remove.optimizer.samples samples.
add_remove.optimizer.hessian_inner_samples=1000

//Number of cycles of thermodynamic integration  (step 3a and 3c) and 
//eq 2.
//Note that the equation 1.25^(i/10) only applies if this number is set 
//to 1000 as it was for all experiemnts in the paper. The actual equation is:
//1.25^(100 * i/add_remove.thermo.samples)
add_remove.thermo.samples=1000

//Outer and inner samples for computing the Hessian using the hybrid method
//in step 3e.
//
//See add_remove.optimizer.hessian_inner_samples for an explanation of the
//meaning.
add_remove.hessian.outer_samples=100
add_remove.hessian.inner_samples=1000

//Number of repeats of step 3.
add_remove.tries=10


//////////////////////////////////////////////////
//
// Image preprocessing.
//
// See "Modelling the image" in supplementary methods.
// The image is normalized to locally zero mean and globally unit standard
// deviation.

// Skip the mean removal step if this is set to 1. 
// This is really only for debugging. Do not change.
preprocess.skip=0

//Low pass filter used for mean removal has has this sigma
preprocess.lpf=5



//////////////////////////////////////////////////
//
// Initial spot placement.
//

//Options are: 
//  uniform (place spots uniformly over the area of interest)
//  intensity_sampled  (place spots more densely in brighter regions)
//intensity_sampled generally leads to slightly faster convergence.
placement=intensity_sampled



////////////////////////////////////////////////////////////////////////////////
//
// Things after here do not do anything.
//
// Things after here have no effect in the plugin, but are required if
// this config file is to be used in the standalone program
//

//Instead of calculating the scaling of the initial image to set the
//standard deviation to 1, use a fixed scaling. This is for debugging
//purposes and is very unlikely to be useful otherwise.
preprocess.fixed_scaling=0

//Threshold the log_ratios image at this level in order to find
//regions for analysis.
threshold=0

//Dilate regions found by thresholding by this radius.
radius=0

//Analyse marked region number 19:
cluster_to_show=19

//If this is set to 1, cluster_to_show is ignored and the largest
//region is used instead.
use_largest=1


