public static double runtestIteration(List <DataSeq> X, bool train) { double _total = 0, _prTotal = 0, _correct = 0; double total = 0, accuracy = 0, recall = 0, f_score = 0; double _total4 = 0, _prTotal4 = 0, _correct4 = 0, accuracy4 = 0, f_score4 = 0, recall4 = 0; Global.threadList = new List <TrainThread>(); TrainThread runThread = new TrainThread(train); List <ManualResetEvent> manualEvents = new List <ManualResetEvent>(); List <DataStep> temp = new List <DataStep>(); StreamWriter sw = new StreamWriter("data/temp/answer.txt"); string[] write_strings = new string[X.Count]; Parallel.ForEach(X, (ex) => { param pa = new param(ex); runThread.runtest(pa); }); for (int i = 0; i < X.Count; i++) { sw.Write(X[i].write_string); } sw.Close(); accuracy = runThread._correct / runThread._prTotal; recall = runThread._correct / runThread._total; accuracy4 = runThread._correct4 / runThread._prTotal4; recall4 = runThread._correct4 / runThread._total4; f_score = 2 * accuracy * recall / (accuracy + recall); f_score4 = 2 * accuracy4 * recall4 / (accuracy4 + recall4); //Console.WriteLine("total windows: " + _total); //Console.WriteLine("acc: " + (accuracy4 * 100).ToString("f3")); //Console.WriteLine("recall: " + (recall4 * 100).ToString("f3")); //Console.WriteLine("fscore: " + f_score4); //Global.swLog.WriteLine("total windows: " + total); //Global.swLog.WriteLine("acc: " + (accuracy4 * 100).ToString("f3")); //Global.swLog.WriteLine("recall: " + (recall4 * 100).ToString("f3")); //Global.swLog.WriteLine("fscore: " + f_score4); //Global.swLog.Flush(); return(f_score4); }
public static double runtrainIteration(List <DataSeq> X, List <DataSeq> Xtest, bool train, int iter) { List <DataSeq> x = new List <DataSeq>(); if (train) { x = shuffle(X);//shuffle every window (point) } TrainThread runThread = new TrainThread(train); List <ManualResetEvent> manualEvents = new List <ManualResetEvent>(); List <DataStep> temp = new List <DataStep>(); int i = 0, j = 0; int length = x.Count(); while (i < length) { if (i != 0 && i % 16 == 0) { testAccuracy1 = runtestIteration(Xtest, false); if (testAccuracy <= testAccuracy1) { LSTMLayer.SerializeWordembedding("model//deepNetwork//embedding"); //LSTMLayer.SerializeBigramWordembedding(); Global.upLSTMLayer.saveLSTM("model//deepNetwork//lstmmodel.txt"); Global.upLSTMLayerr.saveLSTM("model//deepNetwork//lstmmodelr.txt"); Global.GRNNLayer1.saveGRNN("model//deepNetwork//grnnmodel1.txt"); Global.GRNNLayer2.saveGRNN("model//deepNetwork//grnnmodel1.txt"); Global.GRNNLayer3.saveGRNN("model//deepNetwork//grnnmodel1.txt"); Global.GRNNLayer4.saveGRNN("model//deepNetwork//grnnmodel1.txt"); Global.feedForwardLayer.saveFFmodel("model//deepNetwork//feedforwardmodel.txt"); testAccuracy = testAccuracy1; } Console.WriteLine("test f-score: {0}", (testAccuracy * 100).ToString("f3")); Console.WriteLine("test1 f-score: {0}", (testAccuracy1 * 100).ToString("f3")); Global.swLog.WriteLine("test f-score: {0}", (testAccuracy * 100).ToString("f3")); Global.swLog.WriteLine("test f-score: {0}", (testAccuracy1 * 100).ToString("f3")); } for (int k = 0; k < Global.nThread && i < length; k++, i++) { ManualResetEvent mre = new ManualResetEvent(false); param pa = new param(x[i]); pa.mre = mre; pa.datastep = x[i].datasteps; manualEvents.Add(mre); for (int m = 0; m < x[i].datasteps.Count; m++) { temp.Add(x[i].datasteps[m]); } ThreadPool.QueueUserWorkItem(new WaitCallback(runThread.run), pa); } WaitHandle.WaitAll(manualEvents.ToArray()); if (train) { UpdateWeight_rmProp(temp); } manualEvents.Clear(); temp.Clear(); } return(runThread.accword / runThread.totalword); }