Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A dedicated library for statistical distributions #104

Merged
merged 26 commits into from
Oct 27, 2023
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f2592e0
Added draft for Dirichlet distribution.
astamm Apr 5, 2023
d0df9e5
Rename concentration param. Switch sign in checking input belongs to …
astamm Apr 6, 2023
90232a6
Move constructors and param setters in child classes.
astamm Apr 6, 2023
b53d06a
Simplify Dirichlet setter. Remove useless hxx.
astamm Apr 6, 2023
e6ab9f9
New Digamma, Trigamma and Inverse Digamma functions
MariePoirierGit May 10, 2023
dfcee21
Dirichlet parameters estimation
MariePoirierGit May 10, 2023
44a5371
Clean gamma functions and related Bessel functions.
astamm May 11, 2023
7f4d315
Fix dirichlet Fit method.
astamm May 11, 2023
b6c7edb
Merge branch 'Inria-Empenn:master' into dirichlet_distribution
astamm Sep 12, 2023
ed672f2
Better handle mask images in gamma estimation filter.
astamm Sep 18, 2023
5ff9258
Added limit cases to compute digamma function to avoid under and over…
astamm Sep 18, 2023
7cc7701
Better handling of corner cases.
astamm Sep 18, 2023
93952e4
Added dirichlet estimation image filter.
astamm Sep 18, 2023
0deaf9c
Added tool for merging anisotropic weights of an MCM image.
astamm Sep 21, 2023
9bd7e2b
Simplify code for merging anisotropic weights in MCM images.
astamm Sep 22, 2023
498d621
Rebase on master.
astamm Oct 6, 2023
04102e8
Fit dirichlet on subdomain in case components have null variance.
astamm Oct 19, 2023
e8954d3
Added Watson distro to statistical distributions library. Missing Fit…
astamm Oct 21, 2023
1176c61
Move image filter along with its binary tool folder.
astamm Oct 25, 2023
1010a06
Add BelongsToSupport() method for all statistical distributions.
astamm Oct 25, 2023
a3799e9
Added Watson distribution to stat distributions library.
astamm Oct 25, 2023
04c35a3
Ensure to not fit gamma distribution if all data is zero.
astamm Oct 25, 2023
6557dfa
Add GetMean and GetVariance methods to statistical distributions. Fix…
astamm Oct 25, 2023
544c6d5
Improved parameter estimation for Dirichlet distribution.
astamm Oct 26, 2023
a2b744b
Invert a double loop.
astamm Oct 26, 2023
9c134ba
Fix bug due to non intialized vector.
astamm Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename concentration param. Switch sign in checking input belongs to …
…simplex in dirichlet distribution.
astamm committed Apr 6, 2023
commit d0df9e5d57a5a1664f2f38eb9abd97c0ae3dd6a9
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ namespace anima
void SetScaleParameter(const SingleValueType val);
double GetScaleParameter() {return m_ScaleParameter;}

void SetConcentrationParameters(const SingleValueType val);
SingleValueType GetConcentrationParameters() {return m_ConcentrationParameters;}
void SetConcentrationParameter(const SingleValueType val);
SingleValueType GetConcentrationParameter() {return m_ConcentrationParameter;}

virtual double GetDensity(const SingleValueType &x) = 0;
virtual double GetLogDensity(const SingleValueType &x) = 0;
@@ -38,7 +38,7 @@ namespace anima
private:
double m_ShapeParameter;
double m_ScaleParameter;
SingleValueType m_ConcentrationParameters;
SingleValueType m_ConcentrationParameter;
};
} // end of namespace

Original file line number Diff line number Diff line change
@@ -23,17 +23,17 @@ void BaseDistribution<TSingleValueType,TMultipleValueType>::SetScaleParameter(co
}

