diff --git a/Algorithm/PathFinding/Grid.php b/Algorithm/PathFinding/Grid.php index c80941125..f2f2b52de 100644 --- a/Algorithm/PathFinding/Grid.php +++ b/Algorithm/PathFinding/Grid.php @@ -74,6 +74,7 @@ class Grid $y = $node->getY(); $neighbors = []; + $s0 = false; $s1 = false; $s2 = false; diff --git a/Algorithm/PathFinding/Heuristic.php b/Algorithm/PathFinding/Heuristic.php index 3ce2fe7a0..8982db5ff 100644 --- a/Algorithm/PathFinding/Heuristic.php +++ b/Algorithm/PathFinding/Heuristic.php @@ -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) { diff --git a/Algorithm/PathFinding/Node.php b/Algorithm/PathFinding/Node.php index 90ac1e220..a579d8bc8 100644 --- a/Algorithm/PathFinding/Node.php +++ b/Algorithm/PathFinding/Node.php @@ -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]; diff --git a/Algorithm/PathFinding/NullJumpPointNode.php b/Algorithm/PathFinding/NullJumpPointNode.php index fe2dcbaa4..f43dd54ea 100644 --- a/Algorithm/PathFinding/NullJumpPointNode.php +++ b/Algorithm/PathFinding/NullJumpPointNode.php @@ -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 { -} \ No newline at end of file +} diff --git a/Algorithm/PathFinding/NullNode.php b/Algorithm/PathFinding/NullNode.php index 1eba27481..58e00320b 100644 --- a/Algorithm/PathFinding/NullNode.php +++ b/Algorithm/PathFinding/NullNode.php @@ -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 diff --git a/Business/Finance/Depreciation.php b/Business/Finance/Depreciation.php index d7913bdcd..237f6e9ed 100644 --- a/Business/Finance/Depreciation.php +++ b/Business/Finance/Depreciation.php @@ -30,7 +30,7 @@ final class Depreciation * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } diff --git a/Business/Finance/FinanceFormulas.php b/Business/Finance/FinanceFormulas.php index 55d3d754d..fe6ef0277 100644 --- a/Business/Finance/FinanceFormulas.php +++ b/Business/Finance/FinanceFormulas.php @@ -35,7 +35,7 @@ final class FinanceFormulas * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } diff --git a/Business/Finance/Loan.php b/Business/Finance/Loan.php index 3188d0014..4ef44ef5d 100644 --- a/Business/Finance/Loan.php +++ b/Business/Finance/Loan.php @@ -33,7 +33,7 @@ final class Loan * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } diff --git a/Business/Finance/Lorenzkurve.php b/Business/Finance/Lorenzkurve.php index 14cc86414..33ff03685 100644 --- a/Business/Finance/Lorenzkurve.php +++ b/Business/Finance/Lorenzkurve.php @@ -30,7 +30,7 @@ final class Lorenzkurve * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } diff --git a/Business/Finance/StockBonds.php b/Business/Finance/StockBonds.php index 90c7353f3..0217e9491 100644 --- a/Business/Finance/StockBonds.php +++ b/Business/Finance/StockBonds.php @@ -33,7 +33,7 @@ final class StockBonds * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } diff --git a/Business/Marketing/Metrics.php b/Business/Marketing/Metrics.php index 33e8d8c0a..892df1579 100644 --- a/Business/Marketing/Metrics.php +++ b/Business/Marketing/Metrics.php @@ -32,8 +32,8 @@ final class Metrics * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() - { + private function __construct() + { } /** diff --git a/Business/Programming/Metrics.php b/Business/Programming/Metrics.php index 4964ecf74..d6a1f3315 100644 --- a/Business/Programming/Metrics.php +++ b/Business/Programming/Metrics.php @@ -32,7 +32,7 @@ final class Metrics * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } diff --git a/Business/Sales/MarketShareEstimation.php b/Business/Sales/MarketShareEstimation.php index 603256a3d..c591a7762 100644 --- a/Business/Sales/MarketShareEstimation.php +++ b/Business/Sales/MarketShareEstimation.php @@ -33,7 +33,7 @@ final class MarketShareEstimation * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } diff --git a/Math/Stochastic/Distribution/BinomialDistribution.php b/Math/Stochastic/Distribution/BinomialDistribution.php index f8c0cdaaa..dc736fcb1 100644 --- a/Math/Stochastic/Distribution/BinomialDistribution.php +++ b/Math/Stochastic/Distribution/BinomialDistribution.php @@ -35,8 +35,6 @@ class BinomialDistribution * * @return float * - * @throws \Exception - * * @since 1.0.0 */ public static function getMode(int $n, float $p) : float diff --git a/Math/Stochastic/Distribution/GammaDistribution.php b/Math/Stochastic/Distribution/GammaDistribution.php index 446f3ef92..5f84455fe 100644 --- a/Math/Stochastic/Distribution/GammaDistribution.php +++ b/Math/Stochastic/Distribution/GammaDistribution.php @@ -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); + } } diff --git a/Math/Stochastic/NaiveBayesFilter.php b/Math/Stochastic/NaiveBayesFilter.php index 89f943d91..e04bddf94 100644 --- a/Math/Stochastic/NaiveBayesFilter.php +++ b/Math/Stochastic/NaiveBayesFilter.php @@ -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]), + ]; + } + } + } } } diff --git a/Math/Topology/Metrics2D.php b/Math/Topology/Metrics2D.php index fe3729048..062f4a4e9 100644 --- a/Math/Topology/Metrics2D.php +++ b/Math/Topology/Metrics2D.php @@ -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; } diff --git a/Utils/Barcode/Datamatrix.php b/Utils/Barcode/Datamatrix.php index d5856600c..a8dfb0b7c 100644 --- a/Utils/Barcode/Datamatrix.php +++ b/Utils/Barcode/Datamatrix.php @@ -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 diff --git a/Utils/Barcode/HIBCC.php b/Utils/Barcode/HIBCC.php index d88936e5b..de7a9139a 100644 --- a/Utils/Barcode/HIBCC.php +++ b/Utils/Barcode/HIBCC.php @@ -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 ''; diff --git a/Utils/Barcode/QR.php b/Utils/Barcode/QR.php index b58c9b2ad..9146c7d1e 100644 --- a/Utils/Barcode/QR.php +++ b/Utils/Barcode/QR.php @@ -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 diff --git a/Utils/Excel/Excel.php b/Utils/Excel/Excel.php index cc99df287..6435d6a75 100644 --- a/Utils/Excel/Excel.php +++ b/Utils/Excel/Excel.php @@ -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 { } diff --git a/Utils/PDF/Pdf.php b/Utils/PDF/Pdf.php index 6e45a897b..cfd6278ae 100644 --- a/Utils/PDF/Pdf.php +++ b/Utils/PDF/Pdf.php @@ -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 { } diff --git a/Utils/RnG/Address.php b/Utils/RnG/Address.php deleted file mode 100644 index 8c1c30547..000000000 --- a/Utils/RnG/Address.php +++ /dev/null @@ -1,19 +0,0 @@ - '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 + ); } } diff --git a/tests/Utils/RnG/AddressTest.php b/tests/Utils/RnG/AddressTest.php deleted file mode 100644 index f1cd3cf9e..000000000 --- a/tests/Utils/RnG/AddressTest.php +++ /dev/null @@ -1,26 +0,0 @@ -