public IEBSResultElement Calculate( IEBSResultElementFactory EBSResultElementFactory, IdIndexElement dIndexElement, Iw w, IBEDS BEDS, Iμ μ, IVariance Variance) { int BEDS_d = BEDS.Value.Value.Value; double ExpectedValue_d = w.Value .Select(y => (double)μ.GetElementAtAsdecimal( y, dIndexElement)) .Sum(); double Variance_d = w.Value .Select(y => (double)Variance.GetElementAtAsdecimal( y, dIndexElement)) .Sum(); double lowerBound = BEDS_d + 0.5; double upperBound = double.PositiveInfinity; double value = 0.5 * (BEDS_d - ExpectedValue_d) * (MathNet.Numerics.SpecialFunctions.Erf( (lowerBound - ExpectedValue_d) * Math.Pow(Math.Sqrt(2 * Variance_d), -1)) - MathNet.Numerics.SpecialFunctions.Erf( (upperBound - ExpectedValue_d) * Math.Pow(Math.Sqrt(2 * Variance_d), -1))) + Math.Sqrt(Variance_d) * Math.Pow(Math.Sqrt(2 * Math.PI), -1) * (Math.Exp( -Math.Pow(lowerBound - ExpectedValue_d, 2) * Math.Pow(2 * Variance_d, -1)) - Math.Exp( -Math.Pow(upperBound - ExpectedValue_d, 2) * Math.Pow(2 * Variance_d, -1))); return(EBSResultElementFactory.Create( dIndexElement, (decimal)value)); }
public IExpectedValueΦResultElement Calculate( IExpectedValueΦResultElementFactory expectedValueΦResultElementFactory, IlIndexElement lIndexElement, IsIndexElement sIndexElement, IΛIndexElement ΛIndexElement, Il l, It t, IL L, Ip p, Iμ μ) { int Ls = L.GetElementAtAsint( sIndexElement); int τLowerBound = 0; int τUpperBound = (int)Math.Floor( (decimal) (Ls - lIndexElement.Value.Value.Value) / t.GetT()); decimal sum = 0; for (int τ = τLowerBound; τ <= τUpperBound; τ = τ + 1) { int lPrimeLowerBound = lIndexElement.Value.Value.Value + τ * t.GetT() + 1; int lPrimeUpperBound = Ls; for (int lPrime = lPrimeLowerBound; lPrime <= lPrimeUpperBound; lPrime = lPrime + 1) { sum += p.GetElementAtAsdecimal( sIndexElement, l.GetElementAt( lPrime), ΛIndexElement); } } return(expectedValueΦResultElementFactory.Create( sIndexElement, lIndexElement, ΛIndexElement, μ.GetElementAtAsdecimal( sIndexElement, ΛIndexElement) * sum)); }
public IVarianceΦResultElement Calculate( IVarianceΦResultElementFactory varianceΦResultElementFactory, IlIndexElement lIndexElement, IsIndexElement sIndexElement, IΛIndexElement ΛIndexElement, Il l, It t, IL L, Ip p, Iμ μ, Iσ σ) { int Ls = L.GetElementAtAsint( sIndexElement); int τLowerBound = 0; int τUpperBound = (int)Math.Floor( (decimal) (Ls - lIndexElement.Value.Value.Value) / t.GetT()); // Mean decimal meanSum = 0; for (int τ = τLowerBound; τ <= τUpperBound; τ = τ + 1) { int lPrimeLowerBound = lIndexElement.Value.Value.Value + τ * t.GetT() + 1; int lPrimeVarianceUpperBound = Math.Min( lIndexElement.Value.Value.Value + τ * t.GetT() + t.GetT(), Ls); int lPrimeCovarianceUpperBound = Math.Min( lIndexElement.Value.Value.Value + τ * t.GetT() + t.GetT(), Ls - 1); // Mean: Variance for (int lPrime = lPrimeLowerBound; lPrime <= lPrimeVarianceUpperBound; lPrime = lPrime + 1) { meanSum += (τ + 1) * p.GetElementAtAsdecimal( sIndexElement, l.GetElementAt( lPrime), ΛIndexElement) * (1 - p.GetElementAtAsdecimal( sIndexElement, l.GetElementAt( lPrime), ΛIndexElement)); } // Mean: Covariance for (int lPrime = lPrimeLowerBound; lPrime <= lPrimeCovarianceUpperBound; lPrime = lPrime + 1) { int lHatLowerBound = lPrime + 1; int lHatUpperBound = Ls; for (int lHat = lHatLowerBound; lHat <= lHatUpperBound; lHat = lHat + 1) { meanSum -= (τ + 1) * 2 * p.GetElementAtAsdecimal( sIndexElement, l.GetElementAt( lPrime), ΛIndexElement) * p.GetElementAtAsdecimal( sIndexElement, l.GetElementAt( lHat), ΛIndexElement); } } } // Variance decimal varianceSum = 0; for (int τ = τLowerBound; τ <= τUpperBound; τ = τ + 1) { int lPrimeLowerBound = lIndexElement.Value.Value.Value + τ * t.GetT() + 1; int lPrimeUpperBound = Ls; for (int lPrime = lPrimeLowerBound; lPrime <= lPrimeUpperBound; lPrime = lPrime + 1) { varianceSum += p.GetElementAtAsdecimal( sIndexElement, l.GetElementAt( lPrime), ΛIndexElement); } } return(varianceΦResultElementFactory.Create( sIndexElement, lIndexElement, ΛIndexElement, μ.GetElementAtAsdecimal( sIndexElement, ΛIndexElement) * meanSum + σ.GetElementAtAsdecimal( sIndexElement, ΛIndexElement) * σ.GetElementAtAsdecimal( sIndexElement, ΛIndexElement) * varianceSum * varianceSum)); }