def plot_z(self,indices=None,figsize=(15,5),loc=1):
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import seaborn as sns
plt.figure(figsize=figsize)
for z in range(1,len(self.z_list)+1):
if indices is not None and z-1 not in indices:
continue
else:
if hasattr(self.z_list[z-1], 'sample'):
sns.distplot(self.z_list[z-1].prior.transform(self.z_list[z-1].sample), rug=False, hist=False,label=self.z_list[z-1].method + ' estimate of ' + self.z_list[z-1].name)
elif hasattr(self.z_list[z-1], 'value') and hasattr(self.z_list[z-1], 'std'):
if self.z_list[z-1].prior.transform_name is None:
x = np.linspace(self.z_list[z-1].value-self.z_list[z-1].std*3.5,self.z_list[z-1].value+self.z_list[z-1].std*3.5,100)
plt.plot(x,mlab.normpdf(x,self.z_list[z-1].value,self.z_list[z-1].std),label=self.z_list[z-1].method + ' estimate of ' + self.z_list[z-1].name)
else:
sims = self.z_list[z-1].prior.transform(np.random.normal(self.z_list[z-1].value,self.z_list[z-1].std,100000))
sns.distplot(sims, rug=False, hist=False,label=self.z_list[z-1].method + ' estimate of ' + self.z_list[z-1].name)
else:
raise ValueError("No information on latent variable to plot!")
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Latent Variable Plot')
plt.legend(loc=1)
plt.show()
评论列表
文章目录