using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Zadanie1; namespace PerceptronNumbers { class NumberSamples { { { -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1 }, 0), { -1, -1, -1, 1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1 }, 1), { -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1 }, 2), { -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1 }, 3), { -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1 }, 4), { -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1 }, 5), { -1, 1, 1, 1,- 1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1 }, 6), { -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1 }, 7), { -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1 }, 8), { -1, 1, 1, 1, -1 , -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1 }, 9) }; public static double[][] MakeDataForPercepton(int perc) { int N = numbers.Length; int index = 0; for (int i = 0; i < 100; i++) { // 26 bo potrzebuej rozmair 5x5 planszy, a 26 bo wrzuca wynik w ostatnie miejsce // 100 x 26 - 100 próbek dla każego percepronu żeby się lepiej uczył // losuję każda z tych liczb int randNumber = rand.Next(0, N); // zamieniam ta liczbe na perceptron // to perceptron sprawdza czy ostatnia liczba tej tablicy jest faktycznie tym numerem, ktory sprawdzam double[] toPerc = numbers[randNumber].ToPerceptron(perc); // jezeli doby to 1, jezeli nie to -1 double isCorrect = toPerc[toPerc.Length - 1]; // to jest tablica, ktora jest tym perceptronem, z wycietym wynikiem - czy jest dobry czy zly // skracam tablice - pod przygotowane tablicy pod DFT // taki jakby temp for (int j = 0; j < toPercShort.Length; j++) toPercShort[j] = toPerc[j]; toPercShort = DFT.DFT2D(toPercShort, 5); for (int j = 0; j < toPercShort.Length; j++) toPerc[j] = toPercShort[j]; toPerc[toPerc.Length - 1] = isCorrect; // dodaje do wyniku ten perceptron i lece dalej wynik[index++] = toPerc; } return wynik; } } } --------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PerceptronNumbers { class Numbers { private int[] values; private int results; public Numbers(int[] values, int results) { this.values = values; this.results = results; } public double[] ToPerceptron(double perceptron) { // +1 żeby w ostatnie miejsce wrzucic wynik (-1 lub 1) for (int i = 0; i < values.Length; i++) wynik[i] = values[i]; if (results == perceptron) wynik[wynik.Length - 1] = 1; else wynik[wynik.Length - 1] = -1; return wynik; } } }