#!/usr/bin/env python # import numpy as np; from numpy import asarray import scipy.misc; from scipy.misc import comb import itertools; from itertools import combinations def antibiotic_growth_power( delta=0, geometric=False, baseline_growth=[23,27,32,35,41,48], subset_size=3 ): """ Returns pi(Delta) """ number_of_rejected_samples = 0 for treated_samples_baseline_growth in combinations( baseline_growth, subset_size ) : # for every possible subset of three control_samples_growth = list( set( baseline_growth ) - set( treated_samples_baseline_growth ) ) if not geometric : treated_samples_growth = asarray( treated_samples_baseline_growth ) + delta else : treated_samples_growth = asarray( treated_samples_baseline_growth ) * ( 1 + delta ) # We reject H_0 if the control ranks are the smallest: # if max( control_samples_growth ) < min( treated_samples_growth ): number_of_rejected_samples += 1 return float(number_of_rejected_samples)/comb(len(baseline_growth),subset_size,exact=True) if __name__=="__main__": print "13.3.6.i: pi(20)= ", antibiotic_growth_power( 20 ) print "13.3.6.ii:" deltas = range(20,30) pis = map( lambda _ : antibiotic_growth_power(_), deltas ) print deltas, pis print "13.3.7: pi(0.4)= ", antibiotic_growth_power( 0.4, geometric=True ) print "13.3.8:" deltas = [ 3, 4, 10, 13 ] pis = map( lambda _ : antibiotic_growth_power(_,baseline_growth=[10,12,17,18,26,42]), deltas ) print deltas, pis