diff --git a/Dockerfile b/Dockerfile index 431d908..d98a582 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /git RUN git clone https://github.com/melmasri/parallelDG.git WORKDIR /git/parallelDG RUN git fetch --all --tag # This is not triggered if the version is changed. It should be. -RUN git checkout v0.8 -b latest +RUN git checkout v0.9.2 -b latest RUN pip install -r requirements.txt ENV PYTHONPATH /git:/git/parallelDG:/git/parallelDG/bin ENV PATH /git/parallelDG/bin:$PATH diff --git a/bin/parallelDG_loglinear_sample b/bin/parallelDG_loglinear_sample index 2011c53..2c74039 100644 --- a/bin/parallelDG_loglinear_sample +++ b/bin/parallelDG_loglinear_sample @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -Generate a Markov chain from particle Gibbs for different +Generate a Markov chain from Metropolis-Hastings trajectories parameter settings. """ diff --git a/parallelDG/auxiliary_functions.py b/parallelDG/auxiliary_functions.py index d4c80a0..6a4749b 100644 --- a/parallelDG/auxiliary_functions.py +++ b/parallelDG/auxiliary_functions.py @@ -379,6 +379,7 @@ def plot_graph_traj_statistics(graph_traj, write_to_file=False): def write_traj_to_file(graph_trajectory, dirt, + labels, output_filename=None, output_format=None): date = datetime.datetime.today().strftime('%Y%m%d%H%m%S') @@ -387,7 +388,7 @@ def write_traj_to_file(graph_trajectory, if output_format == 'benchpress': filename = dirt + "/"+output_filename filename_sub = dirt+"/"+output_filename[:-4]+'_subindex.csv' - df = graph_trajectory.graph_diff_trajectory_df() + df = graph_trajectory.graph_diff_trajectory_df(labels=labels) _cols_main = ['added', 'index', 'removed', 'score'] _cols_sub = ['added_sub', 'subindex', 'removed_sub'] df2 = df[_cols_main].dropna(axis=0) diff --git a/parallelDG/graph/trajectory.py b/parallelDG/graph/trajectory.py index 1f0caaa..19cb242 100644 --- a/parallelDG/graph/trajectory.py +++ b/parallelDG/graph/trajectory.py @@ -200,13 +200,18 @@ def default(o): with open(filename, 'w') as outfile: json.dump(self.to_json(optional=optional), outfile, default=default) - def graph_diff_trajectory_df(self, subindex=True): + def graph_diff_trajectory_df(self, subindex=True, labels=None): + + if labels is None: + p = self.init_graph.number_of_nodes() + labels = np.array(list(range(p))) + def list_to_string(edge_list): s = "[" for i, e in enumerate(edge_list): e = sorted(e) - s += str(e[0]) + "-" + str(e[1]) + s += str(labels[e[0]]) + "-" + str(labels[e[1]]) if i != len(edge_list)-1: s += ";" return s + "]" diff --git a/parallelDG/mh_parallel.py b/parallelDG/mh_parallel.py index 53583e9..ff04049 100644 --- a/parallelDG/mh_parallel.py +++ b/parallelDG/mh_parallel.py @@ -494,6 +494,7 @@ def trajectory_to_file(n_samples, reset_cache=True, output_directory=".", reseed=False, + labels=None, **args): """ Writes the trajectory of graphs generated by particle Gibbs to file. @@ -521,10 +522,11 @@ def trajectory_to_file(n_samples, if not output_filename: output_filename = 'graph_traj_'+str(seed)+'.csv' output_format = args.get("output_format", None) - aux.write_traj_to_file(graph_trajectory, + aux.write_traj_to_file(graph_trajectory=graph_trajectory, dirt=output_directory, output_filename=output_filename, - output_format=output_format + output_format=output_format, + labels=labels ) return graph_trajectory @@ -545,6 +547,8 @@ def sample_trajectories_ggm_to_file(dataframe, sd = seqdist.GGMJTPosterior() sd_graph = get_prior(graph_prior) graph_trajectories = [] + node_labels = np.array(dataframe.columns.get_level_values(0)) + for _ in range(reps): for T in n_samples: for r in randomize: @@ -557,6 +561,7 @@ def sample_trajectories_ggm_to_file(dataframe, seqdist_graph=sd_graph, reset_cache=reset_cache, output_directory=output_directory, + labels=node_labels, **args) graph_trajectories.append(graph_trajectory) return graph_trajectories @@ -654,6 +659,8 @@ def sample_trajectories_loglin_to_file(dataframe, dt = dataframe.to_numpy() sd_graph = get_prior(graph_prior) graph_trajectories = [] + node_labels = np.array(dataframe.columns.get_level_values(0)) + for _ in range(reps): for T in n_samples: for r in randomize: @@ -666,6 +673,7 @@ def sample_trajectories_loglin_to_file(dataframe, seqdist_graph=sd_graph, reset_cache=reset_cache, output_directory=output_directory, + labels=node_labels, **args) graph_trajectories.append(graph_trajectory) return graph_trajectories