Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
 def add_data(self, data, **kwargs):
     self.labels_list.append(
         Labels(data=np.asarray(data), model=self, **kwargs))
Ejemplo n.º 5
0
 def add_data(self,data,**kwargs):
     self.labels_list.append(Labels(data=np.asarray(data),                  
         components=self.components,weights=self.weights,
         **kwargs))
Ejemplo n.º 6
0
 def add_data(self, data):
     self.labels_list.append(
         Labels(data=np.asarray(data, dtype=np.float64),
                components=self.components,
                weights=self.weights))