Topic: 求助,一个奇怪问题的诊断

  Print this page

1.求助,一个奇怪问题的诊断 Copy to clipboard
Posted by: wastelandxf
Posted on: 2009-11-09 16:30

问题描述:LeastSquares类的init(),getMatrix(),getMatrix(int hostTypeId,String beginDate,String endDate,int ncount,int mcount)
方法分别是直接赋值来初始化,从文件初始化,从数据库来初始化aarray和barray
数组的方法,OLS()是计算最小二乘法线性拟合参数的方法,问题估计不是发生在这里,你可以先不管他。clearData()用于初始所有用到的数组的所有元素的归0

问题:当用getMatrix(int hostTypeId,String beginDate,String endDate,int ncount,int mcount)方法来初始化数组时,OLS()计算出来的结果不正确。
我还发现,用分别用1.getMatrix(int hostTypeId,String beginDate,String endDate,int ncount,int mcount),2.getMatrix(),3.init()方法初始化数组后,
即使这3方法初始化后aarray,barray的数据完全一样,但用第1种方法初始化,
OLS()计算出来的结果仍然与用其他两个方法初始化再用OLS()计算出来的结果不一样。
但是用init()初始化后,再用getMatrix(int hostTypeId,String beginDate,String endDate,int ncount,int mcount)初始化,OLS()计算出来的结果就是正确的
见如下代码:
以下3个main方法的代码片段:
(1).leastSquares.getMatrix();
    leastSquares.OLS();
(2).
   leastSquares.init();
    leastSquares.OLS();
(3).
    leastSquares.opConnect();
    leastSquares.getMatrix(4,"2008-07-01", "2009-10-01", 16, 3);//从数据库初始化X和y矩阵
    leastSquares.OLS();
(4).
    leastSquares.init();
    leastSquares.opConnect();
    leastSquares.getMatrix(4,"2008-07-01", "2009-10-01", 16, 3);//从数据库初始化X和y矩阵
    leastSquares.OLS();
(5).
    leastSquares.init();
    leastSquares.opConnect();
    leastSquares.clearData();//重置缓存数组
    leastSquares.getMatrix(4,"2008-07-01", "2009-10-01", 16, 3);//从数据库初始化X和y矩阵
    leastSquares.OLS();
其中,代码片段(3),和代码片段(5)计算出来的结果是错误的,请高手帮忙诊断和分析一下,不胜感激!
qq:254608920
LeastSquares因为太长,放在附件中
测试代码示例:
public class LeastSquaresTest
{
  public static void main(String[] args) throws IOException
  {
    LeastSquares leastSquares=new LeastSquares();
    LeastSquaresTest leastSquaresTest=new LeastSquaresTest();
    
    leastSquares.getMatrix();
    leastSquares.opConnect();
    leastSquares.clearData();//重置缓存数组
    leastSquares.getMatrix(4,"2008-07-01", "2009-10-01", 16, 3);//从数据库初始化X和y矩阵
    leastSquares.OLS();
   }
}

LeastSquares.java (21.84k)


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923