双色球特征分析代码实现
2012-11-05 18:17
274 查看
个人闲来无事写了一段代码来分析时下流行的双色球。
1 中彩网下载双色球所以历史数据写入MYSQL形成0 1码表
2 分析分开中的号码特征码,再提取下次开奖的33个红球特征码加入分析引擎进行分析。主要代码入下希望有此兴趣的大侠一起研究》
1 中彩网下载双色球所以历史数据写入MYSQL形成0 1码表
2 分析分开中的号码特征码,再提取下次开奖的33个红球特征码加入分析引擎进行分析。主要代码入下希望有此兴趣的大侠一起研究》
/// <summary> /// 提取表中所有特征码 /// </summary> /// <param name="dtTable"></param> /// <returns></returns> public List<Features> GetAllFeatures(DataTable dtTable,int featuresSize) { //特征集合 List<Features> listFeatures = new List<Features>(); //检查需要提取的特征码 for (int i = featuresSize+1; i < dtTable.Rows.Count; i++) { for (int c = 0; c < dtTable.Columns.Count; c++) { //只有为1时才提取 if (dtTable.Rows[i][c].ToString() == "1") { //提取特征 listFeatures.Add(GetFeatures(i,c,featuresSize,dtTable)); } } } return listFeatures; } /// <summary> /// 从指定DataTable中提取特征码 /// </summary> /// <param name="row">定位的行</param> /// <param name="col">定位的列</param> /// <param name="size">长宽</param> /// <param name="dtTable">按时间升序排列(只保留当前号码列数)</param> /// <returns></returns> public Features GetFeatures(int row, int col, int size, DataTable dtTable) { //定义特征类型 Features features = new Features(size, size); //按行列定位到指定单元格再取以上行的size长方体 for (int s = size; s > 0; s--) { //数组的X定位 int arrX = s - 1; int rowIndex = row - s; if (rowIndex <= 0) continue; //先定位行 DataRow dr = dtTable.Rows[rowIndex]; //取列 分别为定位点的两侧的col/2个 int colSize = col / 2; for (int c = -colSize; c <= colSize; c++) { //数组的X定位 int arrY = colSize + c; //定位列 int colIndex = col + c; //左边溢出 if (colIndex < 0) { //如为-2则定位到33-2=31位置 colIndex = dtTable.Columns.Count + colIndex; } //右边溢出 else if (colIndex > dtTable.Columns.Count - 1) { //如为34则定位到33-32=1位置 colIndex = colIndex - dtTable.Columns.Count; } //写入特征数组 features.features[arrX, arrY] = int.Parse(dr[colIndex].ToString()); } } //返回特征 return features; } /// <summary> /// 比较两个特征相似性(只取值为1的,为0暂不做对比) /// </summary> /// <param name="sourceFeatures">源特征,作为对比的参数</param> /// <param name="targetFeatures">目标特征,参与对比的特征</param> /// <returns>返回双精度</returns> public double FeaturesCompare(Features sourceFeatures, Features targetFeatures) { //源特征开总中次数 int totalCount = 0; //目标特征跟源特征开中的相似个数 int comparaCount = 0; for (int i = 0; i < sourceFeatures.arrX; i++) { for (int c = 0; c < sourceFeatures.arrY; c++) { //源特征为1 if (sourceFeatures.features[i, c] == 1) { //目标特征为1 if (targetFeatures.features[i, c] == 1) { //相似个数加1 comparaCount++; } //总数加1 totalCount++; } } } //返回特征相似性比率 return Convert.ToDouble(comparaCount) / Convert.ToDouble(totalCount); } } /// <summary> /// 特征实体类 /// </summary> public class Features { //定义二维数据长高度 int x = 0; int y = 0; int[,] baseFeatures; //构造特征二维数组 public Features(int ax, int ay) { x = ax; y = ay; baseFeatures = new int[x, y]; } //Get方法 public int[,] features { get { return baseFeatures; } } //返回数据长度 public int arrX { get { return x; } } //返回数据高度 public int arrY { get { return y; } } }
相关文章推荐
- Berkeley DB 源代码分析 (1) --- 代码特征与游标的实现
- Berkeley DB 源代码分析 (1) --- 代码特征与游标的实现
- 【图像特征提取12】OpenCv的SIFT图像局部特征提取描述算法C++代码的实现
- 基于visual c++之windows核心编程代码分析(47)实现交换网络的QQ号嗅探
- 基于visual c++之windows核心编程代码分析(54)实现Winlogon注入dll
- 基于硬件的ORB特征提取与实现(第一部分)——特征点算法仔细分析
- 控制台版2048游戏C程序项目分析(仅供参考,后期代码实现结构有所调整)
- Apache Mahout的Taste基于Hadoop实现协同过滤推荐引擎的代码分析
- 贪吃蛇小游戏java实现代码分析
- 充电器类型检测实现代码分析
- 后缀数组的学习(四):SA数组实现代码分析
- 第一篇:K-近邻分类算法原理分析与代码实现
- 0-1背包问题分析及代码实现
- 随机森林的原理分析及Python代码实现
- 基于visual c++之windows核心编程代码分析 实现开机自启动
- Java NIO原理 图文分析及代码实现
- ORB特征提取匹配opencv3代码实现
- snort_inline中与防火墙联动的实现以及代码inline.c分析
- Java NIO原理 图文分析及代码实现
- Java NIO原理 图文分析及代码实现