Wednesday, January 25, 2012

Python Patterns: Non-Empty Strings are True

The idiomatic way in Python of writing a non-terminating while-loop is:
    while 1:
or the (slightly slower) alternative:
    while True:
I saw a suggestion on the Python mailing list that I really like, which relies on the behaviour that non-empty strings are evaluated by conditions to be True and provides a self-documented truth-condition, which can note why the loop is non-terminating or what the break condition is.
    while "the program is running":

    while "data is still streaming":

    while "no one presses escape":

Wednesday, January 04, 2012

Where to begin?

My one and only resolution for 2012 is to stop talking about writing a game and actually do it, preferably before the Eschaton. This isn't the first time I've made this promise, however; in the past I've always rapidly hit the issue of having too much choice and not being sure how to progress. And this time isn't really any different.

Friday, October 07, 2011

Stratified Randomisation 2: The Working Version

Yesterday I posted a basic proof-of-concept class for generating a randomisation schedule based on strata. Unfortunately, this code was flawed and was incorrect in its results: because it uses block randomisation within each stratum, the most a single stratum could differ by is the size of the block used minus 1. The following updated code is now completely self-contained, having no dependencies on the original article's code, and uses a generator to produce the schedule.

Thursday, October 06, 2011

Stratified Randomisation

The next randomisation protocol to be implemented is used to ensure treatment balance across 'strata', participant characteristics that are relevant for the trial study.

Wednesday, October 05, 2011

Balancing Randomness

As part of a project, I'm required to implement various protocols for randomisation of statistical trials. The most basic of these we call "simple": it's the equivalent of flipping a coin every item. This is generally enough for most purposes, although even with a perfectly weighted coin there is still the possibility of a variance between the number of heads and the number of tails. For a clinical trial, for statistical purposes it can be preferred that both heads and tails - in this case, experimental treatments, placebos and/or controls - end up flipping the same number of times, while still requiring each individual result to be completely random.