forked from QuantEcon/QuantEcon.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecdf.py
51 lines (37 loc) · 1 KB
/
ecdf.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Implements the empirical cumulative distribution function given an array
of observations.
"""
import numpy as np
class ECDF:
"""
One-dimensional empirical distribution function given a vector of
observations.
Parameters
----------
observations : array_like
An array of observations
Attributes
----------
observations : see Parameters
"""
def __init__(self, observations):
self.observations = np.asarray(observations)
def __repr__(self):
return self.__str__()
def __str__(self):
m = "Empirical CDF:\n - number of observations: {n}"
return m.format(n=self.observations.size)
def __call__(self, x):
"""
Evaluates the ecdf at x
Parameters
----------
x : scalar(float)
The x at which the ecdf is evaluated
Returns
-------
scalar(float)
Fraction of the sample less than x
"""
return np.mean(self.observations <= x)