From 777f084a397e8da06a3669eb0bd2830f81837d1b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 22 Dec 2016 21:16:05 +0100 Subject: [PATCH] Fix dockblocks and minor bugs --- Algorithm/Knappsack/Backpack.php | 1 + Config/SettingsAbstract.php | 2 +- DataStorage/Database/DataMapperAbstract.php | 2 +- Localization/L11nManager.php | 2 +- Localization/Localization.php | 2 - Math/Finance/Forecasting/AR.php | 17 +- Math/Finance/Forecasting/ARCH.php | 17 +- Math/Finance/Forecasting/ARFIMA.php | 17 +- Math/Finance/Forecasting/ARIMA.php | 27 ++- Math/Finance/Forecasting/ARMA.php | 17 +- .../Forecasting/ClassicalDecomposition.php | 169 ++++++++++++++++-- .../Forecasting/ExponentialSmoothing.php | 17 +- .../ExponentialSmoothing/Brown.php | 92 ++++++---- Math/Finance/Forecasting/GARCH.php | 17 +- Math/Finance/Forecasting/MA.php | 17 +- Math/Finance/Forecasting/NAR.php | 17 +- Math/Finance/Forecasting/NMA.php | 17 +- Math/Finance/Forecasting/SARIMA.php | 17 +- Math/Functions/Functions.php | 8 +- Math/Optimization/Graph/Dijkstra.php | 17 +- Math/Optimization/Graph/FloydWarshall.php | 17 +- Math/Optimization/Knappsack/Backpack.php | 17 +- Math/Optimization/Knappsack/BruteForce.php | 17 +- Math/Optimization/Knappsack/GA.php | 17 +- Math/Optimization/Knappsack/Item.php | 17 +- Math/Optimization/Knappsack/ItemPool.php | 17 +- Math/Optimization/Knappsack/Population.php | 17 +- .../ShiftScheduling/BruteForce.php | 17 +- Math/Optimization/ShiftScheduling/GA.php | 17 +- .../ShiftScheduling/Population.php | 17 +- Math/Optimization/ShiftScheduling/Workday.php | 17 +- Math/Optimization/ShiftScheduling/Worker.php | 17 +- .../ShiftScheduling/WorkerPool.php | 17 +- Math/Shape/D2/Polygon.php | 61 +++++-- Math/Shape/D2/Quadrilateral.php | 16 +- Math/Shape/D3/Prism.php | 16 +- Math/Shape/D3/Sphere.php | 81 ++++++++- Math/Statistic/Average.php | 30 ++-- Math/Statistic/Forecast/Error.php | 55 +++++- .../Forecast/ForecastIntervalMultiplier.php | 2 +- Math/Statistic/Forecast/Forecasts.php | 7 +- .../Regression/LevelLogRegression.php | 2 +- .../Regression/LogLevelRegression.php | 2 +- .../Forecast/Regression/LogLogRegression.php | 4 +- .../Regression/MultipleLinearRegression.php | 23 ++- .../Regression/RegressionAbstract.php | 19 +- .../Distribution/BetaDistribution.php | 17 +- .../Distribution/BinomialDistribution.php | 2 +- .../Distribution/ChiSquaredDistribution.php | 2 +- .../Stochastic/Distribution/FDistribution.php | 17 +- .../Distribution/GammaDistribution.php | 17 +- .../HypergeometricDistribution.php | 17 +- .../Distribution/LogDistribution.php | 17 +- .../Distribution/LogNormalDistribution.php | 17 +- .../Distribution/LogisticDistribution.php | 17 +- .../Distribution/ParetoDistribution.php | 17 +- .../Distribution/PoissonDistribution.php | 2 +- .../Stochastic/Distribution/TDistribution.php | 17 +- .../Distribution/WeibullDistribution.php | 17 +- Message/Mail/OAuth.php | 17 +- Message/Mail/Pop3.php | 17 +- Message/Mail/Smtp.php | 17 +- Message/Socket/Request.php | 17 +- Message/Socket/Response.php | 17 +- Module/ActivateAbstract.php | 4 +- Module/DeactivateAbstract.php | 4 +- Module/InstallerAbstract.php | 6 +- Module/UninstallAbstract.php | 2 +- Module/UpdateAbstract.php | 2 +- Stdlib/Collection/Collection.php | 16 +- Stdlib/Graph/BinaryTree.php | 12 +- Stdlib/Graph/Graph.php | 125 ++++++++----- Stdlib/Graph/Tree.php | 4 +- Stdlib/Queue/PriorityQueue.php | 6 +- System/File/Local/Directory.php | 1 + System/File/Local/File.php | 31 ++++ Utils/ArrayUtils.php | 27 +-- Utils/Barcode/C128Abstract.php | 7 +- Utils/Barcode/HIBCC.php | 6 +- Utils/TaskSchedule/Schedule.php | 4 +- Utils/TaskSchedule/SchedulerAbstract.php | 1 + Utils/TaskSchedule/SchedulerFactory.php | 2 +- Utils/TaskSchedule/TaskAbstract.php | 2 +- Utils/TaskSchedule/TaskFactory.php | 2 +- Utils/TaskSchedule/TaskScheduler.php | 6 +- Views/View.php | 8 +- 86 files changed, 1279 insertions(+), 291 deletions(-) diff --git a/Algorithm/Knappsack/Backpack.php b/Algorithm/Knappsack/Backpack.php index 34812a24b..9054f219f 100644 --- a/Algorithm/Knappsack/Backpack.php +++ b/Algorithm/Knappsack/Backpack.php @@ -14,6 +14,7 @@ * @link http://orange-management.com */ namespace phpOMS\Algorithm\Knappsack; +use phpOMS\Algorithm\AlgorithmType; /** * Knappsack algorithm implementations diff --git a/Config/SettingsAbstract.php b/Config/SettingsAbstract.php index 32534bf28..a50409466 100644 --- a/Config/SettingsAbstract.php +++ b/Config/SettingsAbstract.php @@ -39,7 +39,7 @@ abstract class SettingsAbstract implements OptionsInterface /** * Cache manager (pool). * - * @var \phpOMS\DataStorage\Cache\Pool + * @var \phpOMS\DataStorage\Cache\CachePool * @since 1.0.0 */ protected $cache = null; diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 4dafcaea8..c2e948cbe 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -1146,7 +1146,7 @@ class DataMapperAbstract implements DataMapperInterface { $query = new Builder(self::$db); $query->prefix(self::$db->getPrefix()) - ->random(static::$primaryKey) + ->random(static::$primaryField) ->from(static::$table) ->limit($amount); diff --git a/Localization/L11nManager.php b/Localization/L11nManager.php index 77d9d8a6e..df2a8442f 100644 --- a/Localization/L11nManager.php +++ b/Localization/L11nManager.php @@ -126,7 +126,7 @@ class L11nManager public function loadLanguageFromFile(string $language, string $from, string $file) /* : void */ { $lang = []; - if (file_exists(file)) { + if (file_exists($file)) { /** @noinspection PhpIncludeInspection */ $lang = include $file; } diff --git a/Localization/Localization.php b/Localization/Localization.php index 5d656a169..abb04bd93 100644 --- a/Localization/Localization.php +++ b/Localization/Localization.php @@ -143,8 +143,6 @@ class Localization /** * Constructor. * - * @param L11nManager $l11nManager Localization manager - * * @since 1.0.0 * @author Dennis Eichhorn */ diff --git a/Math/Finance/Forecasting/AR.php b/Math/Finance/Forecasting/AR.php index 7dd4a76d8..c5d1ee8d9 100644 --- a/Math/Finance/Forecasting/AR.php +++ b/Math/Finance/Forecasting/AR.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class AR { diff --git a/Math/Finance/Forecasting/ARCH.php b/Math/Finance/Forecasting/ARCH.php index f2e8e260a..346686a61 100644 --- a/Math/Finance/Forecasting/ARCH.php +++ b/Math/Finance/Forecasting/ARCH.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class ARCH { diff --git a/Math/Finance/Forecasting/ARFIMA.php b/Math/Finance/Forecasting/ARFIMA.php index ed0357ac6..2d9a6ed01 100644 --- a/Math/Finance/Forecasting/ARFIMA.php +++ b/Math/Finance/Forecasting/ARFIMA.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class ARFIMA { diff --git a/Math/Finance/Forecasting/ARIMA.php b/Math/Finance/Forecasting/ARIMA.php index 2ca1ce104..ef7303209 100644 --- a/Math/Finance/Forecasting/ARIMA.php +++ b/Math/Finance/Forecasting/ARIMA.php @@ -1,13 +1,34 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; -namespace phpOMS\Math\Finance\Forecasting; +use phpOMS\Math\Statistic\Average; class ARIMA { + private $data = []; + private $order = 0; + public function __construct(array $data, int $order = 12) { + $this->data = $data; + $this->order = $order; + if ($order !== 12 && $order !== 4) { - throw new \Exceptions('ARIMA only supports quarterly and monthly decomposition'); + throw new \Exception('ARIMA only supports quarterly and monthly decomposition'); } } @@ -67,7 +88,7 @@ class ARIMA private function removeOutliers(array $data, float $deviation = 0.5) : array { - $avg = AVerage::arithmeticMean($data); + $avg = Average::arithmeticMean($data); foreach ($data as $key => $value) { if ($value / $avg - 1 > $deviation) { diff --git a/Math/Finance/Forecasting/ARMA.php b/Math/Finance/Forecasting/ARMA.php index 50c4a4a3f..060e712bd 100644 --- a/Math/Finance/Forecasting/ARMA.php +++ b/Math/Finance/Forecasting/ARMA.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class ARMA { diff --git a/Math/Finance/Forecasting/ClassicalDecomposition.php b/Math/Finance/Forecasting/ClassicalDecomposition.php index 45ff19a83..b5ae2272d 100644 --- a/Math/Finance/Forecasting/ClassicalDecomposition.php +++ b/Math/Finance/Forecasting/ClassicalDecomposition.php @@ -1,19 +1,96 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ namespace phpOMS\Math\Finance\Forecasting; use phpOMS\Math\Statistic\Average; +/** + * Classical decomposition class. + * + * This can be used to simplify time series patterns for forecasts. + * + * @category Framework + * @package phpOMS\Math\Finance\Forecasting + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @see https://www.otexts.org/fpp/6/1 + * @since 1.0.0 + */ class ClassicalDecomposition { + /** + * Decomposition mode. + * + * @var int + * @since 1.0.0 + */ /* public */ const ADDITIVE = 0; + + /** + * Decomposition mode. + * + * @var int + * @since 1.0.0 + */ /* public */ const MULTIPLICATIVE = 1; + /** + * Decomposition mode. + * + * @var int + * @since 1.0.0 + */ private $mode = self::ADDITIVE; + + /** + * Raw data. + * + * @var array + * @since 1.0.0 + */ private $data = []; + + /** + * Order or seasonal period. + * + * @var int + * @since 1.0.0 + */ private $order = 0; + + /** + * Raw data size. + * + * @var int + * @since 1.0.0 + */ private $dataSize = 0; + /** + * Constructor. + * + * @param array $data Historic data + * @param int $order Seasonal period (e.g. 4 = quarterly, 12 = monthly, 7 = weekly pattern in daily data) + * @param int $mode Decomposition mode + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function __construct(array $data, int $order, int $mode = self::ADDITIVE) { $this->mode = $mode; @@ -23,12 +100,20 @@ class ClassicalDecomposition $this->dataSize = count($data); } + /** + * Get decomposition. + * + * @return array Returns an array containing the trend cycle component, detrended series, seasonal component and remainder component. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getDecomposition() : array { $trendCycleComponent = self::computeTrendCycle($this->data, $this->order); $detrendedSeries = self::computeDetrendedSeries($this->data, $trendCycleComponent, $this->mode); $seasonalComponent = $this->computeSeasonalComponent($detrendedSeries, $this->order); - $remainderComponent = $this->computeRemainderComponent($trendCycleComponent, $seasonalComponent); + $remainderComponent = self::computeRemainderComponent($this->data, $trendCycleComponent, $seasonalComponent, $this->mode); return [ 'trendCycleComponent' => $trendCycleComponent, @@ -38,13 +123,36 @@ class ClassicalDecomposition ]; } + /** + * Calculate trend cycle + * + * @param array $data Data to analyze + * @param int $order Seasonal period (e.g. 4 = quarterly, 12 = monthly, 7 = weekly pattern in daily data) + * + * @return array Total moving average 2 x m-MA + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function computeTrendCycle(array $data, int $order) : array { $mMA = Average::totalMovingAverage($data, $order, null, true); - return $order % 2 === 0 ? Average::totalMovingAverage($mMA, 2, null, true) : $mMA; + return $order % 2 === 0 ? Average::totalMovingAverage($mMA, $order, null, true) : $mMA; } + /** + * Calculate detrended series + * + * @param array $data Data to analyze + * @param array $trendCycleComponent Trend cycle component + * @param int $mode Detrend mode + * + * @return array Detrended series / seasonal normalized data + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function computeDetrendedSeries(array $data, array $trendCycleComponent, int $mode) : array { $detrended = []; @@ -59,23 +167,46 @@ class ClassicalDecomposition } /** - * Moving average can't start at index 0 since it needs to go m indices back for average -> can only start at m + * Calculate the data start point for the decomposition + * + * By using averaging methods some initial data get's incorporated into the average which reduces the data points. + * + * @param int $dataSize Original data size + * @param int $trendCycleComponents Trend cycle component size + * + * @return int New data start index + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int { return ($dataSize - $trendCycleComponents) / 2; } - private function computeSeasonalComponent() : array + /** + * Calculate the seasonal component + * + * Average of the detrended values for every month, quarter, day etc. + * + * @param array $detrendedSeries Detrended series + * @param int $order Seasonal period (e.g. 4 = quarterly, 12 = monthly, 7 = weekly pattern in daily data) + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + private function computeSeasonalComponent(array $detrendedSeries, int $order) : array { $seasonalComponent = []; - $count = count($this->data); + $count = count($detrendedSeries); - for ($i = 0; $i < $this->dataSize; $i++) { + for ($i = 0; $i < $order; $i++) { $temp = []; - for ($j = $i * $this->order; $j < $count; $j += $this->order) { - $temp[] = $this->data[$j]; + for ($j = $i; $j < $count; $j += $order) { + $temp[] = $detrendedSeries[$j]; } $seasonalComponent[] = Average::arithmeticMean($temp); @@ -84,15 +215,29 @@ class ClassicalDecomposition return $seasonalComponent; } - public static function computeRemainderComponent(array $trendCycleComponent, array $seasonalComponent) : array + /** + * Calculate the remainder component or error + * + * @param array $data Raw data + * @param array $trendCycleComponent Trend cycle component + * @param array $seasonalComponent Seasonal component + * @param int $mode Detrend mode + * + * @return array All remainders or absolute errors + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function computeRemainderComponent(array $data, array $trendCycleComponent, array $seasonalComponent, int $mode = self::ADDITIVE) : array { + $dataSize = count($data); $remainderComponent = []; $count = count($trendCycleComponent); - $start = self::getStartOfDecomposition($this->dataSize, $count); + $start = self::getStartOfDecomposition($dataSize, $count); $seasons = count($seasonalComponent); for ($i = 0; $i < $count; $i++) { - $remainderComponent[] = $this->mode === self::ADDITIVE ? $this->data[$start + $i] - $trendCycleComponent[$i] - $seasonalComponent[$i % $seasons] : $this->data[$start + $i] / ($trendCycleComponent[$i] * $seasonalComponent[$i % $seasons]); + $remainderComponent[] = $mode === self::ADDITIVE ? $data[$start + $i] - $trendCycleComponent[$i] - $seasonalComponent[$i % $seasons] : $data[$start + $i] / ($trendCycleComponent[$i] * $seasonalComponent[$i % $seasons]); } return $remainderComponent; diff --git a/Math/Finance/Forecasting/ExponentialSmoothing.php b/Math/Finance/Forecasting/ExponentialSmoothing.php index 107efdfb6..cb8cf442c 100644 --- a/Math/Finance/Forecasting/ExponentialSmoothing.php +++ b/Math/Finance/Forecasting/ExponentialSmoothing.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class ExponentialSmoothing { diff --git a/Math/Finance/Forecasting/ExponentialSmoothing/Brown.php b/Math/Finance/Forecasting/ExponentialSmoothing/Brown.php index dd1a86a34..8ea58cbf0 100644 --- a/Math/Finance/Forecasting/ExponentialSmoothing/Brown.php +++ b/Math/Finance/Forecasting/ExponentialSmoothing/Brown.php @@ -1,8 +1,22 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; -namespace phpOMS\Math\Finance\Forecasting; - -use phpOMS\Math\Finance\Forecasting\SmoothingType; +use phpOMS\Math\Statistic\Average; +use phpOMS\Math\Statistic\Forecast\Error; class Brown { @@ -19,10 +33,10 @@ class Brown private $mae = 0.0; private $sse = 0.0; - + public function __construct(array $data, int $cycle = 0) { - $this->data = $data; + $this->data = $data; $this->cycle = $cycle; } @@ -33,7 +47,7 @@ class Brown public function getRMSE() : float { - return $this->getRMSE; + return $this->rmse; } public function getMSE() : float @@ -58,13 +72,13 @@ class Brown public function getForecast(int $future = 1, int $smoothing = SmoothingType::CENTERED_MOVING_AVERAGE) : array { - $trendCycle = $this->getTrendCycle($this->$cycle); - $seasonality = $this->getSeasonality($trendCycle); - $seasonalityIndexMap = $this->generateSeasonalityMap($this->cycle, $seasonality); + $trendCycle = $this->getTrendCycle($this->cycle); + $seasonality = $this->getSeasonality($trendCycle); + $seasonalityIndexMap = $this->generateSeasonalityMap($this->cycle, $seasonality); $adjustedSeasonalityIndexMap = $this->generateAdjustedSeasonalityMap($this->cycle, $seasonalityIndexMap); - $seasonalIndex = $this->getSeasonalIndex($this->cycle, $adjustedSeasonalityIndexMap); - $adjustedData = $this->getAdjustedData($this->cycle, $seasonalIndex); - $optimizedForecast = $this->getOptimizedForecast($future, $adjustedData); + $seasonalIndex = $this->getSeasonalIndex($this->cycle, $adjustedSeasonalityIndexMap); + $adjustedData = $this->getAdjustedData($this->cycle, $seasonalIndex); + $optimizedForecast = $this->getOptimizedForecast($future, $adjustedData); return $this->getReseasonalized($optimizedForecast, $seasonalIndex); } @@ -74,8 +88,8 @@ class Brown $centeredMovingAverage = []; $length = count($this->data); - for($i = $cycle; $i < $length - $cycle; $i++) { - $centeredMovingAverage[$i] = Average::arithmetic(array_slice($this->data, $i - $cycle, $cycle)); + for ($i = $cycle; $i < $length - $cycle; $i++) { + $centeredMovingAverage[$i] = Average::arithmeticMean(array_slice($this->data, $i - $cycle, $cycle)); } return $centeredMovingAverage; @@ -84,21 +98,21 @@ class Brown private function getSeasonality(array $trendCycle) : array { $seasonality = []; - foreach($trendCycle as $key => $value) { - $seasonality[$key] = $this->data[$key]/$value; + foreach ($trendCycle as $key => $value) { + $seasonality[$key] = $this->data[$key] / $value; } return $seasonality; } - private function generateSeasonality(int $cycle, array $seasonality) : array + private function generateSeasonalityMap(int $cycle, array $seasonality) : array { $map = []; - foreach($seasonality as $key => $value) { + foreach ($seasonality as $key => $value) { $map[$key % $cycle][] = $value; } - foreach($map as $key => $value) { + foreach ($map as $key => $value) { $map[$key] = Average::arithmeticMean($value); } @@ -109,7 +123,7 @@ class Brown { $total = array_sum($seasonality); - foreach($seasonality as $key => $value) { + foreach ($seasonality as $key => $value) { $seasonality[$key] = $cycle * $value / $total; } @@ -120,7 +134,7 @@ class Brown { $index = []; - foreach($this->data as $key => $value) { + foreach ($this->data as $key => $value) { $index[$key] = $seasonalityMap[$key % $cycle]; } @@ -131,7 +145,7 @@ class Brown { $adjusted = []; - foreach($this->data as $key => $value) { + foreach ($this->data as $key => $value) { $adjusted[$key] = $this->data[$key] / $seasonalIndex[$key]; } @@ -141,7 +155,7 @@ class Brown private function forecast(int $future, float $alpha, array $data, array &$error) : array { $forecast = []; - $length = count($data) + $future; + $length = count($data) + $future; $forecast[0] = $data[0]; $forecast[1] = $data[1]; @@ -149,46 +163,46 @@ class Brown $error[0] = 0; $error[1] = $data[1] - $forecast[1]; - for($i = 2; $i < $length; $i++) { - $forecast[$i] = 2 * $data[$i-1] - $data[$i - 2] - 2 * (1 - $alpha) * $error[$i-1] + pow(1-$alpah, 2) * $error[$i - 2]; - $error[$i] = $data[$i] - $forecast[$i]; + for ($i = 2; $i < $length; $i++) { + $forecast[$i] = 2 * $data[$i - 1] - $data[$i - 2] - 2 * (1 - $alpha) * $error[$i - 1] + pow(1 - $alpha, 2) * $error[$i - 2]; + $error[$i] = $data[$i] - $forecast[$i]; } return $forecast; - } + } private function getOptimizedForecast(int $future, array $adjustedData) : array { - $rmse = 0; - $alpha = 0.00; - $forecast = []; + $this->rmse = 0; + $alpha = 0.00; + $forecast = []; + $error = []; - while($alpha < 1) { - $error = []; + while ($alpha < 1) { $tempForecast = $this->forecast($future, $alpha, $adjustedData, $error); $alpha += 0.01; $tempRMSE = Error::getRootMeanSquaredError($error); - if($tempRMSE < $this->rmse) { + if ($tempRMSE < $this->rmse) { $this->rmse = $tempRMSE; - $forecast = $tempForecast; + $forecast = $tempForecast; } } $this->errors = $error; - $this->mse = Error::getMeanSquaredError($error); - $this->mae = Error::getMeanAbsoluteError($error); - $this->sse = Error::getSumSquaredError($error); + $this->mse = Error::getMeanSquaredError($error); + $this->mae = Error::getMeanAbsoulteError($error); + $this->sse = Error::getSumSquaredError($error); return $forecast; } - private function getReseasonalized(array $forecast, array $seasonalIndex) : array + private function getReseasonalized(array $forecast, array $seasonalIndex) : array { $reSeasonalized = []; - foreach($forecast as $key => $value) { + foreach ($forecast as $key => $value) { $reSeasonalized[$key] = $value * $seasonalIndex[$key]; } diff --git a/Math/Finance/Forecasting/GARCH.php b/Math/Finance/Forecasting/GARCH.php index 36a6ab57d..c1cd261e6 100644 --- a/Math/Finance/Forecasting/GARCH.php +++ b/Math/Finance/Forecasting/GARCH.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class GARCH { diff --git a/Math/Finance/Forecasting/MA.php b/Math/Finance/Forecasting/MA.php index 664b5de94..2959b464e 100644 --- a/Math/Finance/Forecasting/MA.php +++ b/Math/Finance/Forecasting/MA.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class MA { diff --git a/Math/Finance/Forecasting/NAR.php b/Math/Finance/Forecasting/NAR.php index 8c18b5071..2ee9e44b3 100644 --- a/Math/Finance/Forecasting/NAR.php +++ b/Math/Finance/Forecasting/NAR.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class NAR { diff --git a/Math/Finance/Forecasting/NMA.php b/Math/Finance/Forecasting/NMA.php index 25f062ce3..e93611ee3 100644 --- a/Math/Finance/Forecasting/NMA.php +++ b/Math/Finance/Forecasting/NMA.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class NMA { diff --git a/Math/Finance/Forecasting/SARIMA.php b/Math/Finance/Forecasting/SARIMA.php index 7e3c2c9dc..448befb59 100644 --- a/Math/Finance/Forecasting/SARIMA.php +++ b/Math/Finance/Forecasting/SARIMA.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Finance\Forecasting; class SARIMA { diff --git a/Math/Functions/Functions.php b/Math/Functions/Functions.php index b972f3790..6c3a59e6b 100644 --- a/Math/Functions/Functions.php +++ b/Math/Functions/Functions.php @@ -231,7 +231,7 @@ class Functions * * @param int $a Value to test * - * @return int + * @return bool * * @since 1.0.0 * @author Dennis Eichhorn @@ -250,7 +250,7 @@ class Functions * * @param int $a Value to test * - * @return int + * @return bool * * @since 1.0.0 * @author Dennis Eichhorn @@ -270,7 +270,9 @@ class Functions * @example The relative fiscal month (August) in a company where the fiscal year starts in July. * @example 2 = getRelativeDegree(8, 12, 7); * - * @param int $a Value to test + * @param mixed $value Value to get degree + * @param mixed $length Circle size + * @param mixed $start Start value * * @return int * diff --git a/Math/Optimization/Graph/Dijkstra.php b/Math/Optimization/Graph/Dijkstra.php index 506a6a95e..fbddbc73a 100644 --- a/Math/Optimization/Graph/Dijkstra.php +++ b/Math/Optimization/Graph/Dijkstra.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\Graph; class Dijkstra { diff --git a/Math/Optimization/Graph/FloydWarshall.php b/Math/Optimization/Graph/FloydWarshall.php index d127d73b6..6d239ed65 100644 --- a/Math/Optimization/Graph/FloydWarshall.php +++ b/Math/Optimization/Graph/FloydWarshall.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\Graph; class FloydWarshall { diff --git a/Math/Optimization/Knappsack/Backpack.php b/Math/Optimization/Knappsack/Backpack.php index 0f319a8e0..c18dcfa8d 100644 --- a/Math/Optimization/Knappsack/Backpack.php +++ b/Math/Optimization/Knappsack/Backpack.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\Knappsack; class Backpack { diff --git a/Math/Optimization/Knappsack/BruteForce.php b/Math/Optimization/Knappsack/BruteForce.php index 09117ebc5..c38aefd29 100644 --- a/Math/Optimization/Knappsack/BruteForce.php +++ b/Math/Optimization/Knappsack/BruteForce.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\Knappsack; class BruteForce { diff --git a/Math/Optimization/Knappsack/GA.php b/Math/Optimization/Knappsack/GA.php index 47affae40..5f17010f6 100644 --- a/Math/Optimization/Knappsack/GA.php +++ b/Math/Optimization/Knappsack/GA.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\Knappsack; class GA { diff --git a/Math/Optimization/Knappsack/Item.php b/Math/Optimization/Knappsack/Item.php index a6a21b61c..3a35d19d3 100644 --- a/Math/Optimization/Knappsack/Item.php +++ b/Math/Optimization/Knappsack/Item.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\Knappsack; class Item { diff --git a/Math/Optimization/Knappsack/ItemPool.php b/Math/Optimization/Knappsack/ItemPool.php index a9e6d4888..ddb499e7e 100644 --- a/Math/Optimization/Knappsack/ItemPool.php +++ b/Math/Optimization/Knappsack/ItemPool.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\Knappsack; class ItemPool { diff --git a/Math/Optimization/Knappsack/Population.php b/Math/Optimization/Knappsack/Population.php index 60adf9a8a..ad44294ce 100644 --- a/Math/Optimization/Knappsack/Population.php +++ b/Math/Optimization/Knappsack/Population.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\Knappsack; class Population { diff --git a/Math/Optimization/ShiftScheduling/BruteForce.php b/Math/Optimization/ShiftScheduling/BruteForce.php index 7a81fd842..6240ee410 100644 --- a/Math/Optimization/ShiftScheduling/BruteForce.php +++ b/Math/Optimization/ShiftScheduling/BruteForce.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\ShiftScheduling; class BruteForce { diff --git a/Math/Optimization/ShiftScheduling/GA.php b/Math/Optimization/ShiftScheduling/GA.php index 114e9f249..b243846e4 100644 --- a/Math/Optimization/ShiftScheduling/GA.php +++ b/Math/Optimization/ShiftScheduling/GA.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\ShiftScheduling; class GA { diff --git a/Math/Optimization/ShiftScheduling/Population.php b/Math/Optimization/ShiftScheduling/Population.php index f97c84d1b..991389e51 100644 --- a/Math/Optimization/ShiftScheduling/Population.php +++ b/Math/Optimization/ShiftScheduling/Population.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\ShiftScheduling; class Population { diff --git a/Math/Optimization/ShiftScheduling/Workday.php b/Math/Optimization/ShiftScheduling/Workday.php index ffb989cb4..bbb15f446 100644 --- a/Math/Optimization/ShiftScheduling/Workday.php +++ b/Math/Optimization/ShiftScheduling/Workday.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\ShiftScheduling; class Workday { diff --git a/Math/Optimization/ShiftScheduling/Worker.php b/Math/Optimization/ShiftScheduling/Worker.php index 05db47abe..301d16c21 100644 --- a/Math/Optimization/ShiftScheduling/Worker.php +++ b/Math/Optimization/ShiftScheduling/Worker.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\ShiftScheduling; class Worker { diff --git a/Math/Optimization/ShiftScheduling/WorkerPool.php b/Math/Optimization/ShiftScheduling/WorkerPool.php index d7601c1db..1c012e2fd 100644 --- a/Math/Optimization/ShiftScheduling/WorkerPool.php +++ b/Math/Optimization/ShiftScheduling/WorkerPool.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Optimization\ShiftScheduling; class WorkerPool { diff --git a/Math/Shape/D2/Polygon.php b/Math/Shape/D2/Polygon.php index 678253016..5a86083a9 100644 --- a/Math/Shape/D2/Polygon.php +++ b/Math/Shape/D2/Polygon.php @@ -28,6 +28,13 @@ namespace phpOMS\Math\Shape\D2; */ class Polygon implements D2ShapeInterface { + /** + * Epsilon for float comparison. + * + * @var float + * @since 1.0.0 + */ + /* public */ const EPSILON = 0.00001; /** * Coordinates. @@ -123,28 +130,44 @@ class Polygon implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function pointInPolygon(array $point) : int + public function pointInPolygon(array $point) : int { - $length = count($this->coord); + return self::isPointInPolygon($point, $this->coord); + } + + /** + * Point polygon relative position + * + * @param array $point Point location + * @param array $polygon Polygon definition + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function isPointInPolygon(array $point, array $polygon) : int + { + $length = count($polygon); // Polygon has to start and end with same point - if ($this->coord[0]['x'] !== $this->coord[$length - 1]['x'] || $this->coord[0]['y'] !== $this->coord[$length - 1]['y']) { - $this->coord[] = $this->coord[0]; + if ($polygon[0]['x'] !== $polygon[$length - 1]['x'] || $polygon[0]['y'] !== $polygon[$length - 1]['y']) { + $polygon[] = $polygon[0]; } // On vertex? - if (self::isOnVertex($point, $this->coord)) { + if (self::isOnVertex($point, $polygon)) { return 0; } // Inside or ontop? $countIntersect = 0; - $this->coord_count = count($this->coord); + $polygon_count = count($polygon); // todo: return based on highest possibility not by first match - for ($i = 1; $i < $this->coord_count; $i++) { - $vertex1 = $this->coord[$i - 1]; - $vertex2 = $this->coord[$i]; + for ($i = 1; $i < $polygon_count; $i++) { + $vertex1 = $polygon[$i - 1]; + $vertex2 = $polygon[$i]; if (abs($vertex1['y'] - $vertex2['y']) < self::EPSILON && abs($vertex1['y'] - $point['y']) < self::EPSILON && $point['x'] > min($vertex1['x'], $vertex2['x']) && $point['x'] < max($vertex1['x'], $vertex2['x'])) { return 0; // boundary @@ -180,9 +203,25 @@ class Polygon implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - private static function isOnVertex(array $point) : bool + public function onVertex(array $point) : bool { - foreach ($this->coord as $vertex) { + return self::isOnVertex($point, $this->coord); + } + + /** + * Is point on vertex? + * + * @param array $point Point location + * @param array $polygon Polygon definition + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + private static function isOnVertex(array $point, array $polygon) : bool + { + foreach ($polygon as $vertex) { if (abs($point['x'] - $vertex['x']) < self::EPSILON && abs($point['y'] - $vertex['y']) < self::EPSILON) { return true; } diff --git a/Math/Shape/D2/Quadrilateral.php b/Math/Shape/D2/Quadrilateral.php index d5c529951..959611f83 100644 --- a/Math/Shape/D2/Quadrilateral.php +++ b/Math/Shape/D2/Quadrilateral.php @@ -1,5 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Shape\D2; class Quadrilateral implements D2ShapeInterface { diff --git a/Math/Shape/D3/Prism.php b/Math/Shape/D3/Prism.php index 5849f25cc..91d86ec2c 100644 --- a/Math/Shape/D3/Prism.php +++ b/Math/Shape/D3/Prism.php @@ -1,5 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Shape\D3; class Prism implements D3ShapeInterface { diff --git a/Math/Shape/D3/Sphere.php b/Math/Shape/D3/Sphere.php index ac46871fd..dc2a35651 100644 --- a/Math/Shape/D3/Sphere.php +++ b/Math/Shape/D3/Sphere.php @@ -19,7 +19,7 @@ namespace phpOMS\Math\Shape\D3; * Sphere shape. * * @category Framework - * @package phpOMS\DataStorage\Database + * @package phpOMS\Math\Shape * @author OMS Development Team * @author Dennis Eichhorn * @license OMS License 1.0 @@ -28,7 +28,22 @@ namespace phpOMS\Math\Shape\D3; */ class Sphere implements D3ShapeInterface { + /** + * Radius. + * + * @var float + * @since 1.0.0 + */ + private $radius = 0.0; + /** + * Constructor. + * + * @param float $radius Sphere radius + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function __construct(float $radius) { $this->radius = $radius; @@ -68,11 +83,31 @@ class Sphere implements D3ShapeInterface return $angle * $radius; } + /** + * Create sphere by radius + * + * @param float $r Radius + * + * @return Sphere + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function byRadius(float $r) : Sphere { return new self($r); } + /** + * Create sphere by volume + * + * @param float $v Sphere volume + * + * @return Sphere + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function byVolume(float $v) : Sphere { return new self(self::getRadiusByVolume($v)); @@ -81,25 +116,35 @@ class Sphere implements D3ShapeInterface /** * Radius * - * @param float $V Volume + * @param float $v Volume * * @return float * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getRadiusByVolume(float $V) : float + public static function getRadiusByVolume(float $v) : float { - return pow($V * 3 / (4 * pi()), 1 / 3); + return pow($v * 3 / (4 * pi()), 1 / 3); } + /** + * Create sphere by surface + * + * @param float $s Sphere surface + * + * @return Sphere + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function bySurface(float $s) : Sphere { return new self(self::getRadiusBySurface($s)); } /** - * Radius + * Get radius by sphere * * @param float $S Surface * @@ -113,13 +158,21 @@ class Sphere implements D3ShapeInterface return sqrt($S / (4 * pi())); } + /** + * Get volume + * + * @return float Sphere volume + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getVolume() : float { return self::getVolumeByRadius($this->radius); } /** - * Volume + * Get sphere volume by radius * * @param float $r Radius * @@ -133,11 +186,27 @@ class Sphere implements D3ShapeInterface return 4 / 3 * pi() * $r ** 3; } + /** + * Get radius + * + * @return float Sphere radius + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getRadius() : float { return $this->radius; } + /** + * Get surface + * + * @return float Sphere surface + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getSurface() : float { return self::getSurfaceByRadius($this->radius); diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php index 2f5315975..86c89bbec 100644 --- a/Math/Statistic/Average.php +++ b/Math/Statistic/Average.php @@ -20,7 +20,7 @@ namespace phpOMS\Math\Statistic; * Average class. * * @category Framework - * @package phpOMS\DataStorage\Database + * @package phpOMS\Math\Statistic * @author OMS Development Team * @author Dennis Eichhorn * @license OMS License 1.0 @@ -61,9 +61,19 @@ class Average } /** - * t = 3 and p = 3 means -1 0 +1, t = 4 and p = 2 means -1 0 - * periods should be replaced with order than it's possible to test for even or odd m - * todo: maybe floor()? + * Moving average of dataset + * + * @param array $x Dataset + * @param int $order Periods to use for average + * @param array $weight Weight for moving average + * @param bool $symmetric Cyclic moving average + * + * @return array Moving average of data + * + * @throws \Exception + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public static function totalMovingAverage(array $x, int $order, array $weight = null, bool $symmetric = false) : array { @@ -79,15 +89,15 @@ class Average } /** - * Moving average or order m. + * Moving average of element in dataset * * @param array $x Dataset * @param int $t Current period - * @param int $periods Periods to use for average + * @param int $order Periods to use for average + * @param array $weight Weight for moving average + * @param bool $symmetric Cyclic moving average * - * @return float - * - * @todo : allow counter i also to go into the future... required for forecast how? should be doable! + * @return float Moving average * * @throws \Exception * @@ -107,7 +117,7 @@ class Average $end = $order % 2 === 0 ? $end - 1 : $end; $start = $t - 1 - ($periods - 2); - if (isset($weight)) { + if (!empty($weight)) { return self::weightedAverage(array_slice($x, $start, $end - $start), array_slice($weight, $start, $end - $start)); } else { return self::arithmeticMean(array_slice($x, $start, $end - $start)); diff --git a/Math/Statistic/Forecast/Error.php b/Math/Statistic/Forecast/Error.php index 6ab77f78e..6d1692736 100644 --- a/Math/Statistic/Forecast/Error.php +++ b/Math/Statistic/Forecast/Error.php @@ -16,7 +16,7 @@ namespace phpOMS\Math\Statistic\Forecast; -use phpOMS\Math\Functions; +use phpOMS\Math\Functions\Functions; use phpOMS\Math\Statistic\Average; use phpOMS\Math\Statistic\MeasureOfDispersion; @@ -124,6 +124,21 @@ class Error return Average::arithmeticMean(Functions::abs($errors)); } + /** + * Get mean squared error (MSE). + * + * @param array $errors Errors + * + * @return float + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function getMeanSquaredError(array $errors) : float + { + return Average::arithmeticMean(self::square($errors)); + } + /** * Get root mean squared error (RMSE). * @@ -136,7 +151,6 @@ class Error */ public static function getRootMeanSquaredError(array $errors) : float { - // sqrt(Average::getVariance($error)+pow(Average::arithmeticMean($error), 2)); return sqrt(Average::arithmeticMean(self::square($errors))); } @@ -195,6 +209,18 @@ class Error return $error; } + /** + * Get R Bar Squared + * + * @param float $R R + * @param int $observations Amount of observations + * @param int $predictors Amount of predictors + * + * @return float + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function getRBarSquared(float $R, int $observations, int $predictors) : float { return 1 - (1 - $R * ($observations - 1) / ($observations - $predictors - 1)); @@ -203,6 +229,14 @@ class Error /** * Get Aike's information criterion (AIC) * + * @param float $sse SSE + * @param int $observations Amount of observations + * @param int $predictors Amount of predictors + * + * @return float + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public static function getAkaikeInformationCriterion(float $sse, int $observations, int $predictors) : float { @@ -213,6 +247,15 @@ class Error * Get corrected Aike's information criterion (AIC) * * Correction for small amount of observations + * + * @param float $aic AIC + * @param int $observations Amount of observations + * @param int $predictors Amount of predictors + * + * @return float + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public static function getCorrectedAkaikeInformationCriterion(float $aic, int $observations, int $predictors) : float { @@ -222,6 +265,14 @@ class Error /** * Get Bayesian information criterion (BIC) * + * @param float $sse SSE + * @param int $observations Amount of observations + * @param int $predictors Amount of predictors + * + * @return float + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public static function getSchwarzBayesianInformationCriterion(float $sse, int $observations, int $predictors) : float { diff --git a/Math/Statistic/Forecast/ForecastIntervalMultiplier.php b/Math/Statistic/Forecast/ForecastIntervalMultiplier.php index b28e54813..90cebc97c 100644 --- a/Math/Statistic/Forecast/ForecastIntervalMultiplier.php +++ b/Math/Statistic/Forecast/ForecastIntervalMultiplier.php @@ -18,7 +18,7 @@ namespace phpOMS\Math\Statistic\Forecast; use phpOMS\Datatypes\Enum; /** - * Address type enum. + * Prediction interval multiplier. * * @category Framework * @package phpOMS\Datatypes diff --git a/Math/Statistic/Forecast/Forecasts.php b/Math/Statistic/Forecast/Forecasts.php index 48261293b..f02f269d0 100644 --- a/Math/Statistic/Forecast/Forecasts.php +++ b/Math/Statistic/Forecast/Forecasts.php @@ -29,10 +29,11 @@ namespace phpOMS\Math\Statistic\Forecast; class Forecasts { /** - * Get forecast interval. + * Get forecast/prediction interval. * - * @param array $observed Dataset - * @param array $forecasted Forecasted + * @param float $forecast Forecast value + * @param float $standardDeviation Standard Deviation of forecast + * @param float $interval Forecast multiplier for prediction intervals * * @return array * diff --git a/Math/Statistic/Forecast/Regression/LevelLogRegression.php b/Math/Statistic/Forecast/Regression/LevelLogRegression.php index 3a6f40f8d..876616522 100644 --- a/Math/Statistic/Forecast/Regression/LevelLogRegression.php +++ b/Math/Statistic/Forecast/Regression/LevelLogRegression.php @@ -39,7 +39,7 @@ class LevelLogRegression extends RegressionAbstract } for ($i = 0; $i < $c; $i++) { - $x[$i] = log($x[i]); + $x[$i] = log($x[$i]); } return parent::getRegression($x, $y); diff --git a/Math/Statistic/Forecast/Regression/LogLevelRegression.php b/Math/Statistic/Forecast/Regression/LogLevelRegression.php index 7c5f65529..c796c9c44 100644 --- a/Math/Statistic/Forecast/Regression/LogLevelRegression.php +++ b/Math/Statistic/Forecast/Regression/LogLevelRegression.php @@ -39,7 +39,7 @@ class LogLevelRegression extends RegressionAbstract } for ($i = 0; $i < $c; $i++) { - $y[$i] = log($y[i]); + $y[$i] = log($y[$i]); } return parent::getRegression($x, $y); diff --git a/Math/Statistic/Forecast/Regression/LogLogRegression.php b/Math/Statistic/Forecast/Regression/LogLogRegression.php index 143ec77b6..604ff9320 100644 --- a/Math/Statistic/Forecast/Regression/LogLogRegression.php +++ b/Math/Statistic/Forecast/Regression/LogLogRegression.php @@ -39,8 +39,8 @@ class LogLogRegression extends RegressionAbstract } for ($i = 0; $i < $c; $i++) { - $x[$i] = log($x[i]); - $y[$i] = log($y[i]); + $x[$i] = log($x[$i]); + $y[$i] = log($y[$i]); } return parent::getRegression($x, $y); diff --git a/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php b/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php index ef8084dc4..a9c92ad58 100644 --- a/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php +++ b/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php @@ -1,6 +1,21 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Statistic\Forecast\Regression; -namespace phpOMS\Math\Statistic\Forecast\Regression; +use phpOMS\Math\Matrix\Matrix; class MultipleLinearRegression { @@ -10,14 +25,14 @@ class MultipleLinearRegression public static function getRegression(array $x, array $y) : array { $X = new Matrix(count($x), count($x[0])); - $X->setArray($x); + $X->setMatrix($x); $XT = $X->transpose(); $Y = new Matrix(count($y)); - $Y->setArray($y); + $Y->setMatrix($y); - return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->toArray(); + return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->getMatrix(); } public static function getVariance() : float diff --git a/Math/Statistic/Forecast/Regression/RegressionAbstract.php b/Math/Statistic/Forecast/Regression/RegressionAbstract.php index fcd353482..99ad0858c 100644 --- a/Math/Statistic/Forecast/Regression/RegressionAbstract.php +++ b/Math/Statistic/Forecast/Regression/RegressionAbstract.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Statistic\Forecast\Regression; use phpOMS\Math\Statistic\Average; use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier; @@ -18,6 +31,8 @@ abstract class RegressionAbstract * * @return array [b0 => ?, b1 => ?] * + * @throws \Exception + * * @since 1.0.0 * @author Dennis Eichhorn */ diff --git a/Math/Stochastic/Distribution/BetaDistribution.php b/Math/Stochastic/Distribution/BetaDistribution.php index 6ca4ae41d..3a5608e3c 100644 --- a/Math/Stochastic/Distribution/BetaDistribution.php +++ b/Math/Stochastic/Distribution/BetaDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class BetaDistribution { diff --git a/Math/Stochastic/Distribution/BinomialDistribution.php b/Math/Stochastic/Distribution/BinomialDistribution.php index 5f3880ce4..5e2e64535 100644 --- a/Math/Stochastic/Distribution/BinomialDistribution.php +++ b/Math/Stochastic/Distribution/BinomialDistribution.php @@ -16,7 +16,7 @@ namespace phpOMS\Math\Stochastic\Distribution; -use phpOMS\Math\Functions; +use phpOMS\Math\Functions\Functions; /** * Binomial distribution. diff --git a/Math/Stochastic/Distribution/ChiSquaredDistribution.php b/Math/Stochastic/Distribution/ChiSquaredDistribution.php index 080e813ca..a6f2c555e 100644 --- a/Math/Stochastic/Distribution/ChiSquaredDistribution.php +++ b/Math/Stochastic/Distribution/ChiSquaredDistribution.php @@ -16,7 +16,7 @@ namespace phpOMS\Math\Stochastic\Distribution; -use phpOMS\Math\Functions; +use phpOMS\Math\Functions\Functions; /** * Chi squared distribution. diff --git a/Math/Stochastic/Distribution/FDistribution.php b/Math/Stochastic/Distribution/FDistribution.php index 2166771ec..06d715615 100644 --- a/Math/Stochastic/Distribution/FDistribution.php +++ b/Math/Stochastic/Distribution/FDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class FDistribution { diff --git a/Math/Stochastic/Distribution/GammaDistribution.php b/Math/Stochastic/Distribution/GammaDistribution.php index 7911d9ee7..32a9bb65b 100644 --- a/Math/Stochastic/Distribution/GammaDistribution.php +++ b/Math/Stochastic/Distribution/GammaDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class GammaDistribution { diff --git a/Math/Stochastic/Distribution/HypergeometricDistribution.php b/Math/Stochastic/Distribution/HypergeometricDistribution.php index 57983301b..1f06dd755 100644 --- a/Math/Stochastic/Distribution/HypergeometricDistribution.php +++ b/Math/Stochastic/Distribution/HypergeometricDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class HypergeometricDistribution { diff --git a/Math/Stochastic/Distribution/LogDistribution.php b/Math/Stochastic/Distribution/LogDistribution.php index f446a129f..f8104b5d6 100644 --- a/Math/Stochastic/Distribution/LogDistribution.php +++ b/Math/Stochastic/Distribution/LogDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class LogDistribution { diff --git a/Math/Stochastic/Distribution/LogNormalDistribution.php b/Math/Stochastic/Distribution/LogNormalDistribution.php index d9c52864f..ffc0e0021 100644 --- a/Math/Stochastic/Distribution/LogNormalDistribution.php +++ b/Math/Stochastic/Distribution/LogNormalDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class LogNormalDistribution { diff --git a/Math/Stochastic/Distribution/LogisticDistribution.php b/Math/Stochastic/Distribution/LogisticDistribution.php index 490476034..15820013c 100644 --- a/Math/Stochastic/Distribution/LogisticDistribution.php +++ b/Math/Stochastic/Distribution/LogisticDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class LogisticDistribution { diff --git a/Math/Stochastic/Distribution/ParetoDistribution.php b/Math/Stochastic/Distribution/ParetoDistribution.php index 2a21ff08e..64b56de0e 100644 --- a/Math/Stochastic/Distribution/ParetoDistribution.php +++ b/Math/Stochastic/Distribution/ParetoDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class ParetoDistribution { diff --git a/Math/Stochastic/Distribution/PoissonDistribution.php b/Math/Stochastic/Distribution/PoissonDistribution.php index b40ed4fc1..cfed56496 100644 --- a/Math/Stochastic/Distribution/PoissonDistribution.php +++ b/Math/Stochastic/Distribution/PoissonDistribution.php @@ -16,7 +16,7 @@ namespace phpOMS\Math\Stochastic\Distribution; -use phpOMS\Math\Functions; +use phpOMS\Math\Functions\Functions; /** * Well known functions class. diff --git a/Math/Stochastic/Distribution/TDistribution.php b/Math/Stochastic/Distribution/TDistribution.php index f314a881e..e657ee1b5 100644 --- a/Math/Stochastic/Distribution/TDistribution.php +++ b/Math/Stochastic/Distribution/TDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class TDistribution { diff --git a/Math/Stochastic/Distribution/WeibullDistribution.php b/Math/Stochastic/Distribution/WeibullDistribution.php index 435de644b..47f12d843 100644 --- a/Math/Stochastic/Distribution/WeibullDistribution.php +++ b/Math/Stochastic/Distribution/WeibullDistribution.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Math\Stochastic\Distribution; class WeibullDistribution { diff --git a/Message/Mail/OAuth.php b/Message/Mail/OAuth.php index a22e473be..a1c38f9fb 100644 --- a/Message/Mail/OAuth.php +++ b/Message/Mail/OAuth.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Message\Mail; class OAuth { diff --git a/Message/Mail/Pop3.php b/Message/Mail/Pop3.php index 02bbac137..5b884ec64 100644 --- a/Message/Mail/Pop3.php +++ b/Message/Mail/Pop3.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Message\Mail; class Pop3 { diff --git a/Message/Mail/Smtp.php b/Message/Mail/Smtp.php index 37b3ccaa4..e46fbbdc7 100644 --- a/Message/Mail/Smtp.php +++ b/Message/Mail/Smtp.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Message\Mail; class Smtp { diff --git a/Message/Socket/Request.php b/Message/Socket/Request.php index 6d0a47523..7ba530ed4 100644 --- a/Message/Socket/Request.php +++ b/Message/Socket/Request.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Message\Socket; class Request { diff --git a/Message/Socket/Response.php b/Message/Socket/Response.php index 188e53b00..02f9c2b30 100644 --- a/Message/Socket/Response.php +++ b/Message/Socket/Response.php @@ -1,6 +1,19 @@ + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ + namespace phpOMS\Message\Socket; class Response { diff --git a/Module/ActivateAbstract.php b/Module/ActivateAbstract.php index 4f2f838e0..80380cef9 100644 --- a/Module/ActivateAbstract.php +++ b/Module/ActivateAbstract.php @@ -35,7 +35,7 @@ class ActivateAbstract /** * Deactivate module. * - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void @@ -68,7 +68,7 @@ class ActivateAbstract /** * Deactivate module in database. * - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void diff --git a/Module/DeactivateAbstract.php b/Module/DeactivateAbstract.php index d2014bd9d..a7dcbc4f5 100644 --- a/Module/DeactivateAbstract.php +++ b/Module/DeactivateAbstract.php @@ -35,7 +35,7 @@ class DeactivateAbstract /** * Deactivate module. * - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void @@ -68,7 +68,7 @@ class DeactivateAbstract /** * Deactivate module in database. * - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index 4ccff112a..eadd0b949 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -38,7 +38,7 @@ class InstallerAbstract /** * Register module in database. * - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void @@ -91,7 +91,7 @@ class InstallerAbstract * Install module. * * @param string $routePath Route Path - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void @@ -109,7 +109,7 @@ class InstallerAbstract /** * Activate after install. * - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void diff --git a/Module/UninstallAbstract.php b/Module/UninstallAbstract.php index 57cd15e25..cdd7ea5d7 100644 --- a/Module/UninstallAbstract.php +++ b/Module/UninstallAbstract.php @@ -34,7 +34,7 @@ class UninstallAbstract /** * Install module. * - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void diff --git a/Module/UpdateAbstract.php b/Module/UpdateAbstract.php index 46a94d765..b7c1c0a3f 100644 --- a/Module/UpdateAbstract.php +++ b/Module/UpdateAbstract.php @@ -34,7 +34,7 @@ class UpdateAbstract /** * Install module. * - * @param Pool $dbPool Database instance + * @param DatabasePool $dbPool Database instance * @param InfoManager $info Module info * * @return void diff --git a/Stdlib/Collection/Collection.php b/Stdlib/Collection/Collection.php index 992068444..7915b811b 100644 --- a/Stdlib/Collection/Collection.php +++ b/Stdlib/Collection/Collection.php @@ -271,7 +271,7 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab /** * Get collection that contains every n-th element. * - * @param $int $n Every n-th element + * @param int $n Every n-th element * * @return Collection * @@ -622,12 +622,16 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab /** * Offset to retrieve - * @link http://php.net/manual/en/arrayaccess.offsetget.php - * @param mixed $offset

