SlideShare a Scribd company logo
1 of 57
Download to read offline
with PHP on a 
Symfony Console 
TicTacToe game 
Artificial 
Neural 
Networks
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
ANN with PHP SymfonyCon Madrid 2014 
Demo 
vs.
ANN with PHP SymfonyCon Madrid 2014 
Symfony Console
ANN with PHP SymfonyCon Madrid 2014 
Symfony Console - Installation 
bin/console 
#!/usr/bin/env php 
<?php 
require __DIR__ . ‘/../vendor/autoload.php'; 
use SymfonyComponentConsoleApplication; 
$app = new Application(); 
$app->run(); 
composer.json 
{ 
... 
"require": { 
"symfony/console": "~2.5" 
} 
... 
}
ANN with PHP SymfonyCon Madrid 2014 
Symfony Console - Installation 
bin/console 
#!/usr/bin/env php 
<?php 
require __DIR__ . ‘/../vendor/autoload.php'; 
use SymfonyComponentConsoleApplication; 
$app = new Application(); 
$app->run(); 
composer.json 
{ 
... 
"require": { 
"symfony/console": "~2.5" 
} 
... 
} 
$ php bin/console 
$ chmod +x bin/console 
$ bin/console
ANN with PHP SymfonyCon Madrid 2014
ANN with PHP SymfonyCon Madrid 2014 
Symfony console style guide 
https://github.com/symfony/symfony-docs/issues/4265 
Created by @javiereguiluz 
Improved by Symfony community
ANN with PHP SymfonyCon Madrid 2014 
Symfony Console Helpers 
Progress bar 
Table 
Question 
Formatter
ANN with PHP SymfonyCon Madrid 2014 
Command.php 
Progress bar 
<?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();
ANN with PHP SymfonyCon Madrid 2014 
We all techies love progress bars
ANN with PHP SymfonyCon Madrid 2014 
Table 
Command.php 
<?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();
ANN with PHP SymfonyCon Madrid 2014 
Question 
Command.php 
<?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!");
ANN with PHP SymfonyCon Madrid 2014 
Formatter 
Command.php 
<?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);
ANN with PHP SymfonyCon Madrid 2014 
Our helper
ANN with PHP SymfonyCon Madrid 2014 
Board 
Command.php 
<?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);
ANN with PHP SymfonyCon Madrid 2014 
Board 
Command.php 
<?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);
ANN with PHP SymfonyCon Madrid 2014 
Board 
Command.php 
<?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);
ANN with PHP SymfonyCon Madrid 2014 
Board 
Board.php 
<?php 
namespace PHPGamesConsoleHelper; 
class Board 
{ 
/** 
* @var SymfonyComponentConsoleOutputOutputInterface 
*/ 
private $output; 
/** 
* Clears the output buffer 
*/ 
private function clear() 
{ 
$this->output->write("e[2J"); 
} 
// ... 
Instruction that 
clears the screen
ANN with PHP SymfonyCon Madrid 2014 
There is a bonus helper
ANN with PHP SymfonyCon Madrid 2014 
Symfony Console - HAL 
Command.php 
<?php 
$hal = new HAL($output); 
$hal->sayHello();
ANN with PHP SymfonyCon Madrid 2014 
Artificial 
Neural 
Networks 
Computer model that intends to simulate how the brain works
ANN with PHP SymfonyCon Madrid 2014 
A typical ANN 
Input neuron 
Hidden neuron 
Output neuron 
Signal & weight
ANN with PHP SymfonyCon Madrid 2014 
Activation Functions 
Functions to process the input and produce a signal as output
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
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
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
ANN with PHP SymfonyCon Madrid 2014 
Backpropagation 
Backward propagation of errors 
Passes error signals backwards through the network during training to update the weights of the network
ANN with PHP SymfonyCon Madrid 2014 
ANN Types
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.
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.
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.
ANN with PHP SymfonyCon Madrid 2014 
ANN Learning
ANN with PHP SymfonyCon Madrid 2014 
ANN Learning 
• Supervised 
• Unsupervised 
• Reinforcement
ANN with PHP SymfonyCon Madrid 2014 
ANN Learning 
• Supervised 
• Unsupervised 
• Reinforcement
ANN with PHP SymfonyCon Madrid 2014 
ANN Learning 
• Supervised 
• Unsupervised 
• Reinforcement
ANN with PHP SymfonyCon Madrid 2014 
We've used 
Reinforcement Learning 
With some slights adaptations to solve
ANN with PHP SymfonyCon Madrid 2014 
Temporal Credit Assignment 
Problem
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
What The Fann 
Artificial Neural Networks with PHP
ANN with PHP SymfonyCon Madrid 2014
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
Meet libfann & PECL fann 
$~> sudo apt-get install libfann; sudo pecl install fann
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
 OS X 
1. 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
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
 OS X 
1. 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
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
 OS X 
1. 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
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
 OS X 
1. 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
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
 OS X 
1. 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
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
Enjoy!
ANN with PHP SymfonyCon Madrid 2014 
(WTF) ANN with 
Show me the code!
ANN with PHP SymfonyCon Madrid 2014 
Demo 
vs.
ANN with PHP SymfonyCon Madrid 2014
ANN with PHP SymfonyCon Madrid 2014 
The two neurons behind this talk
ANN with PHP SymfonyCon Madrid 2014 
Eduardo Gulias 
@egulias 
• EmailValidator 
(Symfony >= 2.5, Drupal 8). 
• ListenersDebugCommandBundle 
(ezPublish 5). 
• PHPMad UG co-founder 
(Former Symfony Madrid). 
• Team leader at
ANN with PHP SymfonyCon Madrid 2014 
Ariel Ferrandini 
@aferrandini 
• Symfony simple password encoder 
service. (Symfony >=2.6). 
• Symfony DX application 
collaborator. 
• PHPMad UG co-founder. 
• Team leader at Paradigma 
Tecnológico
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)
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)
ANN with PHP SymfonyCon Madrid 2014 
Thank you! 
https://joind.in/12951
ANN with PHP SymfonyCon Madrid 2014 
Questions? 
https://joind.in/12951

More Related Content

What's hot

Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)fefe7270
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performancesjulien pauli
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objectsjulien pauli
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension reviewjulien pauli
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate WorksGoro Fuji
 
C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)Yuki Tamura
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced pythonCharles-Axel Dein
 
PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5julien pauli
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perlgarux
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersLin Yo-An
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)fefe7270
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 

What's hot (20)

PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performances
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
 
Functions
FunctionsFunctions
Functions
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension review
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate Works
 
C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)C++の話(本当にあった怖い話)
C++の話(本当にあった怖い話)
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
 
PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Usp
UspUsp
Usp
 
Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 

Similar to Artificial Neural Networks with PHP & Symfony con 2014

CodePolitan Webinar: The Rise of PHP
CodePolitan Webinar: The Rise of PHPCodePolitan Webinar: The Rise of PHP
CodePolitan Webinar: The Rise of PHPSteeven Salim
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6Wim Godden
 
CLI, the other SAPI
CLI, the other SAPICLI, the other SAPI
CLI, the other SAPICombell NV
 
Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Vyacheslav Matyukhin
 
symfony: Simplify your professional web development with PHP (IPC Frankfurt 2...
symfony: Simplify your professional web development with PHP (IPC Frankfurt 2...symfony: Simplify your professional web development with PHP (IPC Frankfurt 2...
symfony: Simplify your professional web development with PHP (IPC Frankfurt 2...Fabien Potencier
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7Wim Godden
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0GrUSP
 
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your worldCakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your worldGraham Weldon
 
3. build your own php extension ai ti aptech
3. build your own php extension   ai ti aptech3. build your own php extension   ai ti aptech
3. build your own php extension ai ti aptechQuang Anh Le
 
07 build your-own_php_extension
07 build your-own_php_extension07 build your-own_php_extension
07 build your-own_php_extensionNguyen Duc Phu
 
Build your own PHP extension
Build your own PHP extensionBuild your own PHP extension
Build your own PHP extensionVõ Duy Tuấn
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Wim Godden
 
Write Plugins for symfony (Symfony Camp 2007)
Write Plugins for symfony (Symfony Camp 2007)Write Plugins for symfony (Symfony Camp 2007)
Write Plugins for symfony (Symfony Camp 2007)Fabien Potencier
 
Symfony Live 09 Symfony 2
Symfony Live 09 Symfony 2Symfony Live 09 Symfony 2
Symfony Live 09 Symfony 2narkoza
 
Artificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console applicationArtificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console applicationEduardo Gulias Davis
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016Codemotion
 

Similar to Artificial Neural Networks with PHP & Symfony con 2014 (20)

CodePolitan Webinar: The Rise of PHP
CodePolitan Webinar: The Rise of PHPCodePolitan Webinar: The Rise of PHP
CodePolitan Webinar: The Rise of PHP
 
Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3
 
PhpSpec extension points
PhpSpec extension pointsPhpSpec extension points
PhpSpec extension points
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 
CLI, the other SAPI
CLI, the other SAPICLI, the other SAPI
CLI, the other SAPI
 
Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)
 
symfony: Simplify your professional web development with PHP (IPC Frankfurt 2...
symfony: Simplify your professional web development with PHP (IPC Frankfurt 2...symfony: Simplify your professional web development with PHP (IPC Frankfurt 2...
symfony: Simplify your professional web development with PHP (IPC Frankfurt 2...
 
Running Symfony
Running SymfonyRunning Symfony
Running Symfony
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0
 
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your worldCakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your world
 
3. build your own php extension ai ti aptech
3. build your own php extension   ai ti aptech3. build your own php extension   ai ti aptech
3. build your own php extension ai ti aptech
 
07 build your-own_php_extension
07 build your-own_php_extension07 build your-own_php_extension
07 build your-own_php_extension
 
Build your own PHP extension
Build your own PHP extensionBuild your own PHP extension
Build your own PHP extension
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?
 
Write Plugins for symfony (Symfony Camp 2007)
Write Plugins for symfony (Symfony Camp 2007)Write Plugins for symfony (Symfony Camp 2007)
Write Plugins for symfony (Symfony Camp 2007)
 
Symfony Live 09 Symfony 2
Symfony Live 09 Symfony 2Symfony Live 09 Symfony 2
Symfony Live 09 Symfony 2
 
Artificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console applicationArtificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console application
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 

Recently uploaded

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 

Artificial Neural Networks with PHP & Symfony con 2014

  • 1. with PHP on a Symfony Console TicTacToe game Artificial Neural Networks
  • 2. 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
  • 3. ANN with PHP SymfonyCon Madrid 2014 Demo vs.
  • 4. ANN with PHP SymfonyCon Madrid 2014 Symfony Console
  • 5. ANN with PHP SymfonyCon Madrid 2014 Symfony Console - Installation bin/console #!/usr/bin/env php <?php require __DIR__ . ‘/../vendor/autoload.php'; use SymfonyComponentConsoleApplication; $app = new Application(); $app->run(); composer.json { ... "require": { "symfony/console": "~2.5" } ... }
  • 6. ANN with PHP SymfonyCon Madrid 2014 Symfony Console - Installation bin/console #!/usr/bin/env php <?php require __DIR__ . ‘/../vendor/autoload.php'; use SymfonyComponentConsoleApplication; $app = new Application(); $app->run(); composer.json { ... "require": { "symfony/console": "~2.5" } ... } $ php bin/console $ chmod +x bin/console $ bin/console
  • 7. ANN with PHP SymfonyCon Madrid 2014
  • 8. ANN with PHP SymfonyCon Madrid 2014 Symfony console style guide https://github.com/symfony/symfony-docs/issues/4265 Created by @javiereguiluz Improved by Symfony community
  • 9. ANN with PHP SymfonyCon Madrid 2014 Symfony Console Helpers Progress bar Table Question Formatter
  • 10. ANN with PHP SymfonyCon Madrid 2014 Command.php Progress bar <?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();
  • 11. ANN with PHP SymfonyCon Madrid 2014 We all techies love progress bars
  • 12. ANN with PHP SymfonyCon Madrid 2014 Table Command.php <?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();
  • 13. ANN with PHP SymfonyCon Madrid 2014 Question Command.php <?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!");
  • 14. ANN with PHP SymfonyCon Madrid 2014 Formatter Command.php <?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);
  • 15. ANN with PHP SymfonyCon Madrid 2014 Our helper
  • 16. ANN with PHP SymfonyCon Madrid 2014 Board Command.php <?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);
  • 17. ANN with PHP SymfonyCon Madrid 2014 Board Command.php <?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);
  • 18. ANN with PHP SymfonyCon Madrid 2014 Board Command.php <?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);
  • 19. ANN with PHP SymfonyCon Madrid 2014 Board Board.php <?php namespace PHPGamesConsoleHelper; class Board { /** * @var SymfonyComponentConsoleOutputOutputInterface */ private $output; /** * Clears the output buffer */ private function clear() { $this->output->write("e[2J"); } // ... Instruction that clears the screen
  • 20. ANN with PHP SymfonyCon Madrid 2014 There is a bonus helper
  • 21. ANN with PHP SymfonyCon Madrid 2014 Symfony Console - HAL Command.php <?php $hal = new HAL($output); $hal->sayHello();
  • 22. ANN with PHP SymfonyCon Madrid 2014 Artificial Neural Networks Computer model that intends to simulate how the brain works
  • 23. ANN with PHP SymfonyCon Madrid 2014 A typical ANN Input neuron Hidden neuron Output neuron Signal & weight
  • 24. ANN with PHP SymfonyCon Madrid 2014 Activation Functions Functions to process the input and produce a signal as output
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. ANN with PHP SymfonyCon Madrid 2014 Backpropagation Backward propagation of errors Passes error signals backwards through the network during training to update the weights of the network
  • 29. ANN with PHP SymfonyCon Madrid 2014 ANN Types
  • 30. 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.
  • 31. 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.
  • 32. 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.
  • 33. ANN with PHP SymfonyCon Madrid 2014 ANN Learning
  • 34. ANN with PHP SymfonyCon Madrid 2014 ANN Learning • Supervised • Unsupervised • Reinforcement
  • 35. ANN with PHP SymfonyCon Madrid 2014 ANN Learning • Supervised • Unsupervised • Reinforcement
  • 36. ANN with PHP SymfonyCon Madrid 2014 ANN Learning • Supervised • Unsupervised • Reinforcement
  • 37. ANN with PHP SymfonyCon Madrid 2014 We've used Reinforcement Learning With some slights adaptations to solve
  • 38. ANN with PHP SymfonyCon Madrid 2014 Temporal Credit Assignment Problem
  • 39. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with What The Fann Artificial Neural Networks with PHP
  • 40. ANN with PHP SymfonyCon Madrid 2014
  • 41. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with Meet libfann & PECL fann $~> sudo apt-get install libfann; sudo pecl install fann
  • 42. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with  OS X 1. 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
  • 43. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with  OS X 1. 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
  • 44. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with  OS X 1. 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
  • 45. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with  OS X 1. 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
  • 46. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with  OS X 1. 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
  • 47. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with Enjoy!
  • 48. ANN with PHP SymfonyCon Madrid 2014 (WTF) ANN with Show me the code!
  • 49. ANN with PHP SymfonyCon Madrid 2014 Demo vs.
  • 50. ANN with PHP SymfonyCon Madrid 2014
  • 51. ANN with PHP SymfonyCon Madrid 2014 The two neurons behind this talk
  • 52. ANN with PHP SymfonyCon Madrid 2014 Eduardo Gulias @egulias • EmailValidator (Symfony >= 2.5, Drupal 8). • ListenersDebugCommandBundle (ezPublish 5). • PHPMad UG co-founder (Former Symfony Madrid). • Team leader at
  • 53. ANN with PHP SymfonyCon Madrid 2014 Ariel Ferrandini @aferrandini • Symfony simple password encoder service. (Symfony >=2.6). • Symfony DX application collaborator. • PHPMad UG co-founder. • Team leader at Paradigma Tecnológico
  • 54. 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)
  • 55. 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)
  • 56. ANN with PHP SymfonyCon Madrid 2014 Thank you! https://joind.in/12951
  • 57. ANN with PHP SymfonyCon Madrid 2014 Questions? https://joind.in/12951