コード例 #1
0
 def m_step(self, expectations, datas, inputs, masks, tags, **kwargs):
     x = np.concatenate(datas)
     weights = np.concatenate([Ez for Ez, _, _ in expectations])
     for k in range(self.K):
         ps = np.clip(np.average(x, axis=0, weights=weights[:, k]), 1e-3,
                      1 - 1e-3)
         self.logit_ps[k] = logit(ps)
コード例 #2
0
    def initialize(self, datas, inputs=None, masks=None, tags=None):

        # Initialize with KMeans
        from sklearn.cluster import KMeans
        data = np.concatenate(datas)
        km = KMeans(self.K).fit(data)
        ps = np.clip(km.cluster_centers_, 1e-3, 1 - 1e-3)
        self.logit_ps = logit(ps)