-
Notifications
You must be signed in to change notification settings - Fork 0
/
lia.py
34 lines (23 loc) · 774 Bytes
/
lia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @File : lia.py
# @Date : 2019-02-16
# @Author : luyang(luyang@novogene.com)
from math import factorial
from scipy.stats import binom
# Binomial_distribution
# f(x) = n!/x!(n-x)!*p^x*(1-p)^(n-x)
def Binomial_distribution(k, n, p):
return factorial(2 ** k) / factorial(n) / factorial(2 ** k - n) * p ** n * (1 - p) ** (2 ** k - n)
def main():
file = 'input/rosalind_lia.txt'
with open(file) as f:
k, n = map(int, f.readline().strip().split())
print(1 - binom.cdf(n - 1, 2 ** k, 0.25))
print('Binomial_distribution')
probability = 1
for i in range(1, n):
probability -= Binomial_distribution(k, i, 1 / 4)
print(probability)
if __name__ == "__main__":
main()