public result_var errorFunc_Online() { result_var result; double lostFunc1; double lostFunc2; double lostFunc3; double lostFunc4; double lostFunc; double temp = 0; double temp0 = 0; Dataset_And dataset_and = new Dataset_And(1); int epoch = 0; lostFunc1 = Math.Abs(dataset_and.d1.output - cost_Sigmoid(dataset_and.d1.x1, dataset_and.d1.x2)); lostFunc2 = Math.Abs(dataset_and.d2.output - cost_Sigmoid(dataset_and.d2.x1, dataset_and.d2.x2)); lostFunc3 = Math.Abs(dataset_and.d3.output - cost_Sigmoid(dataset_and.d3.x1, dataset_and.d3.x2)); lostFunc4 = Math.Abs(dataset_and.d4.output - cost_Sigmoid(dataset_and.d4.x1, dataset_and.d4.x2)); lostFunc = Math.Abs(dataset_and.d1.output - cost_Sigmoid(dataset_and.d1.x1, dataset_and.d1.x2) + dataset_and.d2.output - cost_Sigmoid(dataset_and.d2.x1, dataset_and.d2.x2) + dataset_and.d3.output - cost_Sigmoid(dataset_and.d3.x1, dataset_and.d3.x2) + dataset_and.d4.output - cost_Sigmoid(dataset_and.d4.x1, dataset_and.d4.x2)) ; while (lostFunc > 0.01) { while (lostFunc1 > 0.01) { bias = bias + (eta * ( (-(1 / Math.Exp((bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2)) * Math.Sin(dataset_and.d1.output + 1 / Math.Exp((bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2)) - 1)) / 2))); weight1 = weight1 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2) * dataset_and.d1.x1 * Math.Sin(dataset_and.d1.output + 1 / Math.Exp(bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2) - 1)) / 2))); weight2 = weight2 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2) * dataset_and.d1.x2 * Math.Sin(dataset_and.d1.output + 1 / Math.Exp(bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2) - 1)) / 2))); lostFunc1 = Math.Abs(dataset_and.d1.output - cost_Sigmoid(dataset_and.d1.x1, dataset_and.d1.x2)); epoch++; if (lostFunc1 == temp) { break; } temp = lostFunc1; } Console.WriteLine("1 COMPLETE"); while (lostFunc2 > 0.01) { bias = bias + (eta * ( (-(1 / Math.Exp((bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2)) * Math.Sin(dataset_and.d2.output + 1 / Math.Exp((bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2)) - 1)) / 2))); weight1 = weight1 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2) * dataset_and.d2.x1 * Math.Sin(dataset_and.d2.output + 1 / Math.Exp(bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2) - 1)) / 2))); weight2 = weight2 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2) * dataset_and.d2.x2 * Math.Sin(dataset_and.d2.output + 1 / Math.Exp(bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2) - 1)) / 2))); lostFunc2 = Math.Abs(dataset_and.d2.output - cost_Sigmoid(dataset_and.d2.x1, dataset_and.d2.x2)); epoch++; if (lostFunc2 == temp) { break; } temp = lostFunc2; //System.Console.WriteLine(bias); //System.Console.WriteLine(weight1); //System.Console.WriteLine(weight2); //System.Console.WriteLine(epoch); //System.Console.WriteLine(lostFunc2); } Console.WriteLine("2 COMPLETE"); while (lostFunc3 > 0.01) { bias = bias + (eta * ( (-(1 / Math.Exp((bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2)) * Math.Sin(dataset_and.d3.output + 1 / Math.Exp((bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2)) - 1)) / 2))); weight1 = weight1 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2) * dataset_and.d3.x1 * Math.Sin(dataset_and.d3.output + 1 / Math.Exp(bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2) - 1)) / 2))); weight2 = weight2 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2) * dataset_and.d3.x2 * Math.Sin(dataset_and.d3.output + 1 / Math.Exp(bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2) - 1)) / 2))); lostFunc3 = Math.Abs(dataset_and.d3.output - cost_Sigmoid(dataset_and.d3.x1, dataset_and.d3.x2)); //System.Console.WriteLine(bias); //System.Console.WriteLine(weight1); //System.Console.WriteLine(weight2); //System.Console.WriteLine(epoch); epoch++; if (lostFunc3 == temp) { break; } temp = lostFunc3; } Console.WriteLine("3 COMPLETE"); while (lostFunc4 > 0.01) { bias = bias + (eta * ( (-(1 / Math.Exp((bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2)) * Math.Sin(dataset_and.d4.output + 1 / Math.Exp((bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2)) - 1)) / 2))); weight1 = weight1 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2) * dataset_and.d4.x1 * Math.Sin(dataset_and.d4.output + 1 / Math.Exp(bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2) - 1)) / 2))); weight2 = weight2 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2) * dataset_and.d4.x2 * Math.Sin(dataset_and.d4.output + 1 / Math.Exp(bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2) - 1)) / 2))); lostFunc4 = Math.Abs(dataset_and.d4.output - cost_Sigmoid(dataset_and.d4.x1, dataset_and.d4.x2)); //System.Console.WriteLine(bias); //System.Console.WriteLine(weight1); //System.Console.WriteLine(weight2); //System.Console.WriteLine(epoch); epoch++; if (lostFunc4 == temp) { break; } temp = lostFunc4; } Console.WriteLine("4 COMPLETE"); lostFunc = Math.Abs(dataset_and.d1.output - cost_Sigmoid(dataset_and.d1.x1, dataset_and.d1.x2) + dataset_and.d2.output - cost_Sigmoid(dataset_and.d2.x1, dataset_and.d2.x2) + dataset_and.d3.output - cost_Sigmoid(dataset_and.d3.x1, dataset_and.d3.x2) + dataset_and.d4.output - cost_Sigmoid(dataset_and.d4.x1, dataset_and.d4.x2)) ; epoch++; if (lostFunc == temp0) { break; } temp0 = lostFunc; } Console.WriteLine("ALL Complete"); result.bias = bias; result.w0 = weight1; result.w1 = weight2; Console.WriteLine("W0 : {0} | W1 : {1} | W2 : {2} | Error : {3} | Epoch : {4} ", bias, weight1, weight2, lostFunc, epoch); return(result); }
public result_var errorFunc_Batch() { result_var result; double lostFunc; Dataset_And dataset_and = new Dataset_And(1); double temp0 = 0; int epoch = 0; lostFunc = Math.Abs(dataset_and.d1.output - cost_Sigmoid(dataset_and.d1.x1, dataset_and.d1.x2) + dataset_and.d2.output - cost_Sigmoid(dataset_and.d2.x1, dataset_and.d2.x2) + dataset_and.d3.output - cost_Sigmoid(dataset_and.d3.x1, dataset_and.d3.x2) + dataset_and.d4.output - cost_Sigmoid(dataset_and.d4.x1, dataset_and.d4.x2)) ; while (lostFunc > 0.01) { bias = bias + (eta * ( (-(1 / Math.Exp((bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2)) * Math.Sin(dataset_and.d1.output + 1 / Math.Exp((bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2)) - 1)) / 2) + (-(1 / Math.Exp((bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2)) * Math.Sin(dataset_and.d2.output + 1 / Math.Exp((bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2)) - 1)) / 2) + (-(1 / Math.Exp((bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2)) * Math.Sin(dataset_and.d3.output + 1 / Math.Exp((bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2)) - 1)) / 2) + (-(1 / Math.Exp((bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2)) * Math.Sin(dataset_and.d4.output + 1 / Math.Exp((bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2)) - 1)) / 2) )); weight1 = weight1 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2) * dataset_and.d1.x1 * Math.Sin(dataset_and.d1.output + 1 / Math.Exp(bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2) - 1)) / 2) + (-(1 / Math.Exp(bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2) * dataset_and.d2.x1 * Math.Sin(dataset_and.d2.output + 1 / Math.Exp(bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2) - 1)) / 2) + (-(1 / Math.Exp(bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2) * dataset_and.d3.x1 * Math.Sin(dataset_and.d3.output + 1 / Math.Exp(bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2) - 1)) / 2) + (-(1 / Math.Exp(bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2) * dataset_and.d4.x1 * Math.Sin(dataset_and.d4.output + 1 / Math.Exp(bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2) - 1)) / 2))); weight2 = weight2 + (eta * ( (-(1 / Math.Exp(bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2) * dataset_and.d1.x2 * Math.Sin(dataset_and.d1.output + 1 / Math.Exp(bias + weight1 * dataset_and.d1.x1 + weight2 * dataset_and.d1.x2) - 1)) / 2) + (-(1 / Math.Exp(bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2) * dataset_and.d2.x2 * Math.Sin(dataset_and.d2.output + 1 / Math.Exp(bias + weight1 * dataset_and.d2.x1 + weight2 * dataset_and.d2.x2) - 1)) / 2) + (-(1 / Math.Exp(bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2) * dataset_and.d3.x2 * Math.Sin(dataset_and.d3.output + 1 / Math.Exp(bias + weight1 * dataset_and.d3.x1 + weight2 * dataset_and.d3.x2) - 1)) / 2) + (-(1 / Math.Exp(bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2) * dataset_and.d4.x2 * Math.Sin(dataset_and.d4.output + 1 / Math.Exp(bias + weight1 * dataset_and.d4.x1 + weight2 * dataset_and.d4.x2) - 1)) / 2))); lostFunc = Math.Abs(dataset_and.d1.output - cost_Sigmoid(dataset_and.d1.x1, dataset_and.d1.x2) + dataset_and.d2.output - cost_Sigmoid(dataset_and.d2.x1, dataset_and.d2.x2) + dataset_and.d3.output - cost_Sigmoid(dataset_and.d3.x1, dataset_and.d3.x2) + dataset_and.d4.output - cost_Sigmoid(dataset_and.d4.x1, dataset_and.d4.x2)); epoch++; Console.WriteLine(lostFunc); if (lostFunc == temp0) { break; } temp0 = lostFunc; //System.Console.WriteLine(bias); //System.Console.WriteLine(weight1); //System.Console.WriteLine(weight2); //System.Console.WriteLine("Lost : {0}", lostFunc); //System.Console.WriteLine("Net : {0}==1", net(bias, weight1, weight2, dataset_and.d1.x1, dataset_and.d1.x2)); //System.Console.WriteLine(epoch); } Console.WriteLine("W0 : {0} | W1 : {1} | W2 : {2} | Error : {3} | Epoch : {4} ", bias, weight1, weight2, lostFunc, epoch); result.bias = bias; result.w0 = weight1; result.w1 = weight2; return(result); }