public static BaseDistribution DistributionUnary(BaseDistribution value, NodeOperationType operationType) { if (value.InnerDistributionType == DistributionType.Number) { return(EvaluateDoubleUnary((double)value, operationType)); } else { switch (operationType) { case NodeOperationType.Abs: { return(value.InnerGetAbs()); } case NodeOperationType.Negate: { return(value.InnerGetNegate()); } case NodeOperationType.Sqrt: { return(value.InnerGetPower(0.5)); } case NodeOperationType.Ln: { return(value.InnerGetLog(Math.E)); } case NodeOperationType.Lg10: { return(value.InnerGetLog(10)); } case NodeOperationType.Sin: { return(CommonRandomMath.Sin(value)); } case NodeOperationType.Cos: { return(CommonRandomMath.Cos(value)); } case NodeOperationType.Tan: { return(CommonRandomMath.Tan(value)); } default: { throw new NotImplementedException(); } } } }
public static DataTable TestData() { DataTable results = new DataTable(); results.Columns.Add(new DataColumn("R", typeof(double))); results.Columns.Add(new DataColumn("Vorg", typeof(double))); results.Columns.Add(new DataColumn("Vmath", typeof(double))); results.Columns.Add(new DataColumn("Vmc", typeof(double))); results.Columns.Add(new DataColumn("Vgum", typeof(double))); Optimizations.UseAnalyticalConvolution = false; Optimizations.UseFftConvolution = false; int experiments = 10; int samples = 1000; int randoms = (int)10e2; int testType = 5; double m1 = 0; double m2 = 0; //для тестов 6, 7 - положение левой границы for (int i = 0; i < experiments; i++) { double s1 = 1; double s2 = s1 * InterpolateLiner(0.1, 10, i, experiments); var pair = GetData(testType, m1, m2, s1, s2, out double vOriginal, out double gum, out string formula); DistributionsEvaluator evaluator = new DistributionsEvaluator(formula); Dictionary <string, BaseDistribution> keyValuePairs = new Dictionary <string, BaseDistribution>(); keyValuePairs.Add("A", pair[0].GetDistribution(samples)); keyValuePairs.Add("B", pair[1].GetDistribution(samples)); BaseDistribution resultMath = evaluator.EvaluateDistributions(keyValuePairs, new List <CorrelatedPair>()); List <double> monteCarloQ = new List <double>(); for (int j = 0; j < 10; j++) { var resultMonteCarlo = new MonteCarloDistribution(formula, new Dictionary <string, DistributionSettings> { { "A", pair[0] }, { "B", pair[1] } }, randoms, 100); monteCarloQ.Add(resultMonteCarlo.Variance); } double monteCarloQresult = Math.Sqrt(monteCarloQ.Sum(x => Math.Pow(x - vOriginal, 2)) / (monteCarloQ.Count - 1)) * 1.96; results.Rows.Add(s2 / s1, vOriginal, resultMath.Variance, vOriginal + monteCarloQresult, gum); } return(results); }
private static void AddChart(ZedGraphControl pdf, ZedGraphControl cdf, BaseDistribution distribution, string name, Color color, int length) { if (distribution == null) { return; } double step = (distribution.MaxX - distribution.MinX) / (length - 1); var pointsPDF = GetPoints(distribution.ProbabilityDensityFunction, distribution.MinX, distribution.MaxX, step, length); var pointsCDF = GetPoints(distribution.DistributionFunction, distribution.MinX, distribution.MaxX, step, length); pdf.GraphPane.AddCurve(name, pointsPDF, color, SymbolType.None); cdf.GraphPane.AddCurve(name, pointsCDF, color, SymbolType.None); }
public static BaseDistribution DistributionBinary(BaseDistribution left, BaseDistribution right, NodeOperationType operationType) { if (left.InnerDistributionType == DistributionType.Number && right.InnerDistributionType == DistributionType.Number) { return(EvaluateDoubleBinary((double)left, (double)right, operationType)); } else { switch (operationType) { case NodeOperationType.Sum: { return(left + right); } case NodeOperationType.Substract: { return(left - right); } case NodeOperationType.Multiply: { return(left * right); } case NodeOperationType.Divide: { return(left / right); } case NodeOperationType.Power: { return(left.InnerGetPower(right)); } case NodeOperationType.Log: { return(left.InnerGetLog(right)); } default: { throw new NotImplementedException(); } } } }
private void FillData(ObservableCollection <DataPoint> points, BaseDistribution distribution, int length) { double step = (distribution.MaxX - distribution.MinX) / (length - 1); List <DataPoint> temp = new List <DataPoint>(); if (DataType == ChartDataType.PDF) { FillPoints(temp, distribution.ProbabilityDensityFunction, distribution.MinX, distribution.MaxX, step, length); } else if (DataType == ChartDataType.CDF) { FillPoints(points, distribution.DistributionFunction, distribution.MinX, distribution.MaxX, step, length); } for (int i = 0; i < temp.Count; i++) { points.Add(temp[i]); } }
/// <summary> /// Performs propagation of distributions set as arguments. /// </summary> /// <param name="arguments">Dictionary of pairs of distributions and arguments.</param> /// <param name="correlations">Correlation coefficients for distribution arguments.</param> /// <returns>Propagation result.</returns> public BaseDistribution EvaluateDistributions(Dictionary <string, BaseDistribution> arguments, List <CorrelatedPair> correlations) { correlations?.ForEach(x => x.Used = false); arguments = arguments ?? new Dictionary <string, BaseDistribution>(); int length = nodeParameters.Count; for (int i = 0; i < length; i++) { NodeParameter parameter = nodeParameters[i]; string arg = parameter.Parameter; if (parameter.Count > 1) { throw new DistributionsInvalidOperationException(DistributionsInvalidOperationExceptionType.ImpossibeToUseRandomAlgebraParameterSetMoreThenOnce); } if (arguments.TryGetValue(arg, out BaseDistribution value)) { parameter.Value = value; } else { throw new DistributionsArgumentException(DistributionsArgumentExceptionType.ParameterValueIsMissing, arg); } } BaseDistribution result = Parsed.EvaluateExtended(correlations); if (correlations.Any(x => !x.Used)) { throw new DistributionsInvalidOperationException(DistributionsInvalidOperationExceptionType.CorrelationParamtersIgnored); } return(result); }