/// <summary> /// 计算峰值 /// </summary> /// <param name="N">回览次数</param> /// <param name="K">成功次数</param> /// <param name="p">正常概率</param> public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); MLDataFactory pkdls = new MLDataFactory();// this.LastUseData()); //Dictionary<int, Dictionary<int, int>> res = pkdls.getAllShiftAndColMaxProbList(this.ReviewExpectCnt- this.InputMinTimes-1, this.InputMinTimes,true); List <MLFeature <int> > features = pkdls.getAllSpecRowRoundFeatures(this.LastUseData().Count - 1, this.InputMinTimes, 0); Dictionary <string, int> AllCodes = new Dictionary <string, int>(); for (int i = 0; i < features.Count; i++) { MLFeature <int> feature = features[i]; MaxEnt me = new MaxEnt(); if (MaxEnt.FeatureSummary == null) { me.OnLoadLocalFile = LoadLocalTrainData; me.LoadSummary(); } me.FillStructBySummary(i); MLInstance <int, int> instance = new MLInstance <int, int>(feature); int label = me.Classify(instance); if (label < 0) { continue; } string strAllCode = string.Format("{0}/{1}", (i + 1) % 10, label); AllCodes.Add(strAllCode, 1); } ////foreach (int key in res.Keys) //// AllCodes.Add(string.Format("{0}/{1}",key,string.Join("",res[key].Keys.ToArray())),1); if (true) { ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 2; cc.InputTimes = 1; cc.strInputTimes = string.Join("_", new string[2] { "1", "1" }); //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.InputExpect = ed; cc.StragId = this.GUID; //cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 0; cc.HoldTimeCnt = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; cc.ExpectCode = ed.Expect; cc.ChanceCode = string.Join("+", AllCodes.Keys.ToArray()); cc.ChipCount = ChanceClass.getChipsByCode(cc.ChanceCode); cc.CreateTime = DateTime.Now; cc.UpdateTime = DateTime.Now; cc.AllowMaxHoldTimeCnt = 1; cc.Closed = false; ret.Add(cc); } return(ret); }
public MLInstance <int, int> getSpecRowRoundLabelFeatures(long rowid, int col, int Deep, int AllowUseShift) { MLInstance <int, int> ret = new MLInstance <int, int>(); if ((rowid - 1) - Deep < 0)//rowid 至少要大于等于Deep; { return(ret); } ret.Feature = getSpecRowRoundFeatures(rowid - 1, col, Deep, AllowUseShift); ret.Label = int.Parse(Data[(int)rowid].ValueList[col]); return(ret); }
MLInstance <int, int> getSpecLengthMatchTimesProb(int col, int Deep, int AllowUseShift) { MLInstance <int, int> ret = new MLInstance <int, int>(); return(ret); }
/// <summary> /// Executes a run of processing the stock data /// </summary> /// <param name="session">The session configuration</param> public static void Run(StockSession session) { // Create the stock processor StockProcessor processor = new StockProcessor(session); // Get the sizes of the features and labels int dstIdx = 0; int numDataPoints = 0; int numFeatures, numLabels; float[,] tmpDst = new float[1, 1024]; int[,] tmpLabels = new int[1, 1]; var tmpDataPoint = processor.DerivedData.First().Value[0]; tmpDataPoint.Load(session); PopulateData(tmpDataPoint, tmpDst, tmpLabels, ref dstIdx, out numFeatures, out numLabels); // Determine the total number of data points List <string> symbols = new List <string>() { "GNTX" }; foreach (var s in symbols) { List <StockDataSet <StockDataSink> > sources; if (!processor.DerivedData.TryGetValue(s, out sources)) { continue; } for (int i = 0; i < sources.Count; i++) { sources[i].Load(session); numDataPoints += sources[i].Count; } } // Allocate the feature and label arrays float[,] features = new float[numDataPoints, numFeatures]; int[,] labels = new int[numDataPoints, numLabels]; // Load the data dstIdx = 0; foreach (var s in symbols) { List <StockDataSet <StockDataSink> > sources; if (!processor.DerivedData.TryGetValue(s, out sources)) { continue; } // Create a table of each data point in the specified range for (int i = 0; i < sources.Count; i++) { sources[i].Load(session); PopulateData(sources[i], features, labels, ref dstIdx, out numFeatures, out numLabels); } } // Create the Machine Learning instance MLInstance ml = new MLInstance(); ml.BuildFullyConnectedGraph(new int[] { numFeatures, numFeatures, numLabels }); ml.PrepareData(features, labels); ml.Train(); }