private double TrueValueGen(GenObject genO, MeasurementError me, double y, double mu, double logY) { SGNFnAParam localA = genO.A.Clone(); localA.Mu = mu; if (genO.LogNormalDistrn) { localA.LogY = logY; } localA.Y = y; localA.Y2 = y * y; if (genO.ThroughSD) { localA.Ksi = me.Parm; localA.Ksi2 = me.Parm * me.Parm; } else { localA.CV2 = me.Parm * me.Parm; } double[] start = genO.Start(localA); //start.Any(zz => !zz.IsFinite()); Icdf icdf = new Icdf(genO, localA, range: genO.Range); double x = icdf.Bidon(start, inestLowerLim: !genO.LogNormalDistrn); if (genO.LogNormalDistrn) { x = Math.Exp(x);// # new_0.11 } return(x); } //# end of truevalue.gen
internal static MEParmGen GetInstance(GenObject o, MeasurementError me, DataSummary data, YGen genY, TrueValuesGen genTV) { MEParmGen instance = new MEParmGen(); double b; double[] tmpY, tmpT; if (me.ThroughCV) { if (o.LogNormalDistrn) { tmpY = Tools.Combine(data.LogY, genY.LogGT, genY.LogLT, genY.LogI); tmpT = Tools.Combine(genTV.LogY, genTV.LogGT, genTV.LogLT, genTV.LogI); b = tmpY.Substract(tmpT).Exp().Substract(1.0).Sqr().Sum(); b /= 2.0; } else { tmpY = Tools.Combine(data.Y, genY.GT, genY.LT, genY.I); tmpT = Tools.Combine(genTV.Y, genTV.GT, genTV.LT, genTV.I); b = tmpY.Divide(tmpT).Substract(1.0).Sqr().Reverse().Sum(); b /= 2.0; } SGNFnAParam localA = o.A.Clone(); localA.B = b; localA.Range = me.GetRange(); double[] range = me.GetRange(); Icdf icdf = new Icdf(o, localA, range); instance.Parm = icdf.Bidon(o.Start(localA), inestLowerLim: range[0] == 0); } else { tmpY = Tools.Combine(data.Y, genY.GT, genY.LT, genY.I); tmpT = Tools.Combine(genTV.Y, genTV.GT, genTV.LT, genTV.I); b = tmpY.Substract(tmpT).Sqr().Sum(); b /= 2.0; if (o.LogNormalDistrn) { SGNFnAParam localA = o.A.Clone(); localA.B = b; localA.Range = me.GetRange(); localA.Truevalues = Tools.Copy(tmpT); //me.parm <- dens.gen.icdf(o, A, range=me$range, inestimable.lower.limit=me$range[1]==0) double[] range = me.GetRange(); Icdf icdf = new Icdf(o, localA, range); instance.Parm = icdf.Bidon(inestLowerLim: range[0] == 0.0); } else { instance.Parm = WebExpoFunctions3.SqrtInvertedGammaGen(data.N, b, me.GetRange(), o); } } return(instance); }
/* * Pour ME_Gen Objects */ internal static GenObject GetMeGenObject(MeasurementError me, bool logNDstrn, int N) { if (me.ThroughCV) { return(new ME_CV_GenObject(N, logNDstrn)); } else { // me.ThroughSD est vrai return(null); } }
private YGen(MeasurementError me, TrueValuesGen genTV, DataSummary data, double mu, double sigma, bool logNormalDistrn = true) { if (me.Any) { // Sample y (censored) values | true values if (data.AnyGT) { double[] tmpMean = genTV.GT; double[] tmpSD; if (me.ThroughCV) { tmpSD = tmpMean.Multiply(me.Parm); } else { tmpSD = Tools.Rep(me.Parm, tmpMean.Length); } this.GT = RNorm4CensoredMeasures.RNormCensored(tmpMean, tmpSD, lower: data.GT); if (logNormalDistrn) { this.LogGT = this.GT.Log(); } } if (data.AnyLT) { double[] tmpMean = genTV.LT; double[] tmpSD; if (me.ThroughCV) { tmpSD = tmpMean.Multiply(me.Parm); } else { tmpSD = Tools.Rep(me.Parm, tmpMean.Length); } this.I = RNorm4CensoredMeasures.RNormCensored(tmpMean, tmpSD, upper: data.LT, negativeDisallowed: logNormalDistrn || me.ThroughCV); if (logNormalDistrn) { this.LogLT = this.LT.Log(); } } if (data.AnyIntervalCensored) { double[] tmpMean = genTV.I; double[] tmpSD; if (me.ThroughCV) { tmpSD = tmpMean.Multiply(me.Parm); } else { tmpSD = Tools.Rep(me.Parm, tmpMean.Length); } this.I = RNorm4CensoredMeasures.RNormCensored(tmpMean, tmpSD, lower: data.IntervalGT, upper: data.IntervalLT); if (logNormalDistrn) { this.LogI = this.I.Log(); } } } else { if (logNormalDistrn) { if (data.AnyGT) { this.LogGT = RNorm4CensoredMeasures.RNormCensored(mu, sigma, lower: data.LogGT); this.GT = this.LogGT.Exp(); } if (data.AnyLT) { this.LogLT = RNorm4CensoredMeasures.RNormCensored(mu, sigma, upper: data.LogLT); this.LT = this.LogLT.Exp(); } if (data.AnyIntervalCensored) { this.LogI = RNorm4CensoredMeasures.RNormCensored(mu, sigma, lower: data.LogIntervalGT, upper: data.LogIntervalLT); this.I = this.LogI.Exp(); } } else { if (data.AnyGT) { this.GT = RNorm4CensoredMeasures.RNormCensored(mu, sigma, lower: data.GT); } if (data.AnyLT) { this.LT = RNorm4CensoredMeasures.RNormCensored(mu, sigma, upper: data.LT); } if (data.AnyIntervalCensored) { this.I = RNorm4CensoredMeasures.RNormCensored(mu, sigma, lower: data.IntervalGT, upper: data.IntervalLT); } } } }// internal YGen (constructor)
public static YGen GetInstance(MeasurementError me, TrueValuesGen genTV, DataSummary data, double mu, double sigma, bool logNormalDistrn = true) { if (me.Any) { YGen newYGen = new YGen(); // Sample y (censored) values | true values if (data.AnyGT) { double[] tmpMean = genTV.GT; double[] tmpSD; if (me.ThroughCV) { tmpSD = tmpMean.Multiply(me.Parm); } else { tmpSD = Tools.Rep(me.Parm, tmpMean.Length); } newYGen.GT = RNorm4CensoredMeasures.RNormCensored(tmpMean, tmpSD, lower: data.GT); if (logNormalDistrn) { newYGen.LogGT = newYGen.GT.Log(); } } if (data.AnyLT) { double[] tmpMean = genTV.LT; double[] tmpSD; if (me.ThroughCV) { tmpSD = tmpMean.Multiply(me.Parm); } else { tmpSD = Tools.Rep(me.Parm, tmpMean.Length); } newYGen.LT = RNorm4CensoredMeasures.RNormCensored(tmpMean, tmpSD, upper: data.LT, negativeDisallowed: logNormalDistrn || me.ThroughCV); if (logNormalDistrn) { newYGen.LogLT = newYGen.LT.Log(); } } if (data.AnyIntervalCensored) { double[] tmpMean = genTV.I; double[] tmpSD; if (me.ThroughCV) { tmpSD = tmpMean.Multiply(me.Parm); } else { tmpSD = Tools.Rep(me.Parm, tmpMean.Length); } newYGen.I = RNorm4CensoredMeasures.RNormCensored(tmpMean, tmpSD, lower: data.IntervalGT, upper: data.IntervalLT); if (logNormalDistrn) { newYGen.LogI = newYGen.I.Log(); } } return(newYGen); } else { return(YGen.Inits(data, mu, sigma, meThroughCV: data.METhroughCV, logNormalDistrn: logNormalDistrn)); } }
private TrueValuesGen(YGen genY, DataSummary data, double mu, double sigma, MeasurementError me, bool logNormalDistrn = true, GenObject o = null) { if (me.ThroughSD && !logNormalDistrn) { double meSD = me.Parm; double tauStar = 1 / Math.Pow(sigma, 2) + 1 / Math.Pow(meSD, 2); double sdStar = 1 / Math.Sqrt(tauStar); if (data.YLength > 0) { double[] tmpMean = (data.Y.Divide(Math.Pow(meSD, 2)).Add(mu / Math.Pow(sigma, 2))).Divide(tauStar); this.Y = NormalDistribution.RNorm(data.YLength, tmpMean, Tools.Rep(sdStar, tmpMean.Length)); } if (data.GTLength > 0) { double[] tmpMean = (genY.GT.Divide(Math.Pow(meSD, 2)).Add(mu / Math.Pow(sigma, 2))).Divide(tauStar); this.Y = NormalDistribution.RNorm(data.GTLength, tmpMean, Tools.Rep(sdStar, tmpMean.Length)); } if (data.LTLength > 0) { double[] tmpMean = (genY.LT.Divide(Math.Pow(meSD, 2)).Add(mu / Math.Pow(sigma, 2))).Divide(tauStar); this.Y = NormalDistribution.RNorm(data.GTLength, tmpMean, Tools.Rep(sdStar, tmpMean.Length)); } if (data.IntervalLength > 0) { double[] tmpMean = (genY.I.Divide(Math.Pow(meSD, 2)).Add(mu / Math.Pow(sigma, 2))).Divide(tauStar); this.Y = NormalDistribution.RNorm(data.GTLength, tmpMean, Tools.Rep(sdStar, tmpMean.Length)); } } else { o.A.Sigma2 = sigma * sigma; this.Y = new double[data.YLength]; this.GT = new double[data.GTLength]; this.LT = new double[data.LTLength]; this.I = new double[data.IntervalLength]; for (int j = 0; j < data.YLength; j++) { this.Y[j] = TrueValueGen(o, me, data.Y[j], mu, logY: logNormalDistrn?data.LogY[j] : Tools.ND); } for (int j = 0; j < data.GTLength; j++) { this.GT[j] = TrueValueGen(o, me, genY.GT[j], mu, logY: logNormalDistrn?genY.LogGT[j] : Tools.ND); } for (int j = 0; j < data.LTLength; j++) { this.LT[j] = TrueValueGen(o, me, genY.LT[j], mu, logY: logNormalDistrn?genY.LogLT[j] : Tools.ND); } for (int j = 0; j < data.IntervalLength; j++) { this.I[j] = TrueValueGen(o, me, genY.I[j], mu, logY: logNormalDistrn?genY.LogI[j] : Tools.ND); } if (logNormalDistrn) { this.LogY = this.Y.Log(); this.LogGT = this.GT.Log(); this.LogLT = this.LT.Log(); this.LogI = this.I.Log(); } } } //# end of truevalues.gen
} //# end of truevalues.gen internal static TrueValuesGen GetInstance(YGen genY, DataSummary data, double mu, double sigma, MeasurementError me, bool logNormalDistrn = true, GenObject o = null) { return(new TrueValuesGen(genY, data, mu, sigma, me, logNormalDistrn, o)); }
private void AddME(string me) { string x = Regex.Replace(me, @" ", ""); if (x.Length < 5) { return; } string meType = x.Substring(0, 2).ToLower(); if (meType != "sd" && meType != "cv") { return; } if (x[2] != '(') { return; } if (x.Last() != ')') { return; } string str = x.Substring(3, x.Length - 4); if (str == string.Empty) { return; } string[] numbers = str.Split(new char[] { '~' }, StringSplitOptions.RemoveEmptyEntries); if ((numbers.Length == 0) || (numbers.Length > 2)) { return; } double a, b; bool test; test = ParseDouble(numbers[0], out a); if (!test) { return; } b = a; if (numbers.Length == 2) { test = ParseDouble(numbers[1], out b); if (!test) { return; } } if (a > b) { Error.AddError(string.Format("({0}, {1}) do not represent a valid range for the measurement error.", a, b), this.ClassName); return; } this.ME = (meType == "sd") ? MeasurementError.NewSDError(a, b) : MeasurementError.NewCVError(a, b); return; }