diff --git a/Math/Stochastic/NaiveBayesFilter.php b/Math/Stochastic/NaiveBayesFilter.php new file mode 100644 index 000000000..ebb0d319d --- /dev/null +++ b/Math/Stochastic/NaiveBayesFilter.php @@ -0,0 +1,63 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace phpOMS\Math\Stochastic; +/** + * Bernulli distribution. + * + * @category Framework + * @package phpOMS\DataStorage\Database + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class NaiveBayesFilter +{ + private $dict = []; + + public function __construct() + { + } + + public function trainMatch($matched) \* : void *\ + { + } + + 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']); + } + } + + return 1 / (1+exp(M_E, $n)); + } + + private function normalizeDictionary() : array + { + return $this->dict; + } +}