Пример #1
0
    def __init__(self, type="KDE", **kwargs):
        self.uod = kwargs.get("uod", None)
        """Universe of discourse"""

        self.data = []

        data = kwargs.get("data", None)

        self.type = type
        """
        If type is histogram, the PDF is discrete
        If type is KDE the PDF is continuous
        """

        self.bins = kwargs.get("bins", None)
        """Number of bins on a discrete PDF"""
        self.labels = kwargs.get("bins_labels", None)
        """Bins labels on a discrete PDF"""

        if self.type == "KDE":
            self.kde = kde.KernelSmoothing(h=kwargs.get("h", 0.5),
                                           kernel=kwargs.get(
                                               "kernel", "epanechnikov"))

        if data is not None and self.uod is None:
            _min = np.nanmin(data)
            _min = _min * .7 if _min > 0 else _min * 1.3
            _max = np.nanmax(data)
            _max = _max * 1.3 if _max > 0 else _max * .7
            self.uod = [_min, _max]

        self.nbins = kwargs.get("num_bins", 100)

        if self.bins is None:
            self.bins = np.linspace(int(self.uod[0]), int(self.uod[1]),
                                    int(self.nbins)).tolist()
            self.labels = [str(k) for k in self.bins]

        if self.uod is not None:
            self.resolution = (self.uod[1] - self.uod[0]) / self.nbins

        self.bin_index = SortedCollection.SortedCollection(
            iterable=sorted(self.bins))
        self.quantile_index = None
        self.distribution = {}
        self.cdf = None
        self.qtl = None
        self.count = 0
        for k in self.bins:
            self.distribution[k] = 0

        if data is not None:
            self.append(data)

        self.name = kwargs.get("name", "")
Пример #2
0
    def __init__(self, type="KDE", **kwargs):
        self.uod = kwargs.get("uod", None)

        self.data = []

        self.type = type

        self.bins = kwargs.get("bins", None)
        self.labels = kwargs.get("bins_labels", None)

        data = kwargs.get("data", None)

        if self.type == "KDE":
            self.kde = kde.KernelSmoothing(
                kwargs.get("h", 0.5), kwargs.get("kernel", "epanechnikov"))
            _min = np.nanmin(data)
            _min = _min * .7 if _min > 0 else _min * 1.3
            _max = np.nanmax(data)
            _max = _max * 1.3 if _max > 0 else _max * .7
            self.uod = [_min, _max]

        self.nbins = kwargs.get("num_bins", 100)

        if self.bins is None:
            self.bins = np.linspace(int(self.uod[0]), int(self.uod[1]),
                                    int(self.nbins)).tolist()
            self.labels = [str(k) for k in self.bins]

        if self.uod is not None:
            self.resolution = (self.uod[1] - self.uod[0]) / self.nbins

        self.bin_index = SortedCollection.SortedCollection(
            iterable=sorted(self.bins))
        self.quantile_index = None
        self.distribution = {}
        self.cdf = None
        self.qtl = None
        self.count = 0
        for k in self.bins:
            self.distribution[k] = 0

        if data is not None:
            self.append(data)

        self.name = kwargs.get("name", "")