Skip to content

Commit

Permalink
adding labels to parallelDG
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamad committed Nov 9, 2022
1 parent 9538939 commit 9290cf4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/parallelDG_loglinear_sample
Original file line number Diff line number Diff line change
@@ -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.
"""

Expand Down
3 changes: 2 additions & 1 deletion parallelDG/auxiliary_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions parallelDG/graph/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "]"
Expand Down
12 changes: 10 additions & 2 deletions parallelDG/mh_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 9290cf4

Please sign in to comment.