From f0bd5ae4244a5c3b8e71400bbb9727d7a68ab35f Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Fri, 12 Aug 2016 16:29:50 +0200 Subject: [PATCH] Create MLP Regressor draft --- src/Phpml/Regression/MLPRegressor.php | 81 +++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/Phpml/Regression/MLPRegressor.php diff --git a/src/Phpml/Regression/MLPRegressor.php b/src/Phpml/Regression/MLPRegressor.php new file mode 100644 index 0000000..b00b4d1 --- /dev/null +++ b/src/Phpml/Regression/MLPRegressor.php @@ -0,0 +1,81 @@ +hiddenLayers = $hiddenLayers; + $this->desiredError = $desiredError; + $this->maxIterations = $maxIterations; + $this->activationFunction = $activationFunction; + } + + + /** + * @param array $samples + * @param array $targets + */ + public function train(array $samples, array $targets) + { + $layers = [count($samples[0])] + $this->hiddenLayers + [count($targets[0])]; + + $this->perceptron = new MultilayerPerceptron($layers, $this->activationFunction); + + $trainer = new Backpropagation($this->perceptron); + $trainer->train($samples, $targets, $this->desiredError, $this->maxIterations); + } + + /** + * @param array $sample + * + * @return array + */ + protected function predictSample(array $sample) + { + return $this->perceptron->setInput($sample)->getOutput(); + } + +}