MCPcopy Index your code
hub / github.com/python/cpython / overlap

Method overlap

Lib/statistics.py:1297–1329  ·  view source on GitHub ↗

Compute the overlapping coefficient (OVL) between two normal distributions. Measures the agreement between two normal probability distributions. Returns a value between 0.0 and 1.0 giving the overlapping area in the two underlying probability density functions.

(self, other)

Source from the content-addressed store, hash-verified

1295 return [self.inv_cdf(i / n) for i in range(1, n)]
1296
1297 def overlap(self, other):
1298 """Compute the overlapping coefficient (OVL) between two normal distributions.
1299
1300 Measures the agreement between two normal probability distributions.
1301 Returns a value between 0.0 and 1.0 giving the overlapping area in
1302 the two underlying probability density functions.
1303
1304 >>> N1 = NormalDist(2.4, 1.6)
1305 >>> N2 = NormalDist(3.2, 2.0)
1306 >>> N1.overlap(N2)
1307 0.8035050657330205
1308 """
1309 # See: "The overlapping coefficient as a measure of agreement between
1310 # probability distributions and point estimation of the overlap of two
1311 # normal densities" -- Henry F. Inman and Edwin L. Bradley Jr
1312 # http://dx.doi.org/10.1080/03610928908830127
1313 if not isinstance(other, NormalDist):
1314 raise TypeError('Expected another NormalDist instance')
1315 X, Y = self, other
1316 if (Y._sigma, Y._mu) < (X._sigma, X._mu): # sort to assure commutativity
1317 X, Y = Y, X
1318 X_var, Y_var = X.variance, Y.variance
1319 if not X_var or not Y_var:
1320 raise StatisticsError('overlap() not defined when sigma is zero')
1321 dv = Y_var - X_var
1322 dm = fabs(Y._mu - X._mu)
1323 if not dv:
1324 return erfc(dm / (2.0 * X._sigma * _SQRT2))
1325 a = X._mu * Y_var - Y._mu * X_var
1326 b = X._sigma * Y._sigma * sqrt(dm * dm + dv * log(Y_var / X_var))
1327 x1 = (a + b) / dv
1328 x2 = (a - b) / dv
1329 return 1.0 - (fabs(Y.cdf(x1) - X.cdf(x1)) + fabs(Y.cdf(x2) - X.cdf(x2)))
1330
1331 def zscore(self, x):
1332 """Compute the Standard Score. (x - mean) / stdev

Callers 1

test_overlapMethod · 0.95

Calls 3

StatisticsErrorClass · 0.85
cdfMethod · 0.80
logFunction · 0.50

Tested by 1

test_overlapMethod · 0.76