Commit 0a4ba61e authored by Andrew Heather's avatar Andrew Heather
Browse files

BUG: corrected 'binned' distribution model

parent bf182b18
......@@ -47,10 +47,6 @@ const char* Foam::distributionModels::binned::header =
void Foam::distributionModels::binned::initialise()
{
const label nSample(xy_.size());
forAll(xy_, bini)
{
xy_[bini][1] /= scalar(nSample);
}
// Convert values to integral values
for (label bini = 1; bini < nSample; ++bini)
......@@ -58,6 +54,13 @@ void Foam::distributionModels::binned::initialise()
xy_[bini][1] += xy_[bini - 1][1];
}
// Normalise
scalar sumProb = xy_.last()[1];
forAll(xy_, bini)
{
xy_[bini][1] /= sumProb;
}
// Calculate the mean value
label bini = 0;
forAll(xy_, i)
......@@ -187,18 +190,9 @@ Foam::scalar Foam::distributionModels::binned::sample() const
for (label i = 0; i < xy_.size() - 1; ++i)
{
if (xy_[i][1] > y)
{
scalar d1 = y - xy_[i][1];
scalar d2 = xy_[i+1][1] - y;
if (d1 < d2)
{
return xy_[i][0];
}
else
{
return xy_[i+1][0];
}
}
}
return xy_.last()[0];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment