Ejemplo n.º 1
0
 public BackPropogation(BasicNetwork network)
     : base((BasicNetwork)network)
 {
     Layer[] layers = network.getLayers();
     errorResp = new double[layers.Length][]; //will hold current node error responsibility
     prevDelta = new double[layers.Length][][]; //used to store the previous weight delta values for momentum
     for (int x = 0; x < errorResp.Length; x++)
     {
         errorResp[x] = new double[layers[x].countNodes()]; //used to track the error resp. of each node
         prevDelta[x] = new double[layers[x].countNodes()][];
         for (int i = 0; i < layers[x].countNodes(); i++)
         {
             errorResp[x][i] = 0;
             if (x != layers.Length - 1)
             {
                 prevDelta[x][i] = new double[layers[x + 1].countNodes()];
                 for (int k = 0; k < layers[x + 1].countNodes(); k++)
                 {
                     prevDelta[x][i][k] = 0;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string fileName = "C:\\Users\\Vince\\Documents\\Dropbox\\Dev\\VStat\\Test Data\\letter-recognition-normalized.csv";//"C:\\Users\\Vince\\Documents\\Dropbox\\Dev\\Neural Network\\iris_converted_normalized.csv";
            int inputs = 16;
            int outputs = 3;
            //string fileName = "C:\\Users\\Vince\\Documents\\Dropbox\\Dev\\VStat\\Test Data\\iris_converted_normalized.csv";//"C:\\Users\\Vince\\Documents\\Dropbox\\Dev\\Neural Network\\iris_converted_normalized.csv";
            //int inputs = 4;
            //int outputs = 3;
            //string fileName = "C:\\Users\\Vince\\Documents\\Dropbox\\Dev\\VStat\\Test Data\\debug.csv";//"C:\\Users\\Vince\\Documents\\Dropbox\\Dev\\Neural Network\\iris_converted_normalized.csv";
            //int inputs = 3;
            //int outputs = 1;
            //create the data source off of an existing file
            TextDataSource dataSource = new TextDataSource(fileName, inputs, outputs, true);
            dataSource.setValidationMode(ValidationMode.Holdout, .2);//(ValidationMode.KFold, 3);
           // dataSource.setValidationMode(ValidationMode.KFold, 4);
            dataSource.loadData();

            //create the neural network
            //BasicNetwork nn = new BasicNetwork( 4, 3, 1, new int[] {10});
            BasicNetwork nn = new BasicNetwork(inputs, outputs, 1, new int[1] {2});

            nn.printConnections();

            //train the NN
            Console.ReadLine();
            VStats.Trainer.BackPropogation trainer = new BackPropogation(nn);
            trainer.train(dataSource);

            //serialize and save the model
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
            formatter.Serialize(stream, nn);
            stream.Close();

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        private void trainButton_Click(object sender, RoutedEventArgs e)
        {
            string fileName = fileTextBox.Text;
            bool header = (bool)headerCheckbox.IsChecked;
            trainButton.IsEnabled = false;
            System.Threading.Thread newThread;
            newThread = new System.Threading.Thread(
                delegate()
                {
                    logTextBlock.Dispatcher.Invoke(
                        DispatcherPriority.Normal,
                        new Action(
                            delegate()
                            {
                                logTextBlock.AppendText("Initializing file: " + fileTextBox.Text + "\n");
                            }
                        )
                    );

                    int inputs = 4;
                    int outputs = 3;
                    TextDataSource dataSource = new TextDataSource(
                        fileName,
                       inputs,
                       outputs,
                       header
                    );
                    dataSource.setValidationMode(ValidationMode.KFold, 4);
                    dataSource.loadData();
                    BasicNetwork nn = new BasicNetwork(inputs, outputs, 10);
                    BackPropogation trainer = new BackPropogation(nn);
                    trainer.epochIterationComplete += new Trainer.EpochIterationComplete(trainer_epochIterationComplete);
                    trainer.train(dataSource);
                    trainButton.Dispatcher.Invoke(
                        DispatcherPriority.Normal,
                        new Action(
                            delegate()
                            {
                                trainButton.IsEnabled = true;
                            }
                        )
                    );
                }
            );
            newThread.Start();
        }