def _regularize(self, datasets, alpha): if __debug__: debug('HPAL', "Using regularized hyperalignment with alpha of %d" % alpha) wmappers = [] for ids in xrange(len(datasets)): U, S, Vh = np.linalg.svd(datasets[ids]) S = 1/np.sqrt( (1-alpha)*np.square(S) + alpha ) S.resize(len(Vh)) S = np.matrix(np.diag(S)) W = np.matrix(Vh.T)*S*np.matrix(Vh) wmapper = StaticProjectionMapper(proj=W) wmappers.append(wmapper) datasets[ids] = wmapper.forward(datasets[ids]) return datasets, wmappers
def _regularize(self, datasets, alpha): if __debug__: debug('HPAL', "Using regularized hyperalignment with alpha of %d" % alpha) wmappers = [] for ids in xrange(len(datasets)): U, S, Vh = np.linalg.svd(datasets[ids]) S = 1 / np.sqrt((1 - alpha) * np.square(S) + alpha) S.resize(len(Vh)) S = np.matrix(np.diag(S)) W = np.matrix(Vh.T) * S * np.matrix(Vh) wmapper = StaticProjectionMapper(proj=W) wmappers.append(wmapper) datasets[ids] = wmapper.forward(datasets[ids]) return datasets, wmappers
def test_staticprojection_reverse_fa(): ds = datasets['uni2small'] proj = np.eye(ds.nfeatures) spm = StaticProjectionMapper(proj=proj[:, :3], recon=proj[:, :3].T) ok_(len(ds.fa) > 0) # we have some fa dsf = spm.forward(ds) ok_(len(dsf.fa) == 0) # no fa were left assert_equal(dsf.nfeatures, 3) # correct # of features assert_equal(dsf.fa.attr_length, 3) # and .fa knows about that dsf.fa['new3'] = np.arange(3) dsfr = spm.reverse(dsf) ok_(len(dsfr.fa) == 0) # no fa were left assert_equal(dsfr.nfeatures, 6) assert_equal(dsfr.fa.attr_length, 6) # .fa knows about them again dsfr.fa['new'] = np.arange(6)
def test_staticprojection_reverse_fa(): ds = datasets['uni2small'] proj = np.eye(ds.nfeatures) spm = StaticProjectionMapper(proj=proj[:,:3], recon=proj[:,:3].T) ok_(len(ds.fa) > 0) # we have some fa dsf = spm.forward(ds) ok_(len(dsf.fa) == 0) # no fa were left assert_equal(dsf.nfeatures, 3) # correct # of features assert_equal(dsf.fa.attr_length, 3) # and .fa knows about that dsf.fa['new3'] = np.arange(3) dsfr = spm.reverse(dsf) ok_(len(dsfr.fa) == 0) # no fa were left assert_equal(dsfr.nfeatures, 6) assert_equal(dsfr.fa.attr_length, 6) # .fa knows about them again dsfr.fa['new'] = np.arange(6)