/*
         * Pre-condition:
         *      X (XMtx) and Y (XMtx) values are initialized
         *
         * Post-condition:
         *      Calculate Beta by using LS method
         *      and set it to the ResultLs
         */
        public void CalcLs()
        {
            (ResultLs = new LsResult()).
            // β = ((X^T) ∙ X)^(-1) ∙ (X^T) ∙ Y
            Beta = Parameters.XMtx.TransposeThisAndMultiply(Parameters.XMtx).Inverse().Multiply(Parameters.XMtx.Transpose()).Multiply(Parameters.YVtr);

            CalcResult(ResultLs);
        }
        /*
         * Finding the coefficient of determination
         */
        private double CalcRp2(LsResult result)
        {
            var yAvg = Parameters.YVtr.Average();

            return
                (1
                 - (result.E.Sum((i) => i * i))
                 / (Parameters.YVtr.Sum((i) => Math.Pow(i - yAvg, 2))));
        }
Exemplo n.º 3
0
        private void DrawSeriesResults(string seriesName, LsResult result, Color color)
        {
            if (!result.IsCalculated)
            {
                return;
            }

            DrawSeries(seriesName, result.YRes);
            chart.Series[seriesName].Color = color;
        }
        public DataTableWindow(LsData lsData, LsResult lsResult, string filePath)
        {
            InitializeComponent();

            this.lsData   = lsData;
            this.lsResult = lsResult;
            this.filePath = filePath;

            InitializeComponents();
        }
        /*
         * Pre-condition:
         *      X (XMtx) and Y (XMtx) values are initialized
         *
         * Post-condition:
         *      Calculate Beta by using ILS method
         *      and set it to the ResultIls
         */
        public void CalcIls()
        {
            CalcMCrit();
            CalcAMtx();
            CalcBVtr();

            (ResultIls = new LsResult()).Beta = AMtx.Inverse().Multiply(BVtr);

            CalcResult(ResultIls);
        }
        /*
         * This section makes analysis of
         * LS or ILS method and set it to Result
         */


        /*
         * Pre-condition:
         *      Takes Result with calculated Beta vector
         *
         * Post-condition:
         *      Makes analysis of Beta
         */
        private void CalcResult(LsResult result)
        {
            result.YRes = CalcYVtrRes(result.Beta);

            result.E     = CalcEVtr(result.YRes);
            result.Delta = CalcDeltaVtr(result.E);
            result.Tbeta = CalcTbetaVtr();

            result.SigmaE = CalcSigmaE(result);
            result.Rp2    = CalcRp2(result);
            result.R      = CalcR(result);

            result.IsCalculated = true;
        }
        private static void WriteResults(Excel.Workbook xlWorkbook, LsResult lsResult, string sheetName)
        {
            if (!lsResult.IsCalculated)
            {
                return;
            }

            try
            {
                xlWorkbook.Worksheets[sheetName].Delete();
            }
            catch (Exception) { }

            CreateReslutWorksheet(xlWorkbook.Worksheets.Add(), lsResult, sheetName);
        }
        private static void CreateReslutWorksheet(Excel.Worksheet sheet, LsResult result, string sheetName)
        {
            sheet.Name = sheetName;
            sheet.Columns[(new XlPosition()).Column].ColumnWidth = 2.5;

            // Setting result values such as:
            //      Beta, e, Delta, Tbeta
            //      Sigma, R, R^2, F, F table

            // Headers
            SetResultHeaders(sheet);

            // Values
            SetResultValues(sheet, result);

            ReleaseMemory(sheet);
        }
        private static void SetResultValues(Excel.Worksheet sheet, LsResult result)
        {
            SetColumnValues(sheet, result.Beta, resBValsSp);
            SetColumnValues(sheet, result.E, resEValsSp);
            SetColumnValues(sheet, result.Delta, resDltValsSp);
            SetColumnValues(sheet, result.Tbeta, resTbValsSp);

            double[] singleResultValues =
            {
                result.BetaAvg,
                result.SigmaE,
                result.R,
                result.Rp2,
                result.F,
                result.Ftable
            };

            SetColumnValues(sheet, Vector <double> .Build.Dense(singleResultValues), resSglValsSp);
        }
 public LsData(LsParameters parameters)
 {
     Parameters = parameters;
     ResultLs   = new LsResult();
     ResultIls  = new LsResult();
 }
 private double CalcR(LsResult result)
 {
     return(Math.Sqrt(result.R));
 }
 /*
  * Finding the mean square error variance disturbances
  * √((∑ e[i]^2 ) / (NumbOfTests - NumbOfXVal - 1))
  */
 private double CalcSigmaE(LsResult result)
 {
     return(Math.Sqrt(
                result.E.Sum(
                    (i) => i * i / (Parameters.NumbOfTests - Parameters.NumbOfXVal - 1))));
 }