using System; using MathNet.Numerics.Distributions; using Ringtoets.Piping.Data.Properties; namespace Ringtoets.Piping.Data.Probabilistics { /// /// This class is a representation of a variable derived from a probabilistic distribution, /// based on a percentile. /// public abstract class DesignVariable where DistributionType : IDistribution { private double percentile; private DistributionType distribution; /// /// Initializes a new instance of the class with /// equal to 0.5. /// /// is null. protected DesignVariable(DistributionType distribution) { Distribution = distribution; percentile = 0.5; } /// /// Gets or sets the probabilistic distribution of the parameter being modeled. /// /// is null. public DistributionType Distribution { get { return distribution; } set { if (value == null) { throw new ArgumentNullException("value", Resources.DesignVariable_GetDesignValue_Distribution_must_be_set); } distribution = value; } } /// /// Gets or sets the percentile used to derive a deterministic value based on . /// public double Percentile { get { return percentile; } set { if (value < 0.0 || value > 1.0) { throw new ArgumentOutOfRangeException("value", Resources.DesignVariable_Percentile_must_be_in_range); } percentile = value; } } /// /// Gets the design value based on the and . /// /// A design value. public abstract double GetDesignValue(); /// /// Determines the design value based on a 'normal space' expected value and standard deviation. /// /// The expected value. /// The standard deviation. /// The design value protected double DetermineDesignValue(double expectedValue, double standardDeviation) { // 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 var designFactor = Normal.InvCDF(0.0, 1.0, Percentile); return expectedValue + designFactor * standardDeviation; } } }