



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C#常用预测算法C#常用预测算法using System;using System.Collections.Generic;using System.Text;using System.Data;namespace DataProcess.Forecast class Forecast /data有二列,第一列表示x值,第二列表示y值 /一元线性回归分析预测,返回相关系数 public static double LinearRegression(double, data,out double A,out double B) double, derivedData = new doubledata.GetLength(0) + 1, data.GetLength(1) + 3; for (int i = 0; i data.GetLength(0); i+) derivedDatai, 0 = datai, 0; /X derivedDatai, 1 = datai, 1; /Y derivedDatai, 2 = datai, 0 * datai, 1; /XY derivedDatai, 3 = datai, 0 * datai, 0; /XX derivedDatai, 4 = datai, 1 * datai, 1; /YY derivedDataderivedData.GetLength(0) - 1, 0 += derivedDatai, 0; /X的累加 derivedDataderivedData.GetLength(0) - 1, 1 += derivedDatai, 1; /Y的累加 derivedDataderivedData.GetLength(0) - 1, 2 += derivedDatai, 2; /XY的累加 derivedDataderivedData.GetLength(0) - 1, 3 += derivedDatai, 3; /XX的累加 derivedDataderivedData.GetLength(0) - 1, 4 += derivedDatai, 4; /YY的累加 double xba = derivedDataderivedData.GetLength(0) - 1, 0 / data.GetLength(0); double yba = derivedDataderivedData.GetLength(0) - 1, 1 / data.GetLength(0); double Lxx = derivedDataderivedData.GetLength(0) - 1, 3 - Math.Pow(derivedDataderivedData.GetLength(0) - 1, 0, 2) / data.GetLength(0); double Lyy = derivedDataderivedData.GetLength(0) - 1, 4 - Math.Pow(derivedDataderivedData.GetLength(0) - 1, 1, 2) / data.GetLength(0); double Lxy = derivedDataderivedData.GetLength(0) - 1, 2 - derivedDataderivedData.GetLength(0) - 1, 0 * derivedDataderivedData.GetLength(0) - 1, 1 / data.GetLength(0); double b = Lxy / Lxx; double a = yba - b * xba; A = a; B = b; return Lxy / Math.Sqrt(Lxx * Lyy); public static double LinearRegression(double, data, double x, out double r) double a; double b; r = LinearRegression(data, out a, out b); return a + b * x; /幂回归分析预测 public static double PowerRegression(double, data, out double A, out double B) double, derivedData = (double,)data.Clone(); for (int i = 0; i derivedData.GetLength(0); i+) for (int j = 0; j derivedData.GetLength(1); j+) derivedDatai, j = Math.Log(derivedDatai, j); double a; double b; double r; r = LinearRegression(derivedData, out a, out b); A = Math.Exp(a); B = b; return r; public static double PowerRegression(double, data, double x, out double r) double a; double b; r = PowerRegression(data, out a, out b); return a * Math.Pow(x, b); /灰色模型法 public static double GM(double data, int x, out double p, out double c) int rowNum = data.GetLength(0); double x0 = new doublerowNum; double x1 = new doublerowNum; x00 = data0; x10 = data0; for (int i = 1; i rowNum; i+) x0i = datai; x1i = x1i - 1 + x0i; double, derivedData = new doublerowNum - 1, 2; for (int i = 0; i rowNum - 1; i+) derivedDatai, 0 = -0.5 * (x1i + x1i + 1); derivedDatai, 1 = x0i + 1; double a; double u; LinearRegression(derivedData, out u, out a); double result; result = (x00 - u / a) * (1 - Math.Exp(a) * Math.Exp(-a * (x - 1); /模型精度检验 double q = new doublerowNum; double epsilon = new doublerowNum; double epsilonSum = 0; for (int i = 0; i rowNum; i+) double x0i = x0i; double xxi = (x00 - u / a) * (1 - Math.Exp(a) * Math.Exp(-a * i); qi = x0i - xxi; epsiloni = qi / x0i; epsilonSum += Math.Abs(epsiloni); double epsilonAverage = epsilonSum / rowNum; p = 1 - epsilonAverage; /后验差比值 double x0Average; double qAverage; double x0Sum = 0; double qSum = 0; for (int i = 0; i rowNum; i+) x0Sum += x0i; qSum += qi; x0Average = x0Sum / rowNum; qAverage = qSum / rowNum; double s1; double s2; double s1Sum = 0; double s2Sum = 0; for (int i = 0; i rowNum; i+) s1Sum += Math.Pow(x0i - x0Average, 2); s2Sum += Math.Pow(qi - qAverage, 2); s1 = s1Sum / rowNum; s2 = s2Sum / rowNum; c = s2 / s1; return result; /加权移动平均法 public static double WeightedMovingAverage(double data, int x) int count = data.GetLength(0); double s = 0.0; for (int i = 0; i x; i+) s = 0.0; for (int j = 0; j co
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 国庆活动升国旗活动方案
- 周末登山活动方案
- 国企疫情志愿者活动方案
- 品牌沙龙活动方案
- 团建聚餐活动方案
- 周末打扫除活动方案
- 哈尔滨超市促销活动方案
- 员工宿舍比拼活动方案
- 品牌建设盛典活动方案
- 国土摄影活动方案
- 安徽省2011年普通高校招生第一批本科院校投档分数及名次
- 时代音画学习通超星期末考试答案章节答案2024年
- GB/T 6003.2-2024试验筛技术要求和检验第2部分:金属穿孔板试验筛
- 猎聘-2024高校毕业生就业数据报告
- 产品质量鉴定程序规范 总则
- 草晶华工作计划
- DZ∕T 0388-2021 矿区地下水监测规范(正式版)
- 脑干损伤护理常规
- MOOC 数值天气预报-南京信息工程大学 中国大学慕课答案
- 跨座式单轨交通工程接触网系统技术标准
- 教师口语智慧树知到期末考试答案2024年
评论
0/150
提交评论