欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    基于VB的灰色模型预测和线性回归预测教学内容.doc

    • 资源ID:52305580       资源大小:238.50KB        全文页数:29页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    基于VB的灰色模型预测和线性回归预测教学内容.doc

    Good is good, but better carries it.精益求精,善益求善。基于VB的灰色模型预测和线性回归预测-灰色模型预测GM(1,1)与线性回归预测(一元、多元)新建一个工程,添加一个模块(.bas),两个命令按钮:窗体代码:OptionExplicitPrivateSubCommand1_Click()'灰色模型预测DimDataAsStringData="2.67,3.13,3.25,3.36,3.56,3.72"GM1_1_PredictDataEndSubPrivateSubCommand2_Click()'线性回归预测DimX1AsString,X2AsString,X3AsString,X4AsString,YAsStringX1="100.38,99.7,92.3,87.6,87.17,88.3,92.75,100.6,90.05;"'最后要加上分号;X2="53.24,51.5,50.5,52.4,59.6,59.7,65.2,62.4,53.68;"'最后要加上分号;X3="226,250,281,272,194,180,105,115,250;"'最后要加上分号;Y="644,640,517,425,385,401,448,599,462"'最后不要加上分号;请注意!Linear_Regression_PredictX1&X2&X3&YEndSub模块代码:OptionExplicitPrivateSubCalculate_1_AGO(X_0()AsDouble,X_1()AsDouble)'做一次累加生成1-AGODimiAsLong,TempXAsDouble,KAsLongK=UBound(X_0)ReDimX_1(K)Fori=0ToKTempX=TempX+X_0(i)X_1(i)=TempXNextiEndSubPrivateSubCalculate_Matrix_B(X_1()AsDouble,B()AsDouble)'计算数据矩阵BDimiAsLong,KAsLongK=UBound(X_1)-1ReDimB(K,1)Fori=0ToKB(i,0)=-0.5*(X_1(i)+X_1(i+1)B(i,1)=1NextiEndSubPrivateSubCalculate_Matrix_YN(X_0()AsDouble,YN()AsDouble)'计算数据矩阵YNDimiAsLong,KAsLongK=UBound(X_0)-1ReDimYN(K,0)Fori=0ToKYN(i,0)=X_0(i+1)NextiEndSub''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''函数名:Matrix_Transpotation'功能:计算矩阵的转置transpotation'参数:m-Integer型变量,矩阵的行数'n-Integer型变量,矩阵的列数'mtxA-Double型mxn二维数组,存放原矩阵'mtxAT-Double型nxm二维数组,返回转置矩阵''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''PrivateSubMatrix_Transpotation(mtxA()AsDouble,mtxAT()AsDouble)DimiAsInteger,jAsIntegerDimMAsInteger,NAsIntegerM=UBound(mtxA,2)N=UBound(mtxA,1)ReDimmtxAT(M,N)Fori=0ToMForj=0ToNmtxAT(i,j)=mtxA(j,i)NextjNextiEndSub''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''函数名:Matrix_Multiplication'功能:计算矩阵的乘法multiplication'参数:m-Integer型变量,相乘的左边矩阵的行数'n-Integer型变量,相乘的左边矩阵的列数和右边矩阵的行数'l-Integer型变量,相乘的右边矩阵的列数'mtxA-Double型mxn二维数组,存放相乘的左边矩阵'mtxB-Double型nxl二维数组,存放相乘的右边矩阵'mtxC-Double型mxl二维数组,返回矩阵乘积矩阵''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''PrivateSubMatrix_Multiplication(mtxA()AsDouble,mtxB()AsDouble,mtxC()AsDouble)DimiAsInteger,jAsInteger,KAsIntegerDimMAsInteger,NAsInteger,LAsIntegerM=UBound(mtxA,1):N=UBound(mtxB,1):L=UBound(mtxB,2)ReDimmtxC(M,L)Fori=0ToMForj=0ToLmtxC(i,j)=0#ForK=0ToNmtxC(i,j)=mtxC(i,j)+mtxA(i,K)*mtxB(K,j)NextKNextjNextiEndSub''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''函数名:Matrix_Inversion'功能:矩阵求逆'参数:n-Integer型变量,矩阵的阶数'mtxA-Double型二维数组,体积为nxn。存放原矩阵A;返回时存放其逆矩阵A-1。'返回值:Boolean型,失败为False,成功为True''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''PrivateFunctionMatrix_Inversion(mtxA()AsDouble)AsBoolean'局部变量DimNAsIntegerN=UBound(mtxA)ReDimnIs(N)AsInteger,nJs(N)AsIntegerDimiAsInteger,jAsInteger,KAsIntegerDimdAsDouble,PAsDouble'全选主元,消元ForK=0ToNd=0#Fori=KToNForj=KToNP=Abs(mtxA(i,j)If(P>d)Thend=PnIs(K)=inJs(K)=jEndIfNextjNexti'求解失败If(d+1#=1#)ThenMatrix_Inversion=FalseExitFunctionEndIfIf(nIs(K)<>K)ThenForj=0ToNP=mtxA(K,j)mtxA(K,j)=mtxA(nIs(K),j)mtxA(nIs(K),j)=PNextjEndIfIf(nJs(K)<>K)ThenFori=0ToNP=mtxA(i,K)mtxA(i,K)=mtxA(i,nJs(K)mtxA(i,nJs(K)=PNextiEndIfmtxA(K,K)=1#/mtxA(K,K)Forj=0ToNIf(j<>K)ThenmtxA(K,j)=mtxA(K,j)*mtxA(K,K)NextjFori=0ToNIf(i<>K)ThenForj=0ToNIf(j<>K)ThenmtxA(i,j)=mtxA(i,j)-mtxA(i,K)*mtxA(K,j)NextjEndIfNextiFori=0ToNIf(i<>K)ThenmtxA(i,K)=-mtxA(i,K)*mtxA(K,K)NextiNextK'调整恢复行列次序ForK=NTo0Step-1If(nJs(K)<>K)ThenForj=0ToNP=mtxA(K,j)mtxA(K,j)=mtxA(nJs(K),j)mtxA(nJs(K),j)=PNextjEndIfIf(nIs(K)<>K)ThenFori=0ToNP=mtxA(i,K)mtxA(i,K)=mtxA(i,nIs(K)mtxA(i,nIs(K)=PNextiEndIfNextK'求解成功Matrix_Inversion=TrueEndFunctionPrivateSubPredicted_Value(ByValX_1_0AsDouble,ByValu_valueAsDouble,ByVala_valueAsDouble,KAsLong,PV()AsDouble)DimiAsLongReDimPV(K)Fori=1ToK+1PV(i-1)=(X_1_0-u_value/a_value)*Exp(-a_value*(i-1)*(1-Exp(a_value)NextiPV(0)=X_1_0EndSubPrivateSubString_to_Array(DataAsString,X_0()AsDouble)'Data字符串转为X_0数组,X_0是原始序列DimPredict_Data()AsString,KAsLong,iAsLongPredict_Data=Split(Data,",")K=UBound(Predict_Data)ReDimX_0(K)Fori=0ToKX_0(i)=Predict_Data(i)NextiEndSubPrivateSubPrint_Array(Arrays()AsDouble,TitleAsString)'打印数组DimiAsLongForm1.PrintvbCrLf&String(25,"-")&Title&String(25,"-")&vbCrLfFori=0ToUBound(Arrays)Form1.PrintFormat(Arrays(i),"0.0000")&""NextiForm1.PrintEndSubPrivateSubPrint_String(Arrays()AsString,TitleAsString)'打印字符-Relative_Residual_Error-RREDimiAsLongForm1.PrintvbCrLf&String(25,"-")&Title&String(25,"-")&vbCrLfFori=0ToUBound(Arrays)Form1.PrintArrays(i)&""NextiForm1.PrintEndSubPrivateSubPrint_One_String(SAsDouble,TitleAsString)Form1.PrintvbCrLf&String(25,"-")&Title&String(25,"-")&vbCrLfForm1.PrintSpace(25)&Format(S,"0.#")EndSubPrivateSubAbsolute_Residual_Error(Array1()AsDouble,Array2()AsDouble,ARE()AsDouble)'绝对残差DimKAsLong,iAsLongK=UBound(Array1)ReDimARE(K)Fori=0ToKARE(i)=Format(Abs(Array2(i)-Array1(i),"0.0000")NextiEndSubPrivateSubRelative_Residual_Error(Array1()AsDouble,ARE()AsDouble,RRE()AsString)'相对残差DimKAsLong,iAsLongK=UBound(Array1)ReDimRRE(K)Fori=0ToKRRE(i)=Format(ARE(i)/Array1(i),"0.000%")NextiEndSubPrivateSubRelatedness_Test(ARE()AsDouble,PAsDouble,RAsDouble)'计算相关度DimiAsLong,KAsLong,MinAsDouble,MaxAsDouble,SumRAsDoubleDimRi()AsDoubleK=UBound(ARE)ReDimRi(K)Min=ARE(0):Max=ARE(0)Fori=0ToKIfARE(i)<MinThenMin=ARE(i)IfARE(i)>MaxThenMax=ARE(i)NextiFori=0ToKRi(i)=(Min+P*Max)/(ARE(i)+P*Max)SumR=SumR+Ri(i)NextiR=Format(SumR/(K+1),"0.0000")EndSubPrivateFunctionArray_Mean(Array1()AsDouble)AsDouble'计算平均数DimiAsLong,KAsLongK=UBound(Array1)Fori=0ToKArray_Mean=Array_Mean+Array1(i)NextiArray_Mean=Array_Mean/(K+1)EndFunctionPrivateFunctionMean_Square_Error(Array1()AsDouble)AsDouble'计算均方差DimAverageAsDouble,iAsLong,KAsLong,TempAsDoubleK=UBound(Array1)Average=Array_Mean(Array1()Fori=0ToKTemp=Temp+(Array1(i)-Average)2NextiMean_Square_Error=Format(Sqr(Temp/(K+1),"0.0000")EndFunctionPublicSubGM1_1_Predict(DataAsString)'Data是原始序列字符,以逗号","分开DimX_0()AsDouble,X_1()AsDouble,B()AsDouble,YN()AsDouble,PV()AsDoubleDimBT()AsDouble,BTB()AsDouble,BTBBT()AsDouble,A()AsDouble,ARE()AsDoubleDimRRE()AsString,RAsDoubleString_to_ArrayData,X_0'Data字符串转为X_0数组,X_0是原始序列Print_ArrayX_0,"原始数据"Calculate_1_AGOX_0,X_1'做一次累加生成X_1Calculate_Matrix_YNX_0,YN'计算矩阵YNCalculate_Matrix_BX_1,B'计算矩阵BMatrix_TranspotationB,BT'计算矩阵B的转置BTMatrix_MultiplicationBT,B,BTB'矩阵BT×B=BTBIfNotMatrix_Inversion(BTB)Then'矩阵BTB求逆,求逆后也是BTBMsgBox"求解失败",vbCritical,"提示"ExitSubEndIfMatrix_MultiplicationBTB,BT,BTBBT'矩阵BTB×BT=BTBBTMatrix_MultiplicationBTBBT,YN,A'矩阵BTBBT×YN=A,A(1,0)=u,A(0,0)=aDebug.Print"u="&A(1,0)&","&"a="&A(0,0)Predicted_ValueX_1(0),A(1,0),A(0,0),UBound(X_1),PV'预测Print_ArrayPV,"预测数据"Absolute_Residual_ErrorX_0,PV,AREPrint_ArrayARE,"绝对残差"Relative_Residual_ErrorX_0,ARE,RREPrint_StringRRE,"相对残差"Relatedness_TestARE,0.5,RPrint_One_StringR,"关联度"Print_One_StringFormat(Array_Mean(X_0),"0.0000"),"原始数据平均数"Print_One_StringFormat(Array_Mean(ARE),"0.0000"),"残差平均数"Print_One_StringMean_Square_Error(X_0),"原始数据均方差S1"Print_One_StringMean_Square_Error(ARE),"残差均方差S2"EndSub'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''以下是线性回归预测''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''PrivateSubLRP_OriginalDate_To_Array(OriginalDateAsString,X()AsDouble,Y()AsDouble)DimODS()AsString,iAsLong,jAsLong,ODS_NAsLong,X_RowAsLong,X_ColumnAsLongODS=Split(OriginalDate,"")ODS_N=UBound(ODS)-1ReDimXn(ODS_N)AsStringFori=0ToODS_NXn(i)=ODS(i)'X1,X2,XnNextiDimTempY()AsStringTempY=Split(ODS(ODS_N+1),",")DimTYAsLongTY=UBound(TempY)ReDimY(TY,0)Forj=0ToTYY(j,0)=TempY(j)Form1.PrintY(j,0)NextjX_Row=TYX_Column=UBound(ODS)ReDimX(X_Row,X_Column)DimTempX()AsStringFori=0To(X_Column-1)TempX=Split(Xn(i),",")Forj=0ToX_Row'9X(j,i+1)=TempX(j)X(j,0)=1NextjNextiTest_Print_ArrayX()EndSubPublicSubLinear_Regression_Predict(OriginalDateAsString)DimX()AsDouble,Y()AsDouble,B()AsDouble,iAsLongDimXT()AsDouble,XTX()AsDouble,XTXXT()AsDoubleLRP_OriginalDate_To_ArrayOriginalDate,X,YMatrix_TranspotationX,XT'计算矩阵X的转置XTMatrix_MultiplicationXT,X,XTX'矩阵XT×X=XTXIfNotMatrix_Inversion(XTX)Then'矩阵BTB求逆,求逆后也是BTBMsgBox"求解失败",vbCritical,"提示"ExitSubEndIfMatrix_MultiplicationXTX,XT,XTXXT'矩阵XTX×XT=XTXXTMatrix_MultiplicationXTXXT,Y,B'矩阵XTXXT×Y=B,A(1,0)=u,A(0,0)=aFori=0ToUBound(B)Print_One_StringB(i,0),"回归系数b"&iNextiEndSubPrivateSubTest_Print_Array(X()AsDouble)'显示二维数组Dimi%,j%Fori=0ToUBound(X(),1)Forj=0ToUBound(X(),2)Form1.PrintFormat(X(i,j),"000.0000")&""NextjForm1.PrintNextiEndSub灰色预测线性回归预测-

    注意事项

    本文(基于VB的灰色模型预测和线性回归预测教学内容.doc)为本站会员(1595****071)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开