// Copyright (C) Stichting Deltares 2017. 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 { private LogNormalDistributionDesignVariableCalculator( double mean, double standardDeviation, double coefficientOfVariation, double shift) : base(mean, standardDeviation, coefficientOfVariation) { Shift = shift; } /// /// 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); } 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); } } }