template <typename TSingleValueType, typename TMultipleValueType>
void BaseDistribution<TSingleValueType,TMultipleValueType>::SetConcentrationParameters(const SingleValueType val)
void BaseDistribution<TSingleValueType,TMultipleValueType>::SetConcentrationParameter(const SingleValueType val)
{
unsigned int numParameters = val.size();
m_ConcentrationParameters.resize(numParameters);
m_ConcentrationParameter.resize(numParameters);

for (unsigned int i = 0;i < numParameters;++i)
{
double tmpValue = val[i];
if (tmpValue < std::numeric_limits<double>::epsilon())
throw itk::ExceptionObject(__FILE__, __LINE__, "The concentration parameters of a statistical distribution should be strictly positive.", ITK_LOCATION);
m_ConcentrationParameters[i] = tmpValue;
m_ConcentrationParameter[i] = tmpValue;
}
}

Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ double DirichletDistribution::GetDensity(const SingleValueType &x)
sumValue += tmpValue;
}

if (std::abs(sumValue - 1.0) < std::numeric_limits<double>::epsilon())
if (std::abs(sumValue - 1.0) > std::numeric_limits<double>::epsilon())
return 0.0;

return std::exp(this->GetLogDensity(x));
@@ -38,10 +38,10 @@ double DirichletDistribution::GetLogDensity(const SingleValueType &x)
sumValue += tmpValue;
}

if (std::abs(sumValue - 1.0) < std::numeric_limits<double>::epsilon())
if (std::abs(sumValue - 1.0) > std::numeric_limits<double>::epsilon())
throw itk::ExceptionObject(__FILE__, __LINE__, "The log-density of the Dirichlet distribution is not defined for elements outside the simplex.", ITK_LOCATION);

SingleValueType alphaParameters = this->GetConcentrationParameters();
SingleValueType alphaParameters = this->GetConcentrationParameter();
if (alphaParameters.size() != numParameters)
throw itk::ExceptionObject(__FILE__, __LINE__, "The input argument does not belong to the same simplex as the one on which the Dirichlet distribution is defined.", ITK_LOCATION);

@@ -62,24 +62,28 @@ double DirichletDistribution::GetLogDensity(const SingleValueType &x)

void DirichletDistribution::Fit(const MultipleValueType &sample, const std::string &method)
{

unsigned int numParameters = sample.cols();
SingleValueType alphaParameters(numParameters, 1.0);

// Here comes the estimation code

this->SetConcentrationParameter(alphaParameters);
}

void DirichletDistribution::Random(MultipleValueType &sample, GeneratorType &generator)
{
unsigned int numObservations = sample.rows();
unsigned int numParameters = sample.cols();

SingleValueType alphaParameters = this->GetConcentrationParameters();
SingleValueType alphaParameters = this->GetConcentrationParameter();
if (alphaParameters.size() != numParameters)
throw itk::ExceptionObject(__FILE__, __LINE__, "The requested sample does not belong to the same simplex as the one on which the Dirichlet distribution is defined.", ITK_LOCATION);

BetaDistributionType betaDist;
UniformDistributionType unifDist(0.0, 1.0);
double samplePartialSum;
for (unsigned int i = 0;i < numObservations;++i)
{
samplePartialSum = 0.0;
double samplePartialSum = 0.0;
for (unsigned int j = 0;j < numParameters - 1;++j)
{
double alphaPartialSum = 0.0;
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ int main(int argc, char **argv)
concentrationParameters[1] = bArg.getValue();

anima::DirichletDistribution dirichletDistribution;
dirichletDistribution.SetConcentrationParameters(concentrationParameters);
dirichletDistribution.SetConcentrationParameter(concentrationParameters);

std::mt19937 generator(1234);

@@ -44,5 +44,13 @@ int main(int argc, char **argv)
}
std::cout << std::endl;

dirichletDistribution.Fit(sample, "mle");

concentrationParameters = dirichletDistribution.GetConcentrationParameter();
std::cout << "Concentration parameters: ";
for (unsigned int i = 0;i < sample.cols();++i)
std::cout << concentrationParameters[i] << " ";
std::cout << std::endl;

return EXIT_SUCCESS;
}