-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathHanesWoolf.php
More file actions
68 lines (59 loc) · 1.74 KB
/
HanesWoolf.php
File metadata and controls
68 lines (59 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace MathPHP\Statistics\Regression;
use MathPHP\Exception;
use MathPHP\Functions\Map\Multi;
/**
* Use the Hanes-Woolf method to fit an equation of the form
* V * x
* y = ----------
* K + x
*
* The equation is linearized and fit using Least Squares
*
* @phpstan-import-type SimpleLinearResultModel from Methods\LeastSquares
* @phpstan-import-type PolynomialResultModel from Methods\LeastSquares
*/
class HanesWoolf extends ParametricRegression
{
/** @use Methods\LeastSquares<SimpleLinearResultModel> */
use Methods\LeastSquares;
use Models\MichaelisMenten;
/**
* @param list<float> $array
* @return SimpleLinearResultModel
*/
protected function createResultModel(array $array): array
{
return $this->createSimpleLinearResultModel($array);
}
/**
* Calculate the regression parameters by least squares on linearized data
* x / y = x / V + K / V
*
* @throws Exception\BadDataException
* @throws Exception\MatrixException
* @throws Exception\MathException
*/
public function calculate(): void
{
// Linearize the relationship by dividing x by y
$y’ = Multi::divide($this->xs, $this->ys);
// Perform Least Squares Fit
$linear_parameters = $this->leastSquares($y’, $this->xs)->getColumn(0);
$V = 1 / $linear_parameters[1];
$K = $linear_parameters[0] * $V;
$this->parameters = [$V, $K];
}
/**
* Evaluate the regression equation at x
* Uses the instance model's evaluateModel method.
*
* @param float $x
*
* @return float
*/
public function evaluate(float $x): float
{
return $this->evaluateModel($x, $this->parameters);
}
}