Skip to content

Commit

Permalink
Minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
markrogoyski committed Oct 28, 2018
1 parent 41fc161 commit 51ed82d
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/LinearAlgebra/VandermondeMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class VandermondeMatrix extends Matrix
/**
* Create the Vandermonde Matrix from a simple array.
*
* @param $M array (α₁, α₂, α₃ ⋯ αm)
* @param $n int
* @param array $M (α₁, α₂, α₃ ⋯ αm)
* @param int $n
*/
public function __construct(array $M, int $n)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NumericalAnalysis/Interpolation/NevillesMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NevillesMethod extends Interpolation
* (point) contains precisely two numbers, an x and y.
* Example array: [[1,2], [2,3], [3,4]].
* Example callback: function($x) {return $x**2;}
* @param numbers ... $args The arguments of our callback function: start,
* @param number ... $args The arguments of our callback function: start,
* end, and n. Example: approximate($source, 0, 8, 5).
* If $source is a set of points, do not input any
* $args. Example: approximate($source).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NewtonPolynomialForward extends Interpolation
* (point) contains precisely two numbers, an x and y.
* Example array: [[1,2], [2,3], [3,4]].
* Example callback: function($x) {return $x**2;}
* @param numbers ... $args The arguments of our callback function: start,
* @param number ... $args The arguments of our callback function: start,
* end, and n. Example: approximate($source, 0, 8, 5).
* If $source is a set of points, do not input any
* $args. Example: approximate($source).
Expand Down
10 changes: 5 additions & 5 deletions src/Probability/Distribution/Continuous/ChiSquared.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class ChiSquared extends Continuous
'x' => '[0,∞)',
];

/** @var number Degrees of Freedom Parameter */
/** @var float Degrees of Freedom Parameter */
protected $k;

