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.

Sunday, May 13, 2012

Machine Learning Class

I'm struggling through a machine learning class in LA. It is difficult to find the time for it and it is a very specialized topic.

On the other hand, seeing how math can be applied to solve problems with a computer is interesting. It seems that using a dedicated tool is a better start than coding up something in C#. For example, I've seen Roborealm applied to machine vision. Presumably using its gui is easier than using opencv. In class there was a demo of  R and Jags. I've played a little bit with R in the past to plot some data and run a linear regression on it, but I feel like I'm just barely scratching the surface of this topic. 

Saturday, May 12, 2012

Software Requirements

A professor in the UK has the "No Silver Bullet" paper online.

This point from the paper is something I'm trying to remember and maybe follow up on later by reading about how Agile software development attempts to address this.

Requirements refinement and rapid prototyping. The hardest single part of building a software system is deciding precisely what to build. No other part of the conceptual work is as difficult as establishing the detailed technical requirements, including all the interfaces to people, to machines, and to other software systems. No other part of the work so cripples the resulting system if done wrong. No other part is more difficult to rectify later.



Sunday, May 06, 2012

Roku development

From the site:
Developing on Roku

Roku introduced the first streaming video player in 2008, in partnership with Netflix. In the first two years nearly a million units have been sold in the US, and there are now over 100 channels available in the Roku Channel Store. Roku is the most affordable product for consumers looking to stream video over the Internet to their TV, and the most open for developers and content owners looking to reach new audiences.

For content owners or distributors, Roku represents a very cost-effective means to deliver their content to a rapidly increasing number of households. Roku has relationships with leading Online Video Platforms and development partners to further simplify bringing your content to Roku.

An open platform, Roku’s Streaming Player enables content owners to bypass traditional distribution routes and reach views and consumers directly. Roku’s platform allows a wide variety of channels and monetization options.

Wednesday, April 04, 2012

Kivy

A github project named Kivy sounds like an interesting chance to try using python for mobile apps.

From the official site:
Kivy - Open source library for rapid development of applications
that make use of innovative user interfaces, such as multi-touch apps.

Cross platform
Kivy is running on Linux, Windows, MacOSX, Android and IOS. You can run the same code on all supported platforms.

It can use natively most inputs protocols and devices like WM_Touch, WM_Pen, Mac OS X Trackpad and Magic Mouse, Mtdev, Linux Kernel HID, TUIO. A multi-touch mouse simulator is included.

Business Friendly
Kivy is 100% free to use, under LGPL 3 licence. The toolkit is professionnally developed, backed and used. You can use it in a product and sell your product.
The framework is stable and has a documented API, plus a programming guide to help for in the first step.

GPU Accelerated
The graphics engine is built over OpenGL ES 2, using modern and fast way of doing graphics.
The toolkit is coming with more than 20 widgets designed to be extensible. Many parts are written in C using Cython, tested with regression tests.

Friday, February 03, 2012

Go Language for Python programmers

I came across a blog about visual effects and scripting. The author, Justin, has a post about learning Go for Python programmers that looked interesting so I'm logging it here. Before reading about Go, I knew only that it was developed in-house by Google. Thanks to the article I now learned that a reason to use it is to get C++ performance with Python syntax. I've been trying to learn more Python lately so I don't think I'll be switching to Go, but it was nice to learn a bit about Go's community and goals.

A Swarm of Nano Quadrotors

Experiments performed with a team of nano quadrotors at the GRASP Lab, University of Pennsylvania. Vehicles developed by KMel Robotics.

A Swarm of Nano Quadrotors

Monday, January 09, 2012

Project Possibility

From the website - About Project Possibility

Project:Possibility is a nonprofit organization dedicated to creating groundbreaking open source software for persons with disabilities. We inspire students through university coding competitions that introduce them to the possibilities unlocked by accessibility and open source assistive technology. Then we connect these students to our community of persons with disabilities and software developers, a collaborative community that creates access to experiences previously impossible to achieve.

Join us in our mission to make the vision of universal accessibility a reality!

Sunday, January 08, 2012

Processing

From the Processing.js web site:

