\hypertarget{classFreeEnergyHessian}{
\subsection{FreeEnergyHessian Class Reference}
\label{classFreeEnergyHessian}\index{FreeEnergyHessian@{FreeEnergyHessian}}
}


Class for computing the Hessian of the negative free energy.  


Inheritance diagram for FreeEnergyHessian:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=2.000000cm]{classFreeEnergyHessian}
\end{center}
\end{figure}
\subsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{classFreeEnergyHessian_a8f3c7982ce9061d1503318ddb9ae5b85}{FreeEnergyHessian} (const \hyperlink{classDataForMCMC}{DataForMCMC} \&d)
\item 
Matrix$<$ 4 $>$ \hyperlink{classFreeEnergyHessian_ae6e22b3482d9f000a5c4e6f62a99f822}{hessian} (const vector$<$ Vector$<$ 4 $>$ $>$ \&spots, int spot) const 
\item 
\hyperlink{structMT19937}{MT19937} \& \hyperlink{classDataForMCMC_a075edc255ded434adab5dc29818ac36f}{get\_\-rng} () const 
\end{DoxyCompactItemize}
\subsubsection*{Protected Attributes}
\begin{DoxyCompactItemize}
\item 
const vector$<$ ImageRef $>$ \& \hyperlink{classDataForMCMC_ab2e18ea9907dbf6c802377805f41b39c}{pixels}
\item 
const vector$<$ vector$<$ double $>$ $>$ \& \hyperlink{classDataForMCMC_af938cc0cf40b14c954121da40acddde8}{pixel\_\-intensities}
\item 
const double \hyperlink{classDataForMCMC_ad6f046e65d3fb7dfed4d1df300df4530}{mu\_\-brightness}
\item 
const double \hyperlink{classDataForMCMC_a00058a98358c328fcf6223d216d7f8d3}{sigma\_\-brightness}
\item 
const double \hyperlink{classDataForMCMC_ae2cdad8d7062a79b3ea33d2a962ac1e7}{mu\_\-blur}
\item 
const double \hyperlink{classDataForMCMC_a8fd8eb85c9ab7e89d80dbb9259c31a9c}{sigma\_\-blur}
\item 
const double \hyperlink{classDataForMCMC_a3e343a540b3ea41d9124fbad4549d8cc}{variance}
\item 
const int \hyperlink{classDataForMCMC_aec3a6d4e2a675e7f402ae38e342f4994}{samples}
\item 
const int \hyperlink{classDataForMCMC_a83103f72475b121baabd05e9b8df1008}{sample\_\-iterations}
\item 
const Matrix$<$ 3 $>$ \hyperlink{classDataForMCMC_a9a6d87f160124548bc024d3729104d1c}{A}
\item 
const Vector$<$ 3 $>$ \hyperlink{classDataForMCMC_a0f6b8af3c843069f6d9f0ea16deffe48}{pi}
\item 
\hyperlink{structMT19937}{MT19937} \& \hyperlink{classDataForMCMC_abae93ccf7880ba57a5cbb322e69e6f16}{rng}
\end{DoxyCompactItemize}


\subsubsection{Detailed Description}
Class for computing the Hessian of the negative free energy. 

Definition at line 627 of file multispot5.cc.



