Friday, May 22, 2015

LayerOne 2015

A security conference called LayerOne is being held this weekend in LA. I'm not planning on attending, but the events sound like they would be fun if I knew more.

Saturday, October 04, 2014

Silicon Valley Code Camp

Next weekend, a free software developer "code camp" in Silicon Valley will be held at Foothill College. I'm not going, but I hope some notes about functional programming will be posted on their website. I'm not using functional programming and do not plan to until I've tried it out on some small projects. I am trying to learn more about it due to the influence of Douglas Crockford and his javascript talks. Hopefully by the end of the month I will checkout the basics of the why and what of functional programming

Friday, October 03, 2014

p-value again

NY Times statistics article describes p-value in a more approachable manner than what I noted earlier. 
Today, this kind of number is called a p-value, the probability that an observed phenomenon or one more extreme could have occurred by chance. Results are usually considered “statistically significant” if the p-value is less than 5 percent.
So the null hypothesis would lead us to use a probability distribution of chance. Statistical hypothesis testing can then disprove this hypothesis by showing that the observation or something more extreme is unlikely to have occurred if the cause were random because calculating the probability based on this picked distribution shows its chances at less than 5 percent.

I believe doing it this way helps make testing the null hypothesis repeatable, but I haven't found an approachable explanation yet.


Friday, May 16, 2014

Machine Learning On Coursera By Andrew Ng

The machine learning class on Coursera by Dr. Andrew Ng is helping people all over the globe. Watching the videos and doing the assignments takes quite a lot of time and can be a struggle. After work, people can feel reluctant to sit in front of a computer for a couple more hours. But, it has been reported in the past that thousands of people, around 10%, are finishing. I'm not sure what the numbers are for the last session of the course that has recently ended. The professor tweeted he is going to work for Baidu now. Yet, another session appears to be scheduled to start June 16. Right now, I am half way through and am glad to restart this path because it seems like machine learning has been used in many applications, such as autonomous vehicles and computer vision. I don't yet see exactly how I will apply this, but I still feel grateful to Coursera and Dr. Ng for taking the time to help the world with this machine learning class.

Sunday, February 02, 2014

notes of Windows 7 install

Over the weekend, an install of Windows 7 as a guest in virtualbox went smoothly. However, after a few hours of use, upon shutdown over 100 updates needed to be applied. A message warned not to force a shutdown, so the laptop needed to sit over an hour waiting for the updates. I have not tried slipstreaming Windows 7 but may need to investigate that option next time. An article about slipstreaming Windows 7 is published at PC World. It looks like a rather involved process however.

Saturday, January 18, 2014

android studio install notes for app project

Android Studio Install Notes:

http://stackoverflow.com/questions/17474963/android-studio-tools-jar-file-is-not-present-in-classpath/17827697#17827697

http://stackoverflow.com/questions/17033726/android-studio-error-after-studio-sh

Linux Mint Maya

http://developer.android.com/sdk/installing/studio.html

http://stackoverflow.com/questions/17033726/android-studio-error-after-studio-sh

sudo apt-get install openjdk-7-jdk

Environment Variable -- sudo nano /etc/environment adding the following line:
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-i386

Reboot

Downloaded:http://services.gradle.org/distributions/gradle-1.8-bin.zip

unpacked and moved to android-studio/plugins/gradle after backing up previous gradle folder

use local gradle distribution
android-studio/plugins/gradle

sudo update-alternatives --config java

after git clone import project not open project

http://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-android-studio-project

manually add libs and modules

Tools -> Android -> SDK Manager
android support library
android 2.2



Saturday, December 28, 2013

machine learning rc car project

A two year old blog post by some one about a remote control car driven by a neural network was interesting. I recently took another look at it, and this time I did something. I'm starting to learn Android development with Java and Android Studio so I modified the code a bit to run in Android Studio, and then forked the remote control car project on github. Used jdk 7 for android studio and gradle 1.8. Encountered some trouble with the alert dialog to get the ip so rewrote it as separate activity. First test with wifi communication between laptop and phone did not work. Not sure why it started working after a reinstall. Will need to test it again later.

