Friday, August 26, 2016

Machine Learning - Basic Simulator


You can run the simulation right here in your browser!
Click on the ▶ symbol to run the simulation of a red dot ("predator") learning to move towards a blue dot ("prey"):


You can look at the code again by clicking on the pencil icon.

Based on code from: 
http://hchiam.blogspot.ca/2016/08/machine-learning-very-basic-code.html

GitHub repo:
https://github.com/hchiam/machineLearning/blob/master/predatorSim1D.py

Tuesday, August 23, 2016

Machine Learning - Very Basic Code

Machine Learning!

Sounds complicated?  Well, it can be.  But I've put together some super simple code at this GitHub repo github.com/hchiam/machineLearning which has my .py Python files (plus one from iamtrask) that you can run on your own computer (I like to use Terminal commandline)... or you can run the code yourself right here on this page!

Instructions:
= Run Code
= Edit Code

The following four code examples are four different neural nets, ranging from differing approaches to giving "feedback" to the "neuron connections", to testing out a layered version.  Each example is commented (Python uses the "#" character for comments, which should turn green in these interfaces).


neuralNet1.py:  Version 1.  Example of a very simplified neural network, and using a sensitivity parameter.



neuralNet2.py:  Version 2.  Example of a very simplified neural network, with weighting based on "responsibilities" of different inputs.  (This one seems really fast but may be unstable or naive because it's basically using learning sensitivity = 1.)



neuralNet3.py:  Version 3.  Example of a very simplified neural network that combines version 1 and version 2, combining sensitivity parameter and "responsibilities" of different inputs.
 


neuralNet4_Layered.py:  Version 4.  Example of a neural network that kinda combines version 2 and version 3:  uses learning error sensitivity, but now also uses a hidden layer. It also has my own "transformed" (i.e. translated) version of the sigmoid function that goes from -1 to 1.


Again, note that I created these code examples to help myself wrap my head around the very basic basics of machine learning, specifically neural networks.  Hopefully they help you too, through experimenting and reading the comments.  You can Google the rest.


LINKS TO INTERESTING READS/FINDS for Machine Learning:
  • Neural network playground:  here.
  • Python neural network in 11 lines of code:  here.
  • Python genetic algorithm in 15 lines of code:  here.
  • Ruby code for "suggested posts" via machine learning:  here.
  • Python Recurrent Neural Network for generating Shakespeare and more:  here.
  • A longer read but great code examples running in-browserhere.
_________________________

LINKS TO OTHER STUFF: 

Favourites
Programming
Original Art
Games

Chinese Learning Projects:
 - Book
 - HSK 1
 - HSK 5
 - Homonyms Mnemonics

Sunday, August 7, 2016

The Code 7 Project - Problem 5 - Pascal Triangle

(Build Schema.  Run SQL.  Pascal triangle row values in tables below.)
The Code 7 Project - Problem 5 - Pascal Triangle

As usual, you can see my code and run it online without installing anything specialhttp://sqlfiddle.com/#!9/87f0d/3 

For problem 5 from this website, my basic goal was to use SQL to create and access values from a math construct called Pascal's triangleYou can choose a row number (i.e. which row in the triangle to look at), and then you receive the values in that row, output in the form of a table.  My code is programmed using the MySQL dialect of SQL, based on the available online compiler that I used.

If you go to that sqlfiddle link for the code, it should automatically run and print out a few tables (the "val" columns are the values that correspond to their respective rows in Pascal's triangle).  I used the online “sqlfiddle” website to create the MySQL table and client because it seemed easier to use than the corresponding TutorialsPoint website.

I found this YouTube video really helpful in figuring out how to get the fiddler website to work (change the “‘;” in the blue button to “//“):  youtube.com/watch?v=QtiCEAeSOYc   

More info on the "Code 7 Project":  hchiam.blogspot.ca/2016/06/code-7-project-github-blog.html

_________________________

A separate side-project:  "Cognate Language" in Python code.  

Description at the GitHub readme file: 
github.com/hchiam/cognateLanguage/blob/master/README.md


And most up-to-date versions of files: 
github.com/hchiam/cognateLanguage 


_________________________

LINKS TO OTHER STUFF: 

Favourites
Programming
Original Art
Games

Chinese Learning Projects:
 - Book
 - HSK 1
 - HSK 5
 - Homonyms Mnemonics

Basic Terminal Commands for GitHub Branch and Merge, in one place:

You can easily Google for websites describing details of how "git branch" and "git merge" work, but I thought it'd be useful to have their basic commands in one page for reference.  If you want fuller descriptions, goto Google(By the way, "commandline" = "Terminal" on Macs.)

First navigate folders using cd and check what files are there using ls before typing the following commands.  You'll be typing each command one at a time (the comments in blue that start with "#" are just for short explanations--they don't perform anything in Terminal).   

In the commands below, "nameOfBranch" is the name of the branch (a copy of files "branching" temporarily from the master copy).  This would be the name of the branch that you want to create, edit, remotely "save", merge with the original master copy, and finally get rid of:

# create branch & use its files
git branch nameOfBranch
git checkout nameOfBranch

# make changes to its files on your computer…

# transfer files to remote repository, with a message describing the “save”
git add --all
git commit -m “message”
git push origin nameOfBranch

# merge changes into master (by first moving to master branch copy)
git checkout master
git merge nameOfBranch

git push origin master

# get rid of old branch
git branch -D nameOfBranch

I've backed up these instructions (if you prefer a file) at: 
github.com/hchiam/code7/blob/master/gitBranchMerge.txt

More examples of Terminal/Command-Line code for GitHub:  (ctrl+f "essential commands")
http://hchiam.blogspot.ca/2016/06/the-code-7-project-problem-1.html


_________________________

LINKS TO OTHER STUFF: 

Favourites
Programming
Original Art
Games

Chinese Learning Projects:
 - Book
 - HSK 1
 - HSK 5
 - Homonyms Mnemonics