php-ml/src/Phpml/Classification/SupportVectorMachine.php

79 lines
1.5 KiB
PHP
Raw Normal View History

2016-04-19 20:54:33 +00:00
<?php
declare (strict_types = 1);
namespace Phpml\Classification;
2016-04-19 20:54:33 +00:00
use Phpml\Classification\Traits\Predictable;
use Phpml\Classification\Traits\Trainable;
2016-04-21 21:21:08 +00:00
use Phpml\Math\Kernel;
2016-04-19 20:54:33 +00:00
class SupportVectorMachine implements Classifier
{
use Trainable, Predictable;
2016-04-20 21:56:33 +00:00
/**
2016-04-21 21:21:08 +00:00
* @var Kernel
2016-04-20 21:56:33 +00:00
*/
2016-04-21 21:21:08 +00:00
private $kernel;
2016-04-20 21:56:33 +00:00
/**
* @var float
*/
2016-04-21 21:21:08 +00:00
private $C;
2016-04-20 21:56:33 +00:00
/**
* @var float
*/
private $tolerance;
/**
* @var int
*/
private $upperBound;
2016-05-04 19:29:26 +00:00
/**
* @var string
*/
private $binPath;
2016-04-20 21:56:33 +00:00
/**
2016-04-21 21:21:08 +00:00
* @param Kernel $kernel
2016-04-25 20:55:34 +00:00
* @param float $C
* @param float $tolerance
* @param int $upperBound
2016-04-20 21:56:33 +00:00
*/
2016-04-21 21:21:08 +00:00
public function __construct(Kernel $kernel = null, float $C = 1.0, float $tolerance = .001, int $upperBound = 100)
2016-04-20 21:56:33 +00:00
{
2016-04-21 21:21:08 +00:00
if (null === $kernel) {
$kernel = new Kernel\RBF($gamma = .001);
}
$this->kernel = $kernel;
$this->C = $C;
2016-04-20 21:56:33 +00:00
$this->tolerance = $tolerance;
$this->upperBound = $upperBound;
2016-05-05 19:57:25 +00:00
$this->binPath = realpath(implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', '..', '..', 'bin'))) . DIRECTORY_SEPARATOR;
2016-04-20 21:56:33 +00:00
}
2016-05-04 19:29:26 +00:00
/**
* @param array $samples
* @param array $labels
*/
public function train(array $samples, array $labels)
{
$this->samples = $samples;
$this->labels = $labels;
}
2016-04-19 20:54:33 +00:00
/**
* @param array $sample
*
* @return mixed
*/
protected function predictSample(array $sample)
{
}
}