예제 #1
0
    def fit(self):
        if self.is_fit:
            return

        if self.mode == 'transform':
            # DONT run the fit, just load a prefitted model from disk
            with tables.open_file(self.load_from) as f:
                self.kcenters = KCenters.from_pytables(f.root.KCenters)

        else:
            dataset = []
            for data, fn in self._yield_input(with_filenames=True):
                self.breakpoints.append(sum(self.breakpoints) + len(data))
                self.traj_filenames.append(fn)
                dataset.append(data)
            dataset = np.concatenate(dataset)

            self.log.info('** Starting fitting KCenters...')
            self.kcenters.fit(dataset)
            self.log.info('** Finished fitting KCenters')

        self.is_fit = True
예제 #2
0
def test_kcenters_1():
    data = np.random.randn(100,4)
    k = KCenters(10).fit(data)
    
    np.testing.assert_array_equal(k.labels_, k.predict(data))
    np.testing.assert_array_equal(k.labels_[k.center_indices_], np.arange(10))