Processing.js is the sister project of the popular Processing visual programming language, designed for the web. Processing.js makes your data visualizations, digital art, interactive animations, educational graphs, video games, etc. work using web standards and without any plug-ins. You write code using the Processing language, include it in your web page, and Processing.js does the rest. It's not magic, but almost.

I heard about this some weeks ago and need to check it out some time.

Saturday, January 07, 2012

Chinese Character For Next Page - #3

下页 (Xià yè) - Next Page

Google translate has a feature to click on a word for alternate translations. Upon trying out this feature, I learned today's character can mean either "next" or "next page".





Friday, December 30, 2011

Chinese Character For Previous - #2

上页 (Shàng yè) - Previous


上一页 (Shàng yī yè) - Previous


Google translate has a text to speech feature that works for Chinese now:

According to the wikipedia article on Google translate, this feature's support for Mandarin launched on December 2010 and the open source project eSpeak was used. From its home page on Sourceforge, eSpeak uses something called a "formant synthesis" method. On eSpeak's languages page is a request for help from native speakers. A list of "provisional" languages indicates the ones that need help. Currently Welsh, Ancient Greek, Hindi, Armenian, Indonesian, Icelandic, Lojban, Georgian, Latin, Macedonian, Norwegian, Russian, Albanian, Vietnamese, Cantonese Chinese are listed.


Tuesday, December 27, 2011

New Year's resolution

一般
Yībān

I'm planning on doing a series of posts on Chinese characters for the New Year. Hopefully I will learn a little bit and have a chance to use some of the knowledge gained by taking an online a.i. class.

Today I did a Google search for a character meaning, and the engine figured out Google translate would be helpful.



Friday, October 21, 2011

Another whiteboard

Codeproject.com has some whiteboard projects to look at. An html5 canvas based whiteboard looked interesting. Besides the code, the author also helped by documenting a bit about how it works. Screenshots were included. They show the drawing board and a chat message box for text conversations. Drawing functionality included making a line, erasing, and clearing the entire space. The writeup also describes that he decided against polling to update the server due to scalability and user experience issues. He mentions the terms HTTP Push or Comet as alternatives, but he picked the WebSocket feature of HTML 5 for ease of implementation. However, his code still needed to "chunk" the message data into pieces small enough to transfer via the socket.

Thursday, October 06, 2011

Bournemouth University

YouTube has some videos of students in the Master of Digital Effects at the National Centre for Computer Animation.

From their page:

Using digital tools to create visual effects for film and television. Visual effects are typically shots or sequences of images that cannot be created live in front of the camera, but have to be created using production and post production processes.

The core of digital effects is the combination of captured live action with synthetic images, though sequences that are created could be all CG or all live action. The digital tools can take a variety of forms, including 3D softwares and compositing softwares. The main softwares taught and used by the students are: Houdini,Nuke, PFTrack.

Objective of the programme

Creating future industry leaders. People who, with time and experience, will become the next generation of visual effects supervisors and designers.

Saturday, September 24, 2011

Dabbleboard

From the Dabbleboard web site:

Dabbleboard is an online collaboration application that’s centered around the whiteboard. With a new type of drawing interface that's actually easy and fun to use, Dabbleboard gets out of your way and just lets you draw. Finally the whiteboard enters the digital age!

It seems to have some object recognition software that helps clean up rough lines, squares, and circles into cleaner geometric shapes.

Also, since the board is web based, naturally the video demonstrates online collaboration on a whiteboard.

Friday, September 23, 2011

Shell scripting

I would like to learn more about shell scripting but am uncertain whether to learn something like Bash-scripting or find and read Python shell scripts.

One advantage to Bash-scripting is mentioned at reddit:

Python uses more memory and requires more disk space to be installed. This is might be important in small resource constraints environments such as embedded systems or small VMs.

Also the shell is always running and so shell scripts should start up faster than Python scripts.

Perhaps on a low cost embedded device Bash-scripting is the way to go. I will try to follow up on this later. As far as I can tell, one must have a shell on the system to work with, but having python is optional if one is willing to give up a lot of software. Therefore, for a system with limited hardware, in a sense you get bash scripting for free.