Monday, November 18, 2013

Machine Learning Basics

This video, Machine Learning: The Basics, with Ron Bekkerman, looks like an interesting introduction to machine learning. I tried the Kaggle digit recognizer kNN benchmark over a month ago and it took several hours on my laptop. He does warn in the video that this algorithm can experience some scalability issues. I haven't had the desire to progress further in the Learning From Data class. Watching this video on machine learning was a step I haven't taken in quite a while. The video didn't get into much technical detail, but I didn't really feel like sitting through that right now.

Friday, October 25, 2013

Quick Note about P-value Confusion

Lately I've been working on learning about p-values and hypothesis testing. I'm still learning introductory statistics and am having trouble keeping the idea so I am going to note it here for future reference. A comment with a mnemonic at cross validated is "p is low, H0 must go". At this point, I believe that means the probability of seeing the data assuming that the null hypothesis is true is too low to believe. It is highly unlikely we would see this data if the original assumption was correct, and so we should reject the null hypothesis. I hope I have this in the right order and that it is not always the probability of the null hypothesis being true given the data collected. The wikipedia page has a list of misunderstandings and criticisms of the p-value that I hope to check out later. Based on a forum post, to interpret p-value again, if the null hypothesis is true then p percent of experiments should show a test statistic that is the same or more extreme than what was collected with the current experiment being analyzed. Hence by repeating the experiment one can become more confident that the data from a previous experiment was not an extreme event. Once more, based on the wikipedia page, the p-value is the probability of observing the test statistic or something more extreme.

Sunday, September 01, 2013

Javascript Homework

Learning From Data
Homework #1 visualization
101 iterations
20 data points
A jQuery Mobile Charts post encouraged me to try out an unusual javascript project. It helped answer question 7 of homework #1 from the 2012 archives of the Learning From Data course by CalTech. In this homework assignment, an exercise is proposed to use a very basic perceptron learning algorithm presented in lecture. The problem definition restricted input to a 2-d feature set to facilitate visualization with scatter charts. Another simplification involved limiting the number of classes to 2. A function defined by a randomly placed line determined class. As can be seen in the picture, above the orange line was the red class, and below the line was the blue class. The orange line in the chart is the function the learning algorithm is trying to approximate. The particular case posted in the image was an outlier that took 101 tries before the learning algorithm hypothesized the green line shown in the picture and thus correctly classified all 20 points of the training data. The two lines look very similar so in this case the classification error was very low. Some runs with a different random set of data were not so close.

The project requirements were not tied to a programming language or platform and don't need high performance. This was just the first homework assignment, and I am sure it gets harder. At first I started with a C# tool due to familiarity, but later I attended a jQuery mobile class and found the related charts blog post. Since I still want to finish my reversi project from last year in javascript and also wanted to try out some of what was taught in the class, I changed platforms and languages. Of course, using javascript for a machine learning solution seems unusual. Most existing machine learning libraries are in another language. But due to the nature of the homework assignment, it seemed to make sense for this special case:

  1. The simple perceptron learning algorithm isn't likely to be found in an existing library because it is too basic to be of practical use.
  2. Coding it from scratch enables learning
  3. It is simple enough to code from scratch
  4. I have some familiarity with javascript language already
  5. It is relatively easy to share the results cross platform
  6. It doesn't take a lot of code as long as you have a plotting library
  7. Performance isn't a requirement
  8. Platform isn't a requirement

 I only needed to restart plotting points and a line to get to the point were I left off in the other language. A problem with the charting library arose, but thankfully a guy from Europe found a workaround and posted it to stack overflow. With his help, I was able to use the jqplot library together with jquery mobile to finish the tool this holiday weekend.

Friday, March 22, 2013

Repost of coding tip


