ThreeB 1.1
Public Member Functions | Private Attributes
SampledMultispot::GibbsSampler2 Class Reference

Gibbs sampling class which masks spots to reduce computation. More...

#include <sampled_multispot.h>

List of all members.

Public Member Functions

 GibbsSampler2 (const vector< vector< double > > &pixel_intensities_, const vector< vector< double > > &spot_intensities_, const vector< Vector< 4 > > &spots_, const vector< vector< int > > &spot_pixels_, const Matrix< 3 > A_, const Vector< 3 > pi_, double variance_, int sample_iterations_)
void set_variance (double v)
void reset ()
template<class T >
void next (T &rng)
const vector< vector< State > > & sample () const
const vector< vector< double > > & sample_intensities () const

Private Attributes

const vector< vector< double > > & pixel_intensities
const vector< vector< double > > & spot_intensities
const vector< Vector< 4 > > spots
const std::vector< std::vector
< int > > & 
spot_pixels
const Matrix< 3 > A
const Vector< 3 > pi
const double base_variance
double variance
const int sample_iterations
const int num_frames
const int num_pixels
const vector< int > O
vector< vector< State > > current_sample
vector< vector< double > > current_sample_intensities
vector< double > cutout_spot_intensities
vector< vector< double > > cutout_pixel_intensities
vector< vector< double > > cutout_current_sample_intensities

Detailed Description

Gibbs sampling class which masks spots to reduce computation.

This draws samples from, the spot states given the spots positions and some data. It is very similar to GibbsSampler, except that it only computes probabilities in a mask around each spot to save on computation. Variable naming matches that in FitSpots.

Definition at line 304 of file sampled_multispot.h.


Constructor & Destructor Documentation

SampledMultispot::GibbsSampler2::GibbsSampler2 ( const vector< vector< double > > &  pixel_intensities_,
const vector< vector< double > > &  spot_intensities_,
const vector< Vector< 4 > > &  spots_,
const vector< vector< int > > &  spot_pixels_,
const Matrix< 3 >  A_,
const Vector< 3 >  pi_,
double  variance_,
int  sample_iterations_ 
) [inline]

Definition at line 328 of file sampled_multispot.h.

References assert_same_size(), and spot_intensities.

    :pixel_intensities(pixel_intensities_), //pixel_intensities: [frame][pixels]
     spot_intensities(spot_intensities_),   //spot_intensities: [spot][pixel]
     spots(spots_),
     spot_pixels(spot_pixels_),
     A(A_),
     pi(pi_),
     base_variance(variance_),
     variance(variance_),
     sample_iterations(sample_iterations_),
     num_frames(pixel_intensities.size()),
     num_pixels(pixel_intensities[0].size()),
        //Observations vector. As usual for this application, the observations are just
        //numbered integers which refer to data held elsewhere.
     O(sequence(num_frames)),
        //Start all spots OFF, so the intensity is 0. OFF is 1 or 2, not 0!!!
        //sample_list: [sample][spot][frame]: list of samples drawn using Gibbs sampling
     current_sample(spots.size(), vector<State>(num_frames, 2)), //current sample [spot][frame]
        //pixel intensities assosciated with the current sample [frame][pixel]
     current_sample_intensities(num_frames, vector<double>(num_pixels)),
     cutout_pixel_intensities(num_frames),
     cutout_current_sample_intensities(num_frames)
    {
        //Check a bunch of stuff
        assert_same_size(pixel_intensities);
        assert_same_size(spot_intensities);
    }

Member Function Documentation

void SampledMultispot::GibbsSampler2::set_variance ( double  v) [inline]

Update the noide variance.

Used for adding thermal noise.

Parameters:
vnoise variance.

Definition at line 365 of file sampled_multispot.h.

Referenced by NegativeFreeEnergy::compute_with_mask().

    {
        variance = v;
    }
void SampledMultispot::GibbsSampler2::reset ( ) [inline]

Reset the gibbs sampler oro the initial state (all spots off)

Definition at line 372 of file sampled_multispot.h.

    {
        vector<State> off(num_frames, 2);
        fill(current_sample.begin(), current_sample.end(), off);

        vector<double> black(num_pixels);
        fill(current_sample_intensities.begin(), current_sample_intensities.end(), black);
        variance = base_variance;
    }
template<class T >
void SampledMultispot::GibbsSampler2::next ( T &  rng) [inline]

Get the next sample.

Parameters:
rngRandom number generator

Definition at line 384 of file sampled_multispot.h.

References SampledMultispot::add_spot(), SampledMultispot::remove_spot(), and spot_intensities.

