Esempio n. 1
0
        public void ThreadProc()
        {
            TrainSelfOrganizingMap train = new TrainSelfOrganizingMap(
                this.network, this.trainingSet, TrainSelfOrganizingMap.LearningMethod.SUBTRACTIVE, 0.5);

            int tries = 1;

            do
            {
                train.Iteration();
                this.txtTries.Text = "" + tries;
                this.txtBestError.Text = "" + train.BestError;
                this.txtLastError.Text = "" + train.TotalError;
                tries++;
                Application.DoEvents();
            } while (train.TotalError > 0.01 && (tries <= 100));
            MessageBox.Show("Training complete.");
        }
        void ThreadProc()
        {
            Random rand = new Random();
            // build the training set
		this.input = new double[SAMPLE_COUNT][];

		for (int i = 0; i < SAMPLE_COUNT; i++) {
            this.input[i] = new double[INPUT_COUNT];
			for (int j = 0; j < INPUT_COUNT; j++) {
				this.input[i][j] = rand.NextDouble();
			}
		}

		// build and train the neural network
		this.net = new SelfOrganizingMap(INPUT_COUNT, OUTPUT_COUNT,
				NormalizationType.MULTIPLICATIVE);
		 TrainSelfOrganizingMap train = new TrainSelfOrganizingMap(
                this.net, this.input, TrainSelfOrganizingMap.LearningMethod.SUBTRACTIVE, 0.5);
		train.Initialize();
		double lastError = Double.MaxValue;
		int errorCount = 0;

		while (errorCount < 10) {
			train.Iteration();
			this.retry++;
			this.totalError = train.TotalError;
			this.bestError = train.BestError;
            this.Invalidate();

			if (this.bestError < lastError) {
				lastError = this.bestError;
				errorCount = 0;
			} else {
				errorCount++;
			}
		}
        }