35 #ifndef AIMS_MATH_PPCA_H
36 #define AIMS_MATH_PPCA_H
52 double distanceRef = 0. );
55 void doIt(
const std::list< Point3d>& selectedPoints,
57 double distanceRef = 0. );
87 double& normMean )
const ;
102 int approx = int( x * 10.) ;
103 double res = (x * 10. - approx) ;
104 return ( 1. - res ) *
_exp[approx] + res *
_exp[approx+1] ;
135 const std::vector< std::list <Point3d> >& classes,
136 int nbOfSignificantEigenValues,
137 const std::vector<double>& PIj
138 = std::vector<double>() ) ;
144 std::vector<double>& maxProbaByClass ) ;
147 std::vector<double>& maxProbaByClass ) ;
157 double thresholdOnMaxPercentage = 0.,
158 double andersonScoreThreshold = 0.2,
165 unsigned int classNb )
167 if( classNb >= _discrElements.size() )
168 throw std::runtime_error(
"Class number exceeds number of classes") ;
170 return _discrElements[classNb].posteriorProbability(x,
pX) ;
178 double weight(
double norm2,
int classe,
float tolerance ) ;
179 double wienerFilter(
double sigma2,
double norm2,
double factor ) ;
180 const std::vector< std::list< Point3d > >& _classes ;
182 double _distanceRef ;
183 std::vector<double> _PIj ;
184 int _nbOfSignificantEigenValues ;
185 std::vector<ProbabilisticPcaElement> _discrElements ;
195 std::cerr <<
"ProbabilisticPcaElement::distance : " << std::endl ;
196 throw std::runtime_error(
"You must doIt first, parameter not yet "
201 std::cerr <<
"Invalid ppca ! "<< std::endl ;
211 for(
int i = 0 ; i < x->getSizeX() ; ++i )
214 for(
int j = 0 ; j < x->getSizeX() ; ++j )
221 std::cout <<
"Distance = " <<
distance << std::endl ;
233 std::cerr <<
"ProbabilisticPcaElement::posteriorProbability : "
235 throw std::runtime_error(
"You must doIt first, parameter not yet "
243 double distance = 0. ;
244 for(
int i = 0 ; i < x->getSizeX() ; ++i ){
246 for(
int j = 0 ; j < x->getSizeX() ; ++j )
247 sum += _invCi(i, j) * ( x->at(j) - _mean(j) ) ;
248 distance += ( x->at(i) - _mean(i) ) *
sum ;
252 std::cout <<
"Distance = " << distance << std::endl ;
257 int index = int( 0.5 * (distance - _distanceRef) * 100.
261 else if( index < 0. )
262 return _normFactor / _exp[ -index ] * _PIj / pX ;
264 return _normFactor * _exp[ index ] * _PIj / pX ;
273 std::cerr <<
"ProbabilisticPcaElement::lnPosteriorProbability : "
275 throw std::runtime_error(
"You must doIt first, parameter not yet "
283 double distance = 0. ;
284 for(
int i = 0 ; i < x->getSizeX() ; ++i )
287 for(
int j = 0 ; j < x->getSizeX() ; ++j )
288 sum += _invCi(i, j) * ( x->at(j) - _mean(j) ) ;
289 distance += ( x->at(i) - _mean(i) ) *
sum ;
294 std::cout <<
"Distance = " << distance << std::endl ;
300 return ( _distanceRef - distance + _lnAddFactor ) ;
double normFactor() const
ProbabilisticPcaElement(int nbOfSignificativeEV, double PIj=1.)
const carto::VolumeRef< double > & mean() const
const carto::VolumeRef< double > & selectedEigenVectors()
carto::VolumeRef< double > _x
double noiseVariance() const
carto::VolumeRef< double > _Wi
const carto::VolumeRef< double > & eigenValues()
carto::VolumeRef< double > _xT
carto::VolumeRef< double > _invCi
carto::VolumeRef< double > _EValues
double distance(const carto::rc_ptr< carto::Volume< double > > &individual)
double exponential(double x)
double lnPosteriorProbability(const carto::rc_ptr< carto::Volume< double > > &individual)
virtual ~ProbabilisticPcaElement()
double posteriorProbability(const carto::rc_ptr< carto::Volume< double > > &individual, double pX)
carto::VolumeRef< double > _mean
carto::VolumeRef< double > _EVect
void doIt(const carto::rc_ptr< carto::Volume< T > > &individuals, double distanceRef=0.)
ProbabilisticPca(const carto::rc_ptr< carto::Volume< T > > &data, const std::vector< std::list< Point3d > > &classes, int nbOfSignificantEigenValues, const std::vector< double > &PIj=std::vector< double >())
std::vector< double > andersonScores(const carto::rc_ptr< carto::Volume< double > > &x, double px, std::vector< double > &maxProbaByClass)
double pX(const carto::rc_ptr< carto::Volume< double > > &x)
bool classification(const carto::rc_ptr< carto::Volume< T > > &dynamicImage, const carto::rc_ptr< carto::Volume< byte > > &mask, carto::rc_ptr< carto::Volume< short > > &segmented)
short nbOfClasses() const
float posteriorProbability(const carto::rc_ptr< carto::Volume< double > > &x, float pX, unsigned int classNb)
std::vector< double > posteriorProbabilities(const carto::rc_ptr< carto::Volume< double > > &x, double px, std::vector< double > &maxProbaByClass)
bool fuzzyClassification(const carto::rc_ptr< carto::Volume< T > > &dynamicImage, const carto::rc_ptr< carto::Volume< byte > > &mask, carto::rc_ptr< carto::Volume< float > > &fuzzySegmented, double thresholdOnMaxPercentage=0., double andersonScoreThreshold=0.2, const carto::rc_ptr< carto::Volume< double > > &indivPriorProbabilities=carto::VolumeRef< double >())
int affectedTo(const carto::rc_ptr< carto::Volume< double > > &x)
BucketMap< Void > * mask(const BucketMap< Void > &src, const BucketMap< Void > &m, bool intersect=true)
DataTypeTraits< T >::LongType sum(const Volume< T > &vol)