mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
Create NaiveBayesFilter draft
This commit is contained in:
parent
f0d0fccf6e
commit
ffa8d39031
63
Math/Stochastic/NaiveBayesFilter.php
Normal file
63
Math/Stochastic/NaiveBayesFilter.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @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 <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user