The document discusses building a Tic Tac Toe game console application using artificial neural networks and PHP. It covers setting up the Symfony Console component, an overview of ANN concepts like activation functions and learning types, using the FANN library for PHP, and includes code examples of implementing the game.
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Artificial Neural Networks on a Tic Tac Toe console application
1. with PHP on a
Symfony Console
TicTacToe game
Artificial
Neural
Networks
2. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Agenda
1. Demo
2. Symfony Console
3. ANN Theory
4. PHP + FANN
5. Show me the code
6. Demo
7. Q&A
9. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Symfony console style guide
https://github.com/symfony/symfony-docs/issues/4265
Created by @javiereguiluz
Improved by Symfony community
10. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Symfony Console - Helpers
Progress bar
Table
Question
Formatter
11. DPCon 2015Artificial Neural Networks
on a Tic Tac Toe
console application
<?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
12. DPCon 2015Artificial Neural Networks
on a Tic Tac Toe
console application
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
13. DPCon 2015Artificial Neural Networks
on a Tic Tac Toe
console application
Question
<?php
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion(
'Do 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
15. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Helper helpers
$~> composer require phpgames/board-helper
16. DPCon 2015Artificial Neural Networks
on a Tic Tac Toe
console application
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
17. DPCon 2015Artificial Neural Networks
on a Tic Tac Toe
console application
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
18. DPCon 2015Artificial Neural Networks
on a Tic Tac Toe
console application
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
19. DPCon 2015Artificial Neural Networks
on a Tic Tac Toe
console application
Board
<?php
namespace PHPGamesConsoleHelper;
class Board
{
/**
* @var SymfonyComponentConsoleOutputOutputInterface
*/
private $output;
/**
* Clears the output buffer
*/
private function clear()
{
$this->output->write("e[2J");
}
// ...
Board.php
Instruction that
clears the
screen
21. DPCon 2015Artificial Neural Networks
on a Tic Tac Toe
console application
Symfony Console - HAL
<?php
$hal = new HAL($output);
$hal->sayHello();
Command.php
22. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Computer model that intends to simulate how the brain works
Artificial
Neural
Networks
23. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Input neuron
A typical ANN
Hidden neuron
Output neuron
Signal & weight
24. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Activation Functions
Functions to process the input and produce a signal as output
25. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Activation Functions
• Step - output is 0 or 1
• Linear Combination - output is input sum plus
a linear bias
• Continuous Log-Sigmoid
26. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Activation Functions
• Step - output is 0 or 1
• Linear Combination - output is input sum plus
a linear bias
• Continuous Log-Sigmoid
27. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Activation Functions
• Step - output is 0 or 1
• Linear Combination - output is input sum plus
a linear bias
• Continuous Log-Sigmoid
28. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
Backpropagation
Backward propagation of errors
Passes error signals backwards through the network during training to update the weights of the network
30. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
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. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
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. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
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.
34. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
ANN Learning
• Supervised
• Unsupervised
• Reinforcement
• Supervised
• Unsupervised
• Reinforcement
35. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
ANN Learning
• Supervised
• Unsupervised
• Reinforcement
36. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
ANN Learning
• Supervised
• Unsupervised
• Reinforcement
37. Artificial Neural Networks
on a Tic Tac Toe
console application
DPCon 2015
With some slights adaptations to solve
We've used
Reinforcement Learning