first add
This commit is contained in:
35
rebuildinpython/andromeda.py
Normal file
35
rebuildinpython/andromeda.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import numpy as np
|
||||
from scipy.special import gammaln # gammaln(x) 计算 ln(x!) 更为高效
|
||||
|
||||
def andromeda_score(k, n, p=0.06):
|
||||
"""
|
||||
计算Andromeda算法的得分。
|
||||
|
||||
参数:
|
||||
- k: 匹配的理论峰数
|
||||
- n: 理论峰的总数
|
||||
- p: 匹配概率,默认0.06
|
||||
|
||||
返回:
|
||||
- Andromeda得分
|
||||
"""
|
||||
# 计算匹配项和不匹配项
|
||||
match_term = -k * np.log(p)
|
||||
non_match_term = -(n - k) * np.log(1 - p)
|
||||
|
||||
# 计算组合项
|
||||
factln_n = gammaln(n + 1) # 对应 Factln(n)
|
||||
factln_k = gammaln(k + 1) # 对应 Factln(k)
|
||||
factln_n_k = gammaln(n - k + 1) # 对应 Factln(n - k)
|
||||
|
||||
# Andromeda得分
|
||||
score = match_term + non_match_term - factln_n + factln_k + factln_n_k
|
||||
|
||||
# 缩放得分
|
||||
score = 10.0 * score / np.log(10)
|
||||
return score
|
||||
|
||||
# 示例计算
|
||||
k = 2
|
||||
n = 5
|
||||
andromeda_score(k, n)
|
||||
Reference in New Issue
Block a user