Alternaria
fit cylinders and ellipsoids to fungus
imaging_moves.cpp
Go to the documentation of this file.
00001 /*
00002  * This work is licensed under a Creative Commons 
00003  * Attribution-Noncommercial-Share Alike 3.0 United States License.
00004  * 
00005  *    http://creativecommons.org/licenses/by-nc-sa/3.0/us/
00006  * 
00007  * You are free:
00008  * 
00009  *    to Share - to copy, distribute, display, and perform the work
00010  *    to Remix - to make derivative works
00011  * 
00012  * Under the following conditions:
00013  * 
00014  *    Attribution. You must attribute the work in the manner specified by the
00015  *    author or licensor (but not in any way that suggests that they endorse you
00016  *    or your use of the work).
00017  * 
00018  *    Noncommercial. You may not use this work for commercial purposes.
00019  * 
00020  *    Share Alike. If you alter, transform, or build upon this work, you may
00021  *    distribute the resulting work only under the same or similar license to
00022  *    this one.
00023  * 
00024  * For any reuse or distribution, you must make clear to others the license
00025  * terms of this work. The best way to do this is by including this header.
00026  * 
00027  * Any of the above conditions can be waived if you get permission from the
00028  * copyright holder.
00029  * 
00030  * Apart from the remix rights granted under this license, nothing in this
00031  * license impairs or restricts the author's moral rights.
00032  */
00033 
00034 
00046 #include <config.h>
00047 
00048 #include <cstdlib>
00049 #include <cmath>
00050 #include <cassert>
00051 #include <iostream>
00052 #include <iomanip>
00053 
00054 #include <inttypes.h>
00055 
00056 #include <jwsc/base/limits.h>
00057 #include <jwsc/prob/pdf.h>
00058 
00059 #include <jwsc++/base/exception.h>
00060 
00061 #include "sampler.h"
00062 #include "imaging_model.h"
00063 #include "imaging_moves.h"
00064 
00065 
00066 using std::isinf;
00067 using std::isnan;
00068 using namespace jwsc;
00069 using jwscxx::base::Exception;
00070 
00071 
00077 bool Imaging_bg_move::run(Sampler_move_parameters* params) throw (Exception)
00078 {
00079     params->init_proposals();
00080 
00081     Imaging_model_density* density = params->imaging->get_density()->clone();
00082     float mu    = params->imaging->get_bg();
00083     float sigma = density->get_bg().get_sigma();
00084     float min   = density->get_bg().get_min();
00085     float max   = density->get_bg().get_max();
00086     density->set_bg(mu, sigma, min, max);
00087 
00088     params->imaging_proposal->set_bg(density->sample_bg());
00089 
00090     delete density;
00091 
00092     params->alternaria_proposal->update_scene(params->psf_proposal, 
00093             params->imaging_proposal);
00094 
00095     params->ll_proposal = params->alternaria_proposal->calc_log_likelihood(
00096             params->psf_proposal, params->imaging_proposal, params->data,
00097             params->data_avg);
00098 
00099     double log_alpha = params->ll_proposal;
00100     log_alpha -= params->ll;
00101     log_alpha += params->imaging_proposal->get_log_prob();
00102     log_alpha -= params->imaging->get_log_prob();
00103 
00104 #if defined ALTERNARIA_HAVE_ISINF && defined ALTERNARIA_HAVE_ISNAN
00105     assert(!isinf(log_alpha) && !isnan(log_alpha));
00106 #endif
00107 
00108     double log_u = log(sample_uniform_pdf_d(JWSC_MIN_LOG_ARG, 1.0));
00109 
00110     if (log_u <= log_alpha)
00111     {
00112         return true;
00113     }
00114     return false;
00115 }
00116 
00117 
00123 const std::ostringstream& Imaging_bg_move::get_info
00124 (
00125     Sampler_move_parameters* params
00126 ) 
00127 { 
00128     assert(params->imaging);
00129     info.str("");
00130     info << std::left << std::setprecision(4) << std::setw(9)
00131          << params->imaging->get_bg(); 
00132     return info;
00133 }
00134 
00135 
00141 const std::ostringstream& Imaging_bg_move::get_proposal_info
00142 (
00143     Sampler_move_parameters* params
00144 ) 
00145 { 
00146     assert(params->imaging_proposal);
00147     proposal_info.str("");
00148     proposal_info << std::left << std::setprecision(4) << std::setw(9)
00149                   << params->imaging_proposal->get_bg(); 
00150     return proposal_info;
00151 }