def save_init_svd(self, fname='', notes='', force=False):
"""
Saves the initial SVD so it can be loaded later without recomputing
Parameters
----------
fname: name of the file
notes: any notes you want to include
force: whether or note to overwrite a file with the same name
"""
if not hasattr(self.blocks[0], 'scores'):
raise ValueError('initial svd has not yet been computed')
if os.path.exists(fname) and (not force):
raise ValueError('%s already exists' % fname)
kwargs = {}
svd_dat = ['scores', 'sing_vals', 'loadings', 'rank']
kwargs['K'] = self.K
for k in range(self.K):
kwargs['%d_scores' % k] = self.blocks[k].scores
kwargs['%d_sv' % k] = self.blocks[k].sv
kwargs['%d_loadings' % k ] = self.blocks[k].loadings
kwargs['%d_init_svd_rank' % k] = self.blocks[k].init_svd_rank
np.savez_compressed(fname, **kwargs)
评论列表
文章目录