示例#1
0
        /// <summary>
        /// Compares 2 batrices and returns true if there are same
        /// </summary>
        /// <param name="matrix1"></param>
        /// <param name="matrix2"></param>
        /// <returns></returns>
        public bool CompareMatrix(double[][] matrix1,
                                  double[][] matrix2)
        {
            bool flag = true;

            if (matrix1.Length != matrix2.Length)
            {
                return(false);
            }
            if (matrix1[0].Length != matrix2[0].Length)
            {
                return(false);
            }

            for (int col = 0; col < matrix1.Length; col++)
            {
                for (int row = 0; row < matrix1[0].Length; row++)
                {
                    if (!SupportFunctions.DoubleCompare(matrix1[col][row],
                                                        matrix2[col][row]))
                    {
                        flag = false;
                        break;
                    }
                }
            }
            return(flag);
        }
示例#2
0
        public void NN_backpropagation_2L_gnb_all_training_samples()
        {
            initData_dataset_gaussian_naive_bayes_jason_example();
            Build2LBackPropagation build =
                new Build2LBackPropagation();

            build.SetParameters(1);

            ModelBackPropagationBase model =
                (ModelBackPropagationBase)build.BuildModel(
                    _trainingData, _attributeHeaders,
                    _indexTargetAttribute);

            int count = 0;

            for (int row = 0; row < 10; row++)
            {
                double[] data  = GetSingleTrainingRowDataForTest(row);
                double   value = model.RunModelForSingleData(data);

                if (SupportFunctions.DoubleCompare(value,
                                                   _trainingData[_indexTargetAttribute][row]))
                {
                    count++;
                }
            }

            Assert.AreEqual(count,
                            10);
        }
示例#3
0
        public void NN_perceptron_multi_all_training_samples_gnb()
        {
            initData_dataset_gaussian_naive_bayes_jason_example();
            BuildMultiUnitPerceptronSGD build =
                new BuildMultiUnitPerceptronSGD();

            ModelMultiUnitPerceptron model =
                (ModelMultiUnitPerceptron)build.BuildModel(
                    _trainingData, _attributeHeaders,
                    _indexTargetAttribute);

            int count = 0;

            for (int row = 0; row < 10; row++)
            {
                double[] data  = GetSingleTrainingRowDataForTest(row);
                double   value = model.RunModelForSingleData(data);

                if (SupportFunctions.DoubleCompare(value,
                                                   _trainingData[_indexTargetAttribute][row]))
                {
                    count++;
                }
            }

            Assert.AreEqual(count,
                            10);
        }
示例#4
0
        public void Matrix_hessenberg_3_row_test_2()
        {
            InitData_dataset_3_rows_symmetric_givens_rotation();
            double[][] U         = null;
            double[][] newMatrix =
                _mo.Hessenberg(_matrix1, ref U);

            //U is null as matrix is already householder
            Assert.IsNull(U);

            Assert.AreEqual(newMatrix.Length, 3);
            Assert.AreEqual(newMatrix[0].Length, 3);

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][0], 6));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][1], 5));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][2], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][0], 5));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][1], 1));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][2], 4));

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][0], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][1], 4));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][2], 3));
        }
示例#5
0
        public void Matrix_hessenberg_4_row_test_0()
        {
            InitData_dataset_4_rows_symmetric_hessenberg();
            double[][] U         = null;
            double[][] newMatrix =
                _mo.Hessenberg(_matrix1, ref U);


            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][0], 4));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][1], 3));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][2], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][3], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][0], 3));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][1], 10.0 / 3.0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][2], 5.0 / 3.0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][3], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][0], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][1], 5.0 / 3.0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][2], -33.0 / 25.0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][3], -68.0 / 75.0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[3][0], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[3][1], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[3][2], -68.0 / 75.0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[3][3], 149.0 / 75.0));
        }
