Bugfixes and improvements on ProbabilityDistribution

This commit is contained in:
Petrônio Cândido de Lima e Silva 2017-07-06 15:28:08 -03:00
parent 011e0ee4ce
commit dd54133468
4 changed files with 32 additions and 3 deletions

View File

@ -826,6 +826,25 @@ def plot_density_rectange(ax, cmap, density, fig, resolution, time_from, time_to
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):
fig = plt.figure(figsize=[13, 6])

View File

@ -82,8 +82,10 @@ class SeasonalEnsembleFTS(ensemble.EnsembleFTS):
tmp = np.ravel(tmp).tolist()
dist = ProbabilityDistribution.ProbabilityDistribution("KDE", uod=[self.original_min, self.original_max], data=tmp,
**kwargs)
name = str(self.indexer.get_index(data.ix[k]))
dist = ProbabilityDistribution.ProbabilityDistribution("KDE", uod=[self.original_min, self.original_max],
data=tmp, name=name, **kwargs)
ret.append(dist)

View File

@ -26,6 +26,9 @@ class SeasonalIndexer(object):
def get_data(self, data):
pass
def get_index(self, data):
pass
class LinearSeasonalIndexer(SeasonalIndexer):
def __init__(self,seasons,units,ignore=None, **kwargs):
@ -196,5 +199,8 @@ class DateTimeSeasonalIndexer(SeasonalIndexer):
def get_data(self, data):
return data[self.data_fields].tolist()
def get_index(self, data):
return data[self.date_field]
def set_data(self, data, value):
raise Exception("Operation not available!")

View File

@ -25,6 +25,7 @@ class ProbabilityDistribution(object):
if self.bins is None:
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.index = SortedCollection.SortedCollection(iterable=sorted(self.bins))
@ -127,7 +128,8 @@ class ProbabilityDistribution(object):
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_ylabel('Probability')