示例#1
0
        private static void Main()
        {
            double baseNonlinearModel(double[] k, double[] x) => k[0] * Math.Pow(k[1], Math.Log(x[0])) * Math.Pow(k[2], x[1]) * Math.Pow(k[3], x[2]);

            // 1) Analyze test data using tools for nonlinear model
            RAProcessorNonLinear nlra = new RAProcessorNonLinear(TestSet.Data);

            nlra.SetModel(
                f: baseNonlinearModel,
                g: (k, x, r) =>
            {                                     //gradient function
                r[0] = k[0] * Math.Pow(k[1], Math.Log(x[0])) * Math.Pow(k[2], x[1]) * Math.Pow(k[3], x[2]);
                r[1] = k[0] * Math.Pow(k[1], Math.Log(x[0])) * Math.Pow(k[2], x[1]) * Math.Pow(k[3], x[2]) * Math.Log(x[0]) / k[1];
                r[2] = k[0] * Math.Pow(k[1], Math.Log(x[0])) * Math.Pow(k[2], x[1]) * Math.Pow(k[3], x[2]) * x[1] / k[2];
                r[3] = k[0] * Math.Pow(k[1], Math.Log(x[0])) * Math.Pow(k[2], x[1]) * Math.Pow(k[3], x[2]) * x[2] / k[3];
            },
                n: 4,                                //number of observed coefficients
                v: new[] { 150.0, 1, 1, 1 });
            nlra.ComputeRAResult();
            RAResultNonLinear nlres = nlra.GetRAresult();

            nlres.ComputeRAResultMetrics();
            PrintRAResult(nlres, "Non-linear analysis processing result:");

            // 2) Transform test dataset to format for linear regression and analyze with tools linear model
            RAData linedata = TestSet.Data.CloneData();      // Clone base test data

            linedata.OutputsTransform(Math.Log);             //perform the logarithm of y
            linedata.InputsTransform(0, Math.Log);           //perform the logarithm of first parametr
            RAProcessorLinear lra = new RAProcessorLinear(linedata);

            lra.ComputeRAResult();
            RAResultBase lres = lra.GetRAresult();

            lres.ComputeRAResultMetrics();
            PrintRAResult(lres, "Linear analysis processing result:");

            // 3) Create RAResultBase with nonlinear model but with model coefficients obtained using linear regression analysis
            RAResultBase checklra = new RAResultBase(TestSet.Data)
            {
                Coefficients = new double[]
                {
                    Math.Exp(lres.Coefficients[0]),
                    Math.Exp(lres.Coefficients[1]),
                    Math.Exp(lres.Coefficients[2]),
                    Math.Exp(lres.Coefficients[3])
                },
                Model = baseNonlinearModel
            };

            checklra.ComputeValuations();
            checklra.ComputeRAResultMetrics();
            PrintRAResult(checklra, "Non-linear analysis metrics with coefficients obtained with linear analysis:");

            Console.WriteLine("Test is passed.");
            Console.ReadKey();
        }
示例#2
0
 public void AddOn(bool relive = false)
 {
     radata      = new RAData("addon");
     this.relive = relive;
     setup();
 }
示例#3
0
 public void Rebuy(bool relive = false)
 {
     radata      = new RAData("rebuy");
     this.relive = relive;
     setup();
 }