Exemple #1
0
 public RegressionCalculator(FunctionMatrices matrices, int number, bool isPolynomial, int degree)
 {
     NumberOfXVariables   = number;
     Matrices             = matrices;
     IsFunctionPolynomial = isPolynomial;
     FunctionDegree       = degree;
 }
Exemple #2
0
        static void Main(string[] args)
        {
            // single.txt: C = 7.1594;  B = { 3.1000; } Y(400) = 1247.2; (works)
            // multi.txt:  C = 1.0441;  B = { 0.1000; 11.100; 5.2001; 4.4000; } (works)
            // poly.txt:   C = 61005.0; B = { 5.6097; -0.031; 2.0968; -1.099; } (works)
            string filePath = AskUserForFileName();
            bool   isPolynomial;

            List <double>         Y        = new List <double>();
            List <List <double> > XColumns = new List <List <double> >();

            ReadDataIntoLists(filePath, XColumns, Y);

            if (XColumns.Count > 1)
            {
                isPolynomial = false;
            }
            else
            {
                isPolynomial = true;
            }

            int degree = 1;
            RegressionCalculator calculator;
            Results results = new Results();

            do
            {
                FunctionMatrices matrices = new FunctionMatrices(XColumns, Y, isPolynomial, degree);
                calculator = new RegressionCalculator(matrices, XColumns.Count, isPolynomial, degree);
                calculator.CalculateRegression();

                var lastParameter = calculator.B[calculator.B.RowCount - 1, 0];
                if (lastParameter < 0.01 && lastParameter > -0.01)
                {
                    break;
                }

                results = new Results(calculator.B, calculator.C);
                degree++;
            }while (isPolynomial);
            degree--;

            results.DisplayRegressionInfo(isPolynomial, degree, calculator);
        }