DGtal  1.5.beta
DGtal::Profile< TValueFunctor, TValue > Class Template Reference

Aim: This class can be used to represent a profile (PX, PY) defined from an input set of samples (Xi, Yi). For all sample (Xk, Yk) having the same value Xk, the associated value PY is computed (by default) by the mean of the values Yk. Note that other definitions can be used (MAX, MIN or MEDIAN). Internally each sample abscissa is an instance of DGtal::Statistic. More...

#include <DGtal/math/Profile.h>

Public Types

enum  ProfileType { MEAN , MAX , MIN , MEDIAN }
 
typedef TValueFunctor Functor
 
typedef TValue Value
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CUnaryFunctor< Functor, Value, Value >))
 
 ~Profile ()
 
 Profile ()
 
 Profile (ProfileType type)
 
 Profile (const Profile &other)
 
Profileoperator= (const Profile &other)
 
void clear ()
 
template<typename Iterator >
void init (Iterator beginXvalues, Iterator endXvalues, const bool storeValsInStats=false)
 
void init (const unsigned int nb, const bool storeValsInStats=false)
 
void addValue (const unsigned int indexX, const TValue value)
 
void addStatistic (const unsigned int indexX, const Statistic< Value > &stat)
 
void stopStatsSaving ()
 
void setType (const ProfileType type)
 
void getProfile (std::vector< Value > &x, std::vector< Value > &y) const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Private Attributes

Functor myFunctor
 
std::vector< Value > * myXsamples
 
std::vector< Statistic< Value > > * myStats
 
ProfileType myProfileDef
 
bool myStoreValInStats
 

Detailed Description

template<typename TValueFunctor = functors::Identity, typename TValue = double>
class DGtal::Profile< TValueFunctor, TValue >

Aim: This class can be used to represent a profile (PX, PY) defined from an input set of samples (Xi, Yi). For all sample (Xk, Yk) having the same value Xk, the associated value PY is computed (by default) by the mean of the values Yk. Note that other definitions can be used (MAX, MIN or MEDIAN). Internally each sample abscissa is an instance of DGtal::Statistic.

Description of class 'Profile'

This class is templated by the type of the functor TValueFunctor which is applied on the two coordinate values of the resulting profile (PX, PY). This functor is by default set to the identity functor. The default type (double) of the values added to the profile can also be changed by using the template parameter TValue.

For instance to construct a Profile defined from a data sample having its Xi integer values from 1 to 10, you can construct and initialize a Profile as follows:

Profile<> sp;
sp.init(10);

Alternatively you can customize the Xi initialisation by using an iterator:

std::vector<double> xDef;
for (double i = 0.5; i < 5; i=i+0.5){
xDef.push_back(i);
}
Profile<> sp;
sp.init(xDef.begin(), xDef.end());

Then, you can add the samples (Xk, Yk):

sp.addValue(0, 23.0);
sp.addValue(0, 20.0);
sp.addValue(1, 20.2);
sp.addValue(2, 10.4);
...
sp.addValue(9, 20);
// then you can get a profile:
std::vector<double> x;
std::vector<double> y;
sp.getProfile(x, y);

To obtain a profile given in log space, you just have to define the following basic log functor:

struct LogFct{
double operator()(const double &a) const {
return log(a);
}
};

And then you can construct a profile as previously:

Profile<LogFct> pLog;
pLog.init(10);
...
Template Parameters
TValueFunctorthe type of the functor applied in the resulting Profile (any model of CUnaryFunctor)
TValuethe type value stored in the profile.

The proposed implementation is mainly a backport from ImaGene with some various refactoring.

Definition at line 136 of file Profile.h.

Member Typedef Documentation

◆ Functor

template<typename TValueFunctor = functors::Identity, typename TValue = double>
typedef TValueFunctor DGtal::Profile< TValueFunctor, TValue >::Functor

The type of the functor applied to the resulting Profile

Definition at line 151 of file Profile.h.

◆ Value

template<typename TValueFunctor = functors::Identity, typename TValue = double>
typedef TValue DGtal::Profile< TValueFunctor, TValue >::Value

The type value stored in the profile.

Definition at line 156 of file Profile.h.

Member Enumeration Documentation

◆ ProfileType

template<typename TValueFunctor = functors::Identity, typename TValue = double>
enum DGtal::Profile::ProfileType

Used to specify the method to compute the profile values (used in getProfile())

Enumerator
MEAN 
MAX 
MIN 
MEDIAN 

Definition at line 146 of file Profile.h.

Constructor & Destructor Documentation

◆ ~Profile()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
DGtal::Profile< TValueFunctor, TValue >::~Profile ( )

Destructor.

◆ Profile() [1/3]

template<typename TValueFunctor = functors::Identity, typename TValue = double>
DGtal::Profile< TValueFunctor, TValue >::Profile ( )

Constructor. The object is not valid.

◆ Profile() [2/3]

template<typename TValueFunctor = functors::Identity, typename TValue = double>
DGtal::Profile< TValueFunctor, TValue >::Profile ( ProfileType  type)

Constructor. The object is not valid.

Parameters
[in]typeallows to specify the used to computes the profile points from the added samples.

◆ Profile() [3/3]

template<typename TValueFunctor = functors::Identity, typename TValue = double>
DGtal::Profile< TValueFunctor, TValue >::Profile ( const Profile< TValueFunctor, TValue > &  other)

Copy constructor.

Parameters
[in]otherthe object to clone.

Member Function Documentation