Referenced by NegativeFreeEnergy::compute_with_mask(), FitSpots::optimize_each_spot_in_turn_for_several_passes(), and FitSpots::try_modifying_model().

    {
    
//double remove=0;
//double cut=0;
//double swb=0;
//double ff_masked=0;
//double bs=0;
//double add=0;
//cvd_timer t;
    std::vector<array<double, 3> > delta3;
        for(int j=0; j < sample_iterations; j++)
            for(int k=0; k < (int) spots.size(); k++)
            {
//t.reset();
                //Subtract off the spot we're interested in.
                remove_spot(current_sample_intensities, spot_intensities[k], current_sample[k], spot_pixels[k]);
//remove+=t.reset();
/*
                //Cut out
                //spot
                cutout_spot_intensities.resize(spot_pixels[k].size());
                for(unsigned int i=0; i < spot_pixels[k].size(); i++)
                    cutout_spot_intensities[i] = spot_intensities[k][spot_pixels[k][i]];

                //others
                for(int f=0; f < num_frames; f++)
                {
                    cutout_current_sample_intensities[f].resize(spot_pixels[k].size());
                    cutout_pixel_intensities[f].resize(spot_pixels[k].size());
                    for(unsigned int i=0; i < spot_pixels[k].size();i++)
                    {
                        cutout_current_sample_intensities[f][i] = current_sample_intensities[f][spot_pixels[k][i]];
                        cutout_pixel_intensities[f][i] = pixel_intensities[f][spot_pixels[k][i]];
                    }
                }*/
//cut += t.reset();
                //Now current_sample_intensities is the image value for every spot in every frame,
                //except the current spot, which is always set to off. This allows us to add it in 
                //easily.

//              SpotWithBackground B(current_sample_intensities, spot_intensities[k], pixel_intensities, variance);
//              vector<array<double, 3> > delta = forward_algorithm_delta(A, pi, B, O);

//ff+=t.reset();

//              SpotWithBackground B2(cutout_current_sample_intensities, cutout_spot_intensities, cutout_pixel_intensities, variance);
//              std::vector<array<double, 3> > delta2 = forward_algorithm_delta(A, pi, B2, O);
//ff_cut+=t.reset();

                SpotWithBackgroundMasked B3(current_sample_intensities, spot_intensities[k], pixel_intensities, variance, spot_pixels[k]);
//swb += t.reset();
                forward_algorithm_delta2<3>(A, pi, B3, O, delta3);
//f_masked+=t.reset();
                /*for(unsigned int i=0; i < delta.size(); i++)
                {
                    cout.precision(20);
                    cout.setf(cout.scientific);
                    std::cout << delta[i][0] << " " << delta[i][1] << " " <<delta[i][2] << std::endl;
                    std::cout << delta2[i][0] << " " << delta2[i][1] << " " <<delta2[i][2] << std::endl;
                    cout << endl;
                }
                std::exit(1);

*/

                current_sample[k] = backward_sampling<3,State, T>(A, delta3, rng);
//bs += t.reset();
                //Put the newly sampled spot in
                add_spot(current_sample_intensities, spot_intensities[k], current_sample[k], spot_pixels[k]);
//add += t.reset();
            }
//      cout << "remove=" <<remove << " cut=" << cut << " swb=" << swb<< " ff_mask=" << ff_masked << " bs=" <<bs << " add="<<add << endl;
    }
const vector<vector<State> >& SampledMultispot::GibbsSampler2::sample ( ) const [inline]

Retrieve the current sample.

Definition at line 465 of file sampled_multispot.h.

Referenced by FitSpots::optimize_each_spot_in_turn_for_several_passes(), and FitSpots::try_modifying_model().

    {
        return current_sample;
    }
const vector<vector<double> >& SampledMultispot::GibbsSampler2::sample_intensities ( ) const [inline]

Retrieve the intensities for the current sample.

Definition at line 470 of file sampled_multispot.h.

Referenced by NegativeFreeEnergy::compute_with_mask(), FitSpots::optimize_each_spot_in_turn_for_several_passes(), and FitSpots::try_modifying_model().


Member Data Documentation

const vector<vector<double> >& SampledMultispot::GibbsSampler2::pixel_intensities [private]

Definition at line 306 of file sampled_multispot.h.

const vector<vector<double> >& SampledMultispot::GibbsSampler2::spot_intensities [private]

Definition at line 307 of file sampled_multispot.h.

const vector<Vector<4> > SampledMultispot::GibbsSampler2::spots [private]

Definition at line 308 of file sampled_multispot.h.

const std::vector<std::vector<int> >& SampledMultispot::GibbsSampler2::spot_pixels [private]

Definition at line 309 of file sampled_multispot.h.

const Matrix<3> SampledMultispot::GibbsSampler2::A [private]

Definition at line 310 of file sampled_multispot.h.

const Vector<3> SampledMultispot::GibbsSampler2::pi [private]

Definition at line 311 of file sampled_multispot.h.

Definition at line 312 of file sampled_multispot.h.

Definition at line 313 of file sampled_multispot.h.

Definition at line 315 of file sampled_multispot.h.

Definition at line 316 of file sampled_multispot.h.

Definition at line 316 of file sampled_multispot.h.

const vector<int> SampledMultispot::GibbsSampler2::O [private]

Definition at line 317 of file sampled_multispot.h.

Definition at line 319 of file sampled_multispot.h.

Definition at line 320 of file sampled_multispot.h.

Definition at line 322 of file sampled_multispot.h.

Definition at line 323 of file sampled_multispot.h.

Definition at line 324 of file sampled_multispot.h.


The documentation for this class was generated from the following file: