artificial neural networks with php & symfony con 2014
TRANSCRIPT
![Page 1: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/1.jpg)
with PHP on a Symfony Console TicTacToe game
Artificial Neural Networks
![Page 2: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/2.jpg)
ANN with PHP SymfonyCon Madrid 2014
Agenda
1. Demo
2. Symfony Console
3. Symfony Console Helpers
4. ANN Theory
6. PHP + FANN
7. Show me the code
8. Demo
9. Q&A
![Page 3: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/3.jpg)
ANN with PHP SymfonyCon Madrid 2014
Demo
vs.
![Page 4: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/4.jpg)
ANN with PHP SymfonyCon Madrid 2014
Symfony Console
![Page 5: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/5.jpg)
ANN with PHP SymfonyCon Madrid 2014
Symfony Console - Installation
#!/usr/bin/env php<?phprequire __DIR__ . ‘/../vendor/autoload.php';
use Symfony\Component\Console\Application; $app = new Application(); $app->run();
bin/console
{ ... "require": { "symfony/console": "~2.5" } ...}
composer.json
![Page 6: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/6.jpg)
ANN with PHP SymfonyCon Madrid 2014
Symfony Console - Installation
#!/usr/bin/env php<?phprequire __DIR__ . ‘/../vendor/autoload.php';
use Symfony\Component\Console\Application; $app = new Application(); $app->run();
bin/console
{ ... "require": { "symfony/console": "~2.5" } ...}
composer.json
$ php bin/console
$ chmod +x bin/console$ bin/console
![Page 7: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/7.jpg)
ANN with PHP SymfonyCon Madrid 2014
![Page 8: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/8.jpg)
ANN with PHP SymfonyCon Madrid 2014
Symfony console style guidehttps://github.com/symfony/symfony-docs/issues/4265
Created by @javiereguiluzImproved by Symfony community
![Page 9: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/9.jpg)
ANN with PHP SymfonyCon Madrid 2014
Symfony Console Helpers
Progress bar
Table
Question
Formatter
![Page 10: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/10.jpg)
ANN with PHP SymfonyCon Madrid 2014
<?php// create a new progress bar (10 units)$progress = new ProgressBar($output, 10); // start and displays the progress bar$progress->start(); $i = 0; while ($i++ < 10) { // ... do some work // advance the progress bar 1 unit $progress->advance(); } // ensure that the progress bar is at 100%$progress->finish();
Command.php
Progress bar
![Page 11: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/11.jpg)
ANN with PHP SymfonyCon Madrid 2014
We all techies love progress bars
![Page 12: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/12.jpg)
ANN with PHP SymfonyCon Madrid 2014
Table
<?php $table = new Table($output); $table ->setHeaders(array('Component', 'Package')) ->setRows(array( array('Console', 'symfony/console'), array('Form', 'symfony/form'), array('Finder', 'symfony/finder'), array('Config', 'symfony/config'), array('...', '...'), )) ; $table->render();
Command.php
![Page 13: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/13.jpg)
ANN with PHP SymfonyCon Madrid 2014
Question
<?php
$helper = $this->getHelper('question'); $question = new ConfirmationQuestion( 'Dou you want to play again? ', false ); if (!$helper->ask($input, $output, $question)) { $output->writeln("Bye bye!"); return; } $output->writeln("Let's play again!");
Command.php
![Page 14: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/14.jpg)
ANN with PHP SymfonyCon Madrid 2014
Formatter
<?php $formatter = $this->getHelper('formatter'); $formattedLine = $formatter->formatSection( 'Game finished', 'Player one wins.'); $output->writeln($formattedLine); $errorMessages = array( 'Error!', 'Move already done.’ ); $formattedBlock = $formatter ->formatBlock($errorMessages, 'error'); $output->writeln($formattedBlock);
Command.php
![Page 15: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/15.jpg)
ANN with PHP SymfonyCon Madrid 2014
Our helper
![Page 16: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/16.jpg)
ANN with PHP SymfonyCon Madrid 2014
Board
<?php
// Board example usage $board = new Board( $output, $this->getApplication() ->getTerminalDimensions(), 3, // Board size false // Don’t override the screen );
// Update and display the board status$board->updateGame(0,0,1);
Command.php
![Page 17: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/17.jpg)
ANN with PHP SymfonyCon Madrid 2014
Board
<?php
// Board example - four in a row$board = new BoardHelper( $output, $this->getApplication() ->getTerminalDimensions(), 4, // Board size false // Don’t override screen true // Board with backgrounded cells );
// Update the board status (Player 1) $board->updateGame(0,0,1);
// Update the board status (Player 2) $board->updateGame(0,1,2);
Command.php
![Page 18: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/18.jpg)
ANN with PHP SymfonyCon Madrid 2014
Board
<?php
// Example TicTacToe with overwrite$board = new TicTacToeHelper( $output, $this->getApplication() ->getTerminalDimensions(), 3, // Board size true // Overwrite screen);
// Update the board status and display$board->updateGame(1,1,1); $board->updateGame(0,0,2); $board->updateGame(2,0,1); $board->updateGame(0,2,2); $board->updateGame(0,1,1); $board->updateGame(2,1,2); $board->updateGame(1,0,1); $board->updateGame(1,2,2); $board->updateGame(2,2,1);
Command.php
![Page 19: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/19.jpg)
ANN with PHP SymfonyCon Madrid 2014
Board<?phpnamespace PHPGames\Console\Helper; class Board{ /** * @var \Symfony\Component\Console\Output\OutputInterface */ private $output; /** * Clears the output buffer */ private function clear() { $this->output->write("\e[2J"); } // ...
Board.php
Instruction thatclears the screen
![Page 20: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/20.jpg)
ANN with PHP SymfonyCon Madrid 2014
There is a bonus helper
![Page 21: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/21.jpg)
ANN with PHP SymfonyCon Madrid 2014
Symfony Console - HAL
<?php
$hal = new HAL($output); $hal->sayHello();
Command.php
![Page 22: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/22.jpg)
ANN with PHP SymfonyCon Madrid 2014
Computer model that intends to simulate how the brain works
Artificial Neural Networks
![Page 23: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/23.jpg)
ANN with PHP SymfonyCon Madrid 2014
Input neuron
A typical ANN
Hidden neuron
Output neuron
Signal & weight
![Page 24: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/24.jpg)
ANN with PHP SymfonyCon Madrid 2014
Activation FunctionsFunctions to process the input and produce a signal as output
![Page 25: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/25.jpg)
ANN with PHP SymfonyCon Madrid 2014
Activation Functions• Step - output is 0 or 1
• Linear Combination - output is input sum plus a linear bias
• Continuous Log-Sigmoid
![Page 26: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/26.jpg)
ANN with PHP SymfonyCon Madrid 2014
Activation Functions• Step - output is 0 or 1
• Linear Combination - output is input sum plus a linear bias
• Continuous Log-Sigmoid
![Page 27: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/27.jpg)
ANN with PHP SymfonyCon Madrid 2014
Activation Functions• Step - output is 0 or 1
• Linear Combination - output is input sum plus a linear bias
• Continuous Log-Sigmoid
![Page 28: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/28.jpg)
ANN with PHP SymfonyCon Madrid 2014
BackpropagationBackward propagation of errors
Passes error signals backwards through the network during training to update the weights of the network
![Page 29: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/29.jpg)
ANN with PHP SymfonyCon Madrid 2014
ANN Types
![Page 30: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/30.jpg)
ANN with PHP SymfonyCon Madrid 2014
ANN types• Feedforward neural network
Information goes only in one direction, forward.
• Radial basis function network (RBF) Interpolation in multidimensional space.
• Kohonen self-organizing network A set of artificial neurons learn to map points in an input space to coordinates in an output space.
![Page 31: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/31.jpg)
ANN with PHP SymfonyCon Madrid 2014
ANN types• Feedforward neural network
Information goes only in one direction, forward.
• Radial basis function network (RBF) Interpolation in multidimensional space.
• Kohonen self-organizing network A set of artificial neurons learn to map points in an input space to coordinates in an output space.
![Page 32: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/32.jpg)
ANN with PHP SymfonyCon Madrid 2014
ANN types• Feedforward neural network
Information goes only in one direction, forward.
• Radial basis function network (RBF) Interpolation in multidimensional space.
• Kohonen self-organizing network A set of artificial neurons learn to map points in an input space to coordinates in an output space.
![Page 33: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/33.jpg)
ANN with PHP SymfonyCon Madrid 2014
ANN Learning
![Page 34: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/34.jpg)
ANN with PHP SymfonyCon Madrid 2014
ANN Learning
• Supervised
• Unsupervised
• Reinforcement
• Supervised
• Unsupervised
• Reinforcement
![Page 35: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/35.jpg)
ANN with PHP SymfonyCon Madrid 2014
ANN Learning
• Supervised
• Unsupervised
• Reinforcement
![Page 36: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/36.jpg)
ANN with PHP SymfonyCon Madrid 2014
ANN Learning
• Supervised
• Unsupervised
• Reinforcement
![Page 37: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/37.jpg)
ANN with PHP SymfonyCon Madrid 2014
With some slights adaptations to solve
We've used Reinforcement Learning
![Page 38: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/38.jpg)
ANN with PHP SymfonyCon Madrid 2014
Temporal Credit Assignment Problem
![Page 39: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/39.jpg)
ANN with PHP SymfonyCon Madrid 2014
(WTF) ANN withArtificial Neural Networks with PHP
What The Fann
![Page 40: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/40.jpg)
ANN with PHP SymfonyCon Madrid 2014
![Page 41: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/41.jpg)
ANN with PHP SymfonyCon Madrid 2014
Meet libfann & PECL fann$~> sudo apt-get install libfann; sudo pecl install fann
(WTF) ANN with
![Page 42: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/42.jpg)
ANN with PHP SymfonyCon Madrid 2014
(WTF) ANN with OS X1. Install autoconf 2. Install cmake 3. Compile FANN 4. Install php fann extension with PECL 5. Add the extension to php.ini
$ brew install autoconf
![Page 43: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/43.jpg)
ANN with PHP SymfonyCon Madrid 2014
(WTF) ANN with OS X1. Install autoconf 2. Install cmake 3. Compile FANN 4. Install php fann extension with PECL 5. Add the extension to php.ini
$ brew install cmake
![Page 44: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/44.jpg)
ANN with PHP SymfonyCon Madrid 2014
(WTF) ANN with OS X1. Install autoconf 2. Install cmake 3. Compile FANN 4. Install php fann extension with PECL 5. Add the extension to php.ini
$ cd FANN-2.2.X-Source $ cmake . $ sudo make install
![Page 45: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/45.jpg)
ANN with PHP SymfonyCon Madrid 2014
(WTF) ANN with OS X1. Install autoconf 2. Install cmake 3. Compile FANN 4. Install php fann extension with PECL 5. Add the extension to php.ini
$ sudo pecl install fann
![Page 46: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/46.jpg)
ANN with PHP SymfonyCon Madrid 2014
(WTF) ANN with OS X1. Install autoconf 2. Install cmake 3. Compile FANN 4. Install php fann extension with PECL 5. Add the extension to php.ini
extension=fann.so
![Page 47: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/47.jpg)
ANN with PHP SymfonyCon Madrid 2014
Enjoy!
(WTF) ANN with
![Page 48: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/48.jpg)
ANN with PHP SymfonyCon Madrid 2014
Show me the code!
(WTF) ANN with
![Page 49: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/49.jpg)
ANN with PHP SymfonyCon Madrid 2014
Demo
vs.
![Page 50: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/50.jpg)
ANN with PHP SymfonyCon Madrid 2014
![Page 51: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/51.jpg)
ANN with PHP SymfonyCon Madrid 2014
The two neurons behind this talk
![Page 52: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/52.jpg)
ANN with PHP SymfonyCon Madrid 2014
Eduardo Gulias
• EmailValidator (Symfony >= 2.5, Drupal 8).
• ListenersDebugCommandBundle (ezPublish 5).
• PHPMad UG co-founder (Former Symfony Madrid).
• Team leader at
@egulias
![Page 53: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/53.jpg)
ANN with PHP SymfonyCon Madrid 2014
Ariel Ferrandini
• Symfony simple password encoder service. (Symfony >=2.6).
• Symfony DX application collaborator.
• PHPMad UG co-founder.
• Team leader at Paradigma Tecnológico
@aferrandini
![Page 54: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/54.jpg)
ANN with PHP SymfonyCon Madrid 2014
Resources• Wikipedia (http://en.wikipedia.org/wiki/Artificial_neural_network)
• Introduction for beginners (http://arxiv.org/pdf/cs/0308031.pdf)
• Introduction to ANN (http://www.theprojectspot.com/tutorial-post/introduction-to-artificial-neural-networks-part-1/7)
• Reinforcement learning (http://www.willamette.edu/~gorr/classes/cs449/Reinforcement/reinforcement0.html)
• PHP FANN (http://www.php.net/fann)
![Page 55: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/55.jpg)
ANN with PHP SymfonyCon Madrid 2014
Resources
• Repo PHPGames (https://github.com/phpgames/ANNTicTacToe)
• Repo Board helper (https://github.com/phpgames/BoardHelper)
• Repo HAL helper (https://github.com/phpgames/HALHelper)
![Page 56: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/56.jpg)
ANN with PHP SymfonyCon Madrid 2014
Thank you!
https://joind.in/12951
![Page 57: Artificial Neural Networks with PHP & Symfony con 2014](https://reader034.vdocument.in/reader034/viewer/2022052400/55a080e31a28abce1f8b4599/html5/thumbnails/57.jpg)
ANN with PHP SymfonyCon Madrid 2014
Questions?
https://joind.in/12951