Esempio n. 1
0
	// Use this for initialization
	public void Start() {
		Stopper s = new Stopper(); 
		Console.WriteLine("How many hidden nodes?");
		hidden = int.Parse(Console.ReadLine());
		Console.WriteLine("Epoch counter?");
		int epochCtr = int.Parse(Console.ReadLine());
		Console.WriteLine("Error threshold?");
		s.errorThresh = float.Parse(Console.ReadLine());
		Thread oThread = new Thread(new ThreadStart(s.run));
		oThread.Start();
		String outPath = "C:/Users/SwoodGrommet/Desktop/game-ai/Assets/Scripts/Datas/";
		outputFile = "weights.txt";
		sets = new ArrayList();
		rec = new Recorder();
		nn = new NeuralNetwork (input, output, hidden);
		numWeights = (input * hidden) + (hidden * output) + (hidden + output);
		weights = getRandomWeights (numWeights);
		nn = new NeuralNetwork (input, output, hidden);
		nn.setWeights (weights);
		Console.WriteLine("chutzpah");
		rec.read (this.sets);
		read = true;
		double changeDel = 0;
		while (/*!trained &&*/ read) {
			double errors = 0;
			//do {
			foreach (TrainingSet set in this.sets) {
				setInputs(set.getInputs());
				setTargets(set.getTargets());
				errors += train();
			}

			//Debug.Log("Current error : " + errors);
			//} while (error > 0.0001);
			error = errors / sets.Count;
			if (s.output) {
				Console.WriteLine("Outputting weights to file");
				this.weights = nn.getWeights();
				nn.outputWeights(weights);
				s.output = false;
			}
			if (s.errorThresh > error || s.stop) {
				Console.WriteLine("All trainings are done!!!");
				break;
			}
			//Console.WriteLine(ctr + ": " + errors);
			if (ctr % epochCtr == 0) {
				Console.WriteLine("epoch: " + ctr / epochCtr + "; error: " + error + "; Delta: " + (changeDel - error));
				changeDel = error;
			}
			ctr++;
		}
		
	}