Ejemplo n.º 1
0
        public static void Test_herlall()
        {
            double[] time = { 2, 1, 2, 3, 2, 1 };
            int[]    num  = { 0, 1, 1, 0, 2, 0 };
            int[]    type = { 0, 0, 0, 0, 0, 0 };
            SRMData  data = new SRMData();

            data.SetData(time, num, type);

            EMConf emconf = new EMConf();

            emconf.Progress = 10000;
            emconf.MaxIter  = 1000000;
            emconf.StopCond = StopCondition.PARAMETER;             //.LLF;

            HErlang.HErlangAll all = new HErlang.HErlangAll(5);
            all.FitAll(data, emconf, null);
            Console.WriteLine(all.GetModelName());
            Console.WriteLine(all.GetParam().ToString());
            Console.WriteLine();

            Result result = all.Calc(data);

            print_result(result);
        }
Ejemplo n.º 2
0
        public static void Test_srm()
        {
            double[] time = { 2, 1, 2, 3, 2, 1 };
            int[]    num  = { 0, 1, 1, 0, 2, 0 };
            int[]    type = { 0, 0, 0, 0, 0, 0 };
            SRMData  data = new SRMData();

            data.SetData(time, num, type);

            SRM[] models = new SRM[11];
            models[0]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.EXP);
            models[1]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.GAMMA);
            models[2]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.PARETO);
            models[3]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.TNORM);
            models[4]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.LNORM);
            models[5]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.TLOGIS);
            models[6]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.LLOGIS);
            models[7]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.TXVMAX);
            models[8]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.TXVMIN);
            models[9]  = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.LXVMAX);
            models[10] = SRMFactory.GetInstance().CreateSRM(OriginalSRMModel.LXVMIN);

            EMConf[] emconf = new EMConf[11];
            EM[]     em     = new EM[11];
            for (int i = 0; i < 11; i++)
            {
                emconf[i] = new EMConf();
                em[i]     = new EM(models[i], emconf[i], new MODELS.SRMConsoleMessage(models[i], emconf[i]));
            }

            for (int i = 0; i < 11; i++)
            {
                emconf[i].Progress = 1;
                emconf[i].StopCond = StopCondition.PARAMETER;
                em[i].Initialize(data);
                em[i].Fit(data);
                Console.WriteLine(emconf[i].Status);
                Result result = models[i].Calc(data);
                print_result(result);
            }
        }
Ejemplo n.º 3
0
        public static void Test_cphem()
        {
            double[] time = { 2, 1, 2, 3, 2, 1 };
            int[]    num  = { 0, 1, 1, 0, 2, 0 };
            int[]    type = { 0, 0, 0, 0, 0, 0 };
            SRMData  data = new SRMData();

            data.SetData(time, num, type);

            int nm = 4;

            SRM[] models = new SRM[nm];
            models[0] = new CPH.CPHEMSRM(new CPH.CPHParam(1));
            models[1] = new CPH.CPHEMSRM(new CPH.CPHParam(2));
            models[2] = new CPH.CPHEMSRM(new CPH.CPHParam(3));
            models[3] = new CPH.CPHEMSRM(new CPH.CPHParam(4));

            EMConf[] emconf = new EMConf[nm];
            EM[]     em     = new EM[nm];
            for (int i = 0; i < nm; i++)
            {
                emconf[i] = new EMConf();
                em[i]     = new EM(models[i], emconf[i], new MODELS.SRMConsoleMessage(models[i], emconf[i]));
            }

            for (int i = 0; i < nm; i++)
            {
                emconf[i].Progress = 1;
                emconf[i].StopCond = StopCondition.LLF;
                em[i].Initialize(data);
                em[i].Fit(data);
                Console.WriteLine(emconf[i].Status);
                Result result = models[i].Calc(data);
                print_result(result);
            }
        }
