예제 #1
0
        private DoubleArray Predict(LightWeightGC gc)
        {
            var x = MakePredictionsWithoutOffSet(gc);

            x = x.Add(daOffSets.GetSlice(gc.timeParameterStart, (gc.timeParameterStart + gc.Xvalues.Length - 1)));
            return(x);
        }
예제 #2
0
        public DoubleArray MakePredictionsWithoutOffSet(LightWeightGC gc)
        {
            ExpParameters ep = WellParameters[gc.Name];
            var           b  = gc.Xvalues.Select(x => Math.Exp(x * ep.GrowthRate));
            DoubleArray   da = DoubleArray.From(b);

            da = da.Multiply(ep.InitPop);
            return(da);
        }
예제 #3
0
        public GroupFitter(GrowthCurveCollection GCC)
        {
            var tmpHold            = new List <LightWeightGC>();
            HashSet <double> times = new HashSet <double>();
            Random           r     = new Random();

            foreach (GrowthCurve gc in GCC)
            {
                if (gc.ExpFit == null || gc.ExpFit.SuccessfulFit == false)
                {
                    throw new Exception("Curve " + gc.DataSetName + " has not been fit with an exponential yet");
                }
                LightWeightGC tmp = new LightWeightGC()
                {
                    Xvalues = gc.FittedXValues, YValues = gc.FittedYValues, Name = gc.DataSetName
                };
                tmpHold.Add(tmp);
                NamesToCurves[gc.DataSetName] = tmp;
                xl.AddRange(gc.FittedXValues);
                yl.AddRange(gc.FittedYValues);
                gc.FittedXValues.ToList().ForEach(x => times.Add(x));
                gc.GroupFit = this;
            }
            //Now to make the data array
            int ParameterArraySize = times.Count + 2 * tmpHold.Count;

            var t2 = times.ToList();

            data = tmpHold.ToArray();
            t2.Sort();
            Times = t2.ToArray();
            //First items 1-n are the time point offsets, next are the GrowthRate,InitPop for the different guys
            Parameters = new double[ParameterArraySize];
            int ArrayStart = times.Count;

            for (int i = 0; i < data.Length; i++)
            {
                if (i < Times.Length)
                {
                    //Parameters[i] = 1e-3;
                }

                data[i].GrowthParameterStart = ArrayStart + (i * 2);
                double v = r.NextDouble() < .5 ? -1.0:1.0;
                Parameters[data[i].GrowthParameterStart] = GCC[i].ExpFit.GrowthRate;         // +GCC[i].ExpFit.GrowthRate * (r.NextDouble() * .005) * v;
                v = r.NextDouble() < .5 ? -1.0:1.0;
                Parameters[data[i].GrowthParameterStart + 1] = GCC[i].ExpFit.InitialPopSize; // +GCC[i].ExpFit.InitialPopSize * (r.NextDouble() * .005) * v;
                double minTime = data[i].Xvalues[0];
                data[i].timeParameterStart = t2.IndexOf(minTime);
            }
            double val  = ShoNS.Optimizer.GradTester.Test(new DiffFunc(GetDerivatives), Parameters);
            double val3 = val + .01;

            val3++;
            FitModel();
        }
예제 #4
0
        public double CalculateRMSE(LightWeightGC gc)
        {
            var    mse          = CalculateResiduals(gc);
            double MSE          = mse.ElementMultiply(mse).Sum();
            double DataPoints   = gc.Xvalues.Length;
            double NumParmeters = Parameters.Length;
            double df           = DataPoints - NumParmeters;

            MSE = MSE / df;
            double RMSE = Math.Sqrt(MSE);

            return(RMSE);
        }
예제 #5
0
 public DoubleArray CalculateResiduals(LightWeightGC gc)
 {
     return(DoubleArray.From(gc.YValues).Subtract(Predict(gc)));
 }