\subsubsection{Constructor \& Destructor Documentation}
\hypertarget{classFreeEnergyHessian_a8f3c7982ce9061d1503318ddb9ae5b85}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!FreeEnergyHessian@{FreeEnergyHessian}}
\index{FreeEnergyHessian@{FreeEnergyHessian}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{FreeEnergyHessian}]{\setlength{\rightskip}{0pt plus 5cm}FreeEnergyHessian::FreeEnergyHessian (
\begin{DoxyParamCaption}
\item[{const {\bf DataForMCMC} \&}]{d}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classFreeEnergyHessian_a8f3c7982ce9061d1503318ddb9ae5b85}


Constructor. 


\begin{DoxyParams}{Parameters}
{\em d} & All data required \\
\hline
\end{DoxyParams}


Definition at line 633 of file multispot5.cc.


\begin{DoxyCode}
    :DataForMCMC(d)
    {
    }
\end{DoxyCode}


\subsubsection{Member Function Documentation}
\hypertarget{classFreeEnergyHessian_ae6e22b3482d9f000a5c4e6f62a99f822}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!hessian@{hessian}}
\index{hessian@{hessian}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{hessian}]{\setlength{\rightskip}{0pt plus 5cm}Matrix$<$4$>$ FreeEnergyHessian::hessian (
\begin{DoxyParamCaption}
\item[{const vector$<$ Vector$<$ 4 $>$ $>$ \&}]{spots, }
\item[{int}]{spot}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classFreeEnergyHessian_ae6e22b3482d9f000a5c4e6f62a99f822}


Compute the Hessian. 


\begin{DoxyParams}{Parameters}
{\em spots} & All spot positions \\
\hline
{\em spot} & spot to compute hessian for \\
\hline
\end{DoxyParams}


Definition at line 641 of file multispot5.cc.



References SampledMultispot::compute\_\-spot\_\-intensity(), SampledMultispot::compute\_\-spot\_\-intensity\_\-hessian(), diff\_\-log\_\-log\_\-normal(), hess\_\-log\_\-log\_\-normal(), SampledMultispot::GibbsSampler::next(), SampledMultispot::GibbsSampler::sample(), and SampledMultispot::GibbsSampler::sample\_\-intensities().



Referenced by FitSpots::optimize\_\-each\_\-spot\_\-in\_\-turn\_\-for\_\-several\_\-passes().


\begin{DoxyCode}
    {
        cout << "----Computing pure MCMC hessian\n";
        const unsigned int nspots  = spots.size();
        const unsigned int nframes = pixel_intensities.size();
        const unsigned int npixels = pixels.size();
        cout << spot << " " << nspots << " " << nframes << " " << npixels << endl
      ;

        vector<vector<double> > spot_intensity; //[spot][pixel]
        for(unsigned int i=0; i < nspots; i++)
            spot_intensity.push_back(compute_spot_intensity(pixels, spots[i]));

        vector<tuple<double, Vector<4>, Matrix<4> > > spot_hess_etc = 
      compute_spot_intensity_hessian(pixels, spots[spot]);

        GibbsSampler sampler(pixel_intensities, spot_intensity, spots, A, pi, 
      variance, sample_iterations);
        
        //Compute derivative of log probability, summed (ie integrated)
        Matrix<4> sum_hess1 = Zeros(spots.size());
        Matrix<4> sum_hess2 = Zeros(spots.size());
        Vector<4> sum_deriv = Zeros(spots.size());

        for(int sample=0; sample < samples; sample++)
        {
            sampler.next(rng);

            //Compute d log P(data | x, model) / d model, for a given sample
            //And the hessian
            Matrix<4> hess = Zeros(spots.size());
            Vector<4> deriv = Zeros(spots.size());
            for(unsigned int frame=0; frame < nframes; frame++)
            {
                for(unsigned int pixel=0; pixel < npixels; pixel++)
                {
                    double e = pixel_intensities[frame][pixel] - sampler.sample_i
      ntensities()[frame][pixel];
                    //Build up the derivative
                    if(sampler.sample()[spot][frame] == 0)
                    {
                        hess += e * get<2>(spot_hess_etc[pixel]) - get<1>(spot_he
      ss_etc[pixel]).as_col() * get<1>(spot_hess_etc[pixel]).as_row();
                        deriv += e * get<1>(spot_hess_etc[pixel]);

                    }
                }
            }

            hess[0][0] += hess_log_log_normal(spots[spot][0], mu_brightness, 
      sigma_brightness);
            hess[1][1] += hess_log_log_normal(spots[spot][1], mu_blur, 
      sigma_blur);
            sum_hess1 += hess;

            deriv[0] += diff_log_log_normal(spots[spot][0], mu_brightness, 
      sigma_brightness);
            deriv[1] += diff_log_log_normal(spots[spot][1], mu_blur, sigma_blur);
      

            sum_hess2 += deriv.as_col() * deriv.as_row();

            sum_deriv = sum_deriv + deriv;
        }

        sum_hess1 /= (samples * variance);
        sum_hess2 /= (samples * variance);
        sum_deriv /= (samples * variance);

        
        cout << sum_hess1 << endl;
        cout << sum_hess2 << endl;
        cout << sum_deriv.as_col() * sum_deriv.as_row() <<  endl;

        cout << "......." << sum_deriv << endl;
        //Put in the prior
        //The derivative prior parts cancel out.
        //Rather sensibly this means that the second derivatives can be
        //computed without reference to the prior, and then the prior can
        //be added in later, i.e.: P(data, parameters) = P(data|parameter) P(para
      meters)

        //The second derivatives have been constructed to be diagonal
        DiagonalMatrix<4> hess_prior = Zeros(spots.size());

        cout << "sum of parts = \n" << sum_hess1 + sum_hess2 - sum_deriv.as_col()
       * sum_deriv.as_row() << endl;
        //TooN cannot currently add DiagonalMatrix to Matrix!!
        //sum_hess.diagonal_slice() += hess_prior.diagonal_slice();

        cout << "++++Done Computing pure MCMC hessian\n";
        return sum_hess1 + sum_hess2 - sum_deriv.as_col() * sum_deriv.as_row();
    }
