Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/LogNormalDistributionDesignVariable.cs =================================================================== diff -u -r1df1e9ae0057dde85489929cbf85d222c26e8c5f -rc90fad2c6d012238ac0b62e52f9820047de76ad6 --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/LogNormalDistributionDesignVariable.cs (.../LogNormalDistributionDesignVariable.cs) (revision 1df1e9ae0057dde85489929cbf85d222c26e8c5f) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/LogNormalDistributionDesignVariable.cs (.../LogNormalDistributionDesignVariable.cs) (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using Core.Common.Base.Data; namespace Ringtoets.Common.Data.Probabilistics @@ -37,30 +36,13 @@ public override RoundedDouble GetDesignValue() { - double normalSpaceDesignValue = DetermineDesignValueInNormalDistributionSpace(); - return ProjectFromNormalToLogNormalSpace(normalSpaceDesignValue) + Distribution.Shift; + return new RoundedDouble( + Distribution.Mean.NumberOfDecimalPlaces, + LogNormalDistributionDesignVariableCalculator.CreateWithStandardDeviation( + Distribution.Mean, + Distribution.StandardDeviation, + Distribution.Shift) + .GetDesignValue(Percentile)); } - - /// - /// Projects into 'normal - /// distribution' space and calculates the design value for that value space. - /// - /// The design value in 'normal distribution' space. - private double DetermineDesignValueInNormalDistributionSpace() - { - // Determine normal distribution parameters from log-normal parameters, as - // design value can only be determined in 'normal distribution' space. - // Below formula's come from Tu-Delft College dictaat "b3 Probabilistisch Ontwerpen" - // by ir. A.C.W.M. Vrouwenvelder and ir.J.K. Vrijling 5th reprint 1987. - double sigmaLogOverMuLog = Distribution.StandardDeviation/(Distribution.Mean - Distribution.Shift); - double sigmaNormal = Math.Sqrt(Math.Log(sigmaLogOverMuLog*sigmaLogOverMuLog + 1.0)); - double muNormal = Math.Log(Distribution.Mean - Distribution.Shift) - 0.5*sigmaNormal*sigmaNormal; - return DetermineDesignValue(muNormal, sigmaNormal); - } - - private RoundedDouble ProjectFromNormalToLogNormalSpace(double normalSpaceDesignValue) - { - return new RoundedDouble(Distribution.Mean.NumberOfDecimalPlaces, Math.Exp(normalSpaceDesignValue)); - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/LogNormalDistributionDesignVariableCalculator.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/LogNormalDistributionDesignVariableCalculator.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/LogNormalDistributionDesignVariableCalculator.cs (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -0,0 +1,96 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; + +namespace Ringtoets.Common.Data.Probabilistics +{ + /// + /// Calculator for design variables for log normal distributions. + /// + internal class LogNormalDistributionDesignVariableCalculator : PercentileBasedDesignVariableCalculator + { + /// + /// Creates a for normal distributions based + /// on mean and standard deviation. + /// + /// The mean of the log normal distribution. + /// The standard deviation of the log normal distribution. + /// The shift of the log normal distribution. + /// A new . + internal static PercentileBasedDesignVariableCalculator CreateWithStandardDeviation(double mean, double standardDeviation, double shift) + { + return new LogNormalDistributionDesignVariableCalculator(mean, standardDeviation, standardDeviation / (mean - shift), shift); + } + + /// + /// Creates a for normal distributions based + /// on mean and standard deviation. + /// + /// The mean of the log normal distribution. + /// The coefficient of variation of the log normal distribution. + /// The shift of the log normal distribution. + /// A new . + internal static PercentileBasedDesignVariableCalculator CreateWithCoefficientOfVariation(double mean, double coefficientOfVariation, double shift) + { + return new LogNormalDistributionDesignVariableCalculator(mean, (mean - shift) * coefficientOfVariation, coefficientOfVariation, shift); + } + + private LogNormalDistributionDesignVariableCalculator( + double mean, + double standardDeviation, + double coefficientOfVariation, + double shift) : base(mean, standardDeviation, coefficientOfVariation) + { + Shift = shift; + } + + internal override double GetDesignValue(double percentile) + { + double normalSpaceDesignValue = DetermineDesignValueInNormalDistributionSpace(percentile); + return ProjectFromNormalToLogNormalSpace(normalSpaceDesignValue) + Shift; + } + + private double Shift { get; } + + /// + /// Projects into 'normal + /// distribution' space and calculates the design value for that value space. + /// + /// The design value in 'normal distribution' space. + private double DetermineDesignValueInNormalDistributionSpace(double percentile) + { + // Determine normal distribution parameters from log-normal parameters, as + // design value can only be determined in 'normal distribution' space. + // Below formula's come from Tu-Delft College dictaat "b3 Probabilistisch Ontwerpen" + // by ir. A.C.W.M. Vrouwenvelder and ir.J.K. Vrijling 5th reprint 1987. + double sigmaNormal = Math.Sqrt(Math.Log(CoefficientOfVariation * CoefficientOfVariation + 1.0)); + double muNormal = Math.Log(Mean - Shift) - 0.5 * sigmaNormal * sigmaNormal; + + return DetermineDesignValue(muNormal, sigmaNormal, percentile); + } + + private static double ProjectFromNormalToLogNormalSpace(double normalSpaceDesignValue) + { + return Math.Exp(normalSpaceDesignValue); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariable.cs =================================================================== diff -u -r1df1e9ae0057dde85489929cbf85d222c26e8c5f -rc90fad2c6d012238ac0b62e52f9820047de76ad6 --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariable.cs (.../NormalDistributionDesignVariable.cs) (revision 1df1e9ae0057dde85489929cbf85d222c26e8c5f) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariable.cs (.../NormalDistributionDesignVariable.cs) (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -36,8 +36,12 @@ public override RoundedDouble GetDesignValue() { - return new RoundedDouble(Distribution.Mean.NumberOfDecimalPlaces, - DetermineDesignValue(Distribution.Mean, Distribution.StandardDeviation)); + return new RoundedDouble( + Distribution.Mean.NumberOfDecimalPlaces, + NormalDistributionDesignVariableCalculator.CreateWithStandardDeviation( + Distribution.Mean, + Distribution.StandardDeviation) + .GetDesignValue(Percentile)); } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariableCalculator.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariableCalculator.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariableCalculator.cs (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -0,0 +1,61 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Ringtoets.Common.Data.Probabilistics +{ + /// + /// Calculator for design variables for normal distributions. + /// + internal class NormalDistributionDesignVariableCalculator : PercentileBasedDesignVariableCalculator + { + /// + /// Creates a for normal distributions based + /// on mean and standard deviation. + /// + /// The mean of the normal distribution. + /// The standard deviation of the normal distribution. + /// A new . + internal static PercentileBasedDesignVariableCalculator CreateWithStandardDeviation(double mean, double standardDeviation) + { + return new NormalDistributionDesignVariableCalculator(mean, standardDeviation, standardDeviation / mean); + } + + /// + /// Creates a for normal distributions based + /// on mean and coefficient of variation. + /// + /// The mean of the normal distribution. + /// The coefficient of variation of the normal distribution. + /// A new . + internal static PercentileBasedDesignVariableCalculator CreateWithCoefficientOfVariation(double mean, double coefficientOfVariation) + { + return new NormalDistributionDesignVariableCalculator(mean, mean * coefficientOfVariation, coefficientOfVariation); + } + + private NormalDistributionDesignVariableCalculator(double mean, double standardDeviation, double coefficientOfVariation) + : base(mean, standardDeviation, coefficientOfVariation) {} + + internal override double GetDesignValue(double percentile) + { + return DetermineDesignValue(Mean, StandardDeviation, percentile); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/PercentileBasedDesignVariableCalculator.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/PercentileBasedDesignVariableCalculator.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/PercentileBasedDesignVariableCalculator.cs (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -0,0 +1,82 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using MathNet.Numerics.Distributions; + +namespace Ringtoets.Common.Data.Probabilistics +{ + /// + /// Base calculator for design variables based on percentile and parameters of a distribution. + /// + internal abstract class PercentileBasedDesignVariableCalculator + { + /// + /// Creates a base calculator. + /// + /// The mean of the distribution. + /// The standard deviation of the distribution. + /// The coefficient of variation of the distribution. + protected PercentileBasedDesignVariableCalculator(double mean, double standardDeviation, double coefficientOfVariation) + { + Mean = mean; + StandardDeviation = standardDeviation; + CoefficientOfVariation = coefficientOfVariation; + } + + /// + /// Calculates and returns the design value. + /// + /// The percentile to obtain the value for. + /// The design value at the given . + internal abstract double GetDesignValue(double percentile); + + /// + /// Gets the mean of the distribution. + /// + protected double Mean { get; } + + /// + /// Gets the standard deviation of the distribution. + /// + protected double StandardDeviation { get; } + + /// + /// Gets the coefficient of variation of the distribution. + /// + protected double CoefficientOfVariation { get; } + + /// + /// Determines the design value based on a 'normal space' expected value and standard deviation. + /// + /// The expected value. + /// The standard deviation. + /// The percentile. + /// The design value. + protected static double DetermineDesignValue(double expectedValue, double standardDeviation, double percentile) + { + // Design factor is determined using the 'probit function', which is the inverse + // CDF function of the standard normal distribution. For more information see: + // "Quantile function" https://en.wikipedia.org/wiki/Normal_distribution + double designFactor = Normal.InvCDF(0.0, 1.0, percentile); + return expectedValue + designFactor * standardDeviation; + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/VariationCoefficientLogNormalDistributionDesignVariable.cs =================================================================== diff -u -r1df1e9ae0057dde85489929cbf85d222c26e8c5f -rc90fad2c6d012238ac0b62e52f9820047de76ad6 --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/VariationCoefficientLogNormalDistributionDesignVariable.cs (.../VariationCoefficientLogNormalDistributionDesignVariable.cs) (revision 1df1e9ae0057dde85489929cbf85d222c26e8c5f) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/VariationCoefficientLogNormalDistributionDesignVariable.cs (.../VariationCoefficientLogNormalDistributionDesignVariable.cs) (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -71,45 +71,13 @@ public override RoundedDouble GetDesignValue() { - double normalSpaceDesignValue = DetermineDesignValueInNormalDistributionSpace(); - return ProjectFromNormalToLogNormalSpace(normalSpaceDesignValue); + return new RoundedDouble( + Distribution.Mean.NumberOfDecimalPlaces, + LogNormalDistributionDesignVariableCalculator.CreateWithCoefficientOfVariation( + Distribution.Mean, + Distribution.CoefficientOfVariation, + 0) + .GetDesignValue(Percentile)); } - - /// - /// Projects into 'normal - /// distribution' space and calculates the design value for that value space. - /// - /// The design value in 'normal distribution' space. - private double DetermineDesignValueInNormalDistributionSpace() - { - // Determine normal distribution parameters from log-normal parameters, as - // design value can only be determined in 'normal distribution' space. - // Below formula's come from Tu-Delft College dictaat "b3 Probabilistisch Ontwerpen" - // by ir. A.C.W.M. Vrouwenvelder and ir.J.K. Vrijling 5th reprint 1987. - double sigmaLogOverMuLog = Distribution.CoefficientOfVariation; - double sigmaNormal = Math.Sqrt(Math.Log(sigmaLogOverMuLog * sigmaLogOverMuLog + 1.0)); - double muNormal = Math.Log(Distribution.Mean) - 0.5 * sigmaNormal * sigmaNormal; - return DetermineDesignValue(muNormal, sigmaNormal); - } - - /// - /// Determines the design value based on a 'normal space' expected value and variation coefficient. - /// - /// The expected value. - /// The standard deviation. - /// The design value - private double DetermineDesignValue(double expectedValue, double variationCoefficient) - { - // Design factor is determined using the 'probit function', which is the inverse - // CDF function of the standard normal distribution. For more information see: - // "Quantile function" https://en.wikipedia.org/wiki/Normal_distribution - double designFactor = Normal.InvCDF(0.0, 1.0, Percentile); - return expectedValue + designFactor * variationCoefficient; - } - - private RoundedDouble ProjectFromNormalToLogNormalSpace(double normalSpaceDesignValue) - { - return new RoundedDouble(Distribution.Mean.NumberOfDecimalPlaces, Math.Exp(normalSpaceDesignValue)); - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Properties/AssemblyInfo.cs =================================================================== diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -rc90fad2c6d012238ac0b62e52f9820047de76ad6 --- Ringtoets/Common/src/Ringtoets.Common.Data/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 4512af7782ee31b36941bb280b54d9da2953dd71) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -20,8 +20,10 @@ // All rights reserved. using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("Ringtoets.Common.Data")] [assembly: AssemblyProduct("Ringtoets.Common.Data")] -[assembly: Guid("c22b2261-cf34-4632-84cf-be4e464c186a")] \ No newline at end of file +[assembly: Guid("c22b2261-cf34-4632-84cf-be4e464c186a")] +[assembly: InternalsVisibleTo("Ringtoets.Common.Data.Test")] \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj =================================================================== diff -u -r1df1e9ae0057dde85489929cbf85d222c26e8c5f -rc90fad2c6d012238ac0b62e52f9820047de76ad6 --- Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision 1df1e9ae0057dde85489929cbf85d222c26e8c5f) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -61,6 +61,9 @@ + + + Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionDesignVariableCalculatorTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionDesignVariableCalculatorTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionDesignVariableCalculatorTest.cs (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -0,0 +1,91 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; + +namespace Ringtoets.Common.Data.Test.Probabilistics +{ + [TestFixture] + public class LogNormalDistributionDesignVariableCalculatorTest + { + [Test] + public void CreateWithStandardDeviation_WithParameters_CreateNewInstance() + { + // Setup + var random = new Random(21); + double mean = random.NextDouble(); + double standardDeviation = random.NextDouble(); + double shift = random.NextDouble(); + + // Call + PercentileBasedDesignVariableCalculator calculator = + LogNormalDistributionDesignVariableCalculator.CreateWithStandardDeviation(mean, standardDeviation, shift); + + // Assert + Assert.IsInstanceOf(calculator); + } + + [Test] + public void CreateWithCoefficientOfVariation_WithParameters_CreateNewInstance() + { + // Setup + var random = new Random(21); + double mean = random.NextDouble(); + double coefficientOfVariation = random.NextDouble(); + double shift = random.NextDouble(); + + // Call + PercentileBasedDesignVariableCalculator calculator = + LogNormalDistributionDesignVariableCalculator.CreateWithCoefficientOfVariation(mean, coefficientOfVariation, shift); + + // Assert + Assert.IsInstanceOf(calculator); + } + + [Test] + [TestCase(8.4, 3.2, 2.5, 0.95, 14.456641939677828)] + [TestCase(15.4, 3.2, 2.5, 0.95, 21.214883819366989)] + [TestCase(8.4, 6.2, 2.5, 0.95, 19.305664447180419)] + [TestCase(8.4, 6.2, 2.5, 0.45, 6.1494547175983385)] + [TestCase(8.4, 6.2, 1.5, 0.45, 6.1594719459843708)] + public void DetermineDesignValue_DifferentValues_BothTypesOfCalculatorsReturnsExpectedValue( + double mean, + double standardDeviation, + double shift, + double percentile, + double expectedValue) + { + // Setup + PercentileBasedDesignVariableCalculator calculatorStd = LogNormalDistributionDesignVariableCalculator.CreateWithStandardDeviation(mean, standardDeviation, shift); + PercentileBasedDesignVariableCalculator calculatorCov = LogNormalDistributionDesignVariableCalculator.CreateWithCoefficientOfVariation(mean, standardDeviation / (mean - shift), shift); + + // Call + double stdDesignValue = calculatorStd.GetDesignValue(percentile); + double covDesignValue = calculatorCov.GetDesignValue(percentile); + + // Assert + Assert.AreEqual(expectedValue, stdDesignValue, 1e-8); + Assert.AreEqual(expectedValue, covDesignValue, 1e-8); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/NormalDistributionDesignVariableCalculatorTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/NormalDistributionDesignVariableCalculatorTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/NormalDistributionDesignVariableCalculatorTest.cs (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -0,0 +1,83 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; + +namespace Ringtoets.Common.Data.Test.Probabilistics +{ + [TestFixture] + public class NormalDistributionDesignVariableCalculatorTest + { + [Test] + public void CreateWithStandardDeviation_WithParameters_CreateNewInstance() + { + // Setup + var random = new Random(21); + double mean = random.NextDouble(); + double standardDeviation = random.NextDouble(); + + // Call + PercentileBasedDesignVariableCalculator calculator = + NormalDistributionDesignVariableCalculator.CreateWithStandardDeviation(mean, standardDeviation); + + // Assert + Assert.IsInstanceOf(calculator); + } + + [Test] + public void CreateWithCoefficientOfVariation_WithParameters_CreateNewInstance() + { + // Setup + var random = new Random(21); + double mean = random.NextDouble(); + double coefficientOfVariation = random.NextDouble(); + + // Call + PercentileBasedDesignVariableCalculator calculator = + NormalDistributionDesignVariableCalculator.CreateWithCoefficientOfVariation(mean, coefficientOfVariation); + + // Assert + Assert.IsInstanceOf(calculator); + } + + [Test] + [TestCase(8.4, 3.2, 0.95, 13.663531606244712)] + [TestCase(15.4, 3.2, 0.95, 20.66353160624471)] + [TestCase(8.4, 6.2, 0.95, 18.59809248709913)] + [TestCase(8.4, 6.2, 0.45, 7.6208996494985417)] + public void DetermineDesignValue_DifferentValues_BothTypesOfCalculatorsReturnsExpectedValue(double mean, double standardDeviation, double percentile, double expectedValue) + { + // Setup + PercentileBasedDesignVariableCalculator calculatorStd = NormalDistributionDesignVariableCalculator.CreateWithStandardDeviation(mean, standardDeviation); + PercentileBasedDesignVariableCalculator calculatorCov = NormalDistributionDesignVariableCalculator.CreateWithCoefficientOfVariation(mean, standardDeviation / mean); + + // Call + double stdDesignValue = calculatorStd.GetDesignValue(percentile); + double covDesignValue = calculatorCov.GetDesignValue(percentile); + + // Assert + Assert.AreEqual(expectedValue, stdDesignValue, 1e-8); + Assert.AreEqual(expectedValue, covDesignValue, 1e-8); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/PercentileBasedDesignVariableCalculatorTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/PercentileBasedDesignVariableCalculatorTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/PercentileBasedDesignVariableCalculatorTest.cs (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -0,0 +1,109 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; + +namespace Ringtoets.Common.Data.Test.Probabilistics +{ + [TestFixture] + public class PercentileBasedDesignVariableCalculatorTest + { + [Test] + public void Constructor_WithParameters_SetParameterValues() + { + // Setup + var random = new Random(21); + double mean = random.NextDouble(); + double standardDeviation = random.NextDouble(); + double coefficientOfVariation = random.NextDouble(); + + // Call + var calculator = new SimplePercentileBasedDesignVariableCalculator(mean, standardDeviation, coefficientOfVariation); + + // Assert + Assert.AreEqual(mean, calculator.PublicMean); + Assert.AreEqual(standardDeviation, calculator.PublicStandardDeviation); + Assert.AreEqual(coefficientOfVariation, calculator.PublicCoefficientOfVariation); + } + + [Test] + [TestCase(8.4, 3.2, 0.95, 13.663531606244712)] + [TestCase(15.4, 3.2, 0.95, 20.66353160624471)] + [TestCase(8.4, 6.2, 0.95, 18.59809248709913)] + [TestCase(8.4, 6.2, 0.45, 7.6208996494985417)] + public void DetermineDesignValue_DifferentValues_ReturnsExpectedValue(double mean, double standardDeviation, double percentile, double expectedValue) + { + // Setup + var calculator = new SimplePercentileBasedDesignVariableCalculator(mean, standardDeviation, double.NaN); + + // Call + double actualDesignVariable = calculator.PublicDetermineDesignVariable(mean, standardDeviation, percentile); + + // Assert + Assert.AreEqual(expectedValue, actualDesignVariable, 1e-8); + } + + private class SimplePercentileBasedDesignVariableCalculator : PercentileBasedDesignVariableCalculator + { + public SimplePercentileBasedDesignVariableCalculator( + double mean, + double standardDeviation, + double coefficientOfVariation) + : base(mean, standardDeviation, coefficientOfVariation) {} + + public double PublicMean + { + get + { + return Mean; + } + } + + public double PublicStandardDeviation + { + get + { + return StandardDeviation; + } + } + + public double PublicCoefficientOfVariation + { + get + { + return CoefficientOfVariation; + } + } + + public double PublicDetermineDesignVariable(double expectedValue, double standardDeviation, double percentile) + { + return DetermineDesignValue(expectedValue, standardDeviation, percentile); + } + + internal override double GetDesignValue(double percentile) + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj =================================================================== diff -u -r1df1e9ae0057dde85489929cbf85d222c26e8c5f -rc90fad2c6d012238ac0b62e52f9820047de76ad6 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 1df1e9ae0057dde85489929cbf85d222c26e8c5f) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision c90fad2c6d012238ac0b62e52f9820047de76ad6) @@ -74,6 +74,9 @@ + + +