public static void TimeAndSD(double[] testpoints, Dictionary <List <double[]>, List <double[, ]> > trainedDictionary, List <double[]> userfeedbacks,
                                     out double meantime, out double SD)
        {
            //need work
            //    SaveandLoadCluters.WriteClutersToCSV(trainedDictionary, Bridge.CSVPath + "TrainningTimeData/xxkk.csv");
            SD       = 0;
            meantime = 0;
            var measures = new List <double>();
            var means    = new List <double>();
            var SDs      = new List <double>();

            OnlineGPupdating.GPprediction(trainedDictionary, testpoints, out measures, out means, out SDs);
            var extractindex = measures.IndexOf(measures.Max());

            meantime = Math.Exp(means[extractindex]);
            SD       = Math.Exp(SDs[extractindex]);
            var maxtime = new double();
            var mintime = new double();

            GetMaxandMinTimefromSignlecluster(trainedDictionary, extractindex, out maxtime, out mintime);
            if (meantime > maxtime * 1.5)
            {
                meantime = maxtime * 1.5;
            }
            if (meantime < mintime * 0.5)
            {
                meantime = mintime * 0.5;
            }
        }
 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 void WriteClutersToCSV(Dictionary <List <double[]>, List <double[, ]> > clusters, string csvaddress)
        {
            System.IO.File.Delete(csvaddress);
            //before your loop
            var csv = new StringBuilder();

            foreach (var clu in clusters)
            {
                string str = "key";
                csv.AppendLine(str);
                foreach (var keyvalue in clu.Key)
                {
                    str = "";
                    for (int i = 0; i < keyvalue.Length; ++i)
                    {
                        str += keyvalue[i].ToString();
                        if (i < keyvalue.Length)
                        {
                            str += ",";
                        }
                    }
                    csv.AppendLine(str);
                }
                str = "values";
                csv.AppendLine(str);
                foreach (var mvalue in clu.Value)
                {
                    var value = OnlineGPupdating.MatrixtoRow(mvalue);
                    str = "";
                    for (int i = 0; i < value.Length; ++i)
                    {
                        str += value[i].ToString();
                        if (i < value.Length)
                        {
                            str += ",";
                        }
                    }
                    csv.AppendLine(str);
                }
            }
            //   csv.AppendLine("Name,age");
            File.AppendAllText(csvaddress, csv.ToString());
        }
        private static void GetMaxandMinTimefromSignlecluster(Dictionary <List <double[]>, List <double[, ]> > trainedDictionary, int extractindex, out double maxtime, out double mintime)
        {
            maxtime = double.NegativeInfinity;
            mintime = double.PositiveInfinity;
            var values = trainedDictionary[trainedDictionary.Keys.ToList()[extractindex]];

            foreach (var value in values)
            {
                var y = OnlineGPupdating.GetYfromTraining(value);
                if (y > maxtime)
                {
                    maxtime = y;
                }
                if (y < mintime)
                {
                    mintime = y;
                }
            }
            maxtime = Math.Exp(maxtime);
            mintime = Math.Exp(mintime);
        }
        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);
        }