Commit 4b034659 authored by Luka Stanisic's avatar Luka Stanisic

rel2: code development

parent 254d53db
...@@ -29,7 +29,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}") ...@@ -29,7 +29,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
include_directories(include) include_directories(include)
set (BIOEM_ICC_FLAGS "-xHost -O3 -fno-alias -fno-fnalias -unroll -g0 -ipo") set (BIOEM_ICC_FLAGS "-O3 -fno-alias -fno-fnalias -unroll -g0 -ip")
set (BIOEM_GCC_FLAGS "-O3 -march=native -fweb -mfpmath=sse -frename-registers -minline-all-stringops -ftracer -funroll-loops -fpeel-loops -fprefetch-loop-arrays -ffast-math -ggdb") set (BIOEM_GCC_FLAGS "-O3 -march=native -fweb -mfpmath=sse -frename-registers -minline-all-stringops -ftracer -funroll-loops -fpeel-loops -fprefetch-loop-arrays -ffast-math -ggdb")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
...@@ -50,11 +50,6 @@ if (NOT FFTW_FOUND) ...@@ -50,11 +50,6 @@ if (NOT FFTW_FOUND)
endif() endif()
include_directories(${FFTW_INCLUDE_DIRS}) include_directories(${FFTW_INCLUDE_DIRS})
find_package( Boost 1.43 REQUIRED COMPONENTS program_options )
include_directories( ${Boost_INCLUDE_DIRS} )
###Find Optional Packages ###Find Optional Packages
###Find CUDA ###Find CUDA
...@@ -163,7 +158,6 @@ if (FFTWF_LIBRARIES) ...@@ -163,7 +158,6 @@ if (FFTWF_LIBRARIES)
else() else()
target_link_libraries(bioEM -L${FFTW_LIBDIR} -lfftw3 -lfftw3f) target_link_libraries(bioEM -L${FFTW_LIBDIR} -lfftw3 -lfftw3f)
endif() endif()
target_link_libraries(bioEM ${Boost_PROGRAM_OPTIONS_LIBRARY})
if (MPI_FOUND) if (MPI_FOUND)
target_link_libraries(bioEM ${MPI_LIBRARIES}) target_link_libraries(bioEM ${MPI_LIBRARIES})
...@@ -172,7 +166,6 @@ endif() ...@@ -172,7 +166,6 @@ endif()
###Show Status ###Show Status
message(STATUS "Build Status") message(STATUS "Build Status")
message(STATUS "FFTW library: ${FFTW_LIBDIR}") message(STATUS "FFTW library: ${FFTW_LIBDIR}")
message(STATUS "Boost directory: ${Boost_LIBRARY_DIRS}")
message(STATUS "FFTW includedir: ${FFTW_INCLUDEDIR}") message(STATUS "FFTW includedir: ${FFTW_INCLUDEDIR}")
message(STATUS "CUDA libraries: ${CUDA_CUDA_LIBRARY}") message(STATUS "CUDA libraries: ${CUDA_CUDA_LIBRARY}")
message(STATUS "CUDART libraries: ${CUDA_LIBRARIES}") message(STATUS "CUDART libraries: ${CUDA_LIBRARIES}")
......
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
< BioEM software for Bayesian inference of Electron Microscopy images>
Copyright (C) 2017 Pilar Cossio, Markus Rampp, Luka Stanisic and Gerhard
Hummer.
Max Planck Institute of Biophysics, Frankfurt, Germany.
Max Planck Computing and Data Facility, Garching, Germany.
Released under the GNU Public License, v3.
See license statement for terms of distribution.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include "autotuner.h" #include "autotuner.h"
void Autotuner::Reset() void Autotuner::Reset()
...@@ -16,64 +28,75 @@ void Autotuner::Reset() ...@@ -16,64 +28,75 @@ void Autotuner::Reset()
fb = 0.; fb = 0.;
fx = 0.; fx = 0.;
if (algo == 3) workload = 50; if (algo == 3)
workload = 50;
} }
bool Autotuner::Needed(int iteration) bool Autotuner::Needed(int iteration)
{ {
if (stopTuning) return false; if (stopTuning)
return false;
switch (algo) switch (algo)
{ {
case 1: case 1:
case 3: case 3:
return iteration % (stable + 1) == stable; return iteration % (stable + 1) == stable;
case 2: return (iteration == (int) stable / 2 ) || (iteration == stable); case 2:
return (iteration == (int) stable / 2) || (iteration == stable);
default: /* Should never happen */; default: /* Should never happen */;
} }
return false; return false;
} }
bool Autotuner::Finished() bool Autotuner::Finished()
{ {
switch (algo) switch (algo)
{ {
case 1: case 1:
if (workload < 30) if (workload < 30)
{ {
workload = best_workload; workload = best_workload;
return stopTuning = true; return stopTuning = true;
} }
break; break;
case 2: case 2:
if (best_workload != 0) return stopTuning = true; if (best_workload != 0)
return stopTuning = true;
break; break;
case 3: case 3:
if ((c - b == limit) && (b - a == limit)) return stopTuning = true; if ((c - b == limit) && (b - a == limit))
return stopTuning = true;
break; break;
default: /* Should never happen */; default: /* Should never happen */;
} }
return false; return false;
} }
void Autotuner::Tune(double compTime) void Autotuner::Tune(double compTime)
{ {
switch (algo) switch (algo)
{ {
case 1: AlgoSimple(compTime); break; case 1:
case 2: AlgoRatio(compTime); break; AlgoSimple(compTime);
case 3: AlgoBisection(compTime); break; break;
case 2:
AlgoRatio(compTime);
break;
case 3:
AlgoBisection(compTime);
break;
default: /* Should never happen */; default: /* Should never happen */;
} }
} }
void Autotuner::AlgoSimple(double compTime) void Autotuner::AlgoSimple(double compTime)
{ {
if (best_time == 0. || compTime < best_time) if (best_time == 0. || compTime < best_time)
{ {
best_time = compTime; best_time = compTime;
best_workload = workload; best_workload = workload;
} }
workload -= 5; workload -= 5;
} }
...@@ -81,46 +104,46 @@ void Autotuner::AlgoSimple(double compTime) ...@@ -81,46 +104,46 @@ void Autotuner::AlgoSimple(double compTime)
void Autotuner::AlgoRatio(double compTime) void Autotuner::AlgoRatio(double compTime)
{ {
if (best_time == 0.) if (best_time == 0.)
{ {
best_time = compTime; best_time = compTime;
workload = 1; workload = 1;
} }
else else
{ {
best_workload = (int) 100 * (compTime / (best_time + compTime)); best_workload = (int) 100 * (compTime / (best_time + compTime));
workload = best_workload; workload = best_workload;
} }
} }
void Autotuner::AlgoBisection(double compTime) void Autotuner::AlgoBisection(double compTime)
{ {
if (fb == 0.) if (fb == 0.)
{ {
fb = compTime; fb = compTime;
x = 75; x = 75;
workload = x; workload = x;
return; return;
} }
fx = compTime; fx = compTime;
if (fx < fb) if (fx < fb)
{ {
if (x < b) if (x < b)
c = b; c = b;
else else
a = b; a = b;
b = x; b = x;
fb = fx; fb = fx;
} }
else else
{ {
if (x < b) if (x < b)
a = x; a = x;
else else
c = x; c = x;
} }
x = (c-b > b-a) ? (int)(b+(c-b)/2) : (int)(a+(b-a+1)/2); x = (c - b > b - a) ? (int) (b + (c - b) / 2) : (int) (a + (b - a + 1) / 2);
workload = x; workload = x;
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
< BioEM software for Bayesian inference of Electron Microscopy images> < BioEM software for Bayesian inference of Electron Microscopy images>
Copyright (C) 2016 Pilar Cossio, David Rohr, Fabio Baruffa, Markus Rampp, Copyright (C) 2017 Pilar Cossio, David Rohr, Fabio Baruffa, Markus Rampp,
Volker Lindenstruth and Gerhard Hummer. Luka Stanisic, Volker Lindenstruth and Gerhard Hummer.
Max Planck Institute of Biophysics, Frankfurt, Germany. Max Planck Institute of Biophysics, Frankfurt, Germany.
Frankfurt Institute for Advanced Studies, Goethe University Frankfurt, Germany. Frankfurt Institute for Advanced Studies, Goethe University Frankfurt,
Max Planck Computing and Data Facility, Garching, Germany. Germany.
Max Planck Computing and Data Facility, Garching, Germany.
Released under the GNU Public License, v3. Released under the GNU Public License, v3.
See license statement for terms of distribution. See license statement for terms of distribution.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#ifndef BIOEM_ALGORITHM_H #ifndef BIOEM_ALGORITHM_H
#define BIOEM_ALGORITHM_H #define BIOEM_ALGORITHM_H
//#include <boost/iterator/iterator_concepts.hpp>
#ifndef BIOEM_GPUCODE __device__ static inline myprob_t
//#define SSECODE //Explicit SSE code, not correct yet since loop counter is assumed multiple of 4, anyway not faster than autovectorized code, only implemented for float, not for double. calc_logpro(const bioem_param_device &param, const myfloat_t amp,
#endif const myfloat_t pha, const myfloat_t env, const myfloat_t sum,
const myfloat_t sumsquare, const myfloat_t crossproMapConv,
#ifdef SSECODE const myfloat_t sumref, const myfloat_t sumsquareref)
#include <emmintrin.h>
#include <smmintrin.h>
#endif
template <int GPUAlgo>
__device__ static inline void update_prob(const myfloat_t logpro, const int iRefMap, const int iOrient, const int iConv, const int cent_x, const int cent_y, bioem_Probability& pProb, bool doAngle, myfloat_t* buf3 = NULL, int* bufint = NULL)
{
// *********** Not using FFT ALGORITHM ******************
//*********** Routine to perform the numerical BioEM intergal ***********
// ******* Summing total Probabilities *************
bioem_Probability_map& pProbMap = pProb.getProbMap(iRefMap);
// ******* Need a constant because of numerical divergence*****
if(pProbMap.Constoadd < logpro)
{
pProbMap.Total = pProbMap.Total * exp(-logpro + pProbMap.Constoadd);
pProbMap.Constoadd = logpro;
// ********** Getting parameters that maximize the probability ***********
if (GPUAlgo == 2)
{
bufint[0] = 1;
buf3[1] = logpro;
}
else
{
pProbMap.max.max_prob_cent_x = - cent_x;
pProbMap.max.max_prob_cent_y = - cent_y;
}
pProbMap.max.max_prob_orient = iOrient;
pProbMap.max.max_prob_conv = iConv;
// pProbMap.max.max_prob_norm = - ( -sumC * RefMap.sum_RefMap[iRefMap] + param.Ntotpi * value ) / ( sumC * sumC - sumsquareC * param.Ntotpi);
// pProbMap.max.max_prob_mu = - ( -sumC * value + sumsquareC * RefMap.sum_RefMap[iRefMap] ) / ( sumC * sumC - sumsquareC * param.Ntotpi);
}
if (GPUAlgo != 2) pProbMap.Total += exp(logpro - pProbMap.Constoadd);
if (doAngle)
{
bioem_Probability_angle& pProbAngle = pProb.getProbAngle(iRefMap, iOrient);
//Summing probabilities for each orientation
if(pProbAngle.ConstAngle < logpro)
{
pProbAngle.forAngles = pProbAngle.forAngles * exp(-logpro + pProbAngle.ConstAngle);
pProbAngle.ConstAngle = logpro;
}
if (GPUAlgo != 2) pProbAngle.forAngles += exp(logpro - pProbAngle.ConstAngle);
}
}
__device__ static inline myfloat_t calc_logpro(const bioem_param_device& param, const myfloat_t amp, const myfloat_t pha, const myfloat_t env, const myfloat_t sum, const myfloat_t sumsquare, const myfloat_t crossproMapConv, const myfloat_t sumref, const myfloat_t sumsquareref)
{ {
//*** MAIN ROUTINE TO CALCULATE THE LOGPRO FOR ALL KERNELS*************// //*** MAIN ROUTINE TO CALCULATE THE LOGPRO FOR ALL KERNELS*************//
// **** calculate the log posterior of Eq. of Pmw in SI of JSB paper ***// // **** calculate the log posterior of Eq. of Pmw in SI of JSB paper ***//
// Related to Reference calculated Projection // Related to Reference calculated Projection
const myfloat_t ForLogProb = (sumsquare * param.Ntotpi - sum * sum); const myprob_t ForLogProb = sumsquare * param.Ntotpi - sum * sum;
// Products of different cross-correlations (first element in formula) // Products of different cross-correlations (first element in formula)
const myfloat_t firstele = param.Ntotpi * (sumsquareref * sumsquare - crossproMapConv * crossproMapConv) + const myprob_t firstele =
2 * sumref * sum * crossproMapConv - sumsquareref * sum * sum - sumref * sumref * sumsquare; param.Ntotpi *
(sumsquareref * sumsquare - crossproMapConv * crossproMapConv) +
2 * sumref * sum * crossproMapConv - sumsquareref * sum * sum -
sumref * sumref * sumsquare;
/// ******* Calculating log of Prob********* /// ******* Calculating log of Prob*********
// As in fortran code: logpro=(3-Ntotpi)*0.5*log(firstele/pConvMap[iOrient].ForLogProbfromConv[iConv])+(Ntotpi*0.5-2)*log(Ntotpi-2)-0.5*log(pConvMap[iOrient].ForLogProbfromConv[iConv])+0.5*log(PI)+(1-Ntotpi*0.5)*(log(2*PI)+1); // As in fortran code:
// logpro=(3-Ntotpi)*0.5*log(firstele/pConvMap[iOrient].ForLogProbfromConv[iConv])+(Ntotpi*0.5-2)*log(Ntotpi-2)-0.5*log(pConvMap[iOrient].ForLogProbfromConv[iConv])+0.5*log(PI)+(1-Ntotpi*0.5)*(log(2*PI)+1);
myfloat_t logpro = (3 - param.Ntotpi) * 0.5 * log(firstele) + (param.Ntotpi * 0.5 - 2) * log((param.Ntotpi - 2) * ForLogProb);
myprob_t logpro =
//*************Adding Gaussian Prior to envelope & Defocus parameter****************** (3 - param.Ntotpi) * 0.5 * log(firstele) +
(param.Ntotpi * 0.5 - 2) * log((param.Ntotpi - 2) * ForLogProb);
if(not param.tousepsf){
logpro = logpro - env * env / 2. / param.sigmaPriorbctf / param.sigmaPriorbctf - //*************Adding Gaussian Prior to envelope & Defocus
(pha - param.Priordefcent ) * (pha - param.Priordefcent ) / 2. / param.sigmaPriordefo / param.sigmaPriordefo ; // parameter******************
} else {
myfloat_t envF,phaF; if (not param.tousepsf)
envF = 4.* M_PI * M_PI * env / ( env * env + pha * pha) ; {
phaF = 4.* M_PI * M_PI * pha / ( env * env + pha * pha); logpro -= env * env / 2. / param.sigmaPriorbctf / param.sigmaPriorbctf -
logpro = logpro - envF * envF / 2. / param.sigmaPriorbctf / param.sigmaPriorbctf - (phaF - param.Priordefcent ) * (phaF - param.Priordefcent ) / 2. / param.sigmaPriordefo / param.sigmaPriordefo ; (pha - param.Priordefcent) * (pha - param.Priordefcent) / 2. /
param.sigmaPriordefo / param.sigmaPriordefo -
(amp - param.Priorampcent) * (amp - param.Priorampcent) / 2. /
param.sigmaPrioramp / param.sigmaPrioramp;
}
else
{
myprob_t envF, phaF;
envF = 4. * M_PI * M_PI * env / (env * env + pha * pha);
phaF = 4. * M_PI * M_PI * pha / (env * env + pha * pha);
logpro -= envF * envF / 2. / param.sigmaPriorbctf / param.sigmaPriorbctf -
(phaF - param.Priordefcent) * (phaF - param.Priordefcent) / 2. /
param.sigmaPriordefo / param.sigmaPriordefo -
(amp - param.Priorampcent) * (amp - param.Priorampcent) / 2. /
param.sigmaPrioramp / param.sigmaPrioramp;
} }
return(logpro); return (logpro);
} }
__device__ static inline void calProb(int iRefMap, int iOrient, int iConv, myfloat_t amp, myfloat_t pha, myfloat_t env, myfloat_t sumC, myfloat_t sumsquareC, myfloat_t value, int disx, int disy, bioem_Probability& pProb, const bioem_param_device& param, const bioem_RefMap& RefMap) __device__ static inline void
calProb(int iRefMap, int iOrient, int iConv, const myfloat_t amp,
const myfloat_t pha, const myfloat_t env, const myfloat_t sumC,
const myfloat_t sumsquareC, myfloat_t value, int disx, int disy,
bioem_Probability &pProb, const bioem_param_device &param,
const bioem_RefMap &RefMap)
{ {
// IMPORTANT ROUTINE Summation of LogProb using FFTALGO // IMPORTANT ROUTINE Summation of LogProb using FFTALGO
// ******************************************************** // ********************************************************
// *********** Calculates the BioEM probability *********** // *********** Calculates the BioEM probability ***********
// ******************************************************** // ********************************************************
myfloat_t logpro = calc_logpro(param, amp, pha, env, sumC, sumsquareC, value, RefMap.sum_RefMap[iRefMap], RefMap.sumsquare_RefMap[iRefMap]); myfloat_t logpro =
calc_logpro(param, amp, pha, env, sumC, sumsquareC, value,
RefMap.sum_RefMap[iRefMap], RefMap.sumsquare_RefMap[iRefMap]);
//GCC is too stupid to inline properly, so the code is copied here #ifdef DEBUG_PROB
//update_prob<-1>(logpro, iRefMap, iOrient, iConv, disx, disy, pProb, param.writeAngles); printf("\t\t\tProb: iRefMap %d, iOrient %d, iConv %d, "
"disx %d, disy %d, address -, value %f, logpro %f\n",
bioem_Probability_map& pProbMap = pProb.getProbMap(iRefMap); iRefMap, iOrient, iConv, disx, disy, value, logpro);
#endif
// printf("Separate PtotBef: %f Const: %f logProb %f %d %d %d \n",pProbMap.Total,pProbMap.Constoadd,logpro,iRefMap,iOrient,iConv);
if(pProbMap.Constoadd < logpro)
{
pProbMap.Total = pProbMap.Total * exp(-logpro + pProbMap.Constoadd);
pProbMap.Constoadd = logpro;
// ********** Getting parameters that maximize the probability *********** bioem_Probability_map &pProbMap = pProb.getProbMap(iRefMap);
pProbMap.max.max_prob_cent_x = - disx;
pProbMap.max.max_prob_cent_y = - disy; if (pProbMap.Constoadd < logpro)
pProbMap.max.max_prob_orient = iOrient; {
pProbMap.max.max_prob_conv = iConv; pProbMap.Total *= exp(-logpro + pProbMap.Constoadd);
pProbMap.max.max_prob_norm = - ( -sumC * RefMap.sum_RefMap[iRefMap] + param.Ntotpi * value ) / ( sumC * sumC - sumsquareC * param.Ntotpi); pProbMap.Constoadd = logpro;
pProbMap.max.max_prob_mu = - ( -sumC * value + sumsquareC * RefMap.sum_RefMap[iRefMap] ) / ( sumC * sumC - sumsquareC * param.Ntotpi);
} // ********** Getting parameters that maximize the probability ***********
pProbMap.max.max_prob_cent_x = -disx;
pProbMap.max.max_prob_cent_y = -disy;
pProbMap.max.max_prob_orient = iOrient;
pProbMap.max.max_prob_conv = iConv;
pProbMap.max.max_prob_norm =
-(-sumC * RefMap.sum_RefMap[iRefMap] + param.Ntotpi * value) /
(sumC * sumC - sumsquareC * param.Ntotpi);
pProbMap.max.max_prob_mu =
-(-sumC * value + sumsquareC * RefMap.sum_RefMap[iRefMap]) /
(sumC * sumC - sumsquareC * param.Ntotpi);
#ifdef DEBUG_PROB
printf("\tProbabilities change: iRefMap %d, iOrient %d, iConv %d, Total "
"%f, Const %f, bestlogpro %f, sumExp -, bestId -\n",
iRefMap, iOrient, iConv, pProbMap.Total, pProbMap.Constoadd, logpro);
printf("\tParameters: iConv %d, myX -, myY -, disx %d, disy %d, probX "
"%d, probY %d\n",
iConv, disx, disy, pProbMap.max.max_prob_cent_x,
pProbMap.max.max_prob_cent_y);
#endif
}
pProbMap.Total += exp(logpro - pProbMap.Constoadd); pProbMap.Total += exp(logpro - pProbMap.Constoadd);
#ifdef DEBUG_PROB
printf("\t\tProbabilities after Sum: iRefMap %d, iOrient %d, iConv %d, "
"Total %f, Const %f, bestlogpro %f, sumExp -, bestId -\n",
iRefMap, iOrient, iConv, pProbMap.Total, pProbMap.Constoadd, logpro);
#endif
if (param.writeAngles) if (param.writeAngles)
{ {
bioem_Probability_angle& pProbAngle = pProb.getProbAngle(iRefMap, iOrient); bioem_Probability_angle &pProbAngle = pProb.getProbAngle(iRefMap, iOrient);
// if(iOrient==1)printf("Separate Ptot: %f Const: %f logProb %f param: %d %d %d \n",logpro,pProbAngle.ConstAngle,pProbAngle.forAngles,disx,disx,iOrient);
if(pProbAngle.ConstAngle < logpro)
{
pProbAngle.forAngles = pProbAngle.forAngles * exp(-logpro + pProbAngle.ConstAngle);
pProbAngle.ConstAngle = logpro;
}
pProbAngle.forAngles += exp(logpro - pProbAngle.ConstAngle);
// if(iOrient==5)printf("After separate Ptot: %f Const: %f logProb %f \n",logpro,pProbAngle.ConstAngle,pProbAngle.forAngles);
}
} if (pProbAngle.ConstAngle < logpro)
__device__ static inline void doRefMapFFT(const int iRefMap, const int iOrient, const int iConv, const myfloat_t amp, const myfloat_t pha, const myfloat_t env, const myfloat_t* lCC, const myfloat_t sumC, const myfloat_t sumsquareC, bioem_Probability& pProb, const bioem_param_device& param, const bioem_RefMap& RefMap)
{
//******************** Using FFT algorithm **************************
//******************* Get cross-crollation of Ical to Iobs *******************
//*********** Routine to get the Cross-Corellation from lCC for the interested center displacement *************
for (int cent_x = 0; cent_x <= param.maxDisplaceCenter; cent_x = cent_x + param.GridSpaceCenter)
{ {
for (int cent_y = 0; cent_y <= param.maxDisplaceCenter; cent_y = cent_y + param.GridSpaceCenter) pProbAngle.forAngles *= exp(-logpro + pProbAngle.ConstAngle);
{ pProbAngle.ConstAngle = logpro;
calProb(iRefMap, iOrient, iConv, amp, pha, env, sumC, sumsquareC, (myfloat_t) lCC[cent_x * param.NumberPixels + cent_y] / (myfloat_t) (param.NumberPixels * param.NumberPixels), cent_x, cent_y, pProb, param, RefMap);
}
for (int cent_y = param.NumberPixels - param.maxDisplaceCenter; cent_y < param.NumberPixels; cent_y = cent_y + param.GridSpaceCenter)
{
calProb(iRefMap, iOrient, iConv,amp, pha, env, sumC, sumsquareC, (myfloat_t) lCC[cent_x * param.NumberPixels + cent_y] / (myfloat_t) (param.NumberPixels * param.NumberPixels), cent_x, cent_y - param.NumberPixels, pProb, param, RefMap);
}
} }
for (int cent_x = param.NumberPixels - param.maxDisplaceCenter; cent_x < param.NumberPixels; cent_x = cent_x + param.GridSpaceCenter) pProbAngle.forAngles += exp(logpro - pProbAngle.ConstAngle);
{ }
for (int cent_y = 0; cent_y < param.maxDisplaceCenter; cent_y = cent_y + param.GridSpaceCenter)
{
calProb(iRefMap, iOrient, iConv,amp, pha, env, sumC, sumsquareC, (myfloat_t) lCC[cent_x * param.NumberPixels + cent_y] / (myfloat_t) (param.NumberPixels * param.NumberPixels), cent_x - param.NumberPixels, cent_y, pProb, param, RefMap);
}
for (int cent_y = param.NumberPixels - param.maxDisplaceCenter ; cent_y < param.NumberPixels; cent_y = cent_y + param.GridSpaceCenter)
{
calProb(iRefMap, iOrient, iConv, amp, pha, env, sumC, sumsquareC, (myfloat_t) lCC[cent_x * param.NumberPixels + cent_y] / (myfloat_t) (param.NumberPixels * param.NumberPixels), cent_x - param.NumberPixels, cent_y - param.NumberPixels, pProb, param, RefMap);
}
}
//************ The following if is not in the manual***********
if (param.writeCC)
{
// If the Cross-correlation is to be written out and stored using Bayesian analysis
int cc=0;
for (int cent_x = 0; cent_x < param.NumberPixels ; cent_x = cent_x + param.CCdisplace)
{
for (int cent_y = 0; cent_y < param.NumberPixels ; cent_y = cent_y + param.CCdisplace)
{
bioem_Probability_cc& pProbCC = pProb.getProbCC(iRefMap, cc);
myfloat_t ttmp,ttmp2;
ttmp2 = (myfloat_t) lCC[cent_x * param.NumberPixels + cent_y] / (myfloat_t) (param.NumberPixels * param.NumberPixels);
if(not param.flipped){
//Here we are inverting the sign of the cross-correlation for the images that are not flipped
ttmp=-ttmp2; }
else{ ttmp=ttmp2; }
if(!param.CCwithBayes){
// Storing Only the Maximum both for flipped and not flipped
if(pProbCC.forCC < ttmp) pProbCC.forCC = ttmp;
}else {
// Storing the Cross-correlation with Bayesian formalism
if(pProbCC.ConstCC < ttmp)
{
pProbCC.forCC = pProbCC.forCC * exp(-ttmp + pProbCC.ConstCC);
pProbCC.ConstCC = ttmp;
}
pProbCC.forCC += exp(ttmp - pProbCC.ConstCC);
}
// printf("Separate %d %d Ptot: %f Const: %f logProb %f \n",cent_x,cent_y,pProbCC.forCC,pProbCC.ConstCC,ttmp);
cc++;
}
}
}