Esempio n. 1
0
        double[] CreateInitialParameterGuess()
        {
            pParameters = new double[3];
            LinearFit LF = new LinearFit(x, (from b in y select Math.Log(b)).ToArray());

            pParameters[(int)ParametersIndex.P0Index]  = Math.Exp(LF.Intercept);
            pParameters[(int)ParametersIndex.rIndex]   = LF.Slope;
            pParameters[(int)ParametersIndex.Carrying] = 5;
            return(pParameters);
        }
Esempio n. 2
0
        /// <summary>
        /// Makes an initial guess based on linear regreesion
        /// </summary>
        /// <returns></returns>
        protected override double[] CreateInitialParameterGuess()
        {
            double[] logdata = y.ToArray();
            logdata = Array.ConvertAll(logdata, z => Math.Log(z));
            LinearFit LF = new LinearFit(x, logdata);

            double[] ParamGuess = new double[2];
            ParamGuess[(int)ParametersIndex.rIndex]  = LF.Slope;
            ParamGuess[(int)ParametersIndex.P0Index] = Math.Exp(LF.Intercept);
            return(ParamGuess);
        }
Esempio n. 3
0
 private void SetNoFit(string comment = "Not Fit")
 {
     this.ForEach(x => x.UsedInFit = false);
     ValidDataSet                   = false;
     ExpFit                         = null;
     LinFit                         = null;
     pGrowthRate.GrowthRate         = Double.NaN;
     pGrowthRate.NumPoints          = 0;
     pGrowthRate.R2                 = Double.NaN;
     pGrowthRate.RMSE               = Double.NaN;
     pGrowthRate.DisplayFittingUsed = "Not Fit";
     pGrowthRate.Notes              = comment;
     OnPropertyChange(new PropertyChangedEventArgs("FittedValues"));
     OnPropertyChange(new PropertyChangedEventArgs("FittedLogValues"));
 }
        protected double[] CreateInitialParameterGuess()
        {
            double[] logdata = y.ToArray();
            var      res     = Enumerable.Zip(x, logdata, (z, yy) => new { x = z, yval = yy - CParamGuess });
            var      res2    = (from xx in res where xx.yval > 0 select xx).ToList();

            double[] xToTry = (from yy in res2 select yy.x).ToArray();
            double[] yToTry = (from yy in res2 select yy.yval).ToArray();
            if (xToTry.Length >= 2)
            {
                logdata = Array.ConvertAll(yToTry, z => Math.Log(z));
                LinearFit LF         = new LinearFit(xToTry, logdata);
                double[]  ParamGuess = new double[3];
                ParamGuess[(int)ParametersIndex.rIndex]      = LF.Slope;;
                ParamGuess[(int)ParametersIndex.P0Index]     = Math.Exp(LF.Intercept);
                ParamGuess[(int)ParametersIndex.OffSetIndex] = CParamGuess * 1.01;
                return(ParamGuess);
            }
            else
            {
                throw new Exception("Exponential Offset model can't be fit with data that isn't above the parameter guess");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Function fits data, should be called everytime the fit changes
        /// </summary>
        public void FitData()
        {
            ValidDataSet = true;
            double[] XtoFit, YtoFit;
            XtoFit = FittedXValues;
            YtoFit = FittedYValues;
            //MixtureErrorModel = null;
            ExpFit = null;
            LinFit = null;
            if (XtoFit.Length >= 2)
            {
                //Linear Fit
                LinFit = new LinearFit(XtoFit, FittedLogYValues);
                pGrowthRate.DisplayFittingUsed = "Linear";
                pGrowthRate.GrowthRate         = LinFit.Slope;
                pGrowthRate.R2         = LinFit.R2;
                pGrowthRate.RMSE       = LinFit.RMSE;
                pGrowthRate.FitterUsed = LinFit;
                //Exponential Fit and others
                if (XtoFit.Length > 2 && USE_EXPONENTIAL_FITTING)
                {
                    ExpFit = new ExponentialFit(XtoFit, YtoFit);
                    if (ExpFit.SuccessfulFit)
                    {
                        pGrowthRate.DisplayFittingUsed = "Exponential";
                        pGrowthRate.GrowthRate         = ExpFit.GrowthRate;
                        pGrowthRate.R2         = ExpFit.R2;
                        pGrowthRate.RMSE       = ExpFit.RMSE;
                        pGrowthRate.FitterUsed = ExpFit;
                        //(ExpFit.Y.Max() - ExpFit.Y.Min()) > .1
                        if (ExpFit.Y.Length > 5)
                        {
                            this.OffSetExp = new OffSetExponentialFit(ExpFit.X, ExpFit.Y, this[0].ODValue);
#if !MONO
                            this.LogisticModel = new LogisticModel(ExpFit.X, ExpFit.Y);
#endif
                        }
                        else
                        {
                            this.OffSetExp = null;
                        }
                    }
                    else
                    {
                        this.OffSetExp = null;
                    }
#if !MONO
                    QuadModel = new QuadraticLinearRegression(XtoFit, YtoFit);
                    #endif
                }

                //Now Set the Growth Rate
                pGrowthRate.NumPoints = FittedXValues.Length;
                OnPropertyChange(new PropertyChangedEventArgs("FittedValues"));
                OnPropertyChange(new PropertyChangedEventArgs("FittedLogValues"));
            }
            else
            {
                SetNoFit();
            }
        }