Interesting tip on the process of coding on tumblr from Brad Milne:
The One Tip That Will Help You Learn To Code 10x Faster

The information about a trap was what struck me:
To be honest, it hurt when I heard it because I literally have spent probably close to 100 hours so far looking for answers online and getting caught up into learning something else. You know how it is… because you don’t know what you don’t know it’s easy to fall into the trap of thinking that whatever you’re learning at the time is worthwhile. IT ISN’T.
It reminds me of a search tree that has branched too widely on a breadth first search or has gone too deeply on a depth first search. It seems one needs a heuristic to bound the search. But as he states, you don't know what you don't know, so it is hard to estimate the distance to finding the goal node from the node you are on.



Saturday, October 27, 2012

Reversi to HTML5

I still have not found any time to continue work on my reversi app. I'm not planning on changing the development language of the game logic due to lack of time, but for the interface it might be a good exercise to try jquery mobile and html5. @Rockncoder has some slides on beginning HTML5 mobile game programming. I would like to make a sprite map to animate disc turnovers during a reversi turn.

As described in the slides, a sprite is a two dimensional image that gets placed into a scene. The map part means that there is a single file composed of several individual sprites. From what I've read, having a single file makes the transfer from server to browser more efficient. Perhaps this is because there are fewer transfers to setup.

On the other hand, I was originally planning on using an animated gif to animate the disc turnovers. A timer would start at the start of the animation and then swap out the animated gif with a regular image at the end of the turnover sequence. This method has a chance of getting the animation out of sync with the image swapping, so the sprite method seems better.

A Github repository has the demonstration code associated with the slides. I also need to look for images to make the sprite map for reversi. To animate the turning, I plan on scaling the images of the black and white disc and saving out the different scaled images with sumo paint online. A different github repository by Christian Cantrell has some images I can try to do this with. They have a transparent background so hopefully all I will need to do is scale the png files.

I don't have much experience with the sumo paint web site, but I assume scaling the images shouldn't be that hard. There should be a way to upload the images and then apply an image resize tool to them. Hopefully it will remember the background is transparent. Also, the newly sized image will need to be recentered and the image background size preserved to keep the sprite sizes the same. Also, since the goal is a collection of images in a sprite map, some of the images may need to be separated out and then put back together. That way, the original images will not get scaled along with the images of the discs turning. Recentering is important so that the disc does not shift during the turnover animation. One way would be to calculate the difference between the new image size and the original image size, divide by 2, and then shift by that amount.

So my next steps for the reversi project are to scale some disc images, collect them into a sprite map, reuse parts of the sprite engine from @rockncoder, and make a test html5 and javascript page that animates disc turning.

Sunday, October 14, 2012

Reversi Blog Posts

I still haven't worked on my Reversi program since the last post. Instead, I did some web browsing and found a blog post by some one who wrote an Othello program in C#. He has several posts on the topic that look like they could be educational. I only had time to look over a couple of them. The Othello program part 2 post had an interesting trick on how to encode a position on the board. Instead of a coordinate pair such as 0,0 or 7,7, he transformed the location into a single offset 0-63 and then started the offset that from a letter to turn the description into an alphanumeric. Since it is text it could now be transmitted as part of a hyperlink.

My current system is not as simple. To turn the coordinate into text I used base64 encoding of a byte array. Each byte I separated into a low and high 4 bit number to get a board coordinate. Base64 uses 6 bits instead of all 8 bits. However it still needs to end on a byte boundary and is an extra call. The minimal amount of bits to describe a coordinate is 6 bits, so it could map to Base64 encoding. However, it seems like it would get complicated aligning a series of 6 bits numbers to byte boundaries so I didn't go to the trouble of doing so.

A calculation can describe a rough estimate of the savings. For a maximum of 60 moves that could be played the single offset method would simply describe it with 60 bytes. If encoding with 6 bits instead of 8 bits, that would result in 360 bits or 45 bytes. So a potential savings of 15 bytes at the end. It seems like a lot of complication for 15 bytes so I haven't done it yet, but there is a difference that could add up if this operation is done a lot. However, if one decides to just send back one move at a time the base64 encoding would actually take up more bytes than the single character encoding method.

