mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-20 13:28:42 +00:00
cleanup unused files and phpcs fixes
This commit is contained in:
parent
0422411c89
commit
1145144a98
|
|
@ -74,6 +74,7 @@ class Grid
|
|||
$y = $node->getY();
|
||||
|
||||
$neighbors = [];
|
||||
|
||||
$s0 = false;
|
||||
$s1 = false;
|
||||
$s2 = false;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,17 @@ use phpOMS\Math\Topology\Metrics2D;
|
|||
*/
|
||||
class Heuristic
|
||||
{
|
||||
/**
|
||||
* Calculate metric/distance between two nodes.
|
||||
*
|
||||
* @param array $node1 Array with 'x' and 'y' coordinate
|
||||
* @param array $node2 Array with 'x' and 'y' coordinate
|
||||
* @param int $heuristic Heuristic to use for calculation
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function metric(array $node1, array $node2, int $heuristic) : float
|
||||
{
|
||||
if ($heuristic === HeuristicType::MANHATTAN) {
|
||||
|
|
|
|||
|
|
@ -24,12 +24,56 @@ namespace phpOMS\Algorithm\PathFinding;
|
|||
*/
|
||||
class Node
|
||||
{
|
||||
/**
|
||||
* X-Coordinate.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $x = 0;
|
||||
|
||||
/**
|
||||
* Y-Coordinate.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $y = 0;
|
||||
|
||||
/**
|
||||
* Cost of the node.
|
||||
*
|
||||
* @var float
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private float $weight = 1.0;
|
||||
|
||||
/**
|
||||
* Can be walked?
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private bool $isWalkable = true;
|
||||
|
||||
/**
|
||||
* Parent node.
|
||||
*
|
||||
* @var null|Node
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?Node $parent = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $x X-Coordinate
|
||||
* @param int $y Y-Coordinate
|
||||
* @param float $weight Cost of reaching this node
|
||||
* @param bool $isWalkable Can be walked on?
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $x, int $y, float $weight = 1.0, bool $isWalkable = true)
|
||||
{
|
||||
$this->x = $x;
|
||||
|
|
@ -38,41 +82,101 @@ class Node
|
|||
$this->isWalkable = $isWalkable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can this node be walked on?
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function isWalkable() : bool
|
||||
{
|
||||
return $this->isWalkable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cost to walk on this node
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getWeight() : float
|
||||
{
|
||||
return $this->weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get x-coordinate
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getX() : int
|
||||
{
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get y-coordinate
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getY() : int
|
||||
{
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent node
|
||||
*
|
||||
* @param null|Node $node Parent node
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setParent(?Node $node) : void
|
||||
{
|
||||
$this->parent = $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent node
|
||||
*
|
||||
* @return null|Node
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getParent() : ?Node
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is node equal to another node?
|
||||
*
|
||||
* @param Node $node Node to compare to
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function isEqual(Node $node) : bool
|
||||
{
|
||||
return $this->x === $node->getX() && $this->y === $node->getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the coordinates of this node.
|
||||
*
|
||||
* @return array ['x' => ?, 'y' => ?]
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCoordinates() : array
|
||||
{
|
||||
return ['x' => $this->x, 'y' => $this->y];
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Algorithm\PathFinding;
|
||||
|
||||
/**
|
||||
* Node on grid.
|
||||
* Null node.
|
||||
*
|
||||
* @package phpOMS\Algorithm\PathFinding
|
||||
* @license OMS License 1.0
|
||||
|
|
@ -25,4 +25,4 @@ namespace phpOMS\Algorithm\PathFinding;
|
|||
class NullJumpPointNode extends JumpPointNode
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Algorithm\PathFinding;
|
||||
|
||||
/**
|
||||
* Node on grid.
|
||||
* Null node.
|
||||
*
|
||||
* @package phpOMS\Algorithm\PathFinding
|
||||
* @license OMS License 1.0
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ final class Depreciation
|
|||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ final class FinanceFormulas
|
|||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ final class Loan
|
|||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ final class Lorenzkurve
|
|||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ final class StockBonds
|
|||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ final class Metrics
|
|||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ final class Metrics
|
|||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ final class MarketShareEstimation
|
|||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,6 @@ class BinomialDistribution
|
|||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getMode(int $n, float $p) : float
|
||||
|
|
|
|||
|
|
@ -13,7 +13,197 @@
|
|||
declare(strict_types=1);
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
use phpOMS\Math\Functions\Gamma;
|
||||
|
||||
/**
|
||||
* Gamma distribution.
|
||||
*
|
||||
* @package phpOMS\Math\Stochastic\Distribution
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GammaDistribution
|
||||
{
|
||||
/**
|
||||
* Get probability density function.
|
||||
*
|
||||
* @param float $x Value x
|
||||
* @param int $k k shape
|
||||
* @param float $theta Theta scale
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getPdfIntegerK(float $x, int $k, float $theta) : float
|
||||
{
|
||||
return 1 / (Gamma::getGammaInteger($k) * $theta ** $k) * \pow($x, $k - 1) * \exp(-$x / $theta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get probability density function.
|
||||
*
|
||||
* @param float $x Value x
|
||||
* @param int $alpha Alpha shape
|
||||
* @param float $beta Beta rate
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getPdfIntegerAlphaBeta(float $x, int $alpha, float $beta) : float
|
||||
{
|
||||
return $beta ** $alpha / Gamma::getGammaInteger($alpha) * \pow($x, $alpha - 1) * \exp(-$beta * $x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param float $k k shape
|
||||
* @param float $theta Theta scale
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getMeanK(float $k, float $theta) : float
|
||||
{
|
||||
return $k * $theta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param float $alpha Alpha shape
|
||||
* @param float $beta Beta rate
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getMeanAlphaBeta(float $alpha, float $beta) : float
|
||||
{
|
||||
return $alpha * $beta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param float $k k shape
|
||||
* @param float $theta Theta scale
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getModeK(float $k, float $theta) : float
|
||||
{
|
||||
return ($k - 1) * $theta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param float $alpha Alpha shape
|
||||
* @param float $beta Beta scale
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getModeAlphaBeta(float $alpha, float $beta) : float
|
||||
{
|
||||
return ($alpha - 1) / $beta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @param float $k Shape k or alpha
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getSkewness(float $k) : float
|
||||
{
|
||||
return 2 / \sqrt($k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @param float $k Shape k or alpha
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getExKurtosis(float $k) : float
|
||||
{
|
||||
return 6 / $k;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param float $k k shape
|
||||
* @param float $theta Theta scale
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getVarianceK(float $k, float $theta) : float
|
||||
{
|
||||
return $k * $theta ** 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param float $alpha Alpha shape
|
||||
* @param float $beta Beta scale
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getVarianceAlphaBeta(float $alpha, float $beta) : float
|
||||
{
|
||||
return $alpha / ($beta ** 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param float $k k shape
|
||||
* @param float $t Value t
|
||||
* @param float $theta Theta scale
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getMgfK(float $k, float $t, float $theta) : float
|
||||
{
|
||||
return \pow(1 - $theta * $t, -$k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param float $t Value t
|
||||
* @param float $alpha Alpha shape
|
||||
* @param float $beta Beta scale
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getMgfAlphaBeta(float $t, float $alpha, float $beta) : float
|
||||
{
|
||||
return \pow(1 - $t / $beta, -$alpha);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,11 @@
|
|||
declare(strict_types=1);
|
||||
namespace phpOMS\Math\Stochastic;
|
||||
|
||||
use phpOMS\Math\Statistic\Average;
|
||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
||||
|
||||
/**
|
||||
* Bernulli distribution.
|
||||
* Naive bayes matching.
|
||||
*
|
||||
* @package phpOMS\Math\Stochastic
|
||||
* @license OMS License 1.0
|
||||
|
|
@ -23,36 +26,177 @@ namespace phpOMS\Math\Stochastic;
|
|||
*/
|
||||
class NaiveBayesFilter
|
||||
{
|
||||
private $dict = [];
|
||||
/**
|
||||
* Dictionary of different criterias.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $dict = [];
|
||||
|
||||
public function __construct()
|
||||
/**
|
||||
* Dictionary changed.
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private bool $changed = true;
|
||||
|
||||
/**
|
||||
* Cached probabilities.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $probabilities = [];
|
||||
|
||||
/**
|
||||
* Train matches.
|
||||
*
|
||||
* @param string $criteria Criteria to match against
|
||||
* @param array $matched Matches
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function train(string $criteria, array $matched) : void
|
||||
{
|
||||
}
|
||||
foreach ($matched as $dataset) {
|
||||
foreach ($dataset as $attr => $value) {
|
||||
if (!isset($this->dict[$criteria][$attr])) {
|
||||
$this->dict[$criteria][$attr] = [];
|
||||
}
|
||||
|
||||
public function trainMatch($matched) : void
|
||||
{
|
||||
}
|
||||
if (\is_string($value) && !isset($this->dict[$criteria][$attr][$value])) {
|
||||
$this->dict[$criteria][$attr][$value] = 0;
|
||||
} elseif (!\is_string($value) && !isset($this->dict[$criteria][$attr])) {
|
||||
$this->dict[$criteria][$attr] = [];
|
||||
}
|
||||
|
||||
public function trainMismatch($mismatch) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function match($toMatch) : float
|
||||
{
|
||||
$normalizedDict = $this->normalizeDictionary();
|
||||
|
||||
$n = 0.0;
|
||||
foreach ($toMatch as $element) {
|
||||
if (isset($normalizedDict[$element])) {
|
||||
$n += \log(1 - $normalizedDict[$element]['match'] / $normalizedDict[$element]['total']) - \log($normalizedDict[$element]['match'] / $normalizedDict[$element]['total']);
|
||||
if (\is_string($value)) {
|
||||
++$this->dict[$criteria][$attr][$value];
|
||||
} else {
|
||||
$this->dict[$criteria][$attr][] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->changed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check against matches.
|
||||
*
|
||||
* @param string $criteria Criteria to match against
|
||||
* @param array $toMatch Values to match
|
||||
* @param int $minimum Minimum amount of ocurances for consideration
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function match(string $criteria, array $toMatch, int $minimum = 3) : float
|
||||
{
|
||||
if ($this->changed) {
|
||||
$this->cache();
|
||||
}
|
||||
|
||||
$pTotalAttribute = 1;
|
||||
|
||||
$evidence = 0;
|
||||
foreach ($this->probability as $criteriaKey => $data) {
|
||||
$temp = 1;
|
||||
foreach ($data as $attr => $value) {
|
||||
$temp *= 1 / \sqrt(2 * M_PI * $this->probability[$criteriaKey][$attr]['variance'])
|
||||
* \exp(-($value - $this->probability[$criteriaKey][$attr]['mean']) ** 2 / (2 * $this->probability[$criteriaKey][$attr]['variance'] ** 2));
|
||||
}
|
||||
|
||||
$evidence += ($this->probability[$criteria] / $this->probability['criteria_all']) * $temp;
|
||||
}
|
||||
|
||||
$n = 0.0;
|
||||
foreach ($toMatch as $attr => $value) {
|
||||
if (!isset($this->dict[$criteria], $this->dict[$criteria][$attr])
|
||||
|| (\is_string($value) && !isset($this->dict[$criteria][$attr][$value]))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\is_array($value)) {
|
||||
/** @var string[] $value */
|
||||
foreach ($value as $word) {
|
||||
if (isset($this->dict[$criteria][$attr][$word])
|
||||
&& $this->dict[$criteria][$attr][$word] >= $minimum
|
||||
) {
|
||||
$n += \log(1 - $this->dict[$criteria][$attr][$word]
|
||||
/ $this->probability['criteria_all'][$attr]
|
||||
)
|
||||
- \log($this->dict[$criteria][$attr][$word]
|
||||
/ $this->probability['criteria_all'][$attr]
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$p = 1 / \sqrt(2 * M_PI * $this->probability[$criteria][$attr]['variance'])
|
||||
* \exp(-($value - $this->probability[$criteria][$attr]['mean']) ** 2 / (2 * $this->probability[$criteria][$attr]['variance'] ** 2));
|
||||
|
||||
$pTotalAttribute *= $p;
|
||||
|
||||
$n += \log(1 - $p) - \log($p);
|
||||
}
|
||||
}
|
||||
|
||||
$pCriteria = $pTotalAttribute / $evidence;
|
||||
|
||||
var_dump($pCriteria);
|
||||
var_dump($pTotalAttribute);
|
||||
var_dump(1 / (1 + \exp($n)));
|
||||
var_dump($n);
|
||||
var_dump($evidence);
|
||||
var_dump($this->probability);
|
||||
|
||||
return 1 / (1 + \exp($n));
|
||||
}
|
||||
|
||||
private function normalizeDictionary() : array
|
||||
/**
|
||||
* Cache probabilities for matching function.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function cache() : void
|
||||
{
|
||||
return $this->dict;
|
||||
foreach ($this->dict as $criteria => $subDict) {
|
||||
if (!isset($this->probability[$criteria]['count'])) {
|
||||
$this->probability[$criteria]['count'] = 0;
|
||||
}
|
||||
|
||||
++$this->probability[$criteria]['count'];
|
||||
|
||||
if (!isset($this->probability['criteria_all']['count'])) {
|
||||
$this->probability['criteria_all']['count'] = 0;
|
||||
}
|
||||
|
||||
++$this->probability['criteria_all']['count'];
|
||||
|
||||
foreach ($subDict as $attr => $valueArray) {
|
||||
if (\is_string(\array_key_first($valueArray))) {
|
||||
if (!isset($this->probability['criteria_all'][$attr])) {
|
||||
$this->probability['criteria_all'][$attr] = 0;
|
||||
}
|
||||
|
||||
foreach ($valueArray as $value => $data) {
|
||||
$this->probability['criteria_all'][$attr] += $data;
|
||||
}
|
||||
} else {
|
||||
$this->probability[$criteria][$attr] = [
|
||||
'mean' => Average::arithmeticMean($this->dict[$criteria][$attr]),
|
||||
'variance' => MeasureOfDispersion::empiricalVariance($this->dict[$criteria][$attr]),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,14 @@ namespace phpOMS\Math\Topology;
|
|||
*/
|
||||
final class Metrics2D
|
||||
{
|
||||
/**
|
||||
* Constructure
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -113,9 +118,9 @@ final class Metrics2D
|
|||
*
|
||||
* @latex d(p, q) = \sqrt[\lambda]{\sum_{n=1}^N{|p_i - q_i|^\lambda}}
|
||||
*
|
||||
* @param array $a 2-D array with x and y coordinate
|
||||
* @param array $b 2-D array with x and y coordinate
|
||||
* @param int $lambda
|
||||
* @param array $a 2-D array with x and y coordinate
|
||||
* @param array $b 2-D array with x and y coordinate
|
||||
* @param int $lambda Lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
|
|
@ -162,8 +167,10 @@ final class Metrics2D
|
|||
*/
|
||||
public static function brayCurtis(array $a, array $b) : float
|
||||
{
|
||||
return (\abs($a['x'] - $b['x']) + \abs($a['y'] - $b['y'])) / (($a['x'] + $b['x'])
|
||||
+ ($a['y'] + $b['y']));
|
||||
return (\abs($a['x'] - $b['x'])
|
||||
+ \abs($a['y'] - $b['y']))
|
||||
/ (($a['x'] + $b['x'])
|
||||
+ ($a['y'] + $b['y']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -180,7 +187,7 @@ final class Metrics2D
|
|||
*/
|
||||
public static function angularSeparation(array $a, array $b) : float
|
||||
{
|
||||
return ($a['x'] * $b['x'] + $a['y'] * $b['y']) / pow(($a['x']**2 + $a['y']**2) * ($b['x'] ** 2 + $b['y'] ** 2), 1 / 2);
|
||||
return ($a['x'] * $b['x'] + $a['y'] * $b['y']) / pow(($a['x'] ** 2 + $a['y'] ** 2) * ($b['x'] ** 2 + $b['y'] ** 2), 1 / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -245,7 +252,9 @@ final class Metrics2D
|
|||
$bPos[$i] = [$b[$i], $i];
|
||||
}
|
||||
|
||||
\usort($bPos, function ($e1, $e2) { return $e1[0] <=> $e2[0]; });
|
||||
\usort($bPos, function ($e1, $e2) {
|
||||
return $e1[0] <=> $e2[0];
|
||||
});
|
||||
|
||||
$vis = \array_fill(0, $size, false);
|
||||
$ans = 0;
|
||||
|
|
@ -256,11 +265,12 @@ final class Metrics2D
|
|||
}
|
||||
|
||||
$cycleSize = 0;
|
||||
$j = $i;
|
||||
$j = $i;
|
||||
|
||||
while (!$vis[$j]) {
|
||||
$vis[$j] = true;
|
||||
$j = $bPos[$j][1];
|
||||
$j = $bPos[$j][1];
|
||||
|
||||
++$cycleSize;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Utils\Barcode;
|
||||
|
||||
/**
|
||||
* Aztec class.
|
||||
* Datamatrix class.
|
||||
*
|
||||
* @package phpOMS\Utils\Barcode
|
||||
* @license OMS License 1.0
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Utils\Barcode;
|
||||
|
||||
/**
|
||||
* Aztec class.
|
||||
* HIBCC class.
|
||||
*
|
||||
* @package phpOMS\Utils\Barcode
|
||||
* @license OMS License 1.0
|
||||
|
|
@ -24,107 +24,283 @@ namespace phpOMS\Utils\Barcode;
|
|||
*/
|
||||
class HIBCC
|
||||
{
|
||||
private $identifier = '';
|
||||
/**
|
||||
* Identifier code (3-characters)
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $identifier = '';
|
||||
|
||||
private $productId = '';
|
||||
/**
|
||||
* Product id.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $productId = '';
|
||||
|
||||
private $measureOfUnit = 0;
|
||||
/**
|
||||
* Meassure of unit (0-9).
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $measureOfUnit = 0;
|
||||
|
||||
private $dateFormat = '';
|
||||
/**
|
||||
* Date format for the shelf life.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $dateFormat = 'Y-m-d';
|
||||
|
||||
private $expirationDate = null;
|
||||
/**
|
||||
* Date of the expiration.
|
||||
*
|
||||
* @var null|\DateTime
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?\DateTime $expirationDate = null;
|
||||
|
||||
private $productionDate = null;
|
||||
/**
|
||||
* Date of the production.
|
||||
*
|
||||
* @var null|\DateTime
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?\DateTime $productionDate = null;
|
||||
|
||||
private $lot = '';
|
||||
/**
|
||||
* Lot number.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $lot = '';
|
||||
|
||||
private $checkValue = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* Check value.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $checkValue = 0;
|
||||
|
||||
/**
|
||||
* Set the identifier.
|
||||
*
|
||||
* @param string $identifier Identifier
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setIdentifier(string $identifier) : void
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getIdentifier() : string
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the product id.
|
||||
*
|
||||
* @param string $id Product id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setProductId(string $id) : void
|
||||
{
|
||||
$this->productId = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the product id.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getProductId() : string
|
||||
{
|
||||
return $this->productId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the product id.
|
||||
*
|
||||
* @param int $measure Measure of the unit
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setMeasureOfUnit(int $measure) : void
|
||||
{
|
||||
$this->measureOfUnit = $measure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the measure of the unit.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getMeasureOfUnit() : int
|
||||
{
|
||||
return $this->measureOfUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date format.
|
||||
*
|
||||
* @param string $format Date format
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setDateFormat(string $format) : void
|
||||
{
|
||||
$this->dateFormat = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date format.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getDateFormat() : string
|
||||
{
|
||||
return $this->dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the expiration date.
|
||||
*
|
||||
* @param \DateTime $date Expiration date
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setExpirationDate(\DateTime $date) : void
|
||||
{
|
||||
$this->expirationDate = $date;
|
||||
}
|
||||
|
||||
public function getExpirationDate() : \DateTime
|
||||
/**
|
||||
* Get the expiration date.
|
||||
*
|
||||
* @return null|\DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getExpirationDate() : ?\DateTime
|
||||
{
|
||||
return $this->expirationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the production date.
|
||||
*
|
||||
* @param \DateTime $date Production date
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setPrductionDate(\DateTime $date) : void
|
||||
{
|
||||
$this->productionDate = $date;
|
||||
}
|
||||
|
||||
public function getProductionDate() : \DateTime
|
||||
/**
|
||||
* Get the production date.
|
||||
*
|
||||
* @return null|\DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getProductionDate() : ?\DateTime
|
||||
{
|
||||
return $this->productionDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the lot.
|
||||
*
|
||||
* @param string $lot Lot number
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setLot(string $lot) : void
|
||||
{
|
||||
$this->lot = $lot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lot number.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getLot() : string
|
||||
{
|
||||
return $this->lot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the check value.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCheckValue() : int
|
||||
{
|
||||
return $this->checkValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary DI.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getPrimaryDi() : string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the secondary DI.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getSecondaryDi() : string
|
||||
{
|
||||
return '';
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Utils\Barcode;
|
||||
|
||||
/**
|
||||
* Aztec class.
|
||||
* QR class.
|
||||
*
|
||||
* @package phpOMS\Utils\Barcode
|
||||
* @license OMS License 1.0
|
||||
|
|
|
|||
|
|
@ -20,11 +20,12 @@ require_once \realpath(__DIR__ . '/../../../Resources/phpexcel/Classes/PHPExcel.
|
|||
/**
|
||||
* Excel class.
|
||||
*
|
||||
* @package phpOMS\Utils\Excel
|
||||
* @since 1.0.0
|
||||
* @package phpOMS\Utils\Excel
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
* @noinspection PhpUndefinedClassInspection
|
||||
*/
|
||||
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
class Excel extends \PHPExcel
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,14 @@ namespace phpOMS\Utils\PDF;
|
|||
include __DIR__ . '/../../../Resources/tcpdf/tcpdf.php';
|
||||
|
||||
/**
|
||||
* Pdf class.
|
||||
* PDF class.
|
||||
*
|
||||
* @package phpOMS\Utils\PDF
|
||||
* @since 1.0.0
|
||||
* @package phpOMS\Utils\PDF
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
* @noinspection PhpUndefinedClassInspection
|
||||
*/
|
||||
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
class Pdf extends \TCPDF
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class Address
|
||||
{
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class City
|
||||
{
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class Email
|
||||
{
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class Iban
|
||||
{
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class Numeric
|
||||
{
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class PostalZip
|
||||
{
|
||||
}
|
||||
|
|
@ -14,13 +14,70 @@
|
|||
|
||||
namespace phpOMS\tests\Math\Stochastic;
|
||||
|
||||
use phpOMS\Math\Stochastic\NaiveBayesFilter;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class NaiveBayesFilterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder() : void
|
||||
const PLAY = [
|
||||
['weather' => 'Overcast'],
|
||||
['weather' => 'Rainy'],
|
||||
['weather' => 'Sunny'],
|
||||
['weather' => 'Sunny'],
|
||||
['weather' => 'Overcast'],
|
||||
['weather' => 'Sunny'],
|
||||
['weather' => 'Rainy'],
|
||||
['weather' => 'Overcast'],
|
||||
['weather' => 'Overcast'],
|
||||
];
|
||||
|
||||
const NO_PLAY = [
|
||||
['weather' => 'Sunny'],
|
||||
['weather' => 'Rainy'],
|
||||
['weather' => 'Rainy'],
|
||||
['weather' => 'Sunny'],
|
||||
['weather' => 'Rainy'],
|
||||
];
|
||||
|
||||
const MALE = [
|
||||
['height' => 6, 'weight' => 180, 'foot' => 12],
|
||||
['height' => 5.92, 'weight' => 190, 'foot' => 11],
|
||||
['height' => 5.58, 'weight' => 170, 'foot' => 12],
|
||||
['height' => 5.92, 'weight' => 165, 'foot' => 10],
|
||||
];
|
||||
|
||||
const FEMALE = [
|
||||
['height' => 5, 'weight' => 100, 'foot' => 6],
|
||||
['height' => 5.5, 'weight' => 150, 'foot' => 8],
|
||||
['height' => 5.42, 'weight' => 130, 'foot' => 7],
|
||||
['height' => 5.75, 'weight' => 150, 'foot' => 9],
|
||||
];
|
||||
|
||||
public function testTextFilter() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
$filter = new NaiveBayesFilter();
|
||||
$filter->train('play', self::PLAY);
|
||||
$filter->train('noplay', self::NO_PLAY);
|
||||
|
||||
self::assertEqualsWithDelta(
|
||||
0.64,
|
||||
$filter->match('play', ['weather' => ['Sunny']], 1),
|
||||
0.01
|
||||
);
|
||||
}
|
||||
|
||||
public function testNumericFilter() : void
|
||||
{
|
||||
$filter = new NaiveBayesFilter();
|
||||
$filter->train('male', self::MALE);
|
||||
$filter->train('female', self::FEMALE);
|
||||
|
||||
self::assertEqualsWithDelta(
|
||||
0.64,
|
||||
$filter->match('play', ['height' => 6, 'weight' => 130, 'foot' => 8]),
|
||||
0.01
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Utils\RnG;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class AddressTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Utils\RnG;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class CityTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Utils\RnG;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class EmailTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Utils\RnG;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class IBANTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Utils\RnG;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class NumericTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Utils\RnG;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class PostalZipTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user