\end{DoxyCode}
\hypertarget{classDataForMCMC_a075edc255ded434adab5dc29818ac36f}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!get\_\-rng@{get\_\-rng}}
\index{get\_\-rng@{get\_\-rng}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{get\_\-rng}]{\setlength{\rightskip}{0pt plus 5cm}{\bf MT19937}\& DataForMCMC::get\_\-rng (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline, inherited\mbox{]}}}}
\label{classDataForMCMC_a075edc255ded434adab5dc29818ac36f}


Definition at line 208 of file multispot5.cc.



Referenced by NegativeFreeEnergy::compute\_\-with\_\-mask(), and NegativeFreeEnergy::operator()().


\begin{DoxyCode}
    {
        return rng;
    }
\end{DoxyCode}


\subsubsection{Member Data Documentation}
\hypertarget{classDataForMCMC_ab2e18ea9907dbf6c802377805f41b39c}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!pixels@{pixels}}
\index{pixels@{pixels}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{pixels}]{\setlength{\rightskip}{0pt plus 5cm}const vector$<$ImageRef$>$\& {\bf DataForMCMC::pixels}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_ab2e18ea9907dbf6c802377805f41b39c}


Definition at line 198 of file multispot5.cc.

\hypertarget{classDataForMCMC_af938cc0cf40b14c954121da40acddde8}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!pixel\_\-intensities@{pixel\_\-intensities}}
\index{pixel\_\-intensities@{pixel\_\-intensities}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{pixel\_\-intensities}]{\setlength{\rightskip}{0pt plus 5cm}const vector$<$vector$<$double$>$ $>$\& {\bf DataForMCMC::pixel\_\-intensities}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_af938cc0cf40b14c954121da40acddde8}


Definition at line 199 of file multispot5.cc.

\hypertarget{classDataForMCMC_ad6f046e65d3fb7dfed4d1df300df4530}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!mu\_\-brightness@{mu\_\-brightness}}
\index{mu\_\-brightness@{mu\_\-brightness}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{mu\_\-brightness}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf DataForMCMC::mu\_\-brightness}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_ad6f046e65d3fb7dfed4d1df300df4530}


Definition at line 200 of file multispot5.cc.

