gstlal 1.13.0
Loading...
Searching...
No Matches
misc.py
Go to the documentation of this file.
1#
2# Copyright (C) 2010,2011 Kipp Cannon <kipp.cannon@ligo.org>
3#
4# This program is free software; you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by the
6# Free Software Foundation; either version 2 of the License, or (at your
7# option) any later version.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12# Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17#
18
19
20
21
22
23#
24# =============================================================================
25#
26# Preamble
27#
28# =============================================================================
29#
30
31
32from scipy import optimize
33import numpy, scipy
34import sys
35
36
37#
38# import all symbols from _misc
39#
40
41
42from ._misc import *
43
44
45#
46# =============================================================================
47#
48# Extras
49#
50# =============================================================================
51#
52
53
54#
55# inverse of cdf_weighted_chisq_P()
56#
57
58
59def cdf_weighted_chisq_Pinv(A, noncent, dof, var, P, lim, accuracy):
60 func = lambda x: cdf_weighted_chisq_P(A, noncent, dof, var, x, lim, accuracy) - P
61 lo = 0.0
62 hi = 1.0
63 while func(hi) < 0:
64 lo = hi
65 hi *= 2
66 print(lo, hi, file=sys.stderr)
67 return optimize.brentq(func, lo, hi, xtol = accuracy * 4)
68
69#
70# Function to compute the threshold at a fixed FAR for weighted \chi^2
71#
72
73
74def max_stat_thresh(coeffs, fap, samp_tol=100.0):
75 num = int(samp_tol/ fap)
76 out = numpy.zeros(num)
77 for c in coeffs: out += c*scipy.randn(num)**2
78 out.sort()
79 return float(out[-int(samp_tol)])
80
81
82#
83# Function to compute the optimal quadratic statistic coefficients given
84# singular values S and a desired signal size amp
85#
86
87
88def ss_coeffs(S, amp=5.5):
89 return S**2. / (S**2. + len(S) / amp**2. )