示例#6
0
        public void NN_backpropagation_2L_nb_custom_activation_SigSig_all_training_samples()
        {
            initData_dataset_naive_bayes_jason_example();
            Build2LBackPropagation build =
                new Build2LBackPropagation();

            build.SetParameters(1);

            build.SetActivationFunction(0, new Dasmic.MLLib.Algorithms.NeuralNetwork.Support.ActivationFunction.Sigmoid());
            build.SetActivationFunction(1, new Dasmic.MLLib.Algorithms.NeuralNetwork.Support.ActivationFunction.Sigmoid());

            ModelBackPropagationBase model =
                (ModelBackPropagationBase)build.BuildModel(
                    _trainingData, _attributeHeaders,
                    _indexTargetAttribute);

            int count = 0;

            for (int row = 0; row < 10; row++)
            {
                double[] data  = GetSingleTrainingRowDataForTest(row);
                double   value = model.RunModelForSingleData(data);

                if (SupportFunctions.DoubleCompare(value,
                                                   _trainingData[_indexTargetAttribute][row]))
                {
                    count++;
                }
            }

            //Due to random weights
            Assert.IsTrue(count >= 8 && count <= 10);
        }
示例#7
0
        public void NN_perceptron_single_sgd_all_training_samples()
        {
            initData_NN_dataset_linear_subgd_jason_example();
            BuildSingleUnitPerceptronSGD build = new BuildSingleUnitPerceptronSGD();

            setPrivateVariablesInBuildObject(build);

            //Set params
            //build.setParameters(1,1,.45);


            ModelSingleUnitPerceptron model =
                (ModelSingleUnitPerceptron)build.BuildModel(
                    _trainingData, _attributeHeaders,
                    _indexTargetAttribute);

            int count = 0;

            for (int row = 0; row < _trainingData[0].Length; row++)
            {
                double[] data  = GetSingleTrainingRowDataForTest(row);
                double   value = model.RunModelForSingleData(data);
                if (SupportFunctions.DoubleCompare(value, _trainingData[_indexTargetAttribute][row]))
                {
                    count++;
                }
            }

            Assert.AreEqual(count,
                            10);
        }
        public void PCA_new_matrix_3_rows_rank_3_1()
        {
            InitData_dataset_3_rows_non_symmetric();
            PrincipalComponentAnalysis pca = new PrincipalComponentAnalysis();

            pca.Rank = 3;
            double[][] rotationMatrix    = null;
            double[]   standardDeviation = null;
            double[][] newMatrix         = pca.GetPrincipleFeatures(_trainingData,
                                                                    _attributeHeaders, ref standardDeviation, ref rotationMatrix);

            Assert.AreEqual(newMatrix.Length, 3);
            Assert.AreEqual(newMatrix[0].Length, _trainingData[0].Length);

            Assert.IsTrue(SupportFunctions.DoubleCompare(standardDeviation[0], 1.73));
            Assert.IsTrue(SupportFunctions.DoubleCompare(standardDeviation[1], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(standardDeviation[2], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[0][0], .57));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[0][1], .57));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[0][2], .57));

            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[1][0], -.81));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[1][1], .40));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[1][2], .40));

            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[2][0], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[2][1], -.70));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[2][2], .70));
        }
        public void PCA_new_matrix_3_rows_rank_2_0()
        {
            InitData_dataset_3_rows_symmetric_hessenberg();
            PrincipalComponentAnalysis pca = new PrincipalComponentAnalysis();

            pca.Rank = 2;
            double[][] rotationMatrix    = null;
            double[]   standardDeviation = null;
            double[][] newMatrix         = pca.GetPrincipleFeatures(_trainingData,
                                                                    _attributeHeaders, ref standardDeviation, ref rotationMatrix);

            Assert.AreEqual(newMatrix.Length, 2);
            Assert.AreEqual(standardDeviation.Length, 2);
            Assert.AreEqual(rotationMatrix.Length, 2);

            Assert.IsTrue(SupportFunctions.DoubleCompare(standardDeviation[0], 1.26));
            Assert.IsTrue(SupportFunctions.DoubleCompare(standardDeviation[1], .85));


            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[0][0], .29));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[0][1], .60));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[0][2], -.74));

            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[1][0], -.52));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[1][1], .75));
            Assert.IsTrue(SupportFunctions.DoubleCompare(rotationMatrix[1][2], .40));
        }
