public ChartPointPredition PredictNextSpecified(string product, List <ChartPoint> LCPoints, List <ChartPoint> LCPointsToCompare, TimeFrame TFrame, int iRound, double[] IASymiliarities) { List <DateTime> LDTSetTime = (from CP in LCPoints select CP.Time).ToList(); List <List <double> > LLDSets = new List <List <double> >(); List <List <double> > LLDSetsToCampare = new List <List <double> >(); int iDeep = IASymiliarities.Length; //int[] IADeeps = new int[4] { iDeep, iDeep, iDeep, iDeep }; LLDSets.Add((from CP in LCPoints select Math.Round(CP.Raise, iRound)).ToList()); LLDSets.Add((from CP in LCPoints select Math.Round(CP.Fall, iRound)).ToList()); LLDSets.Add((from CP in LCPoints select Math.Round(CP.Peak, iRound)).ToList()); LLDSets.Add((from CP in LCPoints select Math.Round(CP.Base, iRound)).ToList()); LLDSetsToCampare.Add((from CP in LCPointsToCompare select Math.Round(CP.Raise, iRound)).ToList()); LLDSetsToCampare.Add((from CP in LCPointsToCompare select Math.Round(CP.Fall, iRound)).ToList()); LLDSetsToCampare.Add((from CP in LCPointsToCompare select Math.Round(CP.Peak, iRound)).ToList()); LLDSetsToCampare.Add((from CP in LCPointsToCompare select Math.Round(CP.Base, iRound)).ToList()); ConcurrentDictionary <int, List <int> > CDILIMatches = new ConcurrentDictionary <int, List <int> >(); List <Thread> LThread = new List <Thread>(); /*for (int i = 0; i < LLDSetsToCampare.Count; i++) * this.AddPredictionSpecified(LLDSets, LLDSetsToCampare, i, ref CDILIMatches, LDTSetTime, IASymiliarities, TFrame);*/ LThread.Add(new Thread(() => AddPredictionSpecified(LLDSets, LLDSetsToCampare, 0, ref CDILIMatches, LDTSetTime, IASymiliarities, TFrame))); LThread.Add(new Thread(() => AddPredictionSpecified(LLDSets, LLDSetsToCampare, 1, ref CDILIMatches, LDTSetTime, IASymiliarities, TFrame))); LThread.Add(new Thread(() => AddPredictionSpecified(LLDSets, LLDSetsToCampare, 2, ref CDILIMatches, LDTSetTime, IASymiliarities, TFrame))); LThread.Add(new Thread(() => AddPredictionSpecified(LLDSets, LLDSetsToCampare, 3, ref CDILIMatches, LDTSetTime, IASymiliarities, TFrame))); foreach (Thread Thrd in LThread) { Thrd.Priority = ThreadPriority.Highest; Thrd.Start(); } foreach (Thread Thrd in LThread) { Thrd.Join(); } return(new ChartPointPredition(CDILIMatches, LLDSets, TFrame, product, LCPointsToCompare[0])); }
public ChartPointsPredition PredictNextSpecified(string product, List <ChartPoint> LCPoints, List <ChartPoint> LCPointsToCompare, TimeFrame TFrame, int iRound, int iMinMatches, double dMinResolution, int ahead, double[] DAWeightFactors) { List <DateTime> LDTSetTime = (from CP in LCPoints select CP.Time).ToList(); double[][] DJSets = new double[5][]; int iDeep = LCPointsToCompare.Count; int iSetCount = LCPoints.Count; LCPointsToCompare = LCPointsToCompare.OrderByDescending(CP => CP.Time).ToList(); for (int id = 0; id < DJSets.Length; id++) { DJSets[id] = new double[iSetCount]; for (int i = 0; i < LCPoints.Count; i++) { DJSets[id][i] = LCPoints[i].GetParam(id, iRound); } } //DateTime DTStart = DateTime.Now; ConcurrentDictionary <int, List <double> > CDILDMatches = new ConcurrentDictionary <int, List <double> >(); List <Thread> LThread = new List <Thread>(); LThread.Add(new Thread(() => AddPredictionSpecified(DJSets[0], LCPointsToCompare, 0, ref CDILDMatches, LDTSetTime, TFrame, ahead, DAWeightFactors, iRound))); /* LThread.Add(new Thread(() => AddPredictionSpecified(DJSets[1], LCPointsToCompare, 1, ref CDILDMatches, LDTSetTime, TFrame, ahead, DAWeightFactors, iRound))); * LThread.Add(new Thread(() => AddPredictionSpecified(DJSets[2], LCPointsToCompare, 2, ref CDILDMatches, LDTSetTime, TFrame, ahead, DAWeightFactors, iRound))); * LThread.Add(new Thread(() => AddPredictionSpecified(DJSets[3], LCPointsToCompare, 3, ref CDILDMatches, LDTSetTime, TFrame, ahead, DAWeightFactors, iRound))); */ foreach (Thread Thrd in LThread) { Thrd.Priority = ThreadPriority.Lowest; Thrd.Start(); } foreach (Thread Thrd in LThread) { Thrd.Join(); } int iCDILDMCount = CDILDMatches[0].Count; List <int> LISMatches = new List <int>(); List <double> LDSimilarities = new List <double>(); double dSimil = 50; List <int> LIMatches = new List <int>(); for (int i = 0; i < iCDILDMCount; i++) { double dSimilarity = Math.Min(CDILDMatches[0][i], CDILDMatches[1][i]); //(CDILDMatches[0][i] * CDILDMatches[1][i] * CDILDMatches[2][i] * CDILDMatches[3][i]) / Math.Pow(100,4-1); dSimilarity = Math.Min(dSimilarity, CDILDMatches[2][i]); dSimilarity = Math.Min(dSimilarity, CDILDMatches[3][i]); if (dSimilarity > dSimil) // && this.CompareTendency(LCPoints, LCPointsToCompare, i, dSimil)) { LIMatches.Add(i); LDSimilarities.Add(dSimilarity); i += iDeep - 1; } } // DateTime DTStop = DateTime.Now; double dMS = (DTStop - DTStart).TotalMilliseconds; double dDisplay = 1 + dMS;//return new ChartPointsPredition(LISMatches, DJSets, TFrame, product, LCPointsToCompare[0], iDeep, ahead, LDSimilarities); return(new ChartPointsPredition(LIMatches, DJSets, TFrame, product, LCPointsToCompare[0], iDeep, ahead, LDSimilarities)); }