Skip to content

Commit

Permalink
Fixes #1995. Setting a value for discrete resets the percentile
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre committed May 2, 2023
1 parent ae46b73 commit 6bc6c43
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ protected override double CalculateFor(IReadOnlyList<IObjectReference> usedObjec

public override double CalculatePercentileForValue(double value, IUsingFormula refObject)
{
return value < Mean(refObject) ? 0 : 0.5;
return 0.5;
}

public override double CalculateValueFromPercentile(double percentile, IUsingFormula refObject)
{
return percentile >= 0.5 ? Mean(refObject) : 0;
return Mean(refObject);
}

public override double ProbabilityDensityFor(double value, IUsingFormula refObject)
Expand Down
9 changes: 2 additions & 7 deletions src/OSPSuite.Core/Domain/WithExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ public static T WithDimension<T>(this T withDimension, IDimension dimension) whe
}

public static T WithValue<T>(this T withValue, double value) where T : IWithValue
{
//A using formula for which no formula is defined? We create a constant formula
if (withValue is IUsingFormula usingFormula && usingFormula.Formula == null)
usingFormula.Formula = new ConstantFormula(value);
else
withValue.Value = value;

{
withValue.Value = value;
return withValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ protected override void Because()
[Observation]
public void distributed_parameter_should_return_correct_value()
{
var distr = new DiscreteDistributionFormula();

_distributedParam.Value.ShouldBeEqualTo(distr.CalculateValueFromPercentile(_distributedParam.Percentile, _distributedParam), 1e-5);
_distributedParam.Value.ShouldBeEqualTo(_distributedParam.MeanParameter.Value);
}
}

Expand Down

0 comments on commit 6bc6c43

Please sign in to comment.