This seems like a change of detail that I might have enough time to do over a weekend. However, I would still need tools to quantify the benefit of making a change to 6 bits, while the change from a pair of numbers to a single character is clearly simpler to work with and may be the way to go. Hopefully, reading his other Othello blog posts will encourage me to work on my project again.



Saturday, October 06, 2012

Ruby Reversi

My progress on a reversi program has stalled. To help revive my interest in the project, I looked around for Ruby implementations. There are a couple from Japan on github. The one called Ruby Reversi looked like it would be easier to understand since it looks like a console application rather than an entire Rails app.

So far I've tried to get a grasp of the overall organization. It looks pretty logical. There are divisions based on the user interface, AI, game rules, board data, and some kind of dynamic controller. Of these divisions, two differences from my project that stand out. One is the separation of the game logic from the board's 2-d array data structure. I'm guessing that separating the 2-d array data structure from the game logic enables the 2-d array to be more reusable while isolating the specific problem domain code in the rule files. Perhaps this also helps readability because once one reads the file name "array2d" the behavior of that file is understood, and one can pretty much skip reading that code.

The other major difference is the method of program flow control. I'm not that familiar with Ruby, but it looks like his or her design is event based. When the user interacts with the program their actions raise events and are not causing a method to be called directly. Instead, it looks like an action method routes the event to the appropriate behavior. Benefits of this design may be those of using the command pattern: undo and macro operations. However I don't see those in the design. I'm not sure whether I like this way of organizing the behavior as it seems to complicate the initial reading, but it could have benefits in terms of centralizing and organizing how a program behaves.

Overall it was interesting to look over some one else's design and see some differences, such as in the language and the organization. It was not entirely obvious what the benefits and drawbacks are to the various differences, but by working on this post, I hope some of them were revealed. I also hope this post encourages me to finish the project.

Sunday, August 19, 2012

git

While rewriting a reversi project from a game programming book to help myself learn python, I ran into difficulty reorganizing the code to extract out a new class. I'm not exactly sure why it took so long and still isn't readable. I believe if I had made the change on a parallel set of files I might now be able to go back and attempt to redo what went wrong. As a result, I'm installing git as a version control system even though I am the only one working on this project. I found a beginner tutorial on getting started with git and also found a git extensions project that has visual studio integration. Now I will need to remember to commit before each set of changes to the project. I had already installed git on a laptop, but lately I've started to develop on my old desktop where I had not done much work on as far as I can recall.

Sunday, July 29, 2012

I continued my attempt at improving at Python by checking with others who are willing to look over code and suggest improvements. They provided most of the code below.

One change  in their updated solution is to use lazy evaluation with yield and itemgetter. A nice change to the list comprehension allowed the removal of the len and range and just iterated over each player in the player list to make tuples. The names were clarified to playerRolls and playerGroups instead of referencing a data structure.  The flag to repeat rolls for ties with a while loop has been cleaned out in favor of recursion down each branch.

I modified the previous code by putting it in a function and adding a roll parameter to let me test their code. The pattern of ordering of player's rolling has been changed. It is like a depth first tree traversal now rather than breadth first.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from itertools import groupby
from operator import itemgetter
from random import randint
from collections import deque
 
def rank_players(playerList, roll):
    playerRolls = [(player, roll()) for player in playerList]
    playerGroups = groupby(
        sorted(playerRolls, key=itemgetter(1), reverse=True),
        itemgetter(1))
    for key, group in playerGroups:
        grouped_players = list(group)
        if len(grouped_players) > 1:
            print('tied, need to reroll',grouped_players)
            for player in rank_players(zip(*grouped_players)[0], roll):
                yield player
        else:
            print('rolled ',grouped_players[0])
            yield grouped_players[0]
 
rollData = deque([ 6, 4, 4, 4, 3, 3, 3, 2, 2, 2, 3, 3, 3, 4, 5, 6 ])
order = rank_players(['one','two','three','four'], lambda: rollData.popleft())
print(list(order))
 

Saturday, July 14, 2012

Python review

I'm starting to forget some python. I've also wanted to work on an old problem encountered at school. So, tonight I'm going to work on it with python.

This particular roadblock to completing the old assignment wasn't that difficult, but for some reason we weren't able to write a solution I felt comfortable with. In the end, the simplest thing to do would've been to randomly pick a permutation of a list. Python provides a shuffle function to do this.

from random import shuffle
x = ['player t', 'player u', 'player v', 'player w', 'player x', 'player y', 'player z']
shuffle(x)
print(x)

Some how we ended up wanting to do a more complicated system to order a list of players. It was about 5 years ago, but I believe the reason was to more faithfully simulate our interpretation of how the game assigned for homework was to be played.The decision was made to go through this sequence:
  1. Each player would roll a die. 
  2. Ties result in another set of rolls to break the tie. But any higher values still count towards ranking ahead of lower values.
  3. For players who did not tie, their relative position would be determined by how high their roll was.
For example, we could have three players, X, Y, Z. If X and Y both rolled a 6 and Z rolled a 1, Z would be assigned the last spot and X and Y would roll again. If X got 5 and Y got 4 for their second rolls, the final order would be X, Y, Z. The follow diagram illustrates that example:

Looking back at it now, it seems to be like a tree expansion. Tree nodes would represent groups of players. For example, the root would be all unsorted players. Visiting the node would generate children by having each player roll their die. A child node of the root could be the players who tied the first round of rolls. Leaves would be players who did not tie. After all the nodes are expanded into leaves, an inorder traversal of the tree would result in the ranking.


from random import randint
from itertools import groupby
 
tree = [['player t', 'player u', 'player v', 'player w', 'player x', 'player y', 'player z']] 
nextGeneration = []
keepPlaying = True
while keepPlaying:
    keepPlaying = False
    for node in tree:
        if len(node) == 1:
            nextGeneration.append(node)
        else:
            keepPlaying  = True
            rolls = [randint(1,6) for i in range(len(node))]
            turn = sorted(zip(rolls,node), reverse=True)
            print 'players roll:', turn
            for key, group in groupby(turn, lambda x: x[0]):
                nextGeneration.append(list(i[1] for i in group))
    tree = nextGeneration
    nextGeneration = []
print([item for sublist in tree for item in sublist])


If I recall correctly,this is what we wanted to do about 5 years ago in school. I don't see much use for it now though other than as an exercise in python. I need to think about how to test it more and make it more testable. A gui might help debug it and make what is happening clearer. At least I learned a little bit about groupby, sorted, zip, and list comprehensions. 

Friday, June 29, 2012

Roku Whiteboard Drawing App

A video on youtube demonstrates a Roku whiteboard drawing app. The author draws on an Android tablet and the tv syncs with a server to show the changes. He has posted the code on github. I hope to browse the source code in the future.

Tuesday, June 05, 2012

8x8x8 LED Cube

I'm looking into building a box with an LED array. An example of one in action is a video on youtube that demonstrates an Asteroids game on an 8x8x8 cube. Right now I need to determine what kind of power supply to get to attach to a driver board, like a rainbowduino. It looks like 9V is recommended for that particular LED driver platform, but it accepts a range of voltages. Also I will need a shield with buttons to control the lights and an Arduino uno to connect the shield with the LED driver.

Saturday, May 26, 2012

Rovio Battery Issue

I had some time to play with a WowWee Rovio robot recently. It is having a battery charge issue where it runs out of charge quickly. A guy posted a fix for his Rovio battery issue online where he found a diode was installed improperly. However, in my case it appears the diodes match the silkscreen direction.