예제 #1
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();
        }
예제 #2
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();
        }