//获得整体偏差度 public override List <double> getAllDistrStdDev(int reviewCnt, int stepLong) { reviewCnt = 10; stepLong = 5; //Dictionary<string, double> ret = new Dictionary<string, double>(); double ret = 0; Dictionary <string, double> CntList = new Dictionary <string, double>(); string key_model = "{0}_{1}"; List <double> AllColsList = new List <double>(); for (int i = 0; i < 10; i++)//遍历所有表列 { string strCol = string.Format("{0}", (i + 1) % 10); List <double> colList = new List <double>(); for (int val = 0; val < 10; val++) { string strKey = string.Format(key_model, strCol, val); List <double> keyInReviewCnt = new List <double>(); for (int r = 0; r < reviewCnt; r++) { string strVal = val.ToString(); int ExistCnt = FindLastDataExistCount(r, stepLong, strCol, strVal); keyInReviewCnt.Add((double)ExistCnt); } double KeyInReviewStdDev = ProbMath.CalculateStdDev(keyInReviewCnt.ToArray()); CntList.Add(strKey, KeyInReviewStdDev); colList.Add(KeyInReviewStdDev); } double colStdDev = ProbMath.CalculateStdDev(colList.ToArray()); AllColsList.Add(colStdDev); } ret = ProbMath.CalculateStdDev(CntList.Values.ToArray()); AllColsList.Add(ret); return(AllColsList); }
private void btn_Combination_Click(object sender, EventArgs e) { int N = int.Parse(this.txt_N.Text); int M = int.Parse(this.txt_M.Text); this.txt_Return.Text = string.Format("{0}", ProbMath.GetCombination(N, M)); }
/// <summary> /// 获得所有车号/名次的熵 /// </summary> /// <param name="reviewCnt"></param> /// <param name="stepLong"></param> /// <returns></returns> public override List <double> getEntropyList(int reviewCnt) { //Dictionary<string, double> ret = new Dictionary<string, double>(); double ret = 0; Dictionary <string, double> CntList = new Dictionary <string, double>(); string key_model = "{0}_{1}"; List <double> AllColsList = new List <double>(); for (int i = 0; i < 10; i++)//遍历所有表列 { string strCol = string.Format("{0}", (i + 1) % 10); List <double> colList = new List <double>(); for (int val = 0; val < 10; val++) { string strKey = string.Format(key_model, strCol, val); //////List<double> keyInReviewCnt = new List<double>(); //////for (int r = 0; r < reviewCnt; r++) //////{ ////// string strVal = val.ToString(); int ExistCnt = FindLastDataExistCount(reviewCnt, strKey, val.ToString()); ////// keyInReviewCnt.Add((double)ExistCnt); //////} //////double KeyInReviewStdDev = ProbMath.CalculateStdDev(keyInReviewCnt.ToArray()); double p = (double)(ExistCnt / reviewCnt); CntList.Add(strKey, p); colList.Add(p); } double colEntropy = EntropyClass.GetEntropy(colList.ToArray());//获得各车/次熵值 AllColsList.Add(colEntropy); } ret = ProbMath.CalculateStdDev(CntList.Values.ToArray()); AllColsList.Add(ret); return(AllColsList); }
double[][] getLastData(int cycs) { double[] currData = OrgData; List <double> boll = new List <double>(); List <double> ub = new List <double>(); List <double> lb = new List <double>(); int M = _M; int i = currData.Length - cycs; List <double> PastVal = null; if (i <= M) { PastVal = currData.ToList <double>(); } else { PastVal = currData.ToList <double>().GetRange(i - M, M); } double std = ProbMath.CalculateStdDev(PastVal); double ma = PastVal.Average(); boll.Add(ma); ub.Add(ma + 2 * std); lb.Add(ma - 2 * std); double[][] r = new double[3][]; r[0] = boll.ToArray(); r[1] = ub.ToArray(); r[2] = lb.ToArray(); _LastResult = r;//所有子类此方法内均需执行该语句 return(r); }
public override double[][] getData() { //////BOLL: MA(CLOSE, M); //////UB: BOLL + 2 * STD(CLOSE, M); //////LB: BOLL - 2 * STD(CLOSE, M); List <double> boll = new List <double>(); List <double> ub = new List <double>(); List <double> lb = new List <double>(); for (int i = 0; i < OrgData.Length; i++) { int M = _M; List <double> PastVal = null; if (i < M) { PastVal = OrgData.ToList <double>(); } else { PastVal = OrgData.ToList <double>().GetRange(OrgData.Length - M, M); } double std = ProbMath.CalculateStdDev(PastVal); double ma = PastVal.Average(); boll.Add(ma); ub.Add(ma + 2 * std); lb.Add(ma - 2 * std); } double[][] r = new double[3][]; r[0] = boll.ToArray(); r[1] = ub.ToArray(); r[2] = lb.ToArray(); _LastResult = r;//所有子类此方法内均需执行该语句 return(r); }
private void btn_Binomial_Click(object sender, EventArgs e) { int N = int.Parse(this.txt_N.Text); int M = int.Parse(this.txt_M.Text); double prob = double.Parse(this.txt_Source.Text); this.txt_Return.Text = string.Format("{0}", ProbMath.GetBinomial(N, M, prob)); }
private void btn_PoissonDistrub_Click(object sender, EventArgs e) { int N = int.Parse(this.txt_N.Text); int M = int.Parse(this.txt_M.Text); double prob = double.Parse(this.txt_Source.Text); this.txt_Return.Text = string.Format("{0}", ProbMath.GetPoission(N, prob, M)); }
/// <summary> /// 计算峰值 /// </summary> /// <param name="N">回览次数</param> /// <param name="K">成功次数</param> /// <param name="p">正常概率</param> void CalcPeakValues(int N, int K, double p) { string strModel = "{0}_{1}"; string key = string.Format(strModel, N, K); List <int> PeakValues = new List <int>(); if (AllBinomPeaks.ContainsKey(key)) { return; } Dictionary <int, double> AllProbs = new Dictionary <int, double>(); for (int i = 1; i <= K; i++) { AllProbs.Add(i, ProbMath.GetBinomial(N, i, p)); } PeakValues = AllProbs.OrderByDescending(c => c.Value).ToDictionary(a => a.Key, b => b.Value).Keys.ToArray <int>().ToList <int>(); AllBinomPeaks.Add(key, PeakValues.GetRange(0, 3));//获取前3位作为峰值列表 }
int getNums(string ccNos, LotteryTypes lts, string nums) { string pType = ccNos.Substring(0, 1); //A,C,P string pVal = ccNos.Substring(1, 1); //1~8 int nVal = int.Parse(pVal); int ret = 1; switch (pType.ToUpper()) { case "C": { int n = nums.Split(' ').Length; Decimal c = ProbMath.GetCombination(n, nVal); ret = (int)c; break; } case "P": { //Decimal c = ProbMath.GetFactorial(n, nVal);//11任意5个的组合为C(11,5) string[] arr = nums.Split(','); int n = 1; for (int i = 0; i < arr.Length; i++) { n = n * arr[i].Split(' ').Length; } ret = n; //重复的暂时不考虑,正常应该要考虑到 1-2-3,3-2-1,1-3-2这种情况 break; } case "A": default: { int n = nums.Split(' ').Length; Decimal c = ProbMath.GetCombination(n, nVal); //11任意5个的组合为C(11,5) ret = (int)c; break; } } return(ret); }
double getRealOdds(string ccNos, LotteryTypes lts, double orgOdds) { //ProbMath 概率计算类 string pType = ccNos.Substring(0, 1); //A,C,P string pVal = ccNos.Substring(1, 1); //1~8 int nVal = int.Parse(pVal); double ret = 0.00; switch (pType.ToUpper()) { case "C": { Decimal c = ProbMath.GetCombination(lts.elementCount, nVal); //11任意5个的组合为C(11,5) Decimal sc = 1; ret = (double)(c / sc); break; } case "P": { Decimal c = ProbMath.GetFactorial(lts.elementCount, nVal); //11任意5个的组合为C(11,5) Decimal sc = 1; ret = (double)(c / sc); break; } case "A": default: { Decimal c = ProbMath.GetCombination(lts.elementCount, nVal); //11任意5个的组合为C(11,5) Decimal sc = ProbMath.GetCombination(lts.seletElementCnt, nVal); if (nVal > lts.seletElementCnt) { sc = ProbMath.GetCombination(lts.elementCount - lts.seletElementCnt, nVal - lts.seletElementCnt); } ret = Math.Round((double)(c / sc), 2); break; } } return((double)Decimal.Round((Decimal)(orgOdds * ret * 2 / 10), 2));; }
public override List <ChanceClass> getChances(CommCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); DataTableEx dt = null; if (this.BySer) { dt = sc.SerialDistributionTable; } else { dt = sc.CarDistributionTable; } if (dt == null) { throw new Exception("无法获得概率分布表!"); } string strCodes = ""; int AllChipCnt = 0; for (int i = 0; i < 10; i++) { //获得各项的最小的 List <double> coldata = null; string strCol = string.Format("{0}", (i + 1) % 10); dt.getColumnData(strCol, ref coldata); double avgval = coldata.Average(); double stdval = ProbMath.CalculateStdDev(coldata); string strSql = string.Format("[{0}]<{1}", strCol, avgval - this.StdvCnt * stdval); string strSort = string.Format("[{0}] asc", "Id"); DataRow[] drs = dt.Select(strSql, strSort); if (drs.Length < this.ChipCount) { continue; } string strCode = ""; StringBuilder sb = new StringBuilder(); bool Matched = false; for (int j = 0; j < drs.Length; j++) { string strId = drs[j]["Id"].ToString(); int RowCnt = sc.FindLastDataExistCount(this.InputMinTimes, strCol, strId); if (RowCnt > 0)//任何一个不匹配最近5期内出现,不满足条件 { Matched = false; break; } sb.Append(drs[j]["Id"].ToString()); Matched = true; } if (!Matched) { continue; } AllChipCnt += drs.Length; if (BySer) { strCode = string.Format("{0}/{1}", strCol, sb.ToString()); } else { strCode = string.Format("{0}/{1}", sb.ToString(), strCol); } if (strCode.Length > 0) { strCodes = string.Format("{0}{1}{2}", strCodes, strCodes.Length > 0?"+":"", strCode); } } if (strCodes.Length < 2 * (this.ChipCount + 2)) { return(ret); } ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 3; cc.InputTimes = 1; cc.strInputTimes = "1"; cc.AllowMaxHoldTimeCnt = 1; cc.InputExpect = ed; cc.ChipCount = AllChipCnt; cc.ChanceCode = strCodes; cc.CreateTime = ed.OpenTime; cc.Closed = false; ret.Add(cc); return(ret); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); DataTableEx dt = null; if (this.BySer) { dt = sc.SerialDistributionTable; } else { dt = sc.CarDistributionTable; } if (dt == null) { throw new Exception("无法获得概率分布表!"); } int MatchCnt = 0; string strAllCodes = ""; double MinSucRate = 0; if (this.FixChipCnt) { MinSucRate = this.CommSetting.Odds / this.ChipCount; //指定注数需要的最小胜率 } for (int i = 0; i < 10; i++) { //获得各项的最小的 List <double> coldata = null; string strCol = string.Format("{0}", (i + 1) % 10); string strVal = ed.ValueList[i]; int ExistCnt = sc.FindLastDataExistCount(this.InputMinTimes, strCol, strVal); if (ExistCnt > 1)//前n次不是最后一次才出现 { continue; } dt.getColumnData(strCol, ref coldata); double avgval = coldata.Average(); double stdval = ProbMath.CalculateStdDev(coldata); string strSql = string.Format("[{0}]={1}", "Id", strVal); string strSort = string.Format("[{0}] asc", "Id"); DataRow[] drs = dt.Select(strSql, ""); if (drs.Length != 1) { throw new Exception("概率数据表错乱!"); } int InAllViewExistCnt = int.Parse(drs[0][strCol].ToString()); //前100(指定的viewcnt)期出现的次数 if (InAllViewExistCnt > avgval - stdval * this.StdvCnt) //如果前100期内出现的概率大于指定的标准差数,跳过 { continue; } if (InAllViewExistCnt > this.ReviewExpectCnt * (1 - MinSucRate))//如果成功数小于对应注数的失败数 { continue; } string strCode = string.Format("{0}/{1}", BySer ? strCol : strVal, BySer ? strVal : strCol); MatchCnt++; strAllCodes = string.Format("{0}{1}{2}", strAllCodes, MatchCnt > 1 ? "+" : "", strCode); } if (MatchCnt < this.ChipCount) { return(ret); } ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 3; cc.InputTimes = 1; cc.strInputTimes = "1"; cc.AllowMaxHoldTimeCnt = 1; cc.InputExpect = ed; cc.ChipCount = MatchCnt; cc.ChanceCode = strAllCodes; cc.CreateTime = ed.OpenTime; cc.NeedConditionEnd = true; cc.OnCheckTheChance += CheckNeedEndTheChance; cc.Closed = false; ret.Add(cc); return(ret); }
public double getProb(DataTypePoint dtp, string strPos, string strTaget, params object[] others) { int iPos = 0; string strType = ""; if (int.TryParse(strPos, out iPos)) { if (iPos < 9) //2~8为任N { strType = "A"; } else if (iPos < 30) //11,14为直选2,3 { strType = "P"; } else //31,32为组2,3 { strType = "C"; } } else { strType = strPos; } Decimal allprob = 0; Decimal iMatch = 0; int iTarget = int.Parse(strTaget); switch (strType) { case "P": { iMatch = 1; allprob = ProbMath.GetFactorial(this.AllNums, iTarget); break; } case "C": { iMatch = 1; allprob = ProbMath.GetCombination(this.AllNums, iTarget); break; } case "A": default: { allprob = ProbMath.GetCombination(this.AllNums, iTarget); if (iTarget <= this.SelNums) { iMatch = ProbMath.GetCombination(this.SelNums, iTarget); } else { iMatch = ProbMath.GetCombination(this.AllNums - this.SelNums, iTarget - this.SelNums); } break; } } return((double)(iMatch / allprob)); }
public override List <ChanceClass> getChances(BaseCollection bsc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); try { CommCollection_KLXxY sc = bsc as CommCollection_KLXxY; if (sc == null) { throw new Exception("数据收集类!"); } //this.ChipCount;//12选5和11选5都是5 //this.InputMaxTimes; //12选5选为8,1选5选为7 //this.InputMinTimes;//12选5和11选5都是4 string[] AllArr = CombinClass.CreateNumArr(sc.AllNums); //CombinClass allcmb = CombinClass.CireateNumCombin(sc,iAllNums, 3);//获得所有的3组合 CombinClass allbigcmb = CombinClass.CreateNumCombin(sc.AllNums, this.InputMaxTimes);//获得所有的8/7个组合 Dictionary <string, MatchItem> allItems = new Dictionary <string, MatchItem>(); allbigcmb.ForEach(a => { MatchItem mi = new MatchItem(AllArr, a, this.ChipCount, this.InputMinTimes); mi.LongItem = a; mi.ShortItem = string.Join(",", mi); allItems.Add(a, mi); }); /* * 列出所有11/7或者12/8码的组合,列出这些组合在回览期内的下列数据 * 1,全部命中次数 * 2,错过1个的次数 * 3,错过2个的次数n * 3,错过3个次数 * 4,错过4个的次数) */ int lastid = sc.orgData.Count - 1; for (int i = 0; i < this.ReviewExpectCnt; i++) { int index = lastid - i; if (index < 0) { break; } string opencode = sc.orgData[index].OpenCode; opencode = CombinGenerator.ResortNumString(opencode, ","); foreach (MatchItem mi in allItems.Values) { for (int c = 0; c < this.InputMinTimes; c++) { int MatchCnt = this.ChipCount - c; CombinClass occ = new CombinClass(opencode, MatchCnt); int mcnt = 0; foreach (string si in occ)//如果开奖号中5-c命中,停止,计数器加1 { if (mi.SubItems[MatchCnt].Contains(si)) { mcnt++; } } mi.SubItemMatchCnt[MatchCnt] += mcnt; if (mcnt > 0) { break; } } } } DataTable dt = new DataTable(); dt.Columns.Add("Id"); for (int i = 0; i < this.InputMinTimes; i++) { dt.Columns.Add(string.Format("MCnt_{0}", this.ChipCount - i), typeof(int)); } foreach (MatchItem mi in allItems.Values) { DataRow dr = dt.NewRow(); dr["Id"] = mi.LongItem; for (int i = 0; i < this.InputMinTimes; i++) { dr[string.Format("MCnt_{0}", this.ChipCount - i)] = mi.SubItemMatchCnt[this.ChipCount - i]; } dt.Rows.Add(dr); } double cnt4avg = allItems.Values.Select(a => a.SubItemMatchCnt[4]).Average(); double cnt3avg = allItems.Values.Select(a => a.SubItemMatchCnt[3]).Average(); double cnt2avg = allItems.Values.Select(a => a.SubItemMatchCnt[2]).Average(); double cnt5avg = allItems.Values.Select(a => a.SubItemMatchCnt[5]).Average(); double cnt4std = ProbMath.CalculateStdDev(allItems.Values.Select(a => a.SubItemMatchCnt[4])); double cnt3std = ProbMath.CalculateStdDev(allItems.Values.Select(a => a.SubItemMatchCnt[3])); double cnt2std = ProbMath.CalculateStdDev(allItems.Values.Select(a => a.SubItemMatchCnt[2])); double cnt5std = ProbMath.CalculateStdDev(allItems.Values.Select(a => a.SubItemMatchCnt[5])); DataTable sdt = dt.Clone(); DataView dv = new DataView(dt); double stdcnt = 2; // string sql = string.Format("MCnt_5<={0} and MCnt_4>{1} and MCnt_3<={2} and MCnt_2<={3}", Math.Max(cnt5avg - stdcnt * cnt5std, 0), cnt4avg + stdcnt * cnt4std, Math.Max(0, cnt3avg - 0 * cnt3std), Math.Max(0, cnt2avg - 0 * cnt2std)); //string sql = string.Format("MCnt_5<={0} and MCnt_4>{1} and MCnt_3<={2}", Math.Max(cnt5avg - stdcnt * cnt5std, 0), cnt4avg + stdcnt * cnt4std, Math.Max(0, cnt3avg - 0 * cnt3std)); dt.Select(sql).ToList().ForEach(a => sdt.Rows.Add(a.ItemArray)); dv = new DataView(sdt); //4个匹配要求最低。 CombinClass cc = new CombinClass(); for (int i = 0; i < Math.Min(dv.Count, 100); i++) { cc.Add(dv[i].Row[0].ToString()); } ret = getChances(sc, cc, AllArr, ed); } catch (Exception ce) { Log(ce.Message, ce.StackTrace); } return(ret); }