\hypertarget{classDataForMCMC_a00058a98358c328fcf6223d216d7f8d3}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!sigma\_\-brightness@{sigma\_\-brightness}}
\index{sigma\_\-brightness@{sigma\_\-brightness}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{sigma\_\-brightness}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf DataForMCMC::sigma\_\-brightness}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_a00058a98358c328fcf6223d216d7f8d3}


Definition at line 200 of file multispot5.cc.

\hypertarget{classDataForMCMC_ae2cdad8d7062a79b3ea33d2a962ac1e7}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!mu\_\-blur@{mu\_\-blur}}
\index{mu\_\-blur@{mu\_\-blur}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{mu\_\-blur}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf DataForMCMC::mu\_\-blur}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_ae2cdad8d7062a79b3ea33d2a962ac1e7}


Definition at line 200 of file multispot5.cc.

\hypertarget{classDataForMCMC_a8fd8eb85c9ab7e89d80dbb9259c31a9c}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!sigma\_\-blur@{sigma\_\-blur}}
\index{sigma\_\-blur@{sigma\_\-blur}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{sigma\_\-blur}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf DataForMCMC::sigma\_\-blur}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_a8fd8eb85c9ab7e89d80dbb9259c31a9c}


Definition at line 200 of file multispot5.cc.

\hypertarget{classDataForMCMC_a3e343a540b3ea41d9124fbad4549d8cc}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!variance@{variance}}
\index{variance@{variance}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{variance}]{\setlength{\rightskip}{0pt plus 5cm}const double {\bf DataForMCMC::variance}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_a3e343a540b3ea41d9124fbad4549d8cc}


Definition at line 201 of file multispot5.cc.

\hypertarget{classDataForMCMC_aec3a6d4e2a675e7f402ae38e342f4994}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!samples@{samples}}
\index{samples@{samples}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{samples}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf DataForMCMC::samples}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_aec3a6d4e2a675e7f402ae38e342f4994}


Definition at line 202 of file multispot5.cc.

\hypertarget{classDataForMCMC_a83103f72475b121baabd05e9b8df1008}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!sample\_\-iterations@{sample\_\-iterations}}
\index{sample\_\-iterations@{sample\_\-iterations}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{sample\_\-iterations}]{\setlength{\rightskip}{0pt plus 5cm}const int {\bf DataForMCMC::sample\_\-iterations}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_a83103f72475b121baabd05e9b8df1008}


Definition at line 202 of file multispot5.cc.

\hypertarget{classDataForMCMC_a9a6d87f160124548bc024d3729104d1c}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!A@{A}}
\index{A@{A}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{A}]{\setlength{\rightskip}{0pt plus 5cm}const Matrix$<$3$>$ {\bf DataForMCMC::A}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_a9a6d87f160124548bc024d3729104d1c}


Definition at line 203 of file multispot5.cc.

\hypertarget{classDataForMCMC_a0f6b8af3c843069f6d9f0ea16deffe48}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!pi@{pi}}
\index{pi@{pi}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{pi}]{\setlength{\rightskip}{0pt plus 5cm}const Vector$<$3$>$ {\bf DataForMCMC::pi}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_a0f6b8af3c843069f6d9f0ea16deffe48}


Definition at line 204 of file multispot5.cc.

\hypertarget{classDataForMCMC_abae93ccf7880ba57a5cbb322e69e6f16}{
\index{FreeEnergyHessian@{FreeEnergyHessian}!rng@{rng}}
\index{rng@{rng}!FreeEnergyHessian@{FreeEnergyHessian}}
\paragraph[{rng}]{\setlength{\rightskip}{0pt plus 5cm}{\bf MT19937}\& {\bf DataForMCMC::rng}\hspace{0.3cm}{\ttfamily  \mbox{[}protected, inherited\mbox{]}}}}
\label{classDataForMCMC_abae93ccf7880ba57a5cbb322e69e6f16}


Definition at line 205 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}
