\hypertarget{classFitSpots}{
\subsection{FitSpots Class Reference}
\label{classFitSpots}\index{FitSpots@{FitSpots}}
}


Mega class which actually does the meat of the spot fitting.  


\subsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{classFitSpots_a11861f227350c3629e60ee4ff2922c70}{FitSpots} (const vector$<$ Image$<$ float $>$ $>$ \&ims\_\-, \hyperlink{classFitSpotsGraphics}{FitSpotsGraphics} \&graphics\_\-, \hyperlink{classUserInterfaceCallback}{UserInterfaceCallback} \&ui\_\-, \hyperlink{structStateParameters}{StateParameters} \&params, ofstream \&save\_\-spots\_\-)
\item 
void \hyperlink{classFitSpots_a98d3369e6efc05a3a98bff9b4251b07c}{optimize\_\-each\_\-spot\_\-in\_\-turn\_\-for\_\-several\_\-passes} ()
\item 
void \hyperlink{classFitSpots_a3241207417f3813e58819596759cf019}{try\_\-modifying\_\-model} ()
\item 
void \hyperlink{classFitSpots_ababf8023f16926f09b7b513d99adff58}{run} ()
\end{DoxyCompactItemize}
\subsubsection*{Private Attributes}
\begin{DoxyCompactItemize}
\item 
const vector$<$ Image$<$ float $>$ $>$ \& \hyperlink{classFitSpots_af02e3dbc54b1ef30884cca1d8222e2fd}{ims}
\item 
\hyperlink{classFitSpotsGraphics}{FitSpotsGraphics} \& \hyperlink{classFitSpots_a44244a8d258dfc635e3904d6f86467fd}{graphics}
\item 
\hyperlink{classUserInterfaceCallback}{UserInterfaceCallback} \& \hyperlink{classFitSpots_aff7da5d4fb18ea492292af48d26e4a22}{ui}
\item 
const vector$<$ ImageRef $>$ \hyperlink{classFitSpots_a5444540b5ee77316e01a54ca2857e3a5}{pixels}
\item 
vector$<$ Vector$<$ 4 $>$ $>$ \hyperlink{classFitSpots_a8146e133fda55f682bc595d8ff83cd7a}{spots}
\item 
const int \hyperlink{classFitSpots_a34e584e04c28a8000bb3ad666a438da9}{start\_\-iteration}
\item 
int \hyperlink{classFitSpots_ab2b156b543081cb65d64d4c5bbf6e49d}{start\_\-pass}
\item 
\hyperlink{structMT19937}{MT19937} \& \hyperlink{classFitSpots_ae492e32e8d98e94ec13f83f6f6eb68a3}{rng}
\item 
const double \hyperlink{classFitSpots_a6873890b1fbb895dd6c4f02b5996a148}{variance}
\item 
const double \hyperlink{classFitSpots_ae48f3c3b3173e1f38226f4c0de9bf83e}{intensity\_\-mu}
\item 
const double \hyperlink{classFitSpots_a0cb9fa2711420af796ac6f3bad9615f3}{intensity\_\-sigma}
\item 
const double \hyperlink{classFitSpots_a72f1fd5086c406b2d3b40a82807ee57d}{blur\_\-mu}
\item 
const double \hyperlink{classFitSpots_a97e382de148a18e7f95be5132e26b8e8}{blur\_\-sigma}
\item 
const double \hyperlink{classFitSpots_ae898a7937d08e4d8b41cd6ee52795bb6}{area\_\-extra\_\-radius}
\item 
set$<$ ImageRef $>$ \hyperlink{classFitSpots_a62abd352dd1ad8d1bd5adba0c50a1fd7}{allowed\_\-area}
\item 
const int \hyperlink{classFitSpots_acad153ae64c850f6dd53c73cb4099f10}{use\_\-position\_\-prior}
\item 
const double \hyperlink{classFitSpots_a3bce4425b9e23c12022c64028aee9473}{position\_\-prior}
\item 
const double \hyperlink{classFitSpots_a2f6e6aea9179104d79b081ccbaf886b9}{max\_\-motion}
\item 
const int \hyperlink{classFitSpots_aec3947201088c5577c317bb870dc9ced}{sample\_\-iterations}
\item 
const int \hyperlink{classFitSpots_aed6a9ddf1dbdd2fbadb465be5c482adf}{main\_\-cg\_\-max\_\-iterations}
\item 
const int \hyperlink{classFitSpots_ab623360a11b3f42745eca5290c2cc61a}{main\_\-samples}
\item 
const int \hyperlink{classFitSpots_ac00c1017307d9e135f6277a6c1c5feb8}{main\_\-passes}
\item 
const int \hyperlink{classFitSpots_a3b12a5a46ea495da8d34e370cdfea359}{outer\_\-loop\_\-iterations}
\item 
const int \hyperlink{classFitSpots_a43d5e75f79385cbca7c3ced431496f2c}{add\_\-remove\_\-tries}
\item 
const int \hyperlink{classFitSpots_a06dc2d646650da802a2e64990765558e}{add\_\-remove\_\-opt\_\-samples}
\item 
const int \hyperlink{classFitSpots_a33d6ca9da02415c810510ab04e8fe44b}{add\_\-remove\_\-opt\_\-retries}
\item 
const int \hyperlink{classFitSpots_a63bfa81cdc107176252e4a11f793a2a1}{add\_\-remove\_\-opt\_\-hess\_\-inner\_\-samples}
\item 
const int \hyperlink{classFitSpots_a3c50c734bdaf39583e1acccd7ef712af}{h\_\-outer\_\-samples}
\item 
const int \hyperlink{classFitSpots_a8d6101d30fcf537fdd24a056b9962b66}{h\_\-inner\_\-samples}
\item 
const int \hyperlink{classFitSpots_a3a1ecaad175fa6e499a5b5511292fc05}{tsamples}
\item 
const Image$<$ float $>$ \hyperlink{classFitSpots_aa89f74f5f08941b8560b76b1b8b04472}{ave}
\item 
ofstream \& \hyperlink{classFitSpots_afb76e9aaabf2b42c808868cad9eb423f}{save\_\-spots}
\item 
double \hyperlink{classFitSpots_ac5647686071f5200fd15ceec48b6fa11}{time\_\-gibbs}
\item 
double \hyperlink{classFitSpots_a8654055addb1b3ddb60d0b43dde2027a}{time\_\-cg}
\item 
const bool \hyperlink{classFitSpots_a7517469f5f4ba151080c03c7a3bbb52f}{scale\_\-brightness\_\-limit}
\item 
const Vector$<$ 4 $>$ \hyperlink{classFitSpots_a368f999e794c375e0d3e4d722a1a3d68}{limit}
\item 
const Matrix$<$ 3 $>$ \hyperlink{classFitSpots_a461417a25390e2ef1a521ea0b3f0d1ce}{A}
\item 
const Vector$<$ 3 $>$ \hyperlink{classFitSpots_adba307176292351c12184211aa8358a9}{pi}
\item 
vector$<$ vector$<$ double $>$ $>$ \hyperlink{classFitSpots_a8ac05a3ed96b7070d54e514688c62b7c}{pixel\_\-intensities}
\item 
\hyperlink{classDataForMCMC}{DataForMCMC} \hyperlink{classFitSpots_a31eb8fd4f3a1e7b801e9ad272bc902ac}{data\_\-for\_\-t\_\-mcmc}
\item 
\hyperlink{classDataForMCMC}{DataForMCMC} \hyperlink{classFitSpots_a545d9daf6d8c3d58d6d16f3290d62ded}{data\_\-for\_\-h\_\-mcmc}
\item 
int \hyperlink{classFitSpots_a5f230f509cc07b945ff3dfb7259a4520}{iteration}
\end{DoxyCompactItemize}


\subsubsection{Detailed Description}
Mega class which actually does the meat of the spot fitting. 

probably could be refactored a bit. 

Definition at line 1367 of file multispot5.cc.



\subsubsection{Constructor \& Destructor Documentation}
\hypertarget{classFitSpots_a11861f227350c3629e60ee4ff2922c70}{
\index{FitSpots@{FitSpots}!FitSpots@{FitSpots}}
\index{FitSpots@{FitSpots}!FitSpots@{FitSpots}}
\paragraph[{FitSpots}]{\setlength{\rightskip}{0pt plus 5cm}FitSpots::FitSpots (
\begin{DoxyParamCaption}
\item[{const vector$<$ Image$<$ float $>$ $>$ \&}]{ims\_\-, }
\item[{{\bf FitSpotsGraphics} \&}]{graphics\_\-, }
\item[{{\bf UserInterfaceCallback} \&}]{ui\_\-, }
\item[{{\bf StateParameters} \&}]{params, }
\item[{ofstream \&}]{save\_\-spots\_\-}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classFitSpots_a11861f227350c3629e60ee4ff2922c70}


Definition at line 1457 of file multispot5.cc.



References assert\_\-same\_\-size().


\begin{DoxyCode}
    :ims(ims_), graphics(graphics_),ui(ui_),
     
     //Set up the main parameters
     pixels(params.pixels),
     spots(params.spots),
     start_iteration(params.iteration),
     start_pass(params.pass),
     rng(*params.rng),


     
     //Set up all the system parameters
     variance(1), // it should be

     //To scale the X axis of a log-normal distribution, only
     //the mu parameter needs to be changed...
     intensity_mu(GV3::get<double>("intensity.rel_mu", 0., -1)  + log(sqrt(
      variance))),
     intensity_sigma(GV3::get<double>("intensity.rel_sigma", 0., -1)),
     blur_mu(GV3::get<double>("blur.mu", 0., -1)),
     blur_sigma(GV3::get<double>("blur.sigma", 0., -1)),
 
     //Spot position prior
     area_extra_radius(GV3::get<double>("position.extra_radius", 0., -1)),
     allowed_area(dilate_mask(pixels, area_extra_radius)),
     use_position_prior(GV3::get<bool>("position.use_prior", true, -1)),
     position_prior(1.0 / allowed_area.size()),
        
     //General optimizing and sampling parameters
     max_motion(GV3::get<double>("cg.max_motion", 0., -1)),
     sample_iterations(GV3::get<int>("gibbs.mixing_iterations", 0, -1)),
     
     //Task specific optimizing and sampling parameters:
 
     //Main optimization loop
     main_cg_max_iterations(GV3::get<double>("main.cg.max_iterations", 0., -1)),
     main_samples(GV3::get<int>("main.gibbs.samples", 0, -1)),
     main_passes(GV3::get<int>("main.passes", 0, -1)),
     outer_loop_iterations(GV3::get<int>("main.total_iterations", 100000000, 1)),
      
     
     //Spot selection loop
     add_remove_tries(GV3::get<int>("add_remove.tries", 0, -1)),
     add_remove_opt_samples(GV3::get<int>("add_remove.optimizer.samples", 0, -1))
      ,
     add_remove_opt_retries(GV3::get<int>("add_remove.optimizer.attempts", 0, -1)
      ),
     add_remove_opt_hess_inner_samples(GV3::get<int>("add_remove.optimizer.hessia
      n_inner_samples", 0, -1)),
     h_outer_samples(GV3::get<int>("add_remove.hessian.outer_samples", 0, -1)),
     h_inner_samples(GV3::get<int>("add_remove.hessian.inner_samples", 0, -1)),
     tsamples(GV3::get<int>("add_remove.thermo.samples", 0, -1)),

     ave(average_image(ims_)),

     save_spots(save_spots_),
     
     time_gibbs(0),
     time_cg(0),
    
     scale_brightness_limit(GV3::get<bool>("max_motion.use_brightness_std", 0, -1
      )),
     limit(makeVector(brightness_motion_limit(intensity_mu, intensity_sigma, 
      scale_brightness_limit), 1, 1, 1)*max_motion),

     A(GV3::get<Matrix<3> >("A", Zeros, 1)),
     pi(GV3::get<Vector<3> >("pi", Zeros, 1)),


     data_for_t_mcmc(pixels, pixel_intensities, intensity_mu, intensity_sigma, 
      blur_mu, blur_sigma, variance, tsamples, sample_iterations, A, pi, rng),
     data_for_h_mcmc(pixels, pixel_intensities, intensity_mu, intensity_sigma, 
      blur_mu, blur_sigma, variance, h_outer_samples, sample_iterations, A, pi, rng)

    {
        assert_same_size(ims);

        //Pixel intensities for all images [frame][pixel]
        pixel_intensities.resize(ims.size(), vector<double>(pixels.size()));
        for(unsigned int frame=0; frame < ims.size(); frame++)
            for(unsigned int p=0; p < pixels.size(); p++)
                pixel_intensities[frame][p] = ims[frame][pixels[p]];
    
    }
\end{DoxyCode}


\subsubsection{Member Function Documentation}
\hypertarget{classFitSpots_a98d3369e6efc05a3a98bff9b4251b07c}{
\index{FitSpots@{FitSpots}!optimize\_\-each\_\-spot\_\-in\_\-turn\_\-for\_\-several\_\-passes@{optimize\_\-each\_\-spot\_\-in\_\-turn\_\-for\_\-several\_\-passes}}
\index{optimize\_\-each\_\-spot\_\-in\_\-turn\_\-for\_\-several\_\-passes@{optimize\_\-each\_\-spot\_\-in\_\-turn\_\-for\_\-several\_\-passes}!FitSpots@{FitSpots}}
\paragraph[{optimize\_\-each\_\-spot\_\-in\_\-turn\_\-for\_\-several\_\-passes}]{\setlength{\rightskip}{0pt plus 5cm}void FitSpots::optimize\_\-each\_\-spot\_\-in\_\-turn\_\-for\_\-several\_\-passes (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classFitSpots_a98d3369e6efc05a3a98bff9b4251b07c}


Perform a complete iteration of the optimzation stage of the spot firrint algorithm. 



Definition at line 1535 of file multispot5.cc.



References boundingbox(), SampledMultispot::compute\_\-spot\_\-intensity(), get\_\-spot\_\-pixels(), FreeEnergyHessian::hessian(), ConjugateGradientOnly$<$ Size, Precision $>$::iterate(), ConjugateGradientOnly$<$ Size, Precision $>$::max\_\-iterations, SampledMultispot::GibbsSampler2::next(), SampledMultispot::remove\_\-spot(), SampledMultispot::GibbsSampler2::sample(), SampledMultispot::GibbsSampler2::sample\_\-intensities(), sampled\_\-background\_\-spot\_\-hessian\_\-ffbs(), scale\_\-to\_\-bytes(), SampledMultispot::sequence(), spots\_\-to\_\-Vector(), TIME, and ConjugateGradientOnly$<$ Size, Precision $>$::x.


\begin{DoxyCode}
    {
        //Precompute the intensities for all spot pixels
        vector<vector<double> > spot_intensities; //[spot][pixel]
        for(unsigned int i=0; i < spots.size(); i++)
            spot_intensities.push_back(compute_spot_intensity(pixels, spots[i]));
      

        //Which pixels does each spot have?
        vector<vector<int> > spot_pixels; //[spot][pixel]
        spot_pixels.resize(spots.size());
        for(unsigned int s=0; s < spots.size(); s++)
            get_spot_pixels(pixels, spots[s], spot_pixels[s]);

        
        //Optimize the model, N spots at a time.
        //
        for(int pass=start_pass; pass < main_passes; pass++)
        {
            save_spots << "Pass: " << pass << endl;
            rng.write(save_spots);
            save_spots << endl;

            start_pass=0; // This is only nonzero first time, since we might chek
      point midway through an iteration
            save_spots << "PASS" << pass << ": " << setprecision(20) << scientifi
      c << spots_to_Vector(spots) << endl;
            save_spots << "ENDCHECKPOINT" << endl << flush;

            ui.per_pass(iteration, pass, spots);
            //Sort spots according to pass%4

            //Sort the spots so that the optimization runs in sweeps
            //This heiristic seems to increase the rate of propagation of informa
      tion
            //about spot positions.

            //Create a list of indices
            vector<int> index = sequence(spots.size());
            
            int passs = pass + iteration;
            //Sort the indices according to the position of the spot that they in
      dex
            if(passs%4 == 0)
                sort(index.begin(), index.end(), 
      IndexLexicographicPosition<less<double>, 2>(spots));
            else if(passs%4==1)
                sort(index.begin(), index.end(), 
      IndexLexicographicPosition<greater<double>, 2>(spots));
            else if(passs%4==1)
                sort(index.begin(), index.end(), 
      IndexLexicographicPosition<less<double>, 3>(spots));
            else
                sort(index.begin(), index.end(), 
      IndexLexicographicPosition<greater<double>, 3>(spots));

            //Reorder the spots and their intensities and their pixel lists
            {
                vector<Vector<4> > tmp_spot(index.size());
                vector<vector<double> > tmp_spot_intensities(index.size());
                vector<vector<int> > tmp_spot_pixels(index.size());
                for(unsigned int i=0; i < index.size(); i++)
                {
                    tmp_spot[i] = spots[index[i]];
                    swap(tmp_spot_intensities[i], spot_intensities[index[i]]);
                    swap(tmp_spot_pixels[i], spot_pixels[i]);
                }

                swap(tmp_spot, spots);
                swap(tmp_spot_intensities, spot_intensities);
                swap(tmp_spot_pixels, spot_pixels);
            }

            //Sweep through and optimize each spot in turn
            for(int s=0; s < (int)spots.size(); s++)
            {
                ui.per_spot(iteration, pass, s, spots.size()); 
                ui.perhaps_stop();

                TIME(timer.reset();)
                //Get some samples with Gibbs sampling
                vector<vector<vector<State> > > sample_list; //[N][spot][frame]: 
      list of samples drawn using Gibbs sampling
                vector<vector<vector<double> > > sample_intensities; //[sample][f
      rame][pixel]

                GibbsSampler2 sampler(pixel_intensities, spot_intensities, spots,
       spot_pixels, A, pi, variance, sample_iterations);
                for(int i=0; i < main_samples; i++)
                {
                    sampler.next(rng);
                    sample_list.push_back(sampler.sample());
                    sample_intensities.push_back(sampler.sample_intensities());

                    ui.perhaps_stop();
                }

                //First, remove the spot from all the samples.
                for(unsigned int i=0; i < sample_list.size(); i++)
                    remove_spot(sample_intensities[i], spot_intensities[s], sampl
      e_list[i][s]);
                
                //cout << timer.get_time() << endl;
                TIME(time_gibbs += timer.reset();)

                //Package up all the data
                SampledBackgroundData data(sample_intensities, pixel_intensities,
       pixels, 
                                           intensity_mu, intensity_sigma, 
      blur_mu, blur_sigma, 
                                           A, pi, variance);
                
                //Derivative computer:
                SpotNegProbabilityDiffWithSampledBackground compute_deriv(data);
                

                graphics.draw_pixels(pixels, 0, 0, 1, 1);
                graphics.draw_krap(spots, scale_to_bytes(ave), boundingbox(
      pixels), s);
                graphics.swap();

                //Optimize spot "s"
                //Optimize with the derivatives only since the actual probability
      
                //is much harder to compute
                ConjugateGradientOnly<4> cg(spots[s], compute_deriv, limit);


                cg.max_iterations = main_cg_max_iterations;


                #if 0
                    cout << setprecision(10);
                    cout << spots_to_Vector(spots) << endl;
                    Matrix<4> hess, hess_errors;
                    cout << "Hello, my name is Inigo Montoya\n";
                    /*for(int i=0; i < 4; i++)
                    {
                        Matrix<4, 2> d = numerical_gradient_with_errors(NthDeriv(
      compute_deriv, i), cg.x);
                        hess[i] = d.T()[0];
                        hess_errors[i] = d.T()[1];
                    }
                    */
                    //cout << "Errors:\n" << hess_errors << endl;
                    //cout << "NHess:\n" << hess<< endl;
                    Matrix<4> rhess =  -sampled_background_spot_hessian(cg.x, dat
      a);
                    cout << "Hess:\n" << rhess << endl;
                    //cout << "Err:\n" << hess - rhess << endl;

                    //Vector<4> grad = compute_deriv(cg.x);

                    //Matrix<4> e = hess - rhess;

                    //for(int i=0; i < 4; i++)
                    //  for(int j=0; j < 4; j++)
                    //      e[i][j] /= hess_errors[i][j];

                    //cout << "Err:\n" << e << endl;
                    cout << "Deriv:" <<  compute_deriv(cg.x) << endl;
                    //cout << "Full:\n" << sampled_background_spot_hessian2(cg.x,
       data) - grad.as_col()*grad.as_row() << endl;

                    FreeEnergyHessian hesscomputer(data_for_h_mcmc);

                    Matrix<4> nhess = hesscomputer.hessian(spots, 0);
                    cout << "NHess:\n" << nhess << endl;

                    cout << "Turbo-N Hess:\n" << 
      sampled_background_spot_hessian_ffbs(cg.x, data, 10000) << endl;

                    cout << "TI energy: " << NegativeFreeEnergy(data_for_t_mcmc)(
      spots_to_Vector(spots)) << endl;
                    cout << "FA energy: " <<  SpotProbabilityWithSampledBackgroun
      dFAKE(data)(cg.x) << endl;



                    //cout << "Numerical hessian from FD:\n" << numerical_hessian
      (SpotProbabilityWithSampledBackgroundFAKE(data), cg.x) << endl;
                    exit(0);
                #endif
                //cout << "Starting opt... " << cg.x << endl;
                while(cg.iterate(compute_deriv))
                {
                    graphics.draw_krap(spots, scale_to_bytes(ave), boundingbox(
      pixels), s, cg.x);
                    graphics.draw_pixels(pixels, 0, 0, 1, .2);
                    graphics.swap();
                    ui.perhaps_stop();
                    //cout << cg.x << endl;
                }

                //Update to use the result of the optimization
                spots[s] = cg.x;
                //cout << "End: " << cg.x << endl;
                
                graphics.draw_krap(spots, scale_to_bytes(ave), boundingbox(
      pixels), -1);
                graphics.swap();
                    
                //Recompute the new spot intensity, since the spot has changed
                spot_intensities[s] = compute_spot_intensity(pixels, spots[s]);

                //Recompute which are the useful pixels
                get_spot_pixels(pixels, spots[s], spot_pixels[s]);
                
                //Is the spot within the allowed area, i.e. is it's prior 0?
                //The prior is sero only if it we are using it and we're in an in
      valid area

                ImageRef quantized_spot_position = ir_rounded(spots[s].slice<2,2>
      ());
                bool zero_prior = use_position_prior && (allowed_area.count(quant
      ized_spot_position)==0);

                //Check to see if spot has been ejected. If spot_pixels is empty,
       then it has certainly been ejected.
                if(spot_pixels[s].empty() || zero_prior)
                {
                    //Spot has been ejected. Erase it.
                    cout  << " Erasing ejected spot: " << spot_pixels[s].empty() 
      << " " << zero_prior << endl;
                    cout << spots[s] << endl;
                    //GUI_Pause(1);

                    spot_intensities.erase(spot_intensities.begin() + s);
                    spot_pixels.erase(spot_pixels.begin() + s);
                    spots.erase(spots.begin() + s);
                    s--;
                    //exit(0);
                }
                
                //cout << timer.get_time() << endl;
                TIME(time_cg += timer.reset();)

                //cout << "Times: " << time_gibbs << " " << time_cg << endl;
                //save_spots << "INTERMEDIATE: " << setprecision(15) << scientifi
      c << spots_to_Vector(spots) << endl;
            }
        }
    }
\end{DoxyCode}
\hypertarget{classFitSpots_a3241207417f3813e58819596759cf019}{
\index{FitSpots@{FitSpots}!try\_\-modifying\_\-model@{try\_\-modifying\_\-model}}
\index{try\_\-modifying\_\-model@{try\_\-modifying\_\-model}!FitSpots@{FitSpots}}
\paragraph[{try\_\-modifying\_\-model}]{\setlength{\rightskip}{0pt plus 5cm}void FitSpots::try\_\-modifying\_\-model (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classFitSpots_a3241207417f3813e58819596759cf019}


Perform a complete iteration of the model size modification stage of the spot fitting algorithm. 



Definition at line 1748 of file multispot5.cc.



References SampledMultispot::add\_\-spot(), boundingbox(), SampledMultispot::compute\_\-spot\_\-intensity(), NegativeFreeEnergy::compute\_\-with\_\-mask(), get\_\-spot\_\-pixels(), ConjugateGradientOnly$<$ Size, Precision $>$::init(), ConjugateGradientOnly$<$ Size, Precision $>$::iterate(), ln(), log\_\-normal\_\-mode(), SampledMultispot::GibbsSampler::next(), SampledMultispot::GibbsSampler2::next(), SampledMultispot::remove\_\-spot(), SampledMultispot::GibbsSampler::sample(), SampledMultispot::GibbsSampler2::sample(), SampledMultispot::GibbsSampler::sample\_\-intensities(), SampledMultispot::GibbsSampler2::sample\_\-intensities(), sampled\_\-background\_\-spot\_\-hessian\_\-ffbs(), scale\_\-to\_\-bytes(), spots\_\-to\_\-Vector(), and ConjugateGradientOnly$<$ Size, Precision $>$::x.


\begin{DoxyCode}
    {

        for(int i=0; i < add_remove_tries; i++)
        {
            ui.per_modification(iteration, i, add_remove_tries);
            ui.perhaps_stop();

            cout << endl << endl << "Modifying the model" << endl << "===========
      ===========\n";
            cout << "Hello\n";
            bool add_spot = (rng() > 0.5) || (spots.size() == 1);
            cout << "World\n";

            vector<Vector<4> > model_1, model_2;

            
            int original; //What is the original model? Model 1 or Model 2?

            if(add_spot)
            {
                model_1 = spots;
                model_2 = model_1;
                
                //Pick a pixel within the thresholded ones as a starting point
                int r;
                do
                {
                    r = (int)(rng() * pixels.size());
                    //cout << r << " " << log_ratios[pixels[r]] << " " << pixels[
      r] << " " << threshold << endl;
                }
                while(0);

                //This version does not (yet?) suppotrt thresholding on log_ratio
      s
                //for placing spots, since the purpose of log_ratios has diminish
      ed.
                //while(log_ratios[pixels[r]] < threshold);


                model_2.push_back(makeVector(log_normal_mode(intensity_mu, 
      intensity_sigma), 
                                             log_normal_mode(blur_mu, blur_sigma)
      , 
                                             pixels[r].x + rng()-.5, pixels[r].y 
      + rng() - .5));
                cout << "Adding a spot\n";

                original = 1;
            }
            else
            {   
                //Pick a random point to optimize/remove
                int a_random_spot = static_cast<int>(rng() * spots.size());
                model_1 = spots;
                swap(model_1[model_1.size()-1], model_1[a_random_spot]);

                model_2 = model_1;

                model_1.pop_back();
                cout << "Removing a spot\n";
                original = 2;
            }
            
            //The mobile spot is always the last spot of model_2
            const int spot = model_2.size() - 1;

            cout << "Original model: " << original << endl;

            //Precompute the intensities for all spot pixels
            //Model 2 is always one longer than model 1 and 
            //differs only on the extra element
            vector<vector<double> > model2_spot_intensities; //[spot][pixel]
            for(unsigned int i=0; i < model_2.size(); i++)
                model2_spot_intensities.push_back(compute_spot_intensity(pixels, 
      model_2[i]));

            //Which pixels does each spot have?
            vector<vector<int> > model2_spot_pixels(model_2.size()); //[spot][pix
      el]
            for(unsigned int s=0; s < model_2.size(); s++)
                get_spot_pixels(pixels, model_2[s], model2_spot_pixels[s]);

            //Optimize spot:
            {
                cout << "Optimizing spot for model selection\n";


                //Get some samples with Gibbs sampling
                vector<vector<vector<State> > > sample_list; //[N][spot][frame]: 
      list of samples drawn using Gibbs sampling
                vector<vector<vector<double> > > sample_intensities; //[sample][f
      rame][pixel]

                GibbsSampler2 sampler(pixel_intensities, model2_spot_intensities,
       model_2, model2_spot_pixels, A, pi, variance, sample_iterations);
                for(int i=0; i < add_remove_opt_samples; i++)
                {
                    sampler.next(rng);
                    sample_list.push_back(sampler.sample());
                    sample_intensities.push_back(sampler.sample_intensities());
                    ui.perhaps_stop();
                }

                //First, remove the spot from all the samples.
                for(unsigned int i=0; i < sample_list.size(); i++)
                    remove_spot(sample_intensities[i], model2_spot_intensities[sp
      ot], sample_list[i][spot]);

                //Package up all the data
                SampledBackgroundData data(sample_intensities, pixel_intensities,
       pixels, 
                                           intensity_mu, intensity_sigma, 
      blur_mu, blur_sigma, 
                                           A, pi, variance);
                
                //Derivative computer:
                SpotNegProbabilityDiffWithSampledBackground compute_deriv(data);
                
                graphics.draw_krap(model_2, scale_to_bytes(ave), boundingbox(
      pixels), spot);
                graphics.swap();

                //Optimize spot "s"
                //Optimize with the derivatives only since the actual probability
      
                //is much harder to compute
                ConjugateGradientOnly<4> cg(model_2[spot], compute_deriv, limit);
      


                for(int attempt=0; attempt < add_remove_opt_retries; attempt++)
                {
                    cout << "Attempt " << attempt << " of " << add_remove_opt_ret
      ries << endl;
                    ui.perhaps_stop();

                    //Optimize with conjugate gradient
                    while(cg.iterate(compute_deriv))
                    {
                        ui.perhaps_stop();
                        graphics.draw_krap(model_2, scale_to_bytes(ave), 
      boundingbox(pixels), spot, cg.x);
                        graphics.swap();
                    }
                    
                    //Check for being at a saddle point (no point checking on the
       last try)
                    //All eigenvectors should be negative at a maximum.
                    //WTF: is this a bug? WTF?
                    //It was this:
                    //if(attempt < add_remove_tries - 1)
                    if(attempt < add_remove_opt_retries - 1)
                    {
                        Matrix<4> hessian = sampled_background_spot_hessian_ffbs(
      cg.x, data, add_remove_opt_hess_inner_samples, rng);
                        SymEigen<4> hess_decomp(hessian);

                        //cout << "What the fuck:" << endl << hessian << endl << 
      hessian3<< endl << hessian2 << endl;
                        
                        cout << "Eigenvalues are: " << hess_decomp.get_evalues() 
      << endl;

                        if(hess_decomp.is_negdef())
                            break;
                        else
                        {
                            //Restart in the direction of the best uphill part
                            cg.init(cg.x + 0.1 * hess_decomp.get_evectors()[3], (
      hess_decomp.get_evectors()[3]));


                            cout << "Grad = " << compute_deriv(cg.x) << endl;
                            for(int i=0; i < 4; i++)
                            {
                                cout << "Direction: " << i << endl;
                                cout << unit(compute_deriv(cg.x + 0.1*hess_decomp
      .get_evectors()[i])) * hess_decomp.get_evectors()[i] << endl;
                            }

                            for(int i=0; i < 4; i++)
                            {
                                cout << "Direction: " << i << endl;
                                Vector<4> d = Zeros;
                                d[i] = 1;
                                cout << unit(compute_deriv(cg.x + d)) * hess_deco
      mp.get_evectors()[i] << endl;
                            }
                        }
                    }
                }


                //Update to use the result of the optimization
                model_2[spot] = cg.x;
                
                graphics.draw_krap(model_2, scale_to_bytes(ave), boundingbox(
      pixels), -1);
                graphics.swap();
    

                //Update cached data based on the new spot position
                model2_spot_intensities[spot] = compute_spot_intensity(pixels, mo
      del_2[spot]);
                get_spot_pixels(pixels, model_2[spot], model2_spot_pixels[spot]);
      

                cout << "Done optimizing for model selection\n";
            }


            //Which model to keep?
            int keep=original;
        
            //Compute position prior (and we might be able to reject it really qu
      ickly here)
            bool zero_prior = use_position_prior && (allowed_area.count(ir_rounde
      d(model_2[spot].slice<2,2>()))==0); 
            
            if(zero_prior)
            {
                //Model 2 went bad, so we clearly keep model 1
                keep = 1;
            }
            else
            {
                
                //The position prior is independent
                //Compute the difference  model2 - model1
                //This is only valid if model2 is in the valid region
                double position_log_prior_model2_minus_model1;
                if(use_position_prior)
                    position_log_prior_model2_minus_model1 = (model_2.size() - mo
      del_1.size()) * ln(position_prior);
                else
                    position_log_prior_model2_minus_model1 = 0;


                //Integrate model_2
                //First compute the Hessian since this might go wrong.

                //FreeEnergyHessian hesscomputer(data_for_h_mcmc);
                Matrix<4> hess;// = hesscomputer.hessian(model_2, spot);

                //Use turbohess here since it is much faster, as the backwards sa
      mpling step is fast
                //We expect this hessian to be really quite different, if the spo
      t has moved from
                //a long way away, since the sampling will have changed dramatica
      lly
                {
                    //Get some samples with Gibbs sampling
                    vector<vector<vector<State> > > sample_list; //[N][spot][fram
      e]: list of samples drawn using Gibbs sampling
                    vector<vector<vector<double> > > sample_intensities; //[sampl
      e][frame][pixel]

                    GibbsSampler sampler(pixel_intensities, model2_spot_intensiti
      es, model_2, A, pi, variance, sample_iterations);
                    for(int i=0; i < h_outer_samples; i++)
                    {
                        ui.perhaps_stop();
                        sampler.next(rng);
                        sample_list.push_back(sampler.sample());
                        sample_intensities.push_back(sampler.sample_intensities()
      );
                    }
                    
                    //First, remove the spot from all the samples.
                    for(unsigned int i=0; i < sample_list.size(); i++)
                        remove_spot(sample_intensities[i], model2_spot_intensitie
      s[spot], sample_list[i][spot]);

                    //Package up all the data
                    SampledBackgroundData data(sample_intensities, 
      pixel_intensities, pixels, 
                                               intensity_mu, intensity_sigma, 
      blur_mu, blur_sigma, 
                                               A, pi, variance);

                    hess = sampled_background_spot_hessian_ffbs(model_2[spot], da
      ta, h_inner_samples, rng);
                }


                double det = determinant(-hess / (M_PI*2));
                SymEigen<4> hess_decomp(-hess);
                cout << "Hessien Eigenvalues are: " << hess_decomp.get_evalues() 
      << endl;
                const double smallest_evalue = 1e-6;

                //If the determinant is negative, then we are still at a saddle p
      oint
                //despite the attempts above, so abandon the attempt.
                if(hess_decomp.get_evalues()[0] >  smallest_evalue)
                {

                    //Compute the free energy of model 2 at the MLE estimate
                    cout << "Model 2:\n";
            //      double model_2_energy = -NegativeFreeEnergy(data_for_t_mcmc)(
      spots_to_Vector(model_2));
                    double model_2_energy = -NegativeFreeEnergy(data_for_t_mcmc).
      compute_with_mask(spots_to_Vector(model_2), model2_spot_pixels);
                    cout << "Energy: " << model_2_energy << endl;
                
                    //Combine the MLE energy and Hessian using Laplace's approxim
      ation
                    double model_2_occam =  -0.5 * log(det);
                    double model_2_prob = model_2_energy + model_2_occam + positi
      on_log_prior_model2_minus_model1;

                    cout << "Occam: " << model_2_occam << endl;
                    cout << "Position: " << position_log_prior_model2_minus_model
      1 << endl;
                    cout << "Prob: " << model_2_prob << endl;

                    //Integrate model_1
                    //It has no parameters, in this formulation.
                    //double model_1_prob = -NegativeFreeEnergy(data_for_t_mcmc)(
      spots_to_Vector(model_1));
                    
                    //Note that model_1 always has one fewer spots, and the last 
      spot is always the one
                    //missing, so we can make the correct mask very easily:
                    model2_spot_pixels.pop_back();
                    double model_1_prob = -NegativeFreeEnergy(data_for_t_mcmc).
      compute_with_mask(spots_to_Vector(model_1), model2_spot_pixels);
                    cout << "Prob: " << model_1_prob << endl;
                    //model_1_prob = -NegativeFreeEnergy(data_for_t_mcmc)(spots_t
      o_Vector(model_1));

                    if(model_2_prob  >  model_1_prob)
                        keep=2;
                    else
                        keep=1;

                    cout << "Models evaluated\n";
                }
                else
                {
                    cout << "Determinant has bad eigenvalues!\n";
                    keep = original;
                    cout << hess_decomp.get_evalues() << endl;
                }
            }

            if(keep == 2)
            {
                spots = model_2;
                cout << "Keeping model 2\n";

            }
            else
            {
                spots = model_1;
                cout << "Keeping model 1\n";
            }

            if(original != keep)
            {
                cout << "Model changed!\n";
                //break;
            }
        }
    }
\end{DoxyCode}
\hypertarget{classFitSpots_ababf8023f16926f09b7b513d99adff58}{
\index{FitSpots@{FitSpots}!run@{run}}
\index{run@{run}!FitSpots@{FitSpots}}
\paragraph[{run}]{\setlength{\rightskip}{0pt plus 5cm}void FitSpots::run (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classFitSpots_ababf8023f16926f09b7b513d99adff58}


Run the complete optimization algorithm. 



Definition at line 2062 of file multispot5.cc.



References spots\_\-to\_\-Vector().



Referenced by fit\_\-spots\_\-new().


\begin{DoxyCode}
    {
        graphics.init(ims[0].size());
        save_spots << "LOGVERSION 2" << endl;
        save_spots << "PIXELS";
        for(unsigned int i=0; i < pixels.size(); i++)
            save_spots << " " << pixels[i].x << " " << pixels[i].y;
        save_spots << endl;

        save_spots << "BEGINGVARLIST" << endl;
        GV3::print_var_list(save_spots, "", 1);
        save_spots << "ENDGVARLIST" << endl;

        //TODO all GVARS are set, so dump out gvars.

        cout << "Limit vector: " << limit << endl;

        for(iteration=start_iteration; iteration < outer_loop_iterations ;
      iteration++)
        {
            save_spots << "Iteration: " << iteration << " (" << iteration *  
      main_passes << ")" << endl;
            save_spots << "MAIN: " << setprecision(20) << scientific << 
      spots_to_Vector(spots) << endl;

            cout << endl << endl << "----------------------" << endl << "Optimizi
      ng:\n";
            cout << spots.size() << endl;
            

            optimize_each_spot_in_turn_for_several_passes();

            //spot_intensities is be correct here!
            try_modifying_model();
        }
        save_spots << "FINAL: " << setprecision(15) << scientific << 
      spots_to_Vector(spots) << endl;
    }
\end{DoxyCode}


\subsubsection{Member Data Documentation}
\hypertarget{classFitSpots_af02e3dbc54b1ef30884cca1d8222e2fd}{
\index{FitSpots@{FitSpots}!ims@{ims}}
\index{ims@{ims}!FitSpots@{FitSpots}}
\paragraph[{ims}]{\setlength{\rightskip}{0pt plus 5cm}const vector$<$Image$<$float$>$ $>$\& {\bf FitSpots::ims}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_af02e3dbc54b1ef30884cca1d8222e2fd}


Input data. 



Definition at line 1369 of file multispot5.cc.

\hypertarget{classFitSpots_a44244a8d258dfc635e3904d6f86467fd}{
\index{FitSpots@{FitSpots}!graphics@{graphics}}
\index{graphics@{graphics}!FitSpots@{FitSpots}}
\paragraph[{graphics}]{\setlength{\rightskip}{0pt plus 5cm}{\bf FitSpotsGraphics}\& {\bf FitSpots::graphics}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a44244a8d258dfc635e3904d6f86467fd}


Graphics class. 



Definition at line 1370 of file multispot5.cc.

\hypertarget{classFitSpots_aff7da5d4fb18ea492292af48d26e4a22}{
\index{FitSpots@{FitSpots}!ui@{ui}}
\index{ui@{ui}!FitSpots@{FitSpots}}
\paragraph[{ui}]{\setlength{\rightskip}{0pt plus 5cm}{\bf UserInterfaceCallback}\& {\bf FitSpots::ui}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_aff7da5d4fb18ea492292af48d26e4a22}


Callbacks to provide user interface. 



Definition at line 1371 of file multispot5.cc.

\hypertarget{classFitSpots_a5444540b5ee77316e01a54ca2857e3a5}{
\index{FitSpots@{FitSpots}!pixels@{pixels}}
\index{pixels@{pixels}!FitSpots@{FitSpots}}
\paragraph[{pixels}]{\setlength{\rightskip}{0pt plus 5cm}const vector$<$ImageRef$>$ {\bf FitSpots::pixels}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a5444540b5ee77316e01a54ca2857e3a5}


Area in which to perform model fitting. 



Definition at line 1372 of file multispot5.cc.

\hypertarget{classFitSpots_a8146e133fda55f682bc595d8ff83cd7a}{
\index{FitSpots@{FitSpots}!spots@{spots}}
\index{spots@{spots}!FitSpots@{FitSpots}}
\paragraph[{spots}]{\setlength{\rightskip}{0pt plus 5cm}vector$<$Vector$<$4$>$ $>$ {\bf FitSpots::spots}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a8146e133fda55f682bc595d8ff83cd7a}


State in terms of current spot positions. 



Definition at line 1375 of file multispot5.cc.

\hypertarget{classFitSpots_a34e584e04c28a8000bb3ad666a438da9}{
\index{FitSpots@{FitSpots}!start\_\-iteration@{start\_\-iteration}}
\index{start\_\-iteration@{start\_\-iteration}!FitSpots@{FitSpots}}
\paragraph[{start\_\-iteration}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::start\_\-iteration}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a34e584e04c28a8000bb3ad666a438da9}


Starting iteration number (for restarting from checkpoint) 



Definition at line 1378 of file multispot5.cc.

\hypertarget{classFitSpots_ab2b156b543081cb65d64d4c5bbf6e49d}{
\index{FitSpots@{FitSpots}!start\_\-pass@{start\_\-pass}}
\index{start\_\-pass@{start\_\-pass}!FitSpots@{FitSpots}}
\paragraph[{start\_\-pass}]{\setlength{\rightskip}{0pt plus 5cm}int {\bf FitSpots::start\_\-pass}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_ab2b156b543081cb65d64d4c5bbf6e49d}


Starting pass (for restarting from checkpoint) 



Definition at line 1379 of file multispot5.cc.

\hypertarget{classFitSpots_ae492e32e8d98e94ec13f83f6f6eb68a3}{
\index{FitSpots@{FitSpots}!rng@{rng}}
\index{rng@{rng}!FitSpots@{FitSpots}}
\paragraph[{rng}]{\setlength{\rightskip}{0pt plus 5cm}{\bf MT19937}\& {\bf FitSpots::rng}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_ae492e32e8d98e94ec13f83f6f6eb68a3}


Random numbewr generator. 



Definition at line 1381 of file multispot5.cc.

\hypertarget{classFitSpots_a6873890b1fbb895dd6c4f02b5996a148}{
\index{FitSpots@{FitSpots}!variance@{variance}}
\index{variance@{variance}!FitSpots@{FitSpots}}
\paragraph[{variance}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf FitSpots::variance}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a6873890b1fbb895dd6c4f02b5996a148}


Variance of noise in data. Must be 1. 



Definition at line 1383 of file multispot5.cc.

\hypertarget{classFitSpots_ae48f3c3b3173e1f38226f4c0de9bf83e}{
\index{FitSpots@{FitSpots}!intensity\_\-mu@{intensity\_\-mu}}
\index{intensity\_\-mu@{intensity\_\-mu}!FitSpots@{FitSpots}}
\paragraph[{intensity\_\-mu}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf FitSpots::intensity\_\-mu}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_ae48f3c3b3173e1f38226f4c0de9bf83e}


Prior for spot intensity. 



Definition at line 1384 of file multispot5.cc.

\hypertarget{classFitSpots_a0cb9fa2711420af796ac6f3bad9615f3}{
\index{FitSpots@{FitSpots}!intensity\_\-sigma@{intensity\_\-sigma}}
\index{intensity\_\-sigma@{intensity\_\-sigma}!FitSpots@{FitSpots}}
\paragraph[{intensity\_\-sigma}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf FitSpots::intensity\_\-sigma}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a0cb9fa2711420af796ac6f3bad9615f3}


Prior for spot intensity. 



Definition at line 1385 of file multispot5.cc.

\hypertarget{classFitSpots_a72f1fd5086c406b2d3b40a82807ee57d}{
\index{FitSpots@{FitSpots}!blur\_\-mu@{blur\_\-mu}}
\index{blur\_\-mu@{blur\_\-mu}!FitSpots@{FitSpots}}
\paragraph[{blur\_\-mu}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf FitSpots::blur\_\-mu}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a72f1fd5086c406b2d3b40a82807ee57d}


Prior for spot shape. 



Definition at line 1386 of file multispot5.cc.

\hypertarget{classFitSpots_a97e382de148a18e7f95be5132e26b8e8}{
\index{FitSpots@{FitSpots}!blur\_\-sigma@{blur\_\-sigma}}
\index{blur\_\-sigma@{blur\_\-sigma}!FitSpots@{FitSpots}}
\paragraph[{blur\_\-sigma}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf FitSpots::blur\_\-sigma}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a97e382de148a18e7f95be5132e26b8e8}


Prior for spt shape. 



Definition at line 1387 of file multispot5.cc.

\hypertarget{classFitSpots_ae898a7937d08e4d8b41cd6ee52795bb6}{
\index{FitSpots@{FitSpots}!area\_\-extra\_\-radius@{area\_\-extra\_\-radius}}
\index{area\_\-extra\_\-radius@{area\_\-extra\_\-radius}!FitSpots@{FitSpots}}
\paragraph[{area\_\-extra\_\-radius}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf FitSpots::area\_\-extra\_\-radius}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_ae898a7937d08e4d8b41cd6ee52795bb6}


Extra size beyone marked region in which spots are allowed to exist. 



Definition at line 1396 of file multispot5.cc.

\hypertarget{classFitSpots_a62abd352dd1ad8d1bd5adba0c50a1fd7}{
\index{FitSpots@{FitSpots}!allowed\_\-area@{allowed\_\-area}}
\index{allowed\_\-area@{allowed\_\-area}!FitSpots@{FitSpots}}
\paragraph[{allowed\_\-area}]{\setlength{\rightskip}{0pt plus 5cm}set$<$ImageRef$>$ {\bf FitSpots::allowed\_\-area}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a62abd352dd1ad8d1bd5adba0c50a1fd7}


Total allowed region, pixels dilated by area\_\-extra\_\-radius. 



Definition at line 1397 of file multispot5.cc.

\hypertarget{classFitSpots_acad153ae64c850f6dd53c73cb4099f10}{
\index{FitSpots@{FitSpots}!use\_\-position\_\-prior@{use\_\-position\_\-prior}}
\index{use\_\-position\_\-prior@{use\_\-position\_\-prior}!FitSpots@{FitSpots}}
\paragraph[{use\_\-position\_\-prior}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::use\_\-position\_\-prior}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_acad153ae64c850f6dd53c73cb4099f10}


Should a proper prior over position be uesd? A clue: yes. 



Definition at line 1398 of file multispot5.cc.

\hypertarget{classFitSpots_a3bce4425b9e23c12022c64028aee9473}{
\index{FitSpots@{FitSpots}!position\_\-prior@{position\_\-prior}}
\index{position\_\-prior@{position\_\-prior}!FitSpots@{FitSpots}}
\paragraph[{position\_\-prior}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf FitSpots::position\_\-prior}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a3bce4425b9e23c12022c64028aee9473}


Value for the posision prior, i.e. reciprocal of area. 



Definition at line 1399 of file multispot5.cc.

\hypertarget{classFitSpots_a2f6e6aea9179104d79b081ccbaf886b9}{
\index{FitSpots@{FitSpots}!max\_\-motion@{max\_\-motion}}
\index{max\_\-motion@{max\_\-motion}!FitSpots@{FitSpots}}
\paragraph[{max\_\-motion}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf FitSpots::max\_\-motion}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a2f6e6aea9179104d79b081ccbaf886b9}


Maximum motion on any axes for optimization. See \hyperlink{structConjugateGradientOnly}{ConjugateGradientOnly}. 



Definition at line 1402 of file multispot5.cc.

\hypertarget{classFitSpots_aec3947201088c5577c317bb870dc9ced}{
\index{FitSpots@{FitSpots}!sample\_\-iterations@{sample\_\-iterations}}
\index{sample\_\-iterations@{sample\_\-iterations}!FitSpots@{FitSpots}}
\paragraph[{sample\_\-iterations}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::sample\_\-iterations}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_aec3947201088c5577c317bb870dc9ced}


Number of mixing samples to use in Gibbs sampling. 



Definition at line 1403 of file multispot5.cc.

\hypertarget{classFitSpots_aed6a9ddf1dbdd2fbadb465be5c482adf}{
\index{FitSpots@{FitSpots}!main\_\-cg\_\-max\_\-iterations@{main\_\-cg\_\-max\_\-iterations}}
\index{main\_\-cg\_\-max\_\-iterations@{main\_\-cg\_\-max\_\-iterations}!FitSpots@{FitSpots}}
\paragraph[{main\_\-cg\_\-max\_\-iterations}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::main\_\-cg\_\-max\_\-iterations}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_aed6a9ddf1dbdd2fbadb465be5c482adf}


Maximum iterations allowed for \hyperlink{structConjugateGradientOnly}{ConjugateGradientOnly} in main optimization loop. 



Definition at line 1408 of file multispot5.cc.

\hypertarget{classFitSpots_ab623360a11b3f42745eca5290c2cc61a}{
\index{FitSpots@{FitSpots}!main\_\-samples@{main\_\-samples}}
\index{main\_\-samples@{main\_\-samples}!FitSpots@{FitSpots}}
\paragraph[{main\_\-samples}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::main\_\-samples}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_ab623360a11b3f42745eca5290c2cc61a}


Number of samples to use in main loop. 



Definition at line 1409 of file multispot5.cc.

\hypertarget{classFitSpots_ac00c1017307d9e135f6277a6c1c5feb8}{
\index{FitSpots@{FitSpots}!main\_\-passes@{main\_\-passes}}
\index{main\_\-passes@{main\_\-passes}!FitSpots@{FitSpots}}
\paragraph[{main\_\-passes}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::main\_\-passes}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_ac00c1017307d9e135f6277a6c1c5feb8}


Number of passes to perform per iteration in main loop. 



Definition at line 1410 of file multispot5.cc.

\hypertarget{classFitSpots_a3b12a5a46ea495da8d34e370cdfea359}{
\index{FitSpots@{FitSpots}!outer\_\-loop\_\-iterations@{outer\_\-loop\_\-iterations}}
\index{outer\_\-loop\_\-iterations@{outer\_\-loop\_\-iterations}!FitSpots@{FitSpots}}
\paragraph[{outer\_\-loop\_\-iterations}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::outer\_\-loop\_\-iterations}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a3b12a5a46ea495da8d34e370cdfea359}


Total number of iterations to perform. 



Definition at line 1411 of file multispot5.cc.

\hypertarget{classFitSpots_a43d5e75f79385cbca7c3ced431496f2c}{
\index{FitSpots@{FitSpots}!add\_\-remove\_\-tries@{add\_\-remove\_\-tries}}
\index{add\_\-remove\_\-tries@{add\_\-remove\_\-tries}!FitSpots@{FitSpots}}
\paragraph[{add\_\-remove\_\-tries}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::add\_\-remove\_\-tries}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a43d5e75f79385cbca7c3ced431496f2c}


Number of attemts to add/remove a spot. 



Definition at line 1414 of file multispot5.cc.

\hypertarget{classFitSpots_a06dc2d646650da802a2e64990765558e}{
\index{FitSpots@{FitSpots}!add\_\-remove\_\-opt\_\-samples@{add\_\-remove\_\-opt\_\-samples}}
\index{add\_\-remove\_\-opt\_\-samples@{add\_\-remove\_\-opt\_\-samples}!FitSpots@{FitSpots}}
\paragraph[{add\_\-remove\_\-opt\_\-samples}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::add\_\-remove\_\-opt\_\-samples}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a06dc2d646650da802a2e64990765558e}


Number of samples to use in model modification phase. 



Definition at line 1415 of file multispot5.cc.

\hypertarget{classFitSpots_a33d6ca9da02415c810510ab04e8fe44b}{
\index{FitSpots@{FitSpots}!add\_\-remove\_\-opt\_\-retries@{add\_\-remove\_\-opt\_\-retries}}
\index{add\_\-remove\_\-opt\_\-retries@{add\_\-remove\_\-opt\_\-retries}!FitSpots@{FitSpots}}
\paragraph[{add\_\-remove\_\-opt\_\-retries}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::add\_\-remove\_\-opt\_\-retries}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a33d6ca9da02415c810510ab04e8fe44b}


Number of attempts restarting the optimization to escape saddle points. 



Definition at line 1416 of file multispot5.cc.

\hypertarget{classFitSpots_a63bfa81cdc107176252e4a11f793a2a1}{
\index{FitSpots@{FitSpots}!add\_\-remove\_\-opt\_\-hess\_\-inner\_\-samples@{add\_\-remove\_\-opt\_\-hess\_\-inner\_\-samples}}
\index{add\_\-remove\_\-opt\_\-hess\_\-inner\_\-samples@{add\_\-remove\_\-opt\_\-hess\_\-inner\_\-samples}!FitSpots@{FitSpots}}
\paragraph[{add\_\-remove\_\-opt\_\-hess\_\-inner\_\-samples}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::add\_\-remove\_\-opt\_\-hess\_\-inner\_\-samples}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a63bfa81cdc107176252e4a11f793a2a1}


Number of extra FFBS samples to use for computing Hessian when testing for convergence to non-\/saddle point. 



Definition at line 1417 of file multispot5.cc.

\hypertarget{classFitSpots_a3c50c734bdaf39583e1acccd7ef712af}{
\index{FitSpots@{FitSpots}!h\_\-outer\_\-samples@{h\_\-outer\_\-samples}}
\index{h\_\-outer\_\-samples@{h\_\-outer\_\-samples}!FitSpots@{FitSpots}}
\paragraph[{h\_\-outer\_\-samples}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::h\_\-outer\_\-samples}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a3c50c734bdaf39583e1acccd7ef712af}


Number of samples used for computing Hessian as part of Laplace's approximation. 



Definition at line 1418 of file multispot5.cc.

\hypertarget{classFitSpots_a8d6101d30fcf537fdd24a056b9962b66}{
\index{FitSpots@{FitSpots}!h\_\-inner\_\-samples@{h\_\-inner\_\-samples}}
\index{h\_\-inner\_\-samples@{h\_\-inner\_\-samples}!FitSpots@{FitSpots}}
\paragraph[{h\_\-inner\_\-samples}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::h\_\-inner\_\-samples}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a8d6101d30fcf537fdd24a056b9962b66}


Number of additional FFBS samples to use for computing Hessian as part of Laplace's approximation. 



Definition at line 1419 of file multispot5.cc.

\hypertarget{classFitSpots_a3a1ecaad175fa6e499a5b5511292fc05}{
\index{FitSpots@{FitSpots}!tsamples@{tsamples}}
\index{tsamples@{tsamples}!FitSpots@{FitSpots}}
\paragraph[{tsamples}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf FitSpots::tsamples}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a3a1ecaad175fa6e499a5b5511292fc05}


Number of samples to use in thermodynamic integration. 



Definition at line 1420 of file multispot5.cc.

\hypertarget{classFitSpots_aa89f74f5f08941b8560b76b1b8b04472}{
\index{FitSpots@{FitSpots}!ave@{ave}}
\index{ave@{ave}!FitSpots@{FitSpots}}
\paragraph[{ave}]{\setlength{\rightskip}{0pt plus 5cm}const Image$<$float$>$ {\bf FitSpots::ave}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_aa89f74f5f08941b8560b76b1b8b04472}


Average of input data: used for. 



Definition at line 1423 of file multispot5.cc.

\hypertarget{classFitSpots_afb76e9aaabf2b42c808868cad9eb423f}{
\index{FitSpots@{FitSpots}!save\_\-spots@{save\_\-spots}}
\index{save\_\-spots@{save\_\-spots}!FitSpots@{FitSpots}}
\paragraph[{save\_\-spots}]{\setlength{\rightskip}{0pt plus 5cm}ofstream\& {\bf FitSpots::save\_\-spots}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_afb76e9aaabf2b42c808868cad9eb423f}


Output stream for log file. 



Definition at line 1427 of file multispot5.cc.

\hypertarget{classFitSpots_ac5647686071f5200fd15ceec48b6fa11}{
\index{FitSpots@{FitSpots}!time\_\-gibbs@{time\_\-gibbs}}
\index{time\_\-gibbs@{time\_\-gibbs}!FitSpots@{FitSpots}}
\paragraph[{time\_\-gibbs}]{\setlength{\rightskip}{0pt plus 5cm}double {\bf FitSpots::time\_\-gibbs}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_ac5647686071f5200fd15ceec48b6fa11}


Benchmarking data. 



Definition at line 1430 of file multispot5.cc.

\hypertarget{classFitSpots_a8654055addb1b3ddb60d0b43dde2027a}{
\index{FitSpots@{FitSpots}!time\_\-cg@{time\_\-cg}}
\index{time\_\-cg@{time\_\-cg}!FitSpots@{FitSpots}}
\paragraph[{time\_\-cg}]{\setlength{\rightskip}{0pt plus 5cm}double {\bf FitSpots::time\_\-cg}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a8654055addb1b3ddb60d0b43dde2027a}


Benchmarking data. 



Definition at line 1431 of file multispot5.cc.

\hypertarget{classFitSpots_a7517469f5f4ba151080c03c7a3bbb52f}{
\index{FitSpots@{FitSpots}!scale\_\-brightness\_\-limit@{scale\_\-brightness\_\-limit}}
\index{scale\_\-brightness\_\-limit@{scale\_\-brightness\_\-limit}!FitSpots@{FitSpots}}
\paragraph[{scale\_\-brightness\_\-limit}]{\setlength{\rightskip}{0pt plus 5cm}const bool {\bf FitSpots::scale\_\-brightness\_\-limit}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a7517469f5f4ba151080c03c7a3bbb52f}


Motion limit for \hyperlink{structConjugateGradientOnly}{ConjugateGradientOnly} The x distance, y distance and spot size are all approximately the same scale which is of order 1. 

The brigntness is not. By default, the brightness limit is also 1. This flag controls whether is should be set to the standard deviation of the brightness prior distribution. This setting will put the motion limit on the same scale as the other three parameters. 

Definition at line 1439 of file multispot5.cc.

\hypertarget{classFitSpots_a368f999e794c375e0d3e4d722a1a3d68}{
\index{FitSpots@{FitSpots}!limit@{limit}}
\index{limit@{limit}!FitSpots@{FitSpots}}
\paragraph[{limit}]{\setlength{\rightskip}{0pt plus 5cm}const Vector$<$4$>$ {\bf FitSpots::limit}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a368f999e794c375e0d3e4d722a1a3d68}


Limit vector for \hyperlink{structConjugateGradientOnly}{ConjugateGradientOnly}. 



Definition at line 1440 of file multispot5.cc.

\hypertarget{classFitSpots_a461417a25390e2ef1a521ea0b3f0d1ce}{
\index{FitSpots@{FitSpots}!A@{A}}
\index{A@{A}!FitSpots@{FitSpots}}
\paragraph[{A}]{\setlength{\rightskip}{0pt plus 5cm}const Matrix$<$3$>$ {\bf FitSpots::A}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a461417a25390e2ef1a521ea0b3f0d1ce}


Transition matrix. 



Definition at line 1442 of file multispot5.cc.

\hypertarget{classFitSpots_adba307176292351c12184211aa8358a9}{
\index{FitSpots@{FitSpots}!pi@{pi}}
\index{pi@{pi}!FitSpots@{FitSpots}}
\paragraph[{pi}]{\setlength{\rightskip}{0pt plus 5cm}const Vector$<$3$>$ {\bf FitSpots::pi}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_adba307176292351c12184211aa8358a9}


Initial probabilities. 



Definition at line 1443 of file multispot5.cc.

\hypertarget{classFitSpots_a8ac05a3ed96b7070d54e514688c62b7c}{
\index{FitSpots@{FitSpots}!pixel\_\-intensities@{pixel\_\-intensities}}
\index{pixel\_\-intensities@{pixel\_\-intensities}!FitSpots@{FitSpots}}
\paragraph[{pixel\_\-intensities}]{\setlength{\rightskip}{0pt plus 5cm}vector$<$vector$<$double$>$ $>$ {\bf FitSpots::pixel\_\-intensities}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a8ac05a3ed96b7070d54e514688c62b7c}


Pixel intensities for all images \mbox{[}frame\mbox{]}\mbox{[}pixel\mbox{]}. 



Definition at line 1446 of file multispot5.cc.

\hypertarget{classFitSpots_a31eb8fd4f3a1e7b801e9ad272bc902ac}{
\index{FitSpots@{FitSpots}!data\_\-for\_\-t\_\-mcmc@{data\_\-for\_\-t\_\-mcmc}}
\index{data\_\-for\_\-t\_\-mcmc@{data\_\-for\_\-t\_\-mcmc}!FitSpots@{FitSpots}}
\paragraph[{data\_\-for\_\-t\_\-mcmc}]{\setlength{\rightskip}{0pt plus 5cm}{\bf DataForMCMC} {\bf FitSpots::data\_\-for\_\-t\_\-mcmc}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a31eb8fd4f3a1e7b801e9ad272bc902ac}


Aggergated data for thermodynamic integration. 



Definition at line 1448 of file multispot5.cc.

\hypertarget{classFitSpots_a545d9daf6d8c3d58d6d16f3290d62ded}{
\index{FitSpots@{FitSpots}!data\_\-for\_\-h\_\-mcmc@{data\_\-for\_\-h\_\-mcmc}}
\index{data\_\-for\_\-h\_\-mcmc@{data\_\-for\_\-h\_\-mcmc}!FitSpots@{FitSpots}}
\paragraph[{data\_\-for\_\-h\_\-mcmc}]{\setlength{\rightskip}{0pt plus 5cm}{\bf DataForMCMC} {\bf FitSpots::data\_\-for\_\-h\_\-mcmc}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a545d9daf6d8c3d58d6d16f3290d62ded}


Aggergated data for finding hessian. 



Definition at line 1449 of file multispot5.cc.

\hypertarget{classFitSpots_a5f230f509cc07b945ff3dfb7259a4520}{
\index{FitSpots@{FitSpots}!iteration@{iteration}}
\index{iteration@{iteration}!FitSpots@{FitSpots}}
\paragraph[{iteration}]{\setlength{\rightskip}{0pt plus 5cm}int {\bf FitSpots::iteration}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classFitSpots_a5f230f509cc07b945ff3dfb7259a4520}


Iteration number. 



Definition at line 1451 of file multispot5.cc.



The documentation for this class was generated from the following file:\begin{DoxyCompactItemize}
\item 
\hyperlink{multispot5_8cc}{multispot5.cc}\end{DoxyCompactItemize}
