Skip to content

Commit

Permalink
Fixed Normal and EllipticalDistribution
Browse files Browse the repository at this point in the history
Now, degenerate covariances are accepted.
  • Loading branch information
regislebrun committed Dec 2, 2024
1 parent 86c3386 commit 0e40ca2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions lib/src/Uncertainty/Distribution/Normal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,17 @@ Normal::Normal(const Point & mean,
{
const Scalar cii = C(i, i);
if (!(cii > 0.0))
throw InvalidArgumentException(HERE) << "Diagonal elements of covariance matrix must be strictly positive";
sigma[i] = std::sqrt(cii);
for (UnsignedInteger j = 0; j < i; ++ j)
R(i, j) = C(i, j) / (sigma[i] * sigma[j]);
{
sigma[i] = 0.0;
// throw InvalidArgumentException(HERE) << "Diagonal elements of covariance matrix must be strictly positive";
}
else
{
sigma[i] = std::sqrt(cii);
for (UnsignedInteger j = 0; j < i; ++ j)
if (sigma[j] > 0.0)
R(i, j) = C(i, j) / (sigma[i] * sigma[j]);
}
}
*this = Normal(mean, sigma, R);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Uncertainty/Model/EllipticalDistribution.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ EllipticalDistribution::EllipticalDistribution(const Point & mu,
<< " mu dimension=" << mu.getDimension();
// We check that the marginal standard deviations are > 0
for(UnsignedInteger i = 0; i < dimension; ++i)
if (!(sigma[i] > 0.0)) throw InvalidArgumentException(HERE) << "The marginal standard deviations must be > 0 sigma=" << sigma[i];
if (!(sigma[i] >= 0.0)) throw InvalidArgumentException(HERE) << "The marginal standard deviations must be >= 0 sigma=" << sigma[i];
// Then we set the dimension of the Elliptical distribution
setDimension(dimension);
// The mean attribute is stored at an upper level
Expand Down

0 comments on commit 0e40ca2

Please sign in to comment.