def test_matrix_sdm(self): matrix_filename = "test_matrix_sdm.sdm" matrix_relative_path = "{}/{}".format(self.TEMP_DIR_NAME, matrix_filename) expected_matrix = scipy.sparse.rand(10, 20, 0.5) matrix_io.write_matrix(matrix_relative_path, expected_matrix) actual_matrix = matrix_io.read_matrix(matrix_relative_path) self.assertTrue((expected_matrix != actual_matrix).nnz == 0)
def test_dense_matrix_csv(self): matrix_filename = "test_dense_matrix_csv.csv" matrix_relative_path = "{}/{}".format(self.TEMP_DIR_NAME, matrix_filename) expected_matrix = numpy.random.randn(10, 20) matrix_io.write_matrix(matrix_relative_path, expected_matrix) actual_matrix = matrix_io.read_matrix(matrix_relative_path) self.assertTrue(numpy.allclose(actual_matrix, expected_matrix))
def test_matrix_ddm(self): matrix_filename = "test_matrix_ddt.ddm" matrix_relative_path = "{}/{}".format(self.TEMP_DIR_NAME, matrix_filename) expected_matrix = numpy.random.randn(10, 20) matrix_io.write_matrix(matrix_relative_path, expected_matrix) actual_matrix = matrix_io.read_matrix(matrix_relative_path) self.assertTrue(numpy.array_equal(actual_matrix, expected_matrix))
def test_matrix_sparse_mtx(self): matrix_filename = "test_matrix_sparse_mtx.mtx" matrix_relative_path = "{}/{}".format(self.TEMP_DIR_NAME, matrix_filename) expected_matrix = scipy.sparse.rand(10, 20, 0.5) matrix_io.write_matrix(matrix_relative_path, expected_matrix) actual_matrix = matrix_io.read_matrix(matrix_relative_path) self.assertTrue( numpy.allclose(actual_matrix.todense(), expected_matrix.todense()))
def test_matrix_sbm(self): matrix_filename = "test_matrix_sbm.sbm" matrix_relative_path = "{}/{}".format(self.TEMP_DIR_NAME, matrix_filename) expected_dense_matrix = numpy.random.randint(0, 2, size=(10, 20)) expected_sparse_matrix = scipy.sparse.coo_matrix(expected_dense_matrix) matrix_io.write_matrix(matrix_relative_path, expected_sparse_matrix) actual_matrix = matrix_io.read_matrix(matrix_relative_path) self.assertTrue((expected_sparse_matrix != actual_matrix).nnz == 0)
def af_cmd_oom_prediction(root_dir, sideinfo, test): tmpdir = mkdtemp() outfile = join(tmpdir, "predictions-average.ddm") sideinfo_file = join(tmpdir, "sideinfo.mm") mio.write_matrix(sideinfo_file, sideinfo.todense()) exec_file = os.path.abspath("./af_predict") cmd = "%s --modeldir %s/ --out %s --features %s" % (exec_file, root_dir, outfile, sideinfo_file) subprocess.call(cmd, shell=True) return calc_rmse(outfile, test)
m = m - mean elif (args.mode == "none"): pass elif (args.mode != "none"): raise ValueError("Unknown centering mode: %s" % (args.mode)) return m train = mio.read_matrix(args.train) test = mio.read_matrix(args.test) assert train.shape == test.shape mean_train = mean(train, args.mode) centered_train = center(train, args.mode, mean_train) centered_test = center(test, args.mode, mean_train) mio.write_matrix(os.path.join(args.output, os.path.basename(args.train)), centered_train) mio.write_matrix(os.path.join(args.output, os.path.basename(args.test)), centered_test) features = [] if args.col_features: features += args.col_features if args.row_features: features += args.row_features for fname in features: m = mio.read_matrix(fname) if (args.mode == "global"): mean_feat = mean_train else: mean_feat = mean(m, args.mode) centered_feat = center(m, args.mode, mean_feat) mio.write_matrix(os.path.join(args.output, os.path.basename(fname)),