Ejemplo n.º 4
0
        public void Fit(SRMData data)
        {
            emparam.Status = Status.PROCESSING;
            //if (emparam.initflag)
            //{
            //	initialize(data);
            //}

            double prev_llf;

            emparam.Llf = -double.MaxValue;

            model.Pre_em(data);
            emparam.Cnt = 0;
            while (true)
            {
                prev_llf = emparam.Llf;
                model.GetParam().CopyTo(prev_param);
                emparam.Llf = model.Emstep(data);

                if (emparam.Llf < prev_llf)
                {
                    msg.Warning();
                }

                switch (emparam.StopCond)
                {
                case StopCondition.LLF:
                    emparam.Aerror = NMath.Abs(emparam.Llf - prev_llf);
                    emparam.Rerror = emparam.Aerror / NMath.Abs(prev_llf);
                    break;

                case StopCondition.PARAMETER:
                    emparam.Aerror = model.GetParam().Adiff(prev_param);
                    emparam.Rerror = model.GetParam().Rdiff(prev_param);
                    break;
                }

                emparam.Cnt++;

                if (double.IsNaN(emparam.Llf))
                {
                    emparam.Status = Status.NUMERICALERROR;
                    break;
                }

                if (emparam.PrintFlag && emparam.Cnt % emparam.Progress == 0)
                {
                    msg.Show();
                }

                if (emparam.Aerror < emparam.Atol && emparam.Rerror < emparam.Rtol)
                {
                    emparam.Status = Status.CONVERGENCE;
                    break;
                }

                if (emparam.Cnt >= emparam.MaxIter)
                {
                    emparam.Status = Status.MAXITERATION;
                    break;
                }
            }
            msg.Final();
            model.Post_em(data);
        }
Ejemplo n.º 5
0
 public void Initialize(SRMData data)
 {
     model.Initialize(data);
 }
Ejemplo n.º 6
0
        public override Result Calc(SRMData data)
        {
            Result result = new Result();
            double te     = data.TotalTime;
            double me     = data.TotalFaults;

            int dsize = 0;

            double[] t = new double[data.Size];
            double[] x = new double[data.Size];
            double[] w = new double[data.Size];
            for (int i = 0; i < data.Size; i++)
            {
                if (data.Time[i] > 0)
                {
                    t[dsize] = data.Time[i];
                    x[dsize] = data.Fault[i];
                    w[dsize] = data.Type[i];
                    dsize++;
                }
                else
                {
                    w[dsize] += data.Fault[i];
                    w[dsize] += data.Type[i];
                }
            }

            double ctime   = 0.0;
            double prevmvf = 0.0;
            double cfault  = 0.0;
            double csum    = 0.0;
            double dsum    = 0.0;
            double llf     = 0.0;
            double cmvf    = 0.0;
            double pdf     = 0.0;
            double dmvf    = 0.0;

            for (int i = 0; i < dsize; i++)
            {
                ctime  += t[i];
                cfault += x[i];
                cfault += w[i];

                cmvf    = Omega * dist.Cdf(ctime);
                pdf     = Omega * dist.Pdf(ctime);
                dmvf    = cmvf - prevmvf;
                prevmvf = cmvf;

                if (x[i] > 0)
                {
                    llf += x[i] * NMath.Log(dmvf) - NMath.Lgamma(x[i] + 1);
                }
                if (w[i] > 0)
                {
                    llf += w[i] * NMath.Log(pdf);
                }
                csum += (cmvf - cfault) * (cmvf - cfault);
                dsum += (dmvf - (x[i] + w[i])) * (dmvf - (x[i] + w[i]));
            }
            llf += -cmvf;

            result.Llf   = llf;
            result.Aic   = -2 * result.Llf + 2 * NParam();
            result.Bic   = -2 * result.Llf + NParam() * NMath.Log(dsize);
            result.CMse  = csum / dsize;
            result.CMsee = csum / (dsize - NParam());
            result.DMse  = dsum / dsize;
            result.DMsee = dsum / (dsize - NParam());

            result.Residual = Omega - cmvf;
            result.Total    = me + result.Residual;
            result.Ffp      = NMath.Exp(-result.Residual);
            result.CMttf    = te / cmvf;
            result.IMttf    = 1.0 / pdf;

            result.Bexlife    = Bexlife(te, cmvf / Omega, result.Ffp, 0.1);
            result.Median     = Bexlife(te, cmvf / Omega, result.Ffp, 0.5);
            result.ConBexlife = ConBexlife(te, cmvf / Omega, result.Ffp, 0.1);
            result.ConMedian  = ConBexlife(te, cmvf / Omega, result.Ffp, 0.5);

            MTTFValue mttf = new MTTFValue(Reliab, 1.0e-8);

            result.ConMttf = mttf.Calc(te, cmvf, result.Ffp, ConBexlife(te, cmvf / Omega, result.Ffp, 1.0e-6));

            return(result);
        }
Ejemplo n.º 7
0
 //		public abstract void fit(Data.SRMFData data);
 public abstract Result Calc(SRMData data);