Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

May 15, 2013

Interesting Little Project

So for calc this quarter we had to do a project. The project revolved around using game theory (specifically the game Prisoner's Dilemma) to analyze how cooperation became an evolutionary viable trait. This project focused on a community of 10,001 people playing games against each other. In order to simplify the problem, we split the players into people playing two strategies: Permanent Retaliation (PR) and Always Exploit (AE). Players playing PR cooperate with the other player until exploited, and players playing AE always exploit the other player. Some more terminology that I'll be using is:
- Turn: One interaction between two players.
- Game: A set of turns between two players.
- Round: A set of games in which every player plays every other player.
In the calc project, each round was viewed as a new generation of 10,001 players, where players that were successful from the previous generation were duplicated and players that were unsuccessful were eliminated. This allowed us to create a simple system which we could model with series.

Because this project interested me, I decided to model it in python. If you're interested, the project is on GitHub*. Oddly enough, it actually simplified the project to not create entirely new generations between rounds, instead pruning the lowest scoring players and replacing them with players of the same type as the top scoring players. To prune the lowest-scoring players, I found the average of all of the points earned, and pruned all of the players below 1.5 times the standard deviation. In addition, each PR player maintains a history of the players that have exploited them.

Please, feel free to take a look and/or contribute to the project!

*This is an ongoing project - I intend on making the program multithreaded to speed up runtimes (it currently slows down significantly with any number of players over 150).

March 13, 2013

Set up a High-Quality Development Box for Under $1000 (Part 2)

Being a college student, money is always short. I'm going to walk you through setting up a high-quality development box with Fedora 18. If you don't mind getting super-involved, you could use Arch Linux, however Fedora is really easy to set up and will get you up and running quickly! This is part 2, which covers the installation of Fedora. Part 1, which is about choosing hardware can be found here.

***NOTE*** For this installation, I'm assuming that you have a wired connection.

First: Acquire the installation media
The link to Fedora's installation .iso can be found here. Choose the .iso that looks nicest to you. I'm choosing GNOME for this tutorial.

***NOTE*** For Reference:
GNOME looks a little bit like OSX in terms of layout, while KDE is laid out more like Windows.
Don't let this influence your decision too much though!
Although I am more experienced with Windows than OSX, I tend to prefer GNOME to KDE.


Second: Burn .iso to USB or CD
I'm using the LinuxLive USB Creator to burn the .iso to USB, however this is for Windows only.

Instructions for Linux and Mac can be found here.

Third: Boot the installation media
While your computer is off, insert your USB drive into a USB port. Press the power button, and look for a prompt at the bottom of your screen saying Hit [Some Key] for boot options, or something similar. Common keys are F2, F9, F11, F12, Delete, or Escape. If you're having trouble finding which key it is, google "[your computer model] boot option key" or something to that affect (Or it is effect...? I can never remember...). And select your USB drive.

Fourth: Base install
Once the media has booted, you are presented with a login screen. Just select Live System User (it should be the only option). Once logged in, if you want to play around with Fedora for a little before committing, click on "Try Fedora". Otherwise, choose "Install to Hard Drive".

First you are asked for the language you would like to use during the install, choose whichever language suits you (the default is English (US)). Click continue.
Under storage, click on "Installation Destination" and configure your hard disk. I suggest sticking with automatic partitioning, but you may have to make some changes if dual-booting or choosing to have a separate data partition. When returned to the screen that reads "Localization" and "Storage," click on Begin Installation.
On this screen, all you need to do is set a root password by clicking on the key icon and entering a password twice and clicking done.

***NOTE*** This should be a secure password! It allows root access to your system and can be used to do naughty things by naughty people (get your mind out of the gutter)!

...now we wait for Fedora to finish installing.

Once done, reboot and remove the installation media. When the system comes back up, you are greeted with a welcome screen. Just follow the prompts and choose the default options and you'll be fine!

Fifth: Do a system upgrade.
To perform a system upgrade, we will use yum, Fedora's package manager. Run

sudo yum upgrade

to upgrade all of your packages. It will take a long time, but is highly suggested (This isn't strictly necessary, but it keeps you up-to-date.).

***NOTE*** This step is not necessary for everyone!
Next, we will get wireless working with a Broadcom wireless card. To find out if you have a wireless card, do

lspci -nn | grep 14e4 (14e4 is Broadcom's vendor ID)

If nothing comes up, you can skip to installing development tools! Otherwise, add the rpmfusion repository following the instructions here. Add both free and nonfree.

Then, install broadcom-wl like so

sudo yum install broadcom-wl

...and reboot when done. On reboot, wireless should come up.

Install any development tools you need (Java, Python 2.x or 3.x). You know your needs best, but common tools are an IDE (I suggest Eclipse if you don't have an IDE in mind), and a good text editor like Sublime.

To install Eclipse, do

sudo yum install eclipse

By default, Python 2 is already installed on your system (Version 2.7.3), however you can install Python 3.3.0 simply by running

sudo yum install python3

to run a Python 2 module, run

python [path to module].py

... likewise, to run a Python 3 module, do

python3 [path to module.py]

Congratulations on your new development environment! If there's anything I missed or you want me to cover, please put it in the comments and I'll add it in!