Esempio n. 1
0
        public void testing_matix(System.Windows.Forms.TextBox textbox)
        {
            // Matrix testing
            if (textbox != null)
            {
                textbox.Text += "Matrix testing" + System.Environment.NewLine;
            }
            double []           in_array = { 1, 2, 1,
                                             4,           1, 6,
                                             1,           2, 3 };
            nkcore.Types.Matrix m1 = new nkcore.Types.Matrix(3, 3, in_array);
            nkcore.Types.Matrix m2 = new nkcore.Types.Matrix(m1);
            nkcore.Types.Matrix m3 = m1 + m2;
            nkcore.Types.Matrix m4 = (m1 + m2) * (m1 + m2);
            nkcore.Types.Matrix m5 = ((m1 + m2) * (m1 + m2)).Inverse();
            nkcore.Types.Matrix m6 = m4 * m5;

            //Console.WriteLine(m1.ToString());
            //Console.WriteLine(m2.ToString());
            Console.WriteLine(m3.ToString());
            Console.WriteLine(m4.ToString());
            Console.WriteLine(m5.ToString());
            Console.WriteLine(m6.ToString());
            Console.WriteLine("");

            if (textbox != null)
            {
                textbox.Text += m3.ToString() + System.Environment.NewLine;
                textbox.Text += m4.ToString() + System.Environment.NewLine;
                textbox.Text += m5.ToString() + System.Environment.NewLine;
                textbox.Text += m6.ToString() + System.Environment.NewLine;
                textbox.Text += System.Environment.NewLine;
            }
        }
Esempio n. 2
0
        public void testing_matix(System.Windows.Forms.TextBox textbox)
        {
            // Matrix testing
            if ( textbox != null ) textbox.Text += "Matrix testing" + System.Environment.NewLine;
            double []in_array = {1, 2, 1,
                                 4, 1, 6,
                                 1, 2, 3};
            nkcore.Types.Matrix m1 = new nkcore.Types.Matrix(3, 3, in_array);
            nkcore.Types.Matrix m2 = new nkcore.Types.Matrix(m1);
            nkcore.Types.Matrix m3 = m1+m2;
            nkcore.Types.Matrix m4 =  (m1+m2)*(m1+m2);
            nkcore.Types.Matrix m5 = ((m1+m2)*(m1+m2)).Inverse();
            nkcore.Types.Matrix m6 = m4*m5;

            //Console.WriteLine(m1.ToString());
            //Console.WriteLine(m2.ToString());
            Console.WriteLine(m3.ToString());
            Console.WriteLine(m4.ToString());
            Console.WriteLine(m5.ToString());
            Console.WriteLine(m6.ToString());
            Console.WriteLine("");

            if ( textbox != null ) {
                textbox.Text += m3.ToString() + System.Environment.NewLine;
                textbox.Text += m4.ToString() + System.Environment.NewLine;
                textbox.Text += m5.ToString() + System.Environment.NewLine;
                textbox.Text += m6.ToString() + System.Environment.NewLine;
                textbox.Text += System.Environment.NewLine;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Считает коэфициенты регрессии для "У" набором данных "Х"
        /// </summary>
        /// <param name="x">Набор данных Х</param>
        /// <param name="y">К чему стремимся</param>
        /// <param name="power">Степенной ряд, для которого делаем счет</param>
        /// <returns></returns>
        public static double [][] Regression(nkcore.Types.Collection y, nkcore.Types.Collection x, int[] powers)
        {
            if (x == null)
            {
                throw new Exception("(x) is null");
            }
            if (y == null)
            {
                throw new Exception("(y) is null");
            }
            if (powers == null)
            {
                throw new Exception("(powers) is null");
            }
            if (powers.Length >= y[0].Count)
            {
                throw new Exception("Length is small");
            }

            int ValuesCount  = y[0].Count;
            int xParamCount  = x.VectorsCount;
            int PolinomLevel = powers.Length;

            double [][] result = new double[xParamCount][];
            for (int i = 0; i < xParamCount; i++)
            {
                result[i] = new double[PolinomLevel];
            }

            nkcore.Types.Matrix XMat = new nkcore.Types.Matrix(ValuesCount, PolinomLevel * xParamCount);
            nkcore.Types.Matrix YMat = new nkcore.Types.Matrix(ValuesCount, 1);
            nkcore.Types.Matrix K    = new Types.Matrix();

            for (int i = 0; i < ValuesCount; i++)
            {
                YMat[i][0] = y[0][i];
            }

            for (int i = 0; i < ValuesCount; i++)
            {
                for (int z = 0; z < xParamCount; z++)
                {
                    for (int k = 0; k < PolinomLevel; k++)
                    {
                        XMat[i][k + z * (PolinomLevel)] = System.Math.Pow(x[z][i], powers[k]);
                    }
                }
            }


            K = (XMat.Transpose() * XMat).Inverse() * XMat.Transpose() * YMat;

            // ---------- K.Rows
            for (int i = 0; i < xParamCount; i++)
            {
                for (int k = 0; k < PolinomLevel; k++)
                {
                    result[i][k] = K[k + i * PolinomLevel][0];
                }
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Считает коэфициенты регрессии для "У" набором данных "Х"
        /// </summary>
        /// <param name="x">Набор данных Х</param>
        /// <param name="y">К чему стремимся</param>
        /// <param name="power">Степенной ряд, для которого делаем счет</param>
        /// <returns></returns>
        public static double[][] Regression( nkcore.Types.Collection y, nkcore.Types.Collection x, int[] powers)
        {
            if ( x             == null       ) throw new Exception("(x) is null");
            if ( y             == null       ) throw new Exception("(y) is null");
            if ( powers        == null       ) throw new Exception("(powers) is null");
            if ( powers.Length >= y[0].Count ) throw new Exception("Length is small");

            int ValuesCount  = y[0].Count;
            int xParamCount  = x.VectorsCount;
            int PolinomLevel = powers.Length;

            double [][]result = new double[xParamCount][];
            for ( int i = 0; i < xParamCount; i++) result[i] = new double[PolinomLevel];

            nkcore.Types.Matrix XMat = new nkcore.Types.Matrix(ValuesCount, PolinomLevel * xParamCount);
            nkcore.Types.Matrix YMat = new nkcore.Types.Matrix(ValuesCount, 1);
            nkcore.Types.Matrix K    = new Types.Matrix();

            for ( int i = 0; i < ValuesCount; i++ ) YMat[i][0] = y[0][i];

            for ( int i = 0; i < ValuesCount; i++)
                for ( int z = 0; z < xParamCount; z++)
                    for ( int k = 0; k < PolinomLevel; k++)
                        XMat[i][k + z*(PolinomLevel)] = System.Math.Pow(x[z][i], powers[k]);

            K = (XMat.Transpose() * XMat).Inverse()*XMat.Transpose()*YMat;

            // ---------- K.Rows
            for ( int i = 0; i < xParamCount; i++)
                for ( int k = 0; k < PolinomLevel; k++ )
                    result[i][k] = K[k + i*PolinomLevel][0];

            return result;
        }