Bugfixes and improvements on ProbabilityDistribution
This commit is contained in:
parent
011e0ee4ce
commit
dd54133468
@ -826,6 +826,25 @@ def plot_density_rectange(ax, cmap, density, fig, resolution, time_from, time_to
|
|||||||
cb.set_label('Density')
|
cb.set_label('Density')
|
||||||
|
|
||||||
|
|
||||||
|
def plot_probabilitydistribution_density(ax, cmap, probabilitydist, fig, time_from):
|
||||||
|
from matplotlib.patches import Rectangle
|
||||||
|
from matplotlib.collections import PatchCollection
|
||||||
|
from matplotlib.colorbar import ColorbarPatch
|
||||||
|
patches = []
|
||||||
|
colors = []
|
||||||
|
for ct, dt in enumerate(probabilitydist):
|
||||||
|
for y in dt.bins:
|
||||||
|
s = Rectangle((time_from+ct, y), 1, dt.resolution, fill=True, lw = 0)
|
||||||
|
patches.append(s)
|
||||||
|
colors.append(dt.distribution[y]*5)
|
||||||
|
pc = PatchCollection(patches=patches, match_original=True)
|
||||||
|
pc.set_clim([0, 1])
|
||||||
|
pc.set_cmap(cmap)
|
||||||
|
pc.set_array(np.array(colors))
|
||||||
|
ax.add_collection(pc)
|
||||||
|
cb = fig.colorbar(pc, ax=ax)
|
||||||
|
cb.set_label('Density')
|
||||||
|
|
||||||
|
|
||||||
def plotCompared(original, forecasts, labels, title):
|
def plotCompared(original, forecasts, labels, title):
|
||||||
fig = plt.figure(figsize=[13, 6])
|
fig = plt.figure(figsize=[13, 6])
|
||||||
|
@ -82,8 +82,10 @@ class SeasonalEnsembleFTS(ensemble.EnsembleFTS):
|
|||||||
|
|
||||||
tmp = np.ravel(tmp).tolist()
|
tmp = np.ravel(tmp).tolist()
|
||||||
|
|
||||||
dist = ProbabilityDistribution.ProbabilityDistribution("KDE", uod=[self.original_min, self.original_max], data=tmp,
|
name = str(self.indexer.get_index(data.ix[k]))
|
||||||
**kwargs)
|
|
||||||
|
dist = ProbabilityDistribution.ProbabilityDistribution("KDE", uod=[self.original_min, self.original_max],
|
||||||
|
data=tmp, name=name, **kwargs)
|
||||||
|
|
||||||
ret.append(dist)
|
ret.append(dist)
|
||||||
|
|
||||||
|
@ -26,6 +26,9 @@ class SeasonalIndexer(object):
|
|||||||
def get_data(self, data):
|
def get_data(self, data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_index(self, data):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LinearSeasonalIndexer(SeasonalIndexer):
|
class LinearSeasonalIndexer(SeasonalIndexer):
|
||||||
def __init__(self,seasons,units,ignore=None, **kwargs):
|
def __init__(self,seasons,units,ignore=None, **kwargs):
|
||||||
@ -196,5 +199,8 @@ class DateTimeSeasonalIndexer(SeasonalIndexer):
|
|||||||
def get_data(self, data):
|
def get_data(self, data):
|
||||||
return data[self.data_fields].tolist()
|
return data[self.data_fields].tolist()
|
||||||
|
|
||||||
|
def get_index(self, data):
|
||||||
|
return data[self.date_field]
|
||||||
|
|
||||||
def set_data(self, data, value):
|
def set_data(self, data, value):
|
||||||
raise Exception("Operation not available!")
|
raise Exception("Operation not available!")
|
@ -25,6 +25,7 @@ class ProbabilityDistribution(object):
|
|||||||
|
|
||||||
if self.bins is None:
|
if self.bins is None:
|
||||||
self.bins = np.linspace(int(self.uod[0]), int(self.uod[1]), int(self.nbins)).tolist()
|
self.bins = np.linspace(int(self.uod[0]), int(self.uod[1]), int(self.nbins)).tolist()
|
||||||
|
self.resolution = (self.uod[1] - self.uod[0])/self.nbins
|
||||||
self.labels = [str(k) for k in self.bins]
|
self.labels = [str(k) for k in self.bins]
|
||||||
|
|
||||||
self.index = SortedCollection.SortedCollection(iterable=sorted(self.bins))
|
self.index = SortedCollection.SortedCollection(iterable=sorted(self.bins))
|
||||||
@ -127,7 +128,8 @@ class ProbabilityDistribution(object):
|
|||||||
axis.plot(self.data, yp, c="red")
|
axis.plot(self.data, yp, c="red")
|
||||||
|
|
||||||
|
|
||||||
axis.plot(self.bins, ys, c=color, label=self.name)
|
axis.plot(self.bins, ys, c=color)
|
||||||
|
axis.set_title(self.name)
|
||||||
|
|
||||||
axis.set_xlabel('Universe of Discourse')
|
axis.set_xlabel('Universe of Discourse')
|
||||||
axis.set_ylabel('Probability')
|
axis.set_ylabel('Probability')
|
||||||
|
Loading…
Reference in New Issue
Block a user