23 throw std::runtime_error(
"Error in GaussianEliminationAlg: Cannot construct with negative step or max.");
31 fDistanceLookupTable.clear();
32 fDistanceLookupTable.reserve(std::ceil(fDistanceMax/fDistanceStepSize)+2);
36 while(x_val <= fDistanceMax+fDistanceStepSize){
37 fDistanceLookupTable.push_back(
std::exp(x_val*x_val*0.5*-1) );
38 x_val += fDistanceStepSize;
41 fDistanceLookupTable.push_back(
std::exp(x_val*x_val*0.5*-1) );
47 if(d_abs > fDistanceMax)
50 size_t low_bin = std::floor(d_abs/fDistanceStepSize);
51 return fDistanceLookupTable[low_bin] -
52 (d_abs/fDistanceStepSize-(double)low_bin)*(fDistanceLookupTable[low_bin]-fDistanceLookupTable[low_bin+1]);
57 const std::vector<float>& sigmaVector,
58 const std::vector<float>& heightVector)
61 if(meanVector.size()!=sigmaVector.size() ||
62 meanVector.size()!=heightVector.size())
63 throw std::runtime_error(
"Error in GaussianEliminationAlg: Vector sizes not equal.");
65 FillAugmentedMatrix(meanVector,sigmaVector,heightVector);
66 GaussianElimination();
73 const std::vector<float>& sigmaVector,
74 const std::vector<float>& heightVector)
77 fMatrix.resize(meanVector.size());
78 for(
size_t i=0; i<meanVector.size(); i++){
80 fMatrix[i].resize(meanVector.size()+1);
81 for(
size_t j=0; j<meanVector.size(); j++){
82 if(sigmaVector[j] < std::numeric_limits<float>::epsilon()){
89 fMatrix[i][j] = GetDistance( (meanVector[i]-meanVector[j])/sigmaVector[j] );
91 fMatrix[i][meanVector.size()] = heightVector[i];
100 fSolutions.resize(fMatrix.size(),0.0);
102 for(
size_t i=0; i<fMatrix.size(); i++){
104 for(
size_t j=i+1; j<(fMatrix[i].size()-1); j++){
105 float scale_value = fMatrix[j][i] / fMatrix[i][i];
106 for(
size_t k=i;
k<fMatrix[i].size();
k++)
107 fMatrix[j][
k] -= fMatrix[i][
k]*scale_value;
112 for(
int i=fMatrix.size()-1; i>=0; i--){
113 fSolutions[i] = fMatrix[i].back();
115 for(
size_t j=i+1; j<fMatrix.size(); j++)
116 fSolutions[i] -= fMatrix[i][j]*fSolutions[j];
118 fSolutions[i] /= fMatrix[i][i];
125 std::cout <<
"GaussianEliminationAlg." << std::endl;
127 std::cout <<
"\tLookup table (step=" << fDistanceStepSize <<
", max=" << fDistanceMax <<
")" << std::endl;
128 for(
size_t i=0; i<fDistanceLookupTable.size(); i++)
129 std::cout <<
"\t\tGaussian(" << fDistanceStepSize*i <<
") = " << fDistanceLookupTable[i] << std::endl;
132 std::cout <<
"\tAugmented matrix " << std::endl;
133 for(
size_t i=0; i<fMatrix.size(); i++){
135 for(
size_t j=0; j<fMatrix[i].size()-1; j++)
137 std::cout <<
" | " << fMatrix[i][fMatrix[i].size()-1] <<
" |" << std::endl;
141 for(
size_t i=0; i<fSolutions.size(); i++)
142 std::cout <<
"\t\t" << i <<
" " << fSolutions[i] << std::endl;
double GetDistance(float) const
void FillDistanceLookupTable()
void GaussianElimination()
void FillAugmentedMatrix(const std::vector< float > &meanVector, const std::vector< float > &sigmaVector, const std::vector< float > &heightVector)
const std::vector< float > & SolveEquations(const std::vector< float > &meanVector, const std::vector< float > &sigmaVector, const std::vector< float > &heightVector)
GaussianEliminationAlg(float, float)
BEGIN_PROLOG could also be cout