def make(model_dir, orig_dmat, config): """ Make a new LuminosoModel in the (nonexistent) directory `dir`, with initial half-association matrix `orig_dmat`. (A half-association matrix is a matrix that gives an association matrix when it is multiplied by its transpose.) """ # Adjust the size of the matrix to match the config, if necessary. if os.access(model_dir, os.F_OK): raise StudyExists("The model directory %r already exists." % model_dir) rows = config['num_concepts'] cols = config['num_axes'] if orig_dmat.shape != (rows, cols): dmat = divisi2.DenseMatrix((rows, cols)) rows_to_copy = orig_dmat.shape[0] if rows < rows_to_copy: raise ValueError("num_concepts is too small to fit the " "existing concepts.") cols_to_copy = min(cols, orig_dmat.shape[1]) dmat[:rows_to_copy, :cols_to_copy] = \ orig_dmat[:rows_to_copy, :cols_to_copy] dmat.row_labels = orig_dmat.row_labels else: dmat = orig_dmat # Make sure that the matrix has a PrioritySet for its row labels. _prioritize_labels(dmat, rows) rmat = divisi2.reconstruct_symmetric(dmat) # Make the model directory and populate its initial files. os.mkdir(model_dir) rmat_file = model_dir + os.sep + LuminosoModel.ASSOC_FILENAME config_file = model_dir + os.sep + LuminosoModel.CONFIG_FILENAME save_pickle(rmat, rmat_file) save_config_file(config, config_file) # Now load the model from that directory and return it. model = LuminosoModel(model_dir) return model
def save_assoc(self): "Save the association matrix to a file." save_pickle(self.assoc, self.filename_in_dir(LuminosoModel.ASSOC_FILENAME))