示例#10
0
        public void Matrix_QR_Householder_3_row_test_0()
        {
            InitData_dataset_3_rows_symmetric_givens_rotation();
            double[][] Q = null;
            double[][] R = null;

            _mo.QRDecomposition_Householder(_matrix1, ref Q, ref R);

            Assert.IsTrue(SupportFunctions.DoubleCompare(R[0][0], 7.81));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[0][1], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[0][2], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(R[1][0], 4.48));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[1][1], 4.68));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[1][2], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(R[2][0], 2.56));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[2][1], .96));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[2][2], -4.18));

            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[0][0], .76));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[0][1], .64));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[0][2], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[1][0], .3327));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[1][1], -.39));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[1][2], .85));

            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[2][0], .54));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[2][1], -.65));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[2][2], -.51));
        }
示例#11
0
        public void NN_activation_function_linear()
        {
            Linear aFunc = new Linear();
            double value = aFunc.GetValue(3.0);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, 3.00));
        }
示例#12
0
        public void NN_activation_function_sigmoid()
        {
            Sigmoid aFunc = new Sigmoid();
            double  value = aFunc.GetValue(3.0);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, 0.9526));
        }
示例#13
0
        public void NN_activation_function_hyperbolictangent()
        {
            HyperbolicTangent aFunc = new HyperbolicTangent();
            double            value = aFunc.GetValue(3.0);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, 0.9950));
        }
        public void Matrix_QR_Givens_Rotation_2_row_non_symmetric_test_1()
        {
            InitData_dataset_2_rows_householder();
            double[][] Q = null;
            double[][] R = null;

            _mo.QRDecomposition_Givens_Rotation(_matrix1, ref Q, ref R);

            //Verify R is upper triangular
            Assert.IsTrue(_mo.IsUpperTriangular(R));

            //---Veriy if A = Q.R
            double[][] T = _mo.Multiply(Q, R);
            Assert.IsTrue(_mo.CompareMatrix(_matrix1, T));

            Assert.IsTrue(SupportFunctions.DoubleCompare(R[0][0], 5));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[0][1], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[1][0], 2.4));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[1][1], -3.2));


            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[0][0], .6));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[0][1], .8));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[1][0], -.8));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[1][1], .6));
        }
        public void Matrix_QR_Givens_Rotation_2_row_symmetric_test_2()
        {
            InitData_dataset_2_rows_symmetric_eigenValue();
            double[][] Q = null;
            double[][] R = null;
            _mo.QRDecomposition_Givens_Rotation(_matrix1, ref Q, ref R);

            //Verify R is upper triangular
            Assert.IsTrue(_mo.IsUpperTriangular(R));

            //---Veriy if A = Q.R
            double[][] T = _mo.Multiply(Q, R);
            Assert.IsTrue(_mo.CompareMatrix(_matrix1, T));

            Assert.IsTrue(SupportFunctions.DoubleCompare(R[0][0], 2.23));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[0][1], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[1][0], 1.78));
            Assert.IsTrue(SupportFunctions.DoubleCompare(R[1][1], 1.34));


            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[0][0], .89));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[0][1], .44));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[1][0], -.44));
            Assert.IsTrue(SupportFunctions.DoubleCompare(Q[1][1], .89));
        }
示例#16
0
        public void Statictics_CoVariance_1()
        {
            InitData_dataset_pca_example();
            double value = Dispersion.CoVarianceSample(_trainingData[0], _trainingData[1]);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, .6154));
        }
