https://doi.org/10.5201/ipol.2019.272
Tip revision: c92e3756afa20b81ced28d0142f3e8f5e8e4f9ba authored by Software Heritage on 01 January 2017, 00:00:00 UTC
ipol: Deposit 663 in collection ipol
ipol: Deposit 663 in collection ipol
Tip revision: c92e375
computeNFPs.py
#!/usr/bin/python
import sys
if len(sys.argv) < 2:
print("Usage: computeNFPs.py input.txt output.txt\n")
sys.exit()
input=sys.argv[1]
output=sys.argv[2]
#From:
# https://stackoverflow.com/questions/809362/how-to-calculate-cumulative-normal-distribution-in-python
from math import *
def cdfZ(x):
#'Cumulative distribution function for the standard normal distribution'
return (1.0 + erf(x / sqrt(2.0))) / 2.0
fout = open(output, "w")
fout.write("Number of false positives (NFP) associated to each detected sub-window:\n")
fout.write("NFP = N x P(detection),\n")
fout.write("where N is the number of tested sub-windows in the image,\n")
fout.write("and P(detection) is the probability of having a value above\n")
fout.write("the detection value associated to the sub-window under the null hypothesis.\n\n")
fout.write("The smaller the NFP associated to a detected sub-window, the more reliable\nis the detection\n\n")
f = open(input, "r")
lines = list(f)
N = float(lines[0])
mu = float(lines[1].split()[0])
sd = float(lines[1].split()[1])
for line in lines[2:]:
v = float(line)
NFP = N * (1-cdfZ((v-mu)/sd))
fout.write('%2.4e\n'%NFP)