/**
* Constructor
*
* @param number $k degrees of freedom parameter k >= 1
* @param float $k degrees of freedom parameter k >= 1
*/
public function __construct($k)
{
Expand All @@ -52,7 +52,7 @@ public function __construct($k)
*
* @param float $x point at which to evaluate > 0
*
* @return number probability
* @return float probability
*/
public function pdf(float $x)
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public function pdf(float $x)
*
* @param float $x Chi-square critical value (CV) > 0
*
* @return number cumulative probability
* @return float cumulative probability
*/
public function cdf(float $x)
{
Expand All @@ -108,7 +108,7 @@ public function cdf(float $x)
*
* μ = k
*
* @return int k
* @return float k
*/
public function mean()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Probability/Distribution/Continuous/Continuous.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class Continuous extends \MathPHP\Probability\Distribution\Distribution
* @param float $target The area for which we are trying to find the $x
*
* @todo check the parameter ranges.
* @return $number
* @return number
*/
public function inverse(float $target)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Probability/Distribution/Continuous/DiracDelta.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct()
*
* @param float $x
*
* @return number probability
* @return float probability
*/
public function pdf(float $x): float
{
Expand Down
2 changes: 1 addition & 1 deletion src/Probability/Distribution/Discrete/Uniform.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function pmf()
*
* Percentile n = b - a + 1
*
* @param number $k percentile
* @param int $k percentile
*
* @return number
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Probability/Distribution/Distribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ abstract class Distribution
/**
* Constructor
*
* @param number[] $params
* @param number $params
*/
public function __construct(...$params)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Probability/Distribution/Multivariate/Dirichlet.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Dirichlet
/**
* Constructor
*
* @param loat[] $αs
* @param float[] $αs
*/
public function __construct(array $αs)
{
Expand All @@ -56,7 +56,7 @@ public function __construct(array $αs)
*
* where B(α) is the multivariate Beta function
*
* @param array float[] $xs
* @param float[] $xs
*
* @return float
*
Expand Down
2 changes: 1 addition & 1 deletion src/Probability/Distribution/Table/StandardNormal.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static function getZScoreProbability(float $Z): float
/**
* Get Z score for confidence interval
*
* @param int $cl confidence level
* @param string $cl confidence level
*
* @return float Z score
*
Expand Down
2 changes: 1 addition & 1 deletion src/SetTheory/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function removeMulti(array $x): Set
*
* @param mixed $x
*
* @return string
* @return string|null
*/
protected function getKey($x)
{
Expand Down
14 changes: 8 additions & 6 deletions src/Statistics/Average.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Average
*
* @param array $numbers
*
* @return number
* @return number|null
*/
public static function mean(array $numbers)
{
Expand All @@ -43,7 +43,7 @@ public static function mean(array $numbers)
* @param array $numbers
* @param array $weights
*
* @return number
* @return number|null
*
* @throws Exception\BadDataException if the number of numbers and weights are not equal
*/
Expand Down Expand Up @@ -76,7 +76,7 @@ function ($xᵢ, $wᵢ) {
*
* @param array $numbers
*
* @return number
* @return number|null
*/
public static function median(array $numbers)
{
Expand Down Expand Up @@ -123,7 +123,7 @@ public static function median(array $numbers)
* @param array $numbers
* @param int $k zero indexed
*
* @return number
* @return number|null
*/
public static function kthSmallest(array $numbers, int $k)
{
Expand Down Expand Up @@ -243,7 +243,8 @@ public static function mode(array $numbers): array
* Geometric mean = ⁿ√a₀a₁a₂ ⋯
*
* @param array $numbers
* @return number
*
* @return number|null
*/
public static function geometricMean(array $numbers)
{
Expand All @@ -264,7 +265,8 @@ public static function geometricMean(array $numbers)
* https://en.wikipedia.org/wiki/Harmonic_mean
*
* @param array $numbers
* @return number
*
* @return number|null
*
* @throws Exception\BadDataException if there are negative numbers
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Statistics/Correlation.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public static function describe(array $X, array $Y, bool $population = false): a
public static function confidenceEllipse(array $X, array $Y, float $z, int $num_points = 11): array
{
$standardNormal = new StandardNormal();
$p = 2 * $standardNormal->CDF($z) - 1;
$p = 2 * $standardNormal->cdf($z) - 1;
$chiSquared = new ChiSquared(2);
$χ² = $chiSquared->inverse($p);

Expand Down
25 changes: 15 additions & 10 deletions src/Statistics/Descriptive.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Descriptive
* R = max x - min x
*
* @param array $numbers
* @return number
*
* @return number|null
*/
public static function range(array $numbers)
{
Expand All @@ -42,7 +43,8 @@ public static function range(array $numbers)
* 2
*
* @param array $numbers
* @return number
*
* @return number|null
*/
public static function midrange(array $numbers)
{
Expand Down Expand Up @@ -78,7 +80,8 @@ public static function midrange(array $numbers)
*
* @param array $numbers
* @param int $ν degrees of freedom
* @return number
*
* @return number|null
*
* @throws Exception\OutOfBoundsException if degrees of freedom is ≤ 0
*/
Expand Down Expand Up @@ -214,7 +217,7 @@ function ($xᵢ, $wᵢ) use ($μw) {
* false returns SD (uses sample variance);
* Default is false (SD (sample variance))
*
* @return number
* @return number|null
*
* @throws Exception\OutOfBoundsException
*/
Expand Down Expand Up @@ -261,7 +264,8 @@ public static function sd(array $numbers, bool $SD+ = false)
* N is the number of numbers in the population set
*
* @param array $numbers
* @return number
*
* @return number|null
*/
public static function meanAbsoluteDeviation(array $numbers)
{
Expand Down Expand Up @@ -294,7 +298,8 @@ function ($xᵢ) use ($x) {
* x̄ is the median
*
* @param array $numbers
* @return number
*
* @return number|null
*/
public static function medianAbsoluteDeviation(array $numbers)
{
Expand Down Expand Up @@ -629,12 +634,12 @@ public static function describe(array $numbers, bool $population = false): array
'quartiles' => self::quartiles($numbers),
'midhinge' => self::midhinge($numbers),
'skewness' => $population ? RandomVariable::populationSkewness($numbers) : RandomVariable::skewness($numbers),
'ses' => $n > 2 ? RandomVariable::SES($n) : null,
'ses' => $n > 2 ? RandomVariable::ses($n) : null,
'kurtosis' => RandomVariable::kurtosis($numbers),
'sek' => $n > 3 ? RandomVariable::SEK($n) : null,
'sek' => $n > 3 ? RandomVariable::sek($n) : null,
'sem' => RandomVariable::standardErrorOfTheMean($numbers),
'ci_95' => RandomVariable::confidenceInterval($μ, $n, $σ, 95),
'ci_99' => RandomVariable::confidenceInterval($μ, $n, $σ, 99),
'ci_95' => RandomVariable::confidenceInterval($μ, $n, $σ, '95'),
'ci_99' => RandomVariable::confidenceInterval($μ, $n, $σ, '99'),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Statistics/Distance.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function ($qᵢ) {

// ∑ P(i) log(P(i)/Q(i))
$Dkl⟮P‖Q⟯ = array_sum(array_map(
function ($P, $Q) use ($p, $q) {
function ($P, $Q) {
return $P * log($P / $Q);
},
$p,
Expand Down
16 changes: 8 additions & 8 deletions src/Statistics/RandomVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RandomVariable
* @param array $X list of numbers (random variable X)
* @param int $n n-th central moment to calculate
*
* @return number n-th central moment
* @return number|null n-th central moment
*/
public static function centralMoment(array $X, int $n)
{
Expand Down Expand Up @@ -83,7 +83,7 @@ function ($xᵢ) use ($μ, $n) {
*
* @param array $X list of numbers (random variable X)
*
* @return number
* @return number|null
*/
public static function populationSkewness(array $X)
{
Expand Down Expand Up @@ -117,7 +117,7 @@ public static function populationSkewness(array $X)
*
* @param array $X list of numbers (random variable X)
*
* @return number
* @return number|null
*/
public static function sampleSkewness(array $X)
{
Expand Down Expand Up @@ -151,7 +151,7 @@ public static function sampleSkewness(array $X)
*
* @param array $X list of numbers (random variable X)
*
* @return number
* @return number|null
*
* @throws Exception\OutOfBoundsException
*/
Expand Down Expand Up @@ -219,7 +219,7 @@ public static function ses(int $n): float
*
* @param array $X list of numbers (random variable X)
*
* @return number
* @return number|null
*/
public static function kurtosis(array $X)
{
Expand Down Expand Up @@ -317,7 +317,7 @@ public static function sek(int $n): float
*
* @param array $X list of numbers (random variable X)
*
* @return float
* @return float|null
*
* @throws Exception\OutOfBoundsException
*/
Expand Down Expand Up @@ -395,7 +395,7 @@ public static function confidenceInterval($μ, int $n, $σ, string $cl): array
*
* @param array $numbers
*
* @return number
* @return number|null
*/
public static function sumOfSquares(array $numbers)
{
Expand All @@ -415,7 +415,7 @@ public static function sumOfSquares(array $numbers)
*
* @param array $numbers
*
* @return number
* @return number|null
*/
public static function sumOfSquaresDeviations(array $numbers)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Statistics/Regression/Methods/LeastSquares.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function leverages(): array
public function sumOfSquaresRegression(): float
{
if ($this->fit_constant == 1) {
return RandomVariable::sumOfSquaresDeviations($this->Yhat());
return RandomVariable::sumOfSquaresDeviations($this->yhat());
}
return array_sum(Single::square($this->reg_Yhat));
}
Expand Down
6 changes: 6 additions & 0 deletions src/Statistics/Regression/PowerLaw.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class PowerLaw extends ParametricRegression
{
use Models\PowerModel, Methods\LeastSquares;

/** @var float */
protected $a;

/** @var float */
protected $b;

/**
* Calculate the regression parameters by least squares on linearized data
* ln(y) = ln(A) + B*ln(x)
Expand Down
2 changes: 1 addition & 1 deletion src/Statistics/Regression/Regression.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class Regression

/**
* Y values of the original points
* @var [type]
* @var array
*/
protected $ys;

Expand Down
Loading

0 comments on commit 51ed82d

Please sign in to comment.