示例#17
0
        public void Matrix_hessenberg_4_row_test_1()
        {
            InitData_dataset_4_rows_symmetric_hessenberg();
            //Convert Matrix 1 to Hessenberg

            _matrix1[0][2] = 0;
            _matrix1[0][3] = 0;
            _matrix1[1][3] = 0;

            double[][] U         = null;
            double[][] newMatrix =
                _mo.Hessenberg(_matrix1, ref U);

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][0], 4));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][1], 1));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][2], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[0][3], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][0], 1));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][1], 2));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][2], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[1][3], 0));

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][0], -2));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][1], 0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][2], 3));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[2][3], -2));

            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[3][0], 2));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[3][1], 1));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[3][2], -2));
            Assert.IsTrue(SupportFunctions.DoubleCompare(newMatrix[3][3], -1));
        }
示例#18
0
        public void NN_backpropagation_generic_std_3L_gnb_all_training_samples()
        {
            initData_dataset_gaussian_naive_bayes_jason_example();
            BuildGenericBackPropagationStandard build =
                new BuildGenericBackPropagationStandard();

            build.SetParameters(1, 2, .5, 1500);
            //build.SetNumberOfHiddenLayers(2);
            build.AddHiddenLayer(0, 2, new Sigmoid());
            build.AddHiddenLayer(1, 2, new Sigmoid());
            build.SetOutputLayerActivationFunction(new Sigmoid());

            ModelBackPropagationBase model =
                (ModelBackPropagationBase)build.BuildModel(
                    _trainingData, _attributeHeaders,
                    _indexTargetAttribute);

            int count = 0;

            for (int row = 0; row < 10; row++)
            {
                double[] data  = GetSingleTrainingRowDataForTest(row);
                double   value = model.RunModelForSingleData(data);

                if (SupportFunctions.DoubleCompare(value,
                                                   _trainingData[_indexTargetAttribute][row]))
                {
                    count++;
                }
            }
            //Due to random weights
            Assert.IsTrue(count >= 5);
        }
示例#19
0
        public void Statistics_Pdf_Example_3()
        {
            DistributionNormal snd =
                new DistributionNormal();
            double value = snd.ProbabilityDensityFunction(4, 0, 1);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, .0001));
        }
示例#20
0
        public void Statictics_CoVariance_matrix_2_cols_1()
        {
            InitData_dataset_pca_example();
            double[][] matrix = Dispersion.CovarianceMatrixSample(_trainingData);

            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][0], .6165));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][1], .6154));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][0], .6154));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][1], .7165));
        }
示例#21
0
 public void Statictics_CoVariance_Matrix_2_cols_0()
 {
     double[][] data = new double[2][];
     data[0] = ta;
     data[1] = ta2;
     double[][] matrix = Dispersion.CovarianceMatrixSample(data);
     Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][0], 52.36));
     Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][1], 21.12));
     Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][0], 21.12));
     Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][1], 55.75));
 }
示例#22
0
        public void Regression_linear_multivariable_web_example_single_row_0()
        {
            InitData_dataset_regression_web_example();
            BuildLinearMultiVariable     lm = new BuildLinearMultiVariable();
            ModelLinearMultiVariableBase mb = (ModelLinearMultiVariableBase)lm.BuildModel(_trainingData,
                                                                                          _attributeHeaders, _indexTargetAttribute);

            double[] data  = GetSingleTrainingRowDataForTest(0);
            double   value = mb.RunModelForSingleData(data);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, 249.98));
        }
示例#23
0
        public void Regression_linear_multivariable_jason_simple()
        {
            Init_dataset_jason_linear_regression();
            BuildLinearMultiVariable lm = new BuildLinearMultiVariable();

            ModelLinearMultiVariableBase mb = (ModelLinearMultiVariableBase)lm.BuildModel(_trainingData,
                                                                                          _attributeHeaders, _indexTargetAttribute);

            double[] data  = { 1 };
            double   value = mb.RunModelForSingleData(data);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, 1.2));
        }