◆ addStatistic()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
void DGtal::Profile< TValueFunctor, TValue >::addStatistic ( const unsigned int  indexX,
const Statistic< Value > &  stat 
)

Adds some statistic at the given X value.

Parameters
[in]indexXsome valid index (according to init).
[in]statany statistic (which is added to the current statistic object).

◆ addValue()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
void DGtal::Profile< TValueFunctor, TValue >::addValue ( const unsigned int  indexX,
const TValue  value 
)

Adds some sample value at the given X value.

Parameters
[in]indexXsome valid index (according to init).
[in]valueany value.

Referenced by TEST_CASE().

◆ BOOST_CONCEPT_ASSERT()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
DGtal::Profile< TValueFunctor, TValue >::BOOST_CONCEPT_ASSERT ( (concepts::CUnaryFunctor< Functor, Value, Value >)  )

◆ clear()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
void DGtal::Profile< TValueFunctor, TValue >::clear ( )

Clears the object as if it has been just created.

◆ getProfile()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
void DGtal::Profile< TValueFunctor, TValue >::getProfile ( std::vector< Value > &  x,
std::vector< Value > &  y 
) const
Parameters
[out]x(modified) adds the x-value of the profile to the back of the vector.
[out]y(modified) adds the y-value of the profile (log(Exp(samples))) to the back of the vector.

Referenced by TEST_CASE().

◆ init() [1/2]

template<typename TValueFunctor = functors::Identity, typename TValue = double>
void DGtal::Profile< TValueFunctor, TValue >::init ( const unsigned int  nb,
const bool  storeValsInStats = false 
)

Initializer. Must be called before adding datas. Specifies the X values of the profile as the sequence (1,2,3,4,...,nb).

Parameters
[in]nban integer number strictly positive.
[in]storeValsInStatsflag to store values in statistics (so that the median value is accessible (default false)).

◆ init() [2/2]

template<typename TValueFunctor = functors::Identity, typename TValue = double>
template<typename Iterator >
void DGtal::Profile< TValueFunctor, TValue >::init ( Iterator  beginXvalues,
Iterator  endXvalues,
const bool  storeValsInStats = false 
)

Initializer. Must be called before adding datas. Specifies the X values of the profile (generally an iterator on a sequence (1,2,3,4,...N)).

Parameters
[in]beginXvaluesan iterator pointing on the first X value.
[in]endXvaluesan iterator pointing after the last X value.
[in]storeValsInStatsflag to store values in statistics (so that the median value is accessible (default false)).

Referenced by TEST_CASE().

◆ isValid()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
bool DGtal::Profile< TValueFunctor, TValue >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

◆ operator=()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
Profile& DGtal::Profile< TValueFunctor, TValue >::operator= ( const Profile< TValueFunctor, TValue > &  other)

Assignment.

Parameters
[in]otherthe object to copy.
Returns
a reference on 'this'. Forbidden by default.

◆ selfDisplay()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
void DGtal::Profile< TValueFunctor, TValue >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
[out]outthe output stream where the object is written.

◆ setType()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
void DGtal::Profile< TValueFunctor, TValue >::setType ( const ProfileType  type)

Used to define the method to determine the profile values from the samples of X statistics.

Parameters
[in]typethe method applied to the statistics samples: MEAN, MAX, MIN.

Referenced by TEST_CASE().

◆ stopStatsSaving()

template<typename TValueFunctor = functors::Identity, typename TValue = double>
void DGtal::Profile< TValueFunctor, TValue >::stopStatsSaving ( )

It stops and Erase the stats saved values. It must be called to avoid to store all statistics values when we have to access to the median value. Typically if you nedd to access to the median value of the profile, you need to follow this example:

// the value are now stored and you can access to the median value of the profile.
sp.init(true);
sp.addValue(0, 10.5);
sp.addValue(0, 9.2);
...
// When all values have been added you can stop to store them again
sp.stopStatsSaving();
// before erasing all statistics data, the median is computed and stored.

Field Documentation

◆ myFunctor

template<typename TValueFunctor = functors::Identity, typename TValue = double>
Functor DGtal::Profile< TValueFunctor, TValue >::myFunctor
private

Definition at line 320 of file Profile.h.

◆ myProfileDef

template<typename TValueFunctor = functors::Identity, typename TValue = double>
ProfileType DGtal::Profile< TValueFunctor, TValue >::myProfileDef
private

Used to define the method to compute the profile: several choice are possible: MEAN (default), MAX, MIN (not efficient) or MEDIAN.

Definition at line 336 of file Profile.h.

◆ myStats

template<typename TValueFunctor = functors::Identity, typename TValue = double>
std::vector< Statistic<Value> >* DGtal::Profile< TValueFunctor, TValue >::myStats
private

The vector containing the different statistics for the analysis.

Definition at line 330 of file Profile.h.

◆ myStoreValInStats

template<typename TValueFunctor = functors::Identity, typename TValue = double>
bool DGtal::Profile< TValueFunctor, TValue >::myStoreValInStats
private

Used to temporaly store values in statistics in order to be able to access to the median value. By default the value is set to false and the median is not available.

See also
setStoreStats

Definition at line 346 of file Profile.h.

◆ myXsamples

template<typename TValueFunctor = functors::Identity, typename TValue = double>
std::vector<Value>* DGtal::Profile< TValueFunctor, TValue >::myXsamples
private

The vector containing the different X samples for the analysis.

Definition at line 325 of file Profile.h.


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