Пожалуйста, помогите мне.
У меня есть математическая функция, которую я не делал. Но возвращает объект «смешанный». Я хочу получить доступ к данным в этом объекте, но, как видите, некоторая информация защищена. Как мне получить эти данные. Когда я использую var_dump ($objectCoeficients)
, возвращает это:
object(Regression\Matrix)#6 (3) {
["rows":protected]=> int(6)
["columns":protected]=> int(1)
["MainMatrix":protected]=> array(6) {
[0]=> array(1) { [0]=> float(40.640558174) }
[1]=> array(1) { [0]=> float(0.7099924250484) }
[2]=> array(1) { [0]=> float(1.6495016392771) }
[3]=> array(1) { [0]=> float(-0.016552419120545) }
[4]=> array(1) { [0]=> float(0.071413971801328) }
[5]=> array(1) { [0]=> float(-1.5120534467321) }
}
}
Я новичок в PHP, извините.
protected $coefficients;
public function exec(){
if (!($this->x instanceof Matrix) || !($this->y instanceof Matrix))
{
throw new RegressionException('X and Y must be matrices.');
}
$XtXInv = $this
->x
->transpose()
->multiply($this->x)
->invert();
//coefficients = b = (X'X)-1 X'Y
$this->coefficients = $XtXInv->multiply($this
->x
->transpose() - > multiply($this->y));
$btXtY = $this
->coefficients
->transpose()
->multiply($this
->x
->transpose())
->multiply($this->y);
$num_independent = $this
->x
->getNumColumns();
$sample_size = $this
->x
->getNumRows();
$dfTotal = $sample_size - 1;
$dfModel = $num_independent - 1;
$dfResidual = $dfTotal - $dfModel;
/*
* Create the unit vector, one row per sample
*/
$um = new Matrix(array_fill(0, $sample_size, array(
1
)));
$this->SSRScalar = $btXtY->subtract($this
->y
->transpose()
->multiply($um)->multiply($um->transpose())
->multiply($this->y)
->scalarDivide($sample_size))->getEntry(0, 0);
$this->SSEScalar = $this
->y
->transpose()
->multiply($this->y)
->subtract($btXtY)->getEntry(0, 0);
$this->SSTOScalar = $this->SSRScalar + $this->SSEScalar;
$this->RSquare = $this->SSTOScalar == 0 ? 1 : $this->SSRScalar / $this->SSTOScalar;
$this->F = ($this->SSRScalar / $dfModel) / ($this->SSEScalar / `enter
code here`$dfResidual);
//MSE = SSE/(df)
$MSE = $this->SSEScalar / $dfResidual;
$this->covariance = $XtXInv->scalarMultiply($MSE);
for ($i = 0;$i < $num_independent;$i++)
{
//get the diagonal elements of the standard errors
$searray[] = array(
sqrt($this
->covariance
->getEntry($i, $i))
);
//compute the t-statistic
$tstat[] = array(
$this
->coefficients
->getEntry($i, 0) / $searray[$i][0]
);
//compute the student p-value from the t-stat
$pvalue[] = array(
$this->getStudentPValue($tstat[$i][0], $dfResidual)
);
//convert into 1-d vectors and store
$this->stderrors[] = $searray[$i][0];
$this->tstats[] = $tstat[$i][0];
$this->pvalues[] = $pvalue[$i][0];
}
return $this;
}
public function getCoefficients()
{
return $this->coefficients;
}