def meanfield_sgdstep(self, data, minibatchfrac, stepsize, **kwargs): l = Labels(data=np.asarray(data), components=self.components, weights=self.weights, **kwargs) ## local vb l.meanfieldupdate() ## sgd steps on global variables self.weights.meanfield_sgdstep(None, l.r, minibatchfrac, stepsize) for idx, c in enumerate(self.components): c.meanfield_sgdstep(l.data, l.r[:, idx], minibatchfrac, stepsize)
def generate(self,N,keep=True): templabels = Labels(components=self.components,weights=self.weights,N=N) out = np.empty(self.components[0].rvs(N).shape) counts = np.bincount(templabels.z,minlength=len(self.components)) for idx,(c,count) in enumerate(zip(self.components,counts)): out[templabels.z == idx,...] = c.rvs(count) perm = np.random.permutation(N) out = out[perm] templabels.z = templabels.z[perm] if keep: templabels.data = out self.labels_list.append(templabels) return out, templabels.z
def generate(self, N, keep=True): templabels = Labels(model=self, N=N) out = np.empty(self.components[0].rvs(N).shape) counts = np.bincount(templabels.z, minlength=len(self.components)) for idx, (c, count) in enumerate(zip(self.components, counts)): out[templabels.z == idx, ...] = c.rvs(count) perm = np.random.permutation(N) out = out[perm] templabels.z = templabels.z[perm] if keep: templabels.data = out self.labels_list.append(templabels) return out, templabels.z
def add_data(self, data, **kwargs): self.labels_list.append( Labels(data=np.asarray(data), model=self, **kwargs))
def add_data(self,data,**kwargs): self.labels_list.append(Labels(data=np.asarray(data), components=self.components,weights=self.weights, **kwargs))
def add_data(self, data): self.labels_list.append( Labels(data=np.asarray(data, dtype=np.float64), components=self.components, weights=self.weights))