Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/VariationCoefficientLogNormalDistribution.cs =================================================================== diff -u -reef2f17598bbe7b051207dfac25952567d57f64c -rc7dca9b1591f0b27c4f0369c6034b152c6849a38 --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/VariationCoefficientLogNormalDistribution.cs (.../VariationCoefficientLogNormalDistribution.cs) (revision eef2f17598bbe7b051207dfac25952567d57f64c) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/VariationCoefficientLogNormalDistribution.cs (.../VariationCoefficientLogNormalDistribution.cs) (revision c7dca9b1591f0b27c4f0369c6034b152c6849a38) @@ -34,6 +34,7 @@ { private RoundedDouble mean; private RoundedDouble coefficientOfVariation; + private RoundedDouble shift; /// /// Initializes a new instance of the class, @@ -44,7 +45,7 @@ /// /// Initializes a new instance of the class, - /// initialized as a log normal distribution (mean=1 and coefficient of variation, CV=1). + /// initialized as a log normal distribution (mean=1, CV=1, theta=0). /// /// The number of decimal places. /// @@ -54,9 +55,31 @@ { mean = new RoundedDouble(numberOfDecimalPlaces, 1.0); coefficientOfVariation = new RoundedDouble(numberOfDecimalPlaces, 1.0); + shift = new RoundedDouble(numberOfDecimalPlaces); } /// + /// Gets or sets the shift of the normal distribution which is the log of the log-normal distribution. + /// + /// Thrown when the shift is larger than the mean. + public RoundedDouble Shift + { + get + { + return shift; + } + set + { + RoundedDouble newShift = value.ToPrecision(shift.NumberOfDecimalPlaces); + if (newShift > Mean) + { + throw new ArgumentOutOfRangeException(null, Resources.LogNormalDistribution_Shift_may_not_exceed_Mean); + } + shift = newShift; + } + } + + /// /// Gets or sets the mean (expected value, E(X)) of the distribution. /// /// Expected value is less than or equal to 0. @@ -123,6 +146,7 @@ { int hashCode = Mean.GetHashCode(); hashCode = (hashCode * 397) ^ CoefficientOfVariation.GetHashCode(); + hashCode = (hashCode * 397) ^ Shift.GetHashCode(); return hashCode; } } @@ -135,7 +159,8 @@ private bool Equals(VariationCoefficientLogNormalDistribution other) { return Mean.Equals(other.Mean) - && CoefficientOfVariation.Equals(other.CoefficientOfVariation); + && CoefficientOfVariation.Equals(other.CoefficientOfVariation) + && Shift.Equals(other.Shift); } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionTest.cs =================================================================== diff -u -rb286d241c3bfefe14166cc01382e806c98b54b5a -rc7dca9b1591f0b27c4f0369c6034b152c6849a38 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionTest.cs (.../LogNormalDistributionTest.cs) (revision b286d241c3bfefe14166cc01382e806c98b54b5a) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionTest.cs (.../LogNormalDistributionTest.cs) (revision c7dca9b1591f0b27c4f0369c6034b152c6849a38) @@ -227,7 +227,8 @@ var original = new LogNormalDistribution(random.Next(1, 16)) { Mean = random.NextRoundedDouble(), - StandardDeviation = random.NextRoundedDouble() + StandardDeviation = random.NextRoundedDouble(), + Shift = random.NextRoundedDouble() }; // Call Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientLogNormalDistributionTest.cs =================================================================== diff -u -rb286d241c3bfefe14166cc01382e806c98b54b5a -rc7dca9b1591f0b27c4f0369c6034b152c6849a38 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientLogNormalDistributionTest.cs (.../VariationCoefficientLogNormalDistributionTest.cs) (revision b286d241c3bfefe14166cc01382e806c98b54b5a) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientLogNormalDistributionTest.cs (.../VariationCoefficientLogNormalDistributionTest.cs) (revision c7dca9b1591f0b27c4f0369c6034b152c6849a38) @@ -53,6 +53,11 @@ otherCoefficientOfVariation.CoefficientOfVariation = (RoundedDouble) 0.987; yield return new TestCaseData(distribution, otherCoefficientOfVariation, false) .SetName(nameof(otherCoefficientOfVariation)); + + VariationCoefficientLogNormalDistribution otherShift = CreateFullyDefinedDistribution(); + otherShift.Shift = (RoundedDouble) 0.987; + yield return new TestCaseData(distribution, otherShift, false) + .SetName(nameof(otherShift)); } } @@ -71,6 +76,8 @@ Assert.AreEqual(1.0, distribution.Mean.Value); Assert.AreEqual(numberOfDecimals, distribution.CoefficientOfVariation.NumberOfDecimalPlaces); Assert.AreEqual(1.0, distribution.CoefficientOfVariation.Value); + Assert.AreEqual(numberOfDecimals, distribution.Shift.NumberOfDecimalPlaces); + Assert.AreEqual(0, distribution.Shift.Value); } [Test] @@ -89,6 +96,8 @@ Assert.AreEqual(1.0, distribution.Mean.Value); Assert.AreEqual(numberOfDecimals, distribution.CoefficientOfVariation.NumberOfDecimalPlaces); Assert.AreEqual(1.0, distribution.CoefficientOfVariation.Value); + Assert.AreEqual(numberOfDecimals, distribution.Shift.NumberOfDecimalPlaces); + Assert.AreEqual(0, distribution.Shift.Value); } [Test] @@ -168,6 +177,45 @@ } [Test] + [TestCase(1, 5.6)] + [TestCase(3, 5.647)] + [TestCase(4, 5.6473)] + [TestCase(15, 5.647300000000000)] + public void Shift_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces(int numberOfDecimalPlaces, double expectedStandardDeviation) + { + // Setup + var distribution = new VariationCoefficientLogNormalDistribution(numberOfDecimalPlaces) + { + Mean = new RoundedDouble(2, 10.0) + }; + + // Call + distribution.Shift = new RoundedDouble(4, 5.6473); + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.Shift.NumberOfDecimalPlaces); + Assert.AreEqual(expectedStandardDeviation, distribution.Shift.Value); + } + + [Test] + public void Shift_SetIllegalValue_ThrowArgumentOutOfRangeException() + { + // Setup + var distribution = new VariationCoefficientLogNormalDistribution(2) + { + Mean = new RoundedDouble(2, 10.0), + CoefficientOfVariation = new RoundedDouble(2, 1.0) + }; + + // Call + TestDelegate call = () => distribution.Shift = new RoundedDouble(2, 100.0); + + // Assert + const string expectedMessage = "De verschuiving mag niet groter zijn dan de verwachtingswaarde."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] public void Clone_Always_ReturnNewInstanceWithCopiedValues() { // Setup @@ -254,7 +302,8 @@ return new VariationCoefficientLogNormalDistribution(5) { Mean = (RoundedDouble) 1, - CoefficientOfVariation = (RoundedDouble) 0.1 + CoefficientOfVariation = (RoundedDouble) 0.1, + Shift = (RoundedDouble) 0.2 }; } }