public MainWindow() { AllocConsole(); InitializeComponent(); SinglePerceptron singlePerceptron = new SinglePerceptron(); singlePerceptron.errorFunc_Batch(); singlePerceptron.errorFunc_Online(); }
private static void SinglePerceptromProgram2(int nInput) { SinglePerceptron nn2 = new SinglePerceptron(nInput); for (int i = 0; i < 1000; i++) { Random random = new Random(Guid.NewGuid().GetHashCode()); double value1 = random.NextDouble(); random = new Random(Guid.NewGuid().GetHashCode()); double value2 = random.NextDouble(); double y = Formula(value1); double result = value2 > y ? 1 : -1; nn2.Train(new List <double>() { value1, value2 }, result); } double n = 0; for (int i = 0; i < 200; i++) { Random random = new Random(Guid.NewGuid().GetHashCode()); double value1 = random.NextDouble(); random = new Random(Guid.NewGuid().GetHashCode()); double value2 = random.NextDouble(); double y = Formula(value1); double result = value2 > y ? 1 : -1; var guess = nn2.Predict(new List <double>() { value1, value2 }).First(); bool correct = result / guess > 0; Console.WriteLine("result : " + result); Console.WriteLine("guess : " + guess); Console.WriteLine("correct : " + correct); Console.WriteLine("--"); if (correct) { n++; } } Console.WriteLine(n / 200); }
private static void SinglePersptronProgram(int nInput) { SinglePerceptron nn2 = new SinglePerceptron(nInput); List <double> data = new List <double>() { 0.2, 0.6, 0.5 }; for (int i = 0; i < 1000; i++) { Random random = new Random(Guid.NewGuid().GetHashCode()); int value1 = random.Next() % 2; random = new Random(Guid.NewGuid().GetHashCode()); int value2 = random.Next() % 2; int xor = AndBool(value1, value2); if (xor == 0) { xor = -1; } nn2.Train(new List <double>() { value1, value2 }, xor); } for (int i = 0; i < 200; i++) { Random random = new Random(Guid.NewGuid().GetHashCode()); int value1 = random.Next() % 2; random = new Random(Guid.NewGuid().GetHashCode()); int value2 = random.Next() % 2; int xor = AndBool(value1, value2); double guess = nn2.Predict(new List <double>() { value1, value2 }).First(); Console.WriteLine("xor : " + xor); Console.WriteLine("guess : " + guess); Console.WriteLine("correct : " + (xor / guess > 0)); Console.WriteLine("--"); } }