Linux脚本开发数学库在PHP中的重要性(3)
文章作者 100test 发表时间 2007:03:14 16:21:10
来源 100Test.Com百考试题网
构造函数 
SimpleLinearRegression 类的构造函数方法接受一个 X 和一个 Y 向量,每个向量都有相同数量的值。您还可以为您预计的 Y 值设置一个缺省为 95% 的置信区间(confidence interval)。 
构造函数方法从验证数据形式是否适合于处理开始。一旦输入向量通过了“大小相等”和“值大于 1”测试,就执行算法的核心部分。 
执行这项任务涉及到通过一系列 getter 方法计算统计过程的中间值和汇总值。将每个方法调用的返回值赋给该类的一个实例变量。用这种方法存储计算结果确保了前后链接的计算中的调用例程可以使用中间值和汇总值。还可以通过调用该类的输出方法来显示这些结果,如清单 2 所描述的那样。 
n        = $numX.
  $this->X        = $X.
  $this->Y        = $Y.
  
  $this->ConfInt     = $ConfidenceInterval.
  $this->Alpha      = (1   ($this->ConfInt / 100) ) / 2.
  
  $this->XMean      = $this->getMean($this->X).
  $this->YMean      = $this->getMean($this->Y).
  $this->SumXX      = $this->getSumXX().
  $this->SumYY      = $this->getSumYY().
  $this->SumXY      = $this->getSumXY().
  $this->Slope      = $this->getSlope().
  $this->YInt      = $this->getYInt().
  $this->PredictedY   = $this->getPredictedY().
  $this->Error      = $this->getError().
  $this->SquaredError  = $this->getSquaredError().
  $this->SumError    = $this->getSumError().
  $this->TotalError   = $this->getTotalError().
  $this->SumSquaredError = $this->getSumSquaredError().
  $this->ErrorVariance  = $this->getErrorVariance().
  $this->StdErr     = $this->getStdErr().
  $this->SlopeStdErr   = $this->getSlopeStdErr().
  $this->YIntStdErr   = $this->getYIntStdErr().
  $this->SlopeTVal    = $this->getSlopeTVal().
  $this->YIntTVal    = $this->getYIntTVal().
  $this->R        = $this->getR().
  $this->RSquared    = $this->getRSquared().
  $this->DF       = $this->getDF().
  $this->SlopeProb    = $this->getStudentProb($this->SlopeTVal, $this->DF).
  $this->YIntProb    = $this->getStudentProb($this->YIntTVal, $this->DF).
  $this->AlphaTVal    = $this->getInverseStudentProb($this->Alpha, $this->DF).
  $this->ConfIntOfSlope = $this->getConfIntOfSlope().
  
  return true.
  }
  ?>  |