linear regression is also hard

This commit is contained in:
Arkadiusz Kondas 2016-04-25 22:55:34 +02:00
parent 46da769ca6
commit af3b57692f
8 changed files with 72 additions and 18 deletions

View File

@ -34,9 +34,9 @@ class SupportVectorMachine implements Classifier
/**
* @param Kernel $kernel
* @param float $C
* @param float $tolerance
* @param int $upperBound
* @param float $C
* @param float $tolerance
* @param int $upperBound
*/
public function __construct(Kernel $kernel = null, float $C = 1.0, float $tolerance = .001, int $upperBound = 100)
{

View File

@ -1,11 +1,11 @@
<?php
declare(strict_types = 1);
declare (strict_types = 1);
namespace Phpml\Math;
interface Kernel
{
/**
* @param float $a
* @param float $b
@ -13,5 +13,4 @@ interface Kernel
* @return float
*/
public function compute($a, $b);
}

View File

@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);
declare (strict_types = 1);
namespace Phpml\Math\Kernel;
@ -35,5 +36,4 @@ class RBF implements Kernel
return $result;
}
}

View File

@ -1,11 +1,11 @@
<?php
declare(strict_types = 1);
declare (strict_types = 1);
namespace Phpml\Math;
class Product
{
/**
* @param array $a
* @param array $b
@ -21,5 +21,4 @@ class Product
return $product;
}
}

View File

@ -0,0 +1,37 @@
<?php
declare (strict_types = 1);
namespace Phpml\Regression;
class LeastSquares implements Regression
{
/**
* @var array
*/
private $features;
/**
* @var array
*/
private $targets;
/**
* @param array $features
* @param array $targets
*/
public function train(array $features, array $targets)
{
$this->features = $features;
$this->targets = $targets;
}
/**
* @param array $features
*
* @return mixed
*/
public function predict(array $features)
{
}
}

View File

@ -0,0 +1,21 @@
<?php
declare (strict_types = 1);
namespace Phpml\Regression;
interface Regression
{
/**
* @param array $features
* @param array $targets
*/
public function train(array $features, array $targets);
/**
* @param array $features
*
* @return mixed
*/
public function predict(array $features);
}

View File

@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);
declare (strict_types = 1);
namespace test\Phpml\Math\Kernel;
@ -7,7 +8,6 @@ use Phpml\Math\Kernel\RBF;
class RBFTest extends \PHPUnit_Framework_TestCase
{
public function testComputeRBFKernelFunction()
{
$rbf = new RBF($gamma = 0.001);
@ -22,5 +22,4 @@ class RBFTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(0.00451, $rbf->compute([1, 2, 3], [4, 5, 6]), '', $delta = 0.0001);
$this->assertEquals(0, $rbf->compute([4, 5], [1, 100]));
}
}

View File

@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);
declare (strict_types = 1);
namespace tests\Phpml\Math;
@ -7,12 +8,10 @@ use Phpml\Math\Product;
class ProductTest extends \PHPUnit_Framework_TestCase
{
public function testScalarProduct()
{
$this->assertEquals(10, Product::scalar([2, 3], [-1, 4]));
$this->assertEquals(-0.1, Product::scalar([1, 4, 1], [-2, 0.5, -0.1]));
$this->assertEquals(8, Product::scalar([2], [4]));
}
}
}