public void NN_backpropagation_generic_rprop_3L_gnb_all_training_samples()
        {
            initData_dataset_gaussian_naive_bayes_jason_example();
            BuildGenericBackPropagationRprop build =
                new BuildGenericBackPropagationRprop();

            build.SetParameters(1, 2, .5, 1500);
            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);
        }
        public void NN_backpropagation_generic_rprop_invalid_layer_throws_exception()
        {
            initData_dataset_gaussian_naive_bayes_jason_example();
            BuildGenericBackPropagationRprop build =
                new BuildGenericBackPropagationRprop();

            build.SetParameters(1, 1, .5, 1500);
            build.AddHiddenLayer(0, 2, new Sigmoid());
            build.AddHiddenLayer(1, 2, new Sigmoid());
            build.SetOutputLayerActivationFunction(new Sigmoid());
        }
        public void NN_backpropagation_generic_rprop_missing_layer_throws_exception()
        {
            initData_dataset_gaussian_naive_bayes_jason_example();
            BuildGenericBackPropagationRprop build =
                new BuildGenericBackPropagationRprop();

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

            ModelBackPropagationBase model =
                (ModelBackPropagationBase)build.BuildModel(
                    _trainingData, _attributeHeaders,
                    _indexTargetAttribute);
        }
Ejemplo n.º 4
0
        BuildModel(double[][] trainingData,
                   string[] attributeHeaders,
                   int indexTargetAttribute)
        {
            VerifyData(trainingData, attributeHeaders, indexTargetAttribute);


            double[] targetValues =
                GetNumberOfTargetValues(_mode, trainingData, indexTargetAttribute);

            _noOfUnitsOutputLayer = targetValues.Length;

            if (NumberOfUnitsHiddenLayer < 0)
            { //Compute this number automatically
                NumberOfUnitsHiddenLayer =
                    GetNumberOfHiddenUnits(_noOfUnitsOutputLayer,
                                           _scalingFactor, _noOfAttributes);
            }

            //Add Hidden Layers
            for (int idx = 0; idx < _noOfHiddenLayers; idx++)
            {
                _buildGenericRprop.AddHiddenLayer(idx, NumberOfUnitsHiddenLayer,
                                                  new Sigmoid());
            }

            _buildGenericRprop.SetOutputLayerActivationFunction(new Linear());

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

            return(model);
        }
        public void NN_backpropagation_generic_rprop_one_hidden_pythagoras_rmse_data_1()
        {
            Init_dataset_pythagoras();
            BuildGenericBackPropagationRprop build =
                new BuildGenericBackPropagationRprop();

            build.SetParameters(0, 1, .02, 20000, .1);//,.005,2000);
            build.AddHiddenLayer(0, 2, new Sigmoid());
            build.SetOutputLayerActivationFunction(new Linear());

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

            /*
             * model.SetWeight(1, 0, 0, .53);
             * model.SetWeight(1, 1, 0, .53);
             * model.SetWeight(1, 2, 0, .53);
             *
             * model.SetWeight(1, 0, 1, .53);
             * model.SetWeight(1, 1, 1, .53);
             * model.SetWeight(1, 2, 1, .53);
             *
             * model.SetWeight(2, 0, 0, .53);
             * model.SetWeight(2, 1, 0, .53);
             * model.SetWeight(2, 2, 0, .53);
             */

            System.Diagnostics.Debug.WriteLine("Weight[1][0][0]:" + model.GetWeight(1, 0, 0));
            System.Diagnostics.Debug.WriteLine("Weight[1][1][0]:" + model.GetWeight(1, 1, 0));
            System.Diagnostics.Debug.WriteLine("Weight[1][2][0]:" + model.GetWeight(1, 2, 0));

            System.Diagnostics.Debug.WriteLine("Weight[1][0][1]:" + model.GetWeight(1, 0, 1));
            System.Diagnostics.Debug.WriteLine("Weight[1][1][1]:" + model.GetWeight(1, 1, 1));
            System.Diagnostics.Debug.WriteLine("Weight[1][2][1]:" + model.GetWeight(1, 2, 1));

            System.Diagnostics.Debug.WriteLine("Weight[2][0][1]:" + model.GetWeight(2, 0, 0));
            System.Diagnostics.Debug.WriteLine("Weight[2][1][1]:" + model.GetWeight(2, 1, 0));
            System.Diagnostics.Debug.WriteLine("Weight[2][2][1]:" + model.GetWeight(2, 2, 0));

            int row = 0;

            double[] data  = GetSingleTrainingRowDataForTest(row);
            double   value = model.RunModelForSingleData(data);

            Assert.IsTrue(value <= 1.69);
        }
        public void NN_backpropagation_generic_rprop_one_hidden_pythagoras_rmse()
        {
            Init_dataset_pythagoras();
            BuildGenericBackPropagationRprop build =
                new BuildGenericBackPropagationRprop();

            build.SetParameters(0, 1, .02, 20000);
            build.AddHiddenLayer(0, 2, new Sigmoid());
            build.SetOutputLayerActivationFunction(new Linear());

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

            double value = model.GetModelRMSE(_trainingData);

            Assert.IsTrue(value <= .13);
        }
        public void NN_backpropagation_generic_rprop_jason_simple_rmse()
        {
            Init_dataset_jason_linear_regression();
            BuildGenericBackPropagationRprop build =
                new BuildGenericBackPropagationRprop();

            build.SetParameters(0, 1, .01, 10000);
            build.AddHiddenLayer(0, 2, new Sigmoid());
            build.SetOutputLayerActivationFunction(new Linear());

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

            double value = model.GetModelRMSE(_trainingData);

            Assert.IsTrue(value < .61 && value > 0);
        }
        public void NN_backpropagation_generic_rprop_gnb_single_training_sample_class_0()
        {
            initData_dataset_gaussian_naive_bayes_jason_example();
            BuildGenericBackPropagationRprop build =
                new BuildGenericBackPropagationRprop();

            build.SetParameters(1, 1);
            build.AddHiddenLayer(0, 2, new Sigmoid());
            build.SetOutputLayerActivationFunction(new Sigmoid());

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

            int row = 0;

            double[] data  = GetSingleTrainingRowDataForTest(row);
            double   value = model.RunModelForSingleData(data);

            Assert.AreEqual(value,
                            _trainingData[_indexTargetAttribute][row]);
        }