Skip to content

Commit

Permalink
linear regression is also hard
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Apr 25, 2016
1 parent 46da769 commit af3b576
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/Phpml/Classifier/SupportVectorMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 2 additions & 3 deletions src/Phpml/Math/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?php
declare(strict_types = 1);

declare (strict_types = 1);

namespace Phpml\Math;

interface Kernel
{

/**
* @param float $a
* @param float $b
*
* @return float
*/
public function compute($a, $b);

}
4 changes: 2 additions & 2 deletions src/Phpml/Math/Kernel/RBF.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare (strict_types = 1);

namespace Phpml\Math\Kernel;

Expand Down Expand Up @@ -35,5 +36,4 @@ public function compute($a, $b)

return $result;
}

}
5 changes: 2 additions & 3 deletions src/Phpml/Math/Product.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
declare(strict_types = 1);

declare (strict_types = 1);

namespace Phpml\Math;

class Product
{

/**
* @param array $a
* @param array $b
Expand All @@ -21,5 +21,4 @@ public static function scalar(array $a, array $b)

return $product;
}

}
37 changes: 37 additions & 0 deletions src/Phpml/Regression/LeastSquares.php
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
21 changes: 21 additions & 0 deletions src/Phpml/Regression/Regression.php
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 2 additions & 3 deletions tests/Phpml/Math/Kernel/RBFTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
declare(strict_types = 1);

declare (strict_types = 1);

namespace test\Phpml\Math\Kernel;

use Phpml\Math\Kernel\RBF;

class RBFTest extends \PHPUnit_Framework_TestCase
{

public function testComputeRBFKernelFunction()
{
$rbf = new RBF($gamma = 0.001);
Expand All @@ -22,5 +22,4 @@ public function testComputeRBFKernelFunction()
$this->assertEquals(0.00451, $rbf->compute([1, 2, 3], [4, 5, 6]), '', $delta = 0.0001);
$this->assertEquals(0, $rbf->compute([4, 5], [1, 100]));
}

}
7 changes: 3 additions & 4 deletions tests/Phpml/Math/ProductTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php
declare(strict_types = 1);

declare (strict_types = 1);

namespace tests\Phpml\Math;

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]));
}

}
}

0 comments on commit af3b576

Please sign in to comment.