- * The offset to retrieve. - *

+ * + * @param mixed $offset The offset to retrieve. + * * @return mixed Can return all value types. - * @since 5.0.0 + * + * @throws \Exception + * + * @link http://php.net/manual/en/arrayaccess.offsetget.php + * + * @since 1.0.0 */ public function offsetGet($offset) { diff --git a/Stdlib/Graph/BinaryTree.php b/Stdlib/Graph/BinaryTree.php index d8dccc0e1..cdd291ced 100644 --- a/Stdlib/Graph/BinaryTree.php +++ b/Stdlib/Graph/BinaryTree.php @@ -46,7 +46,7 @@ class BinaryTree extends Tree /** * Get left node of a node. * - * @param Node $node Tree node + * @param Node $base Tree node * * @return Node Left node * @@ -64,7 +64,7 @@ class BinaryTree extends Tree /** * Get right node of a node. * - * @param Node $node Tree node + * @param Node $base Tree node * * @return Node Right node * @@ -73,7 +73,7 @@ class BinaryTree extends Tree */ public function getRight(Node $base) { - $neighbors = $base->getNeighbors($base); + $neighbors = $this->getNeighbors($base); // todo: index can be wrong, see setLeft/setRight return $neighbors[1] ?? null; @@ -93,7 +93,7 @@ class BinaryTree extends Tree public function setLeft(Node $base, Node $left) : BinaryTree { if($this->getLeft($base) === null) { - $this->addNode($base, $left); + $this->addNodeRelative($base, $left); // todo: doesn't know that this is left // todo: maybe need to add numerics to edges? } else { @@ -117,7 +117,7 @@ class BinaryTree extends Tree public function setRight(Node $base, Node $right) /* : void */ { if($this->getRight($base) === null) { - $this->addNode($base, $right); + $this->addNodeRelative($base, $right); // todo: doesn't know that this is right // todo: maybe need to add numerics to edges? } else { @@ -196,6 +196,8 @@ class BinaryTree extends Tree * * @param Node $node1 Tree node1 * @param Node $node2 Tree node2 (optional, can be different tree) + * + * @return bool True if tree is symmetric, false if tree is not symmetric * * @since 1.0.0 * @author Dennis Eichhorn diff --git a/Stdlib/Graph/Graph.php b/Stdlib/Graph/Graph.php index aa7083698..32073d636 100644 --- a/Stdlib/Graph/Graph.php +++ b/Stdlib/Graph/Graph.php @@ -54,30 +54,46 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function addNode(Node $node) : Graph + public function addNode(Node $node) : Graph { - $this->nodes[] = $node; + $this->nodes[] = $node; - return $this; - } + return $this; + } /** - * Set node in graph. + * Add node to graph. * - * @param mixed $key Key of node - * @param Node $node Graph node + * @param Node $relative Relative graph node + * @param Node $node Graph node * * @return Graph * * @since 1.0.0 * @author Dennis Eichhorn */ - public function setNode($key, Node $node) : Graph + public function addNodeRelative(Node $relative, Node $node) : Graph { - $this->nodes[$key] = $node; + return $this; + } - return $this; - } + /** + * Set node in graph. + * + * @param mixed $key Key of node + * @param Node $node Graph node + * + * @return Graph + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setNode($key, Node $node) : Graph + { + $this->nodes[$key] = $node; + + return $this; + } /** * Add edge to graph. @@ -91,28 +107,28 @@ class Graph */ public function addEdge(Edge $edge) : Graph { - $this->edges[] = $edge; + $this->edges[] = $edge; - return $this; - } + return $this; + } /** * Set edge in graph. * - * @param mixed $key Edge key - * @param Edge $edge Edge to set + * @param mixed $key Edge key + * @param Edge $edge Edge to set * * @return Graph * * @since 1.0.0 * @author Dennis Eichhorn */ - public function setEdge($key, Edge $edge) /* : void */ + public function setEdge($key, Edge $edge) /* : void */ { - $this->edges[$key] = $edge; + $this->edges[$key] = $edge; - return $this; - } + return $this; + } /** * Get graph node @@ -124,10 +140,23 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getNode($key) : Node - { - return $this->nodes[$key]; - } + public function getNode($key) : Node + { + return $this->nodes[$key]; + } + + /** + * Get graph nodes + * + * @return Node[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getNodes() : array + { + return $this->nodes; + } /** * Get graph edge. @@ -139,10 +168,10 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getEdge($key) : Edge - { - return $this->edges[$key]; - } + public function getEdge($key) : Edge + { + return $this->edges[$key]; + } /** * Get all edges of a node @@ -154,17 +183,17 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getEdgesOfNode($node) : array + public function getEdgesOfNode($node) : array { - if(!($node instanceof Node)) { + if (!($node instanceof Node)) { $node = $this->getNode($node); } $edges = []; - foreach($this->edges as $edge) { + foreach ($this->edges as $edge) { $nodes = $edge->getNodes(); - if($nodes[0] === $node || $nodes[1] === $node) { + if ($nodes[0] === $node || $nodes[1] === $node) { $edges[] = $edge; } } @@ -182,21 +211,21 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getNeighbors($node) : array + public function getNeighbors($node) : array { - if(!($node instanceof Node)) { + if (!($node instanceof Node)) { $node = $this->getNode($node); } - $edges = $this->getEdgesOfNode($node); + $edges = $this->getEdgesOfNode($node); $neighbors = []; - foreach($edges as $edge) { + foreach ($edges as $edge) { $nodes = $edge->getNodes(); - if($nodes[0] !== $node && $nodes[0] !== null) { + if ($nodes[0] !== $node && $nodes[0] !== null) { $neighbors[] = $nodes[0]; - } elseif($nodes[1] !== $node && $nodes[0] !== null) { + } elseif ($nodes[1] !== $node && $nodes[0] !== null) { $neighbors[] = $nodes[1]; } } @@ -212,7 +241,7 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getDimension() : int + public function getDimension() : int { // todo: implement return 0; @@ -240,7 +269,7 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getKruskalMinimalSpanningTree() : Tree + public function getKruskalMinimalSpanningTree() : Tree { // todo: implement return new Tree(); @@ -254,7 +283,7 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getPrimMinimalSpanningTree() : Tree + public function getPrimMinimalSpanningTree() : Tree { // todo: implement return new Tree(); @@ -268,7 +297,7 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getCircle() : array + public function getCircle() : array { // todo: implement } @@ -281,7 +310,7 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function getFloydWarshallShortestPath() : array + public function getFloydWarshallShortestPath() : array { // todo: implement } @@ -307,7 +336,7 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function depthFirstTraversal() : array + public function depthFirstTraversal() : array { // todo: implement } @@ -320,7 +349,7 @@ class Graph * @since 1.0.0 * @author Dennis Eichhorn */ - public function breadthFirstTraversal() : array + public function breadthFirstTraversal() : array { // todo: implement } @@ -398,9 +427,9 @@ class Graph { $diameter = 0; - foreach($this->nodes as $node1) { - foreach($this->nodes as $node2) { - if($node1 === $node2) { + foreach ($this->nodes as $node1) { + foreach ($this->nodes as $node2) { + if ($node1 === $node2) { continue; } diff --git a/Stdlib/Graph/Tree.php b/Stdlib/Graph/Tree.php index f2541bd19..b7317c176 100644 --- a/Stdlib/Graph/Tree.php +++ b/Stdlib/Graph/Tree.php @@ -231,7 +231,7 @@ class Tree extends Graph } $callback($node); - $neighbors = $this->getNeighbors(); + $neighbors = $this->getNeighbors($node); foreach($neighbors as $neighbor) { // todo: get neighbors needs to return in ordered way @@ -253,7 +253,7 @@ class Tree extends Graph return; } - $neighbors = $this->getNeighbors(); + $neighbors = $this->getNeighbors($node); foreach($neighbors as $neighbor) { // todo: get neighbors needs to return in ordered way diff --git a/Stdlib/Queue/PriorityQueue.php b/Stdlib/Queue/PriorityQueue.php index 855faaabc..bffcd9cc0 100644 --- a/Stdlib/Queue/PriorityQueue.php +++ b/Stdlib/Queue/PriorityQueue.php @@ -16,7 +16,7 @@ namespace phpOMS\Stdlib\Queue; /** - * Router class. + * Priority queue class. * * @category Framework * @package phpOMS\Stdlib @@ -45,15 +45,13 @@ class PriorityQueue implements \Countable, \Serializable */ private $queue = []; - private $mode = 0; - /** * Constructor. * * @since 1.0.0 * @author Dennis Eichhorn */ - public function __construct($mode = '') + public function __construct() { } diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index a2084921c..e371d25e0 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -397,6 +397,7 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function name(string $path) : string { + // todo: name doesn' t make sense // TODO: Implement name() method. } diff --git a/System/File/Local/File.php b/System/File/Local/File.php index b97430a6e..25cde75ba 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -225,6 +225,21 @@ class File extends FileAbstract implements FileInterface * @author Dennis Eichhorn */ public static function dirname(string $path) : string + { + return basename(dirname($path)); + } + + /** + * Gets the directory path of a file. + * + * @param string $path Path of the file to get the directory name for. + * + * @return string Returns the directory name of the file. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function dirpath(string $path) : string { return dirname($path); } @@ -287,11 +302,27 @@ class File extends FileAbstract implements FileInterface return true; } + /** + * Gets the directory name of a file. + * + * @return string Returns the directory name of the file. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getDirName() : string { return basename(dirname($this->path)); } + /** + * Gets the directory path of a file. + * + * @return string Returns the directory path of the file. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getDirPath() : string { return dirname($this->path); diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index f46f598c9..a0879b638 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -227,10 +227,8 @@ class ArrayUtils * * Useful for parsing command line parsing * - * @param array $data Data to convert - * @param string $delimiter Delim to use - * @param string $enclosure Enclosure to use - * @param string $escape Escape to use + * @param string $id Id to find + * @param array $args CLI command list * * @return string * @@ -251,7 +249,7 @@ class ArrayUtils * * Reduces multi dimensional array to one dimensional array. Flatten tries to maintain the index as far as possible. * - * @param array $array Multi dimensional array to flatten + * @param array $array Multi dimensional array to flatten * * @return array * @@ -278,18 +276,25 @@ class ArrayUtils } /** - * todo: what did i smoke? what is this? + * Sum of array elements + * + * @param array $array Array to sum + * @param int $start Start index + * @param int $count Amount of elements to sum + * + * @return int|float + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public static function arraySum(array $array, int $start = 0, int $count = 0) { $count = $count === 0 ? count($array) : $count; - $sum = 0.0; + $sum = 0; + + $array = array_values($array); for ($i = $start; $i <= $count - 1; $i++) { - if (!isset($array[$i])) { - continue; - } - $sum += $array[$i]; } diff --git a/Utils/Barcode/C128Abstract.php b/Utils/Barcode/C128Abstract.php index cc39904e0..49a45bbc8 100644 --- a/Utils/Barcode/C128Abstract.php +++ b/Utils/Barcode/C128Abstract.php @@ -124,7 +124,8 @@ abstract class C128Abstract * Constructor * * @param string $content Content to encrypt - * @param int $size Barcode height + * @param int $width Barcode width + * @param int $height Barcode height * @param int $orientation Orientation of the barcode * * @todo : add mirror parameter @@ -142,7 +143,7 @@ abstract class C128Abstract /** * Set barcode dimensions * - * @param int $width Barcode width + * @param int $width Barcode width * @param int $height Barcode height * * @since 1.0.0 @@ -158,7 +159,7 @@ abstract class C128Abstract throw new \OutOfBoundsException($height); } - $this->dimension['width'] = $width; + $this->dimension['width'] = $width; $this->dimension['height'] = $height; } diff --git a/Utils/Barcode/HIBCC.php b/Utils/Barcode/HIBCC.php index 8060bdac1..07676203a 100644 --- a/Utils/Barcode/HIBCC.php +++ b/Utils/Barcode/HIBCC.php @@ -45,12 +45,12 @@ class HIBCC public function setIdentifier(string $identifier) /* : void */ { - $this->identifer = $identifier; + $this->identifier = $identifier; } public function getIdentifier() : string { - return $this->identifer; + return $this->identifier; } public function setProductId(string $id) /* : void */ @@ -88,7 +88,7 @@ class HIBCC $this->expirationDate = $date; } - public function getExpirationDate() : \Datetime + public function getExpirationDate() : \DateTime { return $this->expirationDate; } diff --git a/Utils/TaskSchedule/Schedule.php b/Utils/TaskSchedule/Schedule.php index 486d1adc6..e8499906d 100644 --- a/Utils/TaskSchedule/Schedule.php +++ b/Utils/TaskSchedule/Schedule.php @@ -31,8 +31,8 @@ class Schedule extends TaskAbstract implements \Serializable /** * Constructor. * - * @param Interval $interval Interval - * @param string $cmd Command to execute + * @param string $name Schedule name + * @param string $cmd Command to execute * * @since 1.0.0 * @author Dennis Eichhorn diff --git a/Utils/TaskSchedule/SchedulerAbstract.php b/Utils/TaskSchedule/SchedulerAbstract.php index 74d45fa35..4a741dc71 100644 --- a/Utils/TaskSchedule/SchedulerAbstract.php +++ b/Utils/TaskSchedule/SchedulerAbstract.php @@ -14,6 +14,7 @@ * @link http://orange-management.com */ namespace phpOMS\Utils\TaskSchedule; +use phpOMS\System\File\PathException; /** * Scheduler abstract. diff --git a/Utils/TaskSchedule/SchedulerFactory.php b/Utils/TaskSchedule/SchedulerFactory.php index a3fb8646e..611084343 100644 --- a/Utils/TaskSchedule/SchedulerFactory.php +++ b/Utils/TaskSchedule/SchedulerFactory.php @@ -35,7 +35,7 @@ final class SchedulerFactory /** * Create scheduler instance. * - * @return ScheduleInterface + * @return SchedulerAbstract * * @throws \Exception * diff --git a/Utils/TaskSchedule/TaskAbstract.php b/Utils/TaskSchedule/TaskAbstract.php index d6ddd047f..f66a2daff 100644 --- a/Utils/TaskSchedule/TaskAbstract.php +++ b/Utils/TaskSchedule/TaskAbstract.php @@ -195,7 +195,7 @@ abstract class TaskAbstract */ public function setNextRunTime(\DateTime $nextRunTime) /* : void */ { - $this->nextRuntime = $nextRunTime; + $this->nextRunTime = $nextRunTime; } /** diff --git a/Utils/TaskSchedule/TaskFactory.php b/Utils/TaskSchedule/TaskFactory.php index 3da1afe11..88d75c148 100644 --- a/Utils/TaskSchedule/TaskFactory.php +++ b/Utils/TaskSchedule/TaskFactory.php @@ -38,7 +38,7 @@ final class TaskFactory * @param string $id Task id * @param string $cmd Command to run * - * @return TaskInterface + * @return TaskAbstract * * @throws \Exception * diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php index e5293f491..b6139dd03 100644 --- a/Utils/TaskSchedule/TaskScheduler.php +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -43,7 +43,7 @@ class TaskScheduler extends SchedulerAbstract * * @param string $cmd Command to run * - * @return array + * @return string * * @throws \Exception * @@ -114,7 +114,7 @@ class TaskScheduler extends SchedulerAbstract } if(DateTime::isValid($jobData[5])) { - $job->setLastRunTime(new \DateTime($jobData[5])); + $job->setLastRuntime(new \DateTime($jobData[5])); } $job->setAuthor($jobData[7]); @@ -171,7 +171,7 @@ class TaskScheduler extends SchedulerAbstract public function getAllByName(string $name, bool $exact = true) : array { if($exact) { - $lines = $this->run('/query /v /fo CSV /tn ' . escapeshellarg($name)); + $lines = explode("\n", $this->normalize($this->run('/query /v /fo CSV /tn ' . escapeshellarg($name)))); unset($lines[0]); $jobs = []; diff --git a/Views/View.php b/Views/View.php index 81f467e12..bc47756aa 100644 --- a/Views/View.php +++ b/Views/View.php @@ -197,23 +197,23 @@ class View extends ViewAbstract } /** - * @return Request + * @return RequestAbstract * * @since 1.0.0 * @author Dennis Eichhorn */ - public function getRequest() : Request + public function getRequest() : RequestAbstract { return $this->request; } /** - * @return Response + * @return ResponseAbstract * * @since 1.0.0 * @author Dennis Eichhorn */ - public function getResponse() : Response + public function getResponse() : ResponseAbstract { return $this->response; }