示例#24
0
        public void Regression_linear_check_model_jason_input_row_2()
        {
            Init_dataset_jason_linear_regression();
            BuildLinearSimple lm = new BuildLinearSimple();

            Dasmic.MLLib.Algorithms.Regression.ModelBase mb = (Dasmic.MLLib.Algorithms.Regression.ModelBase)lm.BuildModel(_trainingData,
                                                                                                                          _attributeHeaders, _indexTargetAttribute);

            double[] data  = GetSingleTrainingRowDataForTest(2);
            double   value = mb.RunModelForSingleData(
                data);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, 3.59));
        }
        public void Matrix_inverse_determinant_0_3_row_test()
        {
            double[][] matrixA = new double[3][];
            matrixA[0] = new double[] { 1, 4, 7 };
            matrixA[1] = new double[] { 2, 5, 8 };
            matrixA[2] = new double[] { 3, 6, 9 };

            MatrixOperations mo = new MatrixOperations();

            double[][] matrixI =
                mo.Inverse(matrixA);

            //Check Det
            Assert.IsFalse(SupportFunctions.DoubleCompare(matrixI[0][0], -11.0 / 12.0));
        }
示例#26
0
        public void Regression_linear_multivariable_jason_simple_rmse()
        {
            Init_dataset_jason_linear_regression();
            BuildLinearMultiVariable lm = new BuildLinearMultiVariable();

            ModelLinearMultiVariableBase mb = (ModelLinearMultiVariableBase)lm.BuildModel(_trainingData,
                                                                                          _attributeHeaders, _indexTargetAttribute);

            //Refill the trainingData array since it gets messed up
            Init_dataset_jason_linear_regression();
            double value = mb.GetModelRMSE(_trainingData);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value,
                                                         0.69));
        }
示例#27
0
        public void Regression_linear_gd_check_rmse_power_input()
        {
            initData_Power();

            BuildLinearSGD lm = new BuildLinearSGD();

            Dasmic.MLLib.Algorithms.Regression.ModelBase mb = (Dasmic.MLLib.Algorithms.Regression.ModelBase)
                                                              lm.BuildModel(_trainingData,
                                                                            _attributeHeaders,
                                                                            _indexTargetAttribute);

            double value = mb.GetModelRMSE(_trainingData);

            //Some issues were seen earlier maybe with parrelization
            Assert.IsTrue(SupportFunctions.DoubleCompare(value, 3.18));
        }
示例#28
0
        public void Regression_linear_gd_check_rmse_power_param()
        {
            initData_Power();

            BuildLinearSGD lm = new BuildLinearSGD();

            lm.SetParameters(.02, 20);

            Dasmic.MLLib.Algorithms.Regression.ModelBase mb = (Dasmic.MLLib.Algorithms.Regression.ModelBase)
                                                              lm.BuildModel(_trainingData,
                                                                            _attributeHeaders,
                                                                            _indexTargetAttribute);

            double value = mb.GetModelRMSE(_trainingData);

            Assert.IsTrue(SupportFunctions.DoubleCompare(value, 3.16));
        }
示例#29
0
        public void Statictics_ZeroCentered_2_rows_0()
        {
            InitData_dataset_pca_example();

            double[][] matrix = Dispersion.GetZeroCenteredData(_trainingData, false);

            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][0], .69));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][1], -1.31));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][2], .39));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][3], .09));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[0][4], 1.29));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][0], .49));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][1], -1.21));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][2], .99));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][3], .29));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrix[1][4], 1.09));
        }
        public void Matrix_inverse_2_row_test()
        {
            double[][] matrixA = new double[2][];
            matrixA[0] = new double[] { 1, 2 };
            matrixA[1] = new double[] { 3, 4 };

            MatrixOperations mo = new MatrixOperations();

            double[][] matrixI =
                mo.Inverse(matrixA);

            //Check Det
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrixI[0][0], -2.0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrixI[0][1], 1.0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrixI[1][0], 3.0 / 2.0));
            Assert.IsTrue(SupportFunctions.DoubleCompare(matrixI[1][1], -1.0 / 2.0));
        }