public static void Gethistoricaldata(double[] testpointsx, List <double[]> userfeedbacks, out double usery) { usery = -1; foreach (var fb in userfeedbacks) { var fbx = OnlineGPupdating.GetXfromTraining(OnlineGPupdating.RowtoMatrix(fb)); if (EvaluationForBinaryTree.IsSameImputs(testpointsx, fbx)) { usery = fb[fb.Length - 1]; break; } else { usery = -1; } } }
public static void WriteUserFeedback(double[] newdata, string csvaddress) { var fxnew = OnlineGPupdating.GetXfromTraining(newdata); var fynew = newdata[newdata.Length - 1]; var olddata = ReadUserFeedback(csvaddress); int deletindex = 0; bool needtodelete = false; for (int i = 0; i < olddata.Count; i++) { var f = olddata[i]; var fxold = OnlineGPupdating.GetXfromTraining(f); if (EvaluationForBinaryTree.IsSameImputs(fxold, OnlineGPupdating.RowtoMatrix(fxnew))) { f[f.Length - 1] = fynew; needtodelete = true; deletindex = i; break; } } if (needtodelete) { olddata.RemoveAt(deletindex); } olddata.Add(newdata); System.IO.File.Delete(csvaddress); var csv = new StringBuilder(); foreach (var value in olddata) { var str = ""; for (int i = 0; i < value.Length; ++i) { str += value[i].ToString(); if (i < value.Length - 1) { str += ","; } } csv.AppendLine(str); } // csv.AppendLine("Name,age"); File.AppendAllText(csvaddress, csv.ToString()); csv.Clear(); }
public static Dictionary <List <double[]>, List <double[, ]> > ReadCSVforclusters(string address) { var reachbottom = false; var clusters = new Dictionary <List <double[]>, List <double[, ]> >(); StreamReader sr = new StreamReader(address); string csvline = ""; var listofnum = new List <double>(); var allline = new List <string>(); while ((csvline = sr.ReadLine()) != null) { allline.Add(csvline); } allline.Add("end"); for (int i = 0; i < allline.Count - 1; i++) { var newkey = new List <double[]>(); var newvalue = new List <double[, ]>(); var line = allline[i]; if (line.Equals("key")) { for (int j = 1; j < 6; j++)//change { var nextline = allline[i + j]; var keyelement = new List <double>(); var elements = nextline.Split(','); for (int k = 0; k < elements.Length - 1; k++) { keyelement.Add(Convert.ToDouble(elements[k])); } newkey.Add(keyelement.ToArray()); } i = i + 5;//change } do { i++; line = allline[i]; if (line.Equals("values")) { continue; } if (line.Equals("end")) { break; } var elements = line.Split(','); var keyelement = new List <double>(); for (int k = 0; k < elements.Length - 1; k++) { keyelement.Add(Convert.ToDouble(elements[k])); } newvalue.Add(OnlineGPupdating.RowtoMatrix(keyelement.ToArray())); }while (!allline[i + 1].Equals("key")); clusters.Add(newkey, newvalue); } sr.Close(); return(clusters); }