Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
""" | |
A problem from civ3 game. Let's say attacker has m hp, defender has n hp. In | |
each round, attacker will inflict damage of 1hp with probability of p, or lose | |
1hp with probability of 1-p. We ask the probability of final outcome. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calculate the prob of P(fake|data) | |
calc_prob <- function(heads) | |
{ | |
P_fake = .1 # my prior belief of the experiment being rigged | |
P_real = 1 - P_fake | |
P_data_given_fake = dnorm(heads, mean=10000, sd=10) # P(data|fake) | |
P_data_given_real = dbinom(heads, size=20000, p=.5) # P(data|real) | |
# bayes theorem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Iterated_function_system to draw fern leaf | |
# http://en.wikipedia.org/wiki/Iterated_function_system | |
funcs = ( | |
lambda x, y: (0, .16*y), | |
lambda x, y: (.2*x-.26*y, .23*x+.22*y+1.6), | |
lambda x, y: (-.15*x+.28*y, .26*x+.24*y+.44), | |
lambda x, y: (.85*x+.04*y, -.04*x+.85*y+1.6), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpdef unsigned int elfHash(char *value): | |
cdef unsigned int i, x, result | |
result = 0 | |
for i in range(len(value)): | |
result = (result << 4) + value[i] | |
x = result & 0xF0000000 | |
if x: | |
result ^= (x >> 24) | |
result &= ~x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
""" | |
This script queries the phytozome database to get gene annotations (chr, start, stop, gene name), commonly known as the .bed format. | |
""" | |
import urllib as U | |
import sys |