Commit fd42e976 authored by Jiri Borovec's avatar Jiri Borovec

Hierarch. cluster - plot fig

parent 51c4b1c8
......@@ -167,12 +167,12 @@ def reinit_atlas_likely_patterns(imgs, w_bins, atlas, label_max=None):
for lb in range(1, label_max + 1):
w_index = lb - 1
w_sum = np.sum(w_bins[:, w_index])
logging.debug('reinit lb: %i with weight sum %i', lb, w_sum)
# logging.debug('reinit lb: %i with weight sum %i', lb, w_sum)
if w_sum > 0:
continue
imgs_rc = reconstruct_samples(atlas_new, w_bins)
atlas_new = insert_new_pattern(imgs, imgs_rc, atlas_new, lb)
logging.debug('w_bins before: %i', np.sum(w_bins[:, w_index]))
# logging.debug('w_bins before: %i', np.sum(w_bins[:, w_index]))
lim_repopulate = 100. / np.prod(atlas_new.shape)
w_bins[:, w_index] = ptn_weight.weights_label_atlas_overlap_threshold(imgs,
atlas_new, lb, lim_repopulate)
......@@ -200,8 +200,7 @@ def atlas_split_indep_ptn(atlas, lb_max):
# take just lb_max largest elements
for i, ptn in enumerate(patterns[:lb_max]):
lb = i + 1
logging.debug('pattern #%i area %i', lb, np.sum(ptn))
# plt.subplot(1,lb_max,l), plt.imshow(ptn), plt.colorbar()
# logging.debug('pattern #%i area %i', lb, np.sum(ptn))
atlas_new[ptn] = lb
# plt.figure()
......
......@@ -29,6 +29,7 @@ from functools import partial
import tqdm
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import dataset_utils as gen_data
import run_apd_reconstruction as r_reconst
......@@ -39,6 +40,7 @@ PREFIX_ATLAS = 'atlas_'
PREFIX_ENCODE = 'encoding_'
PREFIX_RECONST = 'reconstruct_'
CSV_RECONT_DIFF = 'reconstruct_hierarchical_clustering.csv'
FIG_RECONT_DIFF = 'reconstruct_hierarchical_clustering.pdf'
POSIX_CSV_SKIP = r_reconst.POSIX_CSV_NEW
DIR_PREFIX = 'hierarchical_clustering_'
POSIX_MERGED = 'merged_nb_labels_%i'
......@@ -165,6 +167,20 @@ def sequence_hierarchical_clustering(dict_params, path_out, img_names, atlas,
return df_merged
def plot_reconst_diff(path_csv):
""" plot trhe recost diff from PD and expoert to a figure
:param path_csv: str
"""
assert os.path.exists(path_csv)
df_diff = pd.DataFrame.from_csv(path_csv)
fig = plt.figure()
df_diff.plot(ax=fig.gca(), title='Reconstruction diff. for estimated atlases')
fig.gca().set_ylabel('reconst. diff [%]')
path_fig = os.path.join(os.path.dirname(path_csv), FIG_RECONT_DIFF)
fig.savefig(path_fig)
def process_experiment(path_expt, nb_jobs=NB_THREADS):
""" process complete folder with experiment
......@@ -215,6 +231,7 @@ def main():
tqdm_bar = tqdm.tqdm(total=len(list_expt))
for path_expt in list_expt:
process_experiment(path_expt, arg_params['nb_jobs'])
plot_reconst_diff(os.path.join(path_expt, CSV_RECONT_DIFF))
gc.collect(), time.sleep(1)
tqdm_bar.update(1)
......
......@@ -26,7 +26,7 @@ import gc
from functools import partial
import matplotlib
matplotlib.use('Agg')
# matplotlib.use('Agg')
import numpy as np
import matplotlib.pylab as plt
import matplotlib.gridspec as gridspec
......@@ -213,9 +213,9 @@ def experiments_test(dict_params=SYNTH_PARAMS):
# INIT_TYPES = ['msc', 'rnd']
# GRAPHCUT_REGUL = [0.0, 1e-3, 0.1]
GRAPHCUT_REGUL = [0.0, 1e-15, 1e-3]
INIT_TYPES = DICT_ATLAS_INIT.keys()
GRAPHCUT_REGUL = [0., 0e-12, 1e-9, 1e-6, 1e-3, 1e-1, 1.0]
# GRAPHCUT_REGUL = [0., 0e-12, 1e-9, 1e-6, 1e-3, 1e-1, 1.0]
NB_PATTERNS_REAL = [5, 8, 10, 12, 14, 16, 18, 20, 25, 30, 40, 60]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment