Generating Pokemon Names Using Neural Network

So while talking about Pokemon Go in the office, we got an idea to generate Pokemon names using a neural network.

The first step for this is gathering all the Pokemon names. Fortunately, I found this site that generates all the names of existing Pokemon in a text file.

Then we’ll be using Torch-RNN to train the neural network and produce new Pokemon names.

After some 5 minutes of training, here are the ouput:

  • Duepiglypuff
  • Hitmoncle
  • Magnetal
  • Galder
  • Cherfree
  • Cabutcen
  • Scactas
  • Magune
  • Keosedogas
  • Felipup
  • Peropat
  • Poundoom
  • Hoathor
  • Honchlaigon
  • Glankey
  • Manting
  • Cingerno
  • Miesproce
  • Hoothon
  • Magnezone
  • Makuhita
  • Nidoras

For training, here’s the command used:

th train.lua -input_h5 data/pokemon.h5 -input_json data/pokemon.json -gpu -1 -batch_size 1 -seq_length 3

For generating the Pokemon names:

th sample.lua -checkpoint cv/pokemon.t7 -length 100 -gpu -1 -temperature 0.9

image source

July 8, 2016

PUV Start Routes 2015

Where are PUVs in Metro Manila coming from?

I found a CSV file from data.gov.ph that contains all the PUV routes in Metro Manila. I then decided to check where are the PUVs coming from.

Here it is:

image

See the full image here.

Some notes:

  • Some or most of the points are just approximate because the CSV file doesn’t contain coordinates.
  • Used Google Maps Reverse Geocoding API to approximate the latitude and longitude of each location.
  • The icon size is determined by how many PUVs started from that location.
  • The locations with the most start routes for PUVs are:
    • Alabang (37, jeepney)
    • Baclaran (26, jeepney)
    • Binangonan (20, jeepney)
    • Antipolo (19, jeepney)
    • Cubao (15, jeepney)
  • In total, there are 512 different routes.
  • But there are only 201 unique start routes.
  • Used D3.js to graph
  • The code is in my Github.
April 2, 2016

Simple Genetic Algorithm AI for FB Messenger’s Basketball game

Recently, a lot of people including me and my friends are passionately playing the Facebook Messenger’s hidden basketball game. We are competitive with each other.

Inspired by Flappy Bird RL, I decided to create an AI for FB Basketball game.

Here’s a sample screenshot:

image


Problem: No FB Basketball game in the web version of Messenger.

Without any choice, I recreated it using the HTML5 game framework called Phaser. It was the hardest part for me because I’m not really adept with javascript and game development in general.

After the game engine, I started creating the AI. I decided to use and study genetic algorithm because I’m really facinated with it.

Genetic algorithm (GA) is a search heuristic that mimics the process of natural selection.

via Wikipedia

I used this website as guide and pattern for the GA in this game. Most of the code in ga.py file is similar to it.

Specifics:

  • Individuals are created by randomly generating an angle in radians (min: -2.5, max: -0.8).
  • For this, the number of population is 20.
  • Fitness is determine by getting the difference of the perfect angle (to target) with the individual angle. The closer (close to 0) the better.

In the evolution phase:

  • Top 30% of the population will be retained to be parents
  • 5% chance to be retained even the individual is not part of the top 30%
  • 5% chance of mutation
  • The parents are used as the minimum and maximum in creating the individual for the children.

Here’s another screenshot:

image


As seen above, red lines are the prospect angles (population) and the green line is the fittest (best) angle.

The highest score I got with this AI is 1110 (generations: 100) before it misses and I stopped running it again.

The process:

  1. The algorithm started by getting the coordinates of the ball (current) and the coordinates of the basketball ring (ring).
  2. The target’s X axis is computed by getting the middle of the current’s X axis and ring’s X axis.[code] Target’s Y axis is 0 which is the highest point in the game. This is done to adjust the target because you can’t actually throw the ball directly to the ring due to the gravity and resulting trajectory.
  3. Then the starting population is generated with random angles as individuals.[code]
  4. The population will evolve, selecting the fittest individuals (closest angle to the target), crossover, mate, and mutate to produce children. More information about this in the Specifics above.
  5. Evolution will happen repeatedly until the specified number of generations (default is 10).[code]
  6. After arriving in the last generation, the algorithm will select the fittest individual among its population.
  7. The angle of the fittest individual will be used for the shot.

Here’s a video of the actual AI in action (generations: 3):

The AI missed in the first part of the video.


BONUS VIDEO: When your AI is now better than Stephen Curry in shooting the basketball (generations: 100)


View the whole code in Github: https://github.com/MojoJolo/fb_basketball

Note: Well, we can make it to never miss by computing the exact angle and trajectory. But it’s not the goal, and where’s the fun in it.

March 31, 2016

Visualizing Earthquake in the Philippines

There was a take home task that was assigned to me after an interview. The simple assignment was for me to show my capabilities in data mining and visualization. The task is to plot the earthquake data of 2014 in the Philippine map. The Philippine Institute of Volcanology and Seismology (PHIVOLCS) have this data, together with the coordinates in their website.

To start with the task, I copy paste the 2014 earthquake data in a text file. I then created a Python script to cleanse the data and produce a csv file out of it.

Here is a screenshot of the data in PHIVOLCS website:

image


And after running a simple Python script, here’s result:

image


With the data properly written in the csv file, I can now visualized it in a map. I decided to try and explore D3.js for the first time. Luckily, I found a tutorial in integrating Google maps and D3.js. While the tutorial is for json files, it still helps a lot and only need a minor tweaks for it to read my csv file.

After few modifications, I settled with the final result. Here it is:

image

Check out the full image here.

Notes:

  • The size of the circle differs from each other because they are based on the magnitude of the earthquake.
  • There are 2000+ different earthquakes happened in the Philippines last year.
  • There are 5 earthquakes last year that have a magnitude of greater than 6.
  • Two of them happened in December.
  • The strongest earthquake last year has a magnitude of 6.4 and occurs near Sultan Kudarat.
  • If you’re afraid of earthquakes, live in Palawan.
  • The code and the data used in this project are in Github.

If you need someone to visualized your data, check out DataTeaser. It’s the company I’m starting. We also offer NLP and machine learning services.

February 22, 2015

TextTeaser is now part of DataTeaser

TextTeaser, an open source automatic summarization algorithm that I started, is now part of DataTeaser.

DataTeaser is a data science and software engineering company that I’m starting. It will offer software services in natural language processing, machine learning, and data mining. With TextTeaser as part of the DataTeaser’s projects, we can also offer custom summarizers based on your company needs.

If your company needs summarizer or other NLP services, just send us an email.

You can also still check out the open source TextTeaser at Github.

DataTeaser website

February 21, 2015
  Next >