Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Artificial Neural Networks on a Tic Tac Toe console application

1.768 visualizaciones

Publicado el

Dutch PHP Conference 2015 Artificial Neural Networks on a Tic Tac Toe console application talk slides.

Publicado en: Tecnología
  • Inicia sesión para ver los comentarios

Artificial Neural Networks on a Tic Tac Toe console application

  1. 1. with PHP on a Symfony Console TicTacToe game Artificial Neural Networks
  2. 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
  3. 3. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Demo vs.
  4. 4. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Symfony Console
  5. 5. DPCon 2015Artificial Neural Networks on a Tic Tac Toe console application Symfony Console - Installation $~> composer require symfony/console
  6. 6. DPCon 2015Artificial Neural Networks on a Tic Tac Toe console application Symfony Console - Usage #!/usr/bin/env php <?php require __DIR__ . ‘/../vendor/autoload.php'; use SymfonyComponentConsoleApplication; $app = new Application(); $app->run(); bin/console
  7. 7. DPCon 2015Artificial Neural Networks on a Tic Tac Toe console application Symfony Console - Usage #!/usr/bin/env php <?php require __DIR__ . ‘/../vendor/autoload.php'; use SymfonyComponentConsoleApplication; $app = new Application(); $app->run(); bin/console $ chmod +x bin/console $ bin/console
  8. 8. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Symfony Console - Usage
  9. 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. 10. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Symfony Console - Helpers Progress bar Table Question Formatter
  11. 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. 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. 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
  14. 14. DPCon 2015Artificial Neural Networks on a Tic Tac Toe console application 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
  15. 15. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Helper helpers $~> composer require phpgames/board-helper
  16. 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. 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. 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. 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
  20. 20. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 There is a bonus helper
  21. 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. 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. 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. 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. 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. 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. 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. 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
  29. 29. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 ANN Types
  30. 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. 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. 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.
  33. 33. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 ANN Learning
  34. 34. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 ANN Learning • Supervised • Unsupervised • Reinforcement • Supervised • Unsupervised • Reinforcement
  35. 35. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 ANN Learning • Supervised • Unsupervised • Reinforcement
  36. 36. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 ANN Learning • Supervised • Unsupervised • Reinforcement
  37. 37. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 With some slights adaptations to solve We've used Reinforcement Learning
  38. 38. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Temporal Credit Assignment Problem
  39. 39. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 A word on Game Theory and Tic Tac Toe
  40. 40. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Don’t desperate, we are almost there.
  41. 41. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Tic Tac Toe • Perfect Information • Deterministic • Complete
  42. 42. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Tic Tac Toe • Perfect Information • Deterministic • Complete
  43. 43. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Tic Tac Toe • Perfect Information • Deterministic • Complete
  44. 44. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 If you want to have a challenging Tic Tac Toe game MiniMax
  45. 45. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 (WTF) ANN with Artificial Neural Networks with PHP What The Fann
  46. 46. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015
  47. 47. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Meet libfann & PECL fann $~> sudo apt-get install libfann; sudo pecl install fann (WTF) ANN with
  48. 48. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Enjoy! (WTF) ANN with
  49. 49. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Show me the code! (WTF) ANN with
  50. 50. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Demo vs.
  51. 51. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015
  52. 52. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 The two neurons behind this talk
  53. 53. DPCon 2015Artificial Neural Networks on a Tic Tac Toe console application Ariel Ferrandini • Symfony simple password encoder service. (Symfony >=2.6). • Symfony DX application collaborator. • PHPMad UG co-founder. • Senior Backend Developer @ Lighthouse Guidance Systems Ltd. @aferrandini
  54. 54. DPCon 2015Artificial Neural Networks on a Tic Tac Toe console application Eduardo Gulias • EmailValidator (Symfony >= 2.5, Drupal 8, Swiftmailer 6 & others). • ListenersDebugCommandBundle (ezPublish 5). • PHPMad UG co-founder (Former Symfony Madrid). • Team leader at @egulias
  55. 55. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 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)
  56. 56. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Resources • Repo PHPGames (https://github.com/phpgames/ANNTicTacToe) • Repo Board helper (https://github.com/phpgames/BoardHelper) • Repo HAL helper (https://github.com/phpgames/HALHelper)
  57. 57. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Thank you! https://joind.in/14212
  58. 58. Artificial Neural Networks on a Tic Tac Toe console application DPCon 2015 Questions? https://joind.in/14212

×