public static TwoP1Example getTestData() { Random u1 = new Random(Guid.NewGuid().GetHashCode()); Random u2 = new Random(Guid.NewGuid().GetHashCode()); TwoP1Example twoP1 = new TwoP1Example(); for (int i = 0; i < TOTALNUM; i++) { double x1 = (u1.NextDouble() - 0.5); double x2 = (u2.NextDouble() - 0.5); double x3 = (u1.NextDouble() - 0.5); double x4 = (u2.NextDouble() - 0.5); double noise = GetZTFB(u1.NextDouble(), u2.NextDouble(), NORMAL_MIU, NORMAL_DELTA); //System.Diagnostics.Debug.WriteLine("noise:: " + noise); //double y = BIASIS + WEIGHT1 * x1 + WEIGHT2 * x2 + noise; double y = Method.CalculateMethod(new Object[] { BIASIS, WEIGHT1, WEIGHT2, WEIGHT3, WEIGHT4 }, new Object[] { x1, x2, x3, x4 }); twoP1.D1x.Add(x1); twoP1.D2x.Add(x2); twoP1.D3x.Add(x3); twoP1.D4x.Add(x4); twoP1.Y.Add(y); } return(twoP1); }
static void Main(string[] args) { TwoP1Example twoP1Example = DataGenerater.getTestData(); for (int i = 0; i < Generation.GENERATION_ITER_COUNT; i++) { twoP1Example.generateNewGeneration(); Console.WriteLine("the " + Generation.GENERATION_INDEX + "'s generation's count is " + twoP1Example.Generations[0].DimensionsGenerations.Count); twoP1Example.calculateLoss(); Console.WriteLine("the " + Generation.GENERATION_INDEX + "'s generation's average loss is " + twoP1Example.getAverageLoss()); twoP1Example.selectBest(); Console.WriteLine("the " + Generation.GENERATION_INDEX + "'s generation's lived average loss is " + twoP1Example.getAverageLoss()); Console.WriteLine("the " + Generation.GENERATION_INDEX + "'s generation's best thetas are:"); int total = 0; if (Generation.GENERATION_WINNER_NUMBER > twoP1Example.Generations[0].DimensionsGenerations.Count) { total = twoP1Example.Generations[0].DimensionsGenerations.Count; } else { total = Generation.GENERATION_WINNER_NUMBER; } if (total == 0) { Console.Write("Generation DIE OUT...."); } for (int j = 0; j < total; j++) { for (int k = 0; k < twoP1Example.Generations[0].DimensionsGenerations[j].DimensionCount; k++) { Console.Write("theta" + k + " = " + twoP1Example.Generations[0].DimensionsGenerations[j].Thetas[k].Weight.ToString("0.0000") + ".."); } Console.WriteLine(""); } } Console.ReadKey(); }