From 37347041652381883b4d389661ea835b72fce1d5 Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Mon, 3 Jan 2022 22:50:37 -0800 Subject: [PATCH 1/9] inserted struct init, not parameter yet --- pastis/optimization/pastis_algorithms.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pastis/optimization/pastis_algorithms.py b/pastis/optimization/pastis_algorithms.py index 48a1cd8c9..d34d46e80 100644 --- a/pastis/optimization/pastis_algorithms.py +++ b/pastis/optimization/pastis_algorithms.py @@ -344,6 +344,7 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, if draft and alpha_ is None: alpha_ = alpha_init if multiscale_factor == 1 and not (draft or simple_diploid): + """ infer_draft_lowres = hsc_lambda > 0 and hsc_r is None need_multiscale_var = use_multiscale_variance and ( multiscale_rounds > 1 or infer_draft_lowres) @@ -372,7 +373,8 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, _print_code_header( ['Draft inference complete', 'INFERRING STRUCTURE'], max_length=80, blank_lines=2) - + """ + struct_draft_fullres = np.load("./results_4DNFI9YAVTI1/struct_draft_fullres/struct_inferred.000.coords") if verbose and outdir is not None: print('OUTPUT: %s' % out_file, flush=True) @@ -429,12 +431,14 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, print( 'INITIALIZATION: initializing with true structure', flush=True) init = struct_true + """ struct_init = initialize( counts=counts, lengths=lengths, init=init, ploidy=ploidy, random_state=random_state, alpha=alpha_init if alpha_ is None else alpha_, bias=bias, multiscale_factor=multiscale_factor, reorienter=reorienter, - mixture_coefs=mixture_coefs, verbose=verbose) + mixture_coefs=mixture_coefs, verbose=verbose)""" + struct_init = np.load("./results_4DNFI9YAVTI1/inferred_structure.epoch_0012000.txt") # HOMOLOG-SEPARATING CONSTRAINT if ploidy == 1 and (hsc_lambda > 0 or mhs_lambda > 0): @@ -468,14 +472,16 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, # COMPUTE OBJECTIVE ON TRUE STRUCTURE if outdir is not None and struct_true is not None and not null and ( reorienter is None or not reorienter.reorient): - struct_true_lowres = decrease_struct_res( - struct_true, multiscale_factor=multiscale_factor, - lengths=lengths) + #struct_true_lowres = decrease_struct_res( + # struct_true, multiscale_factor=multiscale_factor, + # lengths=lengths) + struct_true_lowre = np.load("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") if simple_diploid: - struct_true_lowres = np.nanmean( - [struct_true_lowres[:int(struct_true.shape[0] / 2)], - struct_true_lowres[int(struct_true.shape[0] / 2):]], - axis=0) + #struct_true_lowres = np.nanmean( + # [struct_true_lowres[:int(struct_true.shape[0] / 2)], + # struct_true_lowres[int(struct_true.shape[0] / 2):]], + # axis=0) + struct_true_lowre = np.load("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") _, obj_true, _, _ = objective( struct_true_lowres, counts=counts, alpha=alpha_init if alpha_ is None else alpha_, From 83262da78e16a9a85ab833b5ec3d54321e14aaf6 Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Thu, 6 Jan 2022 12:16:48 -0800 Subject: [PATCH 2/9] nploadtxt --- pastis/optimization/pastis_algorithms.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pastis/optimization/pastis_algorithms.py b/pastis/optimization/pastis_algorithms.py index d34d46e80..7e33ae51e 100644 --- a/pastis/optimization/pastis_algorithms.py +++ b/pastis/optimization/pastis_algorithms.py @@ -374,7 +374,7 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, ['Draft inference complete', 'INFERRING STRUCTURE'], max_length=80, blank_lines=2) """ - struct_draft_fullres = np.load("./results_4DNFI9YAVTI1/struct_draft_fullres/struct_inferred.000.coords") + struct_draft_fullres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_fullres/struct_inferred.000.coords") if verbose and outdir is not None: print('OUTPUT: %s' % out_file, flush=True) @@ -438,7 +438,7 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, alpha=alpha_init if alpha_ is None else alpha_, bias=bias, multiscale_factor=multiscale_factor, reorienter=reorienter, mixture_coefs=mixture_coefs, verbose=verbose)""" - struct_init = np.load("./results_4DNFI9YAVTI1/inferred_structure.epoch_0012000.txt") + struct_init = np.loadtxt("./results_4DNFI9YAVTI1/inferred_structure.epoch_0012000.txt") # HOMOLOG-SEPARATING CONSTRAINT if ploidy == 1 and (hsc_lambda > 0 or mhs_lambda > 0): @@ -475,13 +475,13 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, #struct_true_lowres = decrease_struct_res( # struct_true, multiscale_factor=multiscale_factor, # lengths=lengths) - struct_true_lowre = np.load("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") + struct_true_lowres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") if simple_diploid: #struct_true_lowres = np.nanmean( # [struct_true_lowres[:int(struct_true.shape[0] / 2)], # struct_true_lowres[int(struct_true.shape[0] / 2):]], # axis=0) - struct_true_lowre = np.load("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") + struct_true_lowres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") _, obj_true, _, _ = objective( struct_true_lowres, counts=counts, alpha=alpha_init if alpha_ is None else alpha_, From 14b0d5bbd8592e446b0bf9b7ad64eddc8c3206c1 Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Tue, 11 Jan 2022 16:18:32 -0800 Subject: [PATCH 3/9] idk --- pastis/optimization/pastis_algorithms.py | 34 +++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/pastis/optimization/pastis_algorithms.py b/pastis/optimization/pastis_algorithms.py index 7e33ae51e..53a1d6203 100644 --- a/pastis/optimization/pastis_algorithms.py +++ b/pastis/optimization/pastis_algorithms.py @@ -344,7 +344,7 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, if draft and alpha_ is None: alpha_ = alpha_init if multiscale_factor == 1 and not (draft or simple_diploid): - """ + #""" infer_draft_lowres = hsc_lambda > 0 and hsc_r is None need_multiscale_var = use_multiscale_variance and ( multiscale_rounds > 1 or infer_draft_lowres) @@ -373,8 +373,18 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, _print_code_header( ['Draft inference complete', 'INFERRING STRUCTURE'], max_length=80, blank_lines=2) - """ - struct_draft_fullres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_fullres/struct_inferred.000.coords") + #""" + #struct_draft_fullres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_fullres/struct_inferred.000.coords") + #alpha_ = -3 + #beta_ = 1.0 + #hsc_r = distance_between_homologs( + # structures=struct_draft_lowres, + # lengths=decrease_lengths_res( + # lengths=lengths, + # multiscale_factor=multiscale_factor_for_lowres), + # mixture_coefs=mixture_coefs, + # simple_diploid=simple_diploid_for_lowres) + #draft_converged = True if verbose and outdir is not None: print('OUTPUT: %s' % out_file, flush=True) @@ -472,16 +482,16 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, # COMPUTE OBJECTIVE ON TRUE STRUCTURE if outdir is not None and struct_true is not None and not null and ( reorienter is None or not reorienter.reorient): - #struct_true_lowres = decrease_struct_res( - # struct_true, multiscale_factor=multiscale_factor, - # lengths=lengths) - struct_true_lowres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") + struct_true_lowres = decrease_struct_res( + struct_true, multiscale_factor=multiscale_factor, + lengths=lengths) + #struct_true_lowres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") if simple_diploid: - #struct_true_lowres = np.nanmean( - # [struct_true_lowres[:int(struct_true.shape[0] / 2)], - # struct_true_lowres[int(struct_true.shape[0] / 2):]], - # axis=0) - struct_true_lowres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") + struct_true_lowres = np.nanmean( + [struct_true_lowres[:int(struct_true.shape[0] / 2)], + struct_true_lowres[int(struct_true.shape[0] / 2):]], + axis=0) + #struct_true_lowres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") _, obj_true, _, _ = objective( struct_true_lowres, counts=counts, alpha=alpha_init if alpha_ is None else alpha_, From bbaea0a641e8731b3f9d06a9da9909be0cefec8a Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Tue, 15 Feb 2022 14:09:26 -0800 Subject: [PATCH 4/9] added save freq 1000 --- pastis/optimization/pastis_algorithms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pastis/optimization/pastis_algorithms.py b/pastis/optimization/pastis_algorithms.py index 53a1d6203..bba4fe794 100644 --- a/pastis/optimization/pastis_algorithms.py +++ b/pastis/optimization/pastis_algorithms.py @@ -707,6 +707,8 @@ def pastis_poisson(counts, lengths, ploidy, outdir='', chromosomes=None, Keys: 'alpha', 'beta', 'hsc_r', 'obj', and 'seed'. """ + save_freq = 1000 + if not isinstance(counts, list): counts = [counts] if verbose: From 031690d265f714a792d98e836856687bf4a2e1c2 Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Tue, 22 Feb 2022 12:51:30 -0800 Subject: [PATCH 5/9] some changes --- pastis/optimization/pastis_algorithms.py | 34 +++++++++++------------- pastis/script/pastis-poisson | 9 +++++++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/pastis/optimization/pastis_algorithms.py b/pastis/optimization/pastis_algorithms.py index bba4fe794..aa815ddbc 100644 --- a/pastis/optimization/pastis_algorithms.py +++ b/pastis/optimization/pastis_algorithms.py @@ -344,7 +344,6 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, if draft and alpha_ is None: alpha_ = alpha_init if multiscale_factor == 1 and not (draft or simple_diploid): - #""" infer_draft_lowres = hsc_lambda > 0 and hsc_r is None need_multiscale_var = use_multiscale_variance and ( multiscale_rounds > 1 or infer_draft_lowres) @@ -373,18 +372,7 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, _print_code_header( ['Draft inference complete', 'INFERRING STRUCTURE'], max_length=80, blank_lines=2) - #""" - #struct_draft_fullres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_fullres/struct_inferred.000.coords") - #alpha_ = -3 - #beta_ = 1.0 - #hsc_r = distance_between_homologs( - # structures=struct_draft_lowres, - # lengths=decrease_lengths_res( - # lengths=lengths, - # multiscale_factor=multiscale_factor_for_lowres), - # mixture_coefs=mixture_coefs, - # simple_diploid=simple_diploid_for_lowres) - #draft_converged = True + if verbose and outdir is not None: print('OUTPUT: %s' % out_file, flush=True) @@ -447,7 +435,8 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, random_state=random_state, alpha=alpha_init if alpha_ is None else alpha_, bias=bias, multiscale_factor=multiscale_factor, reorienter=reorienter, - mixture_coefs=mixture_coefs, verbose=verbose)""" + mixture_coefs=mixture_coefs, verbose=verbose) + """ struct_init = np.loadtxt("./results_4DNFI9YAVTI1/inferred_structure.epoch_0012000.txt") # HOMOLOG-SEPARATING CONSTRAINT @@ -485,13 +474,11 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, struct_true_lowres = decrease_struct_res( struct_true, multiscale_factor=multiscale_factor, lengths=lengths) - #struct_true_lowres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") if simple_diploid: struct_true_lowres = np.nanmean( [struct_true_lowres[:int(struct_true.shape[0] / 2)], struct_true_lowres[int(struct_true.shape[0] / 2):]], axis=0) - #struct_true_lowres = np.loadtxt("./results_4DNFI9YAVTI1/struct_draft_lowres/struct_inferred.000.coords") _, obj_true, _, _ = objective( struct_true_lowres, counts=counts, alpha=alpha_init if alpha_ is None else alpha_, @@ -621,7 +608,8 @@ def pastis_poisson(counts, lengths, ploidy, outdir='', chromosomes=None, piecewise_step1_accuracy=1, alpha_true=None, struct_true=None, init='mds', input_weight=None, exclude_zeros=False, null=False, mixture_coefs=None, - verbose=True): + verbose=True, save_freq=None, restart_struct=None, + restart_iter=None): """Infer 3D structures with PASTIS via Poisson model. Infer 3D structure from Hi-C contact counts data for haploid or diploid @@ -697,6 +685,16 @@ def pastis_poisson(counts, lengths, ploidy, outdir='', chromosomes=None, homolog-separating constraint specificying the expected mean inter- homolog count for each chromosome, scaled by beta and biases. If not supplied, `mhs_k` will be estimated from the counts data. + save_freq : int + Number of iterations used as an interval to save a checkpoint of the + structure. + restart_struct : str + The structure to restart inference from (used as the initialization). + Number of beads per homolog of each chromosome, or hiclib .bed file with + lengths data. + restart_iter : int + The number of iterations to restart from (corresponds to the + restart_struct file). Returns ------- @@ -707,8 +705,6 @@ def pastis_poisson(counts, lengths, ploidy, outdir='', chromosomes=None, Keys: 'alpha', 'beta', 'hsc_r', 'obj', and 'seed'. """ - save_freq = 1000 - if not isinstance(counts, list): counts = [counts] if verbose: diff --git a/pastis/script/pastis-poisson b/pastis/script/pastis-poisson index 7017bb6db..f4cc9439d 100644 --- a/pastis/script/pastis-poisson +++ b/pastis/script/pastis-poisson @@ -51,6 +51,15 @@ parser.add_argument("--multiscale_rounds", default=1, type=int, " should be inferred during multiscale optimization." " Values of 1 or 0 disable multiscale" " optimization.") +parser.add_argument("--save_freq", type=int, default=None, + help="The number of iterations used as an interval to save" + " a checkpoint of the structure at.") +parser.add_argument("--restart_struct", type=str, default=None, + help="The structure to restart inference from (used as the" + " initialization.") +parser.add_argument("--restart_iter", type=int, default=None, + help="The number of iterations to restart from (corresponds" + " to the restart_struct file).") # Optimization convergence parser.add_argument("--max_iter", default=30000, type=int, From 1820360e8c2c606e8583b1f2611515c230a8b235 Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Tue, 22 Feb 2022 17:47:23 -0800 Subject: [PATCH 6/9] edited callback and allows restarting now --- pastis/optimization/callbacks.py | 6 +++- pastis/optimization/pastis_algorithms.py | 37 ++++++++++++++++-------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/pastis/optimization/callbacks.py b/pastis/optimization/callbacks.py index cc43cb229..c498f0155 100644 --- a/pastis/optimization/callbacks.py +++ b/pastis/optimization/callbacks.py @@ -52,6 +52,8 @@ class Callback(object): True alpha, to be used by `analysis_function`. verbose : bool, optional Verbosity. + restart_iter : int + The number of iterations to restart from. Attributes ---------- @@ -124,7 +126,7 @@ def __init__(self, lengths, ploidy, counts=None, multiscale_factor=1, history=None, analysis_function=None, frequency=None, on_training_begin=None, on_training_end=None, on_epoch_end=None, directory=None, struct_true=None, - alpha_true=None, verbose=False): + alpha_true=None, verbose=False, restart_iter=None): self.ploidy = ploidy self.multiscale_factor = multiscale_factor self.lengths = decrease_lengths_res(lengths, multiscale_factor) @@ -171,6 +173,8 @@ def __init__(self, lengths, ploidy, counts=None, multiscale_factor=1, self.opt_type = None self.alpha_loop = None self.epoch = -1 + if restart_iter is not None: + self.epoch = restart_iter self.time = '0:00:00.0' self.structures = None self.alpha = None diff --git a/pastis/optimization/pastis_algorithms.py b/pastis/optimization/pastis_algorithms.py index aa815ddbc..385033969 100644 --- a/pastis/optimization/pastis_algorithms.py +++ b/pastis/optimization/pastis_algorithms.py @@ -205,7 +205,8 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, struct_draft_fullres=None, draft=False, simple_diploid=False, callback_freq=None, callback_function=None, reorienter=None, alpha_true=None, struct_true=None, input_weight=None, - exclude_zeros=False, null=False, mixture_coefs=None, verbose=True): + exclude_zeros=False, null=False, mixture_coefs=None, verbose=True, + restart_struct=None, restart_iter=None): """Infer 3D structures with PASTIS via Poisson model. Optimize 3D structure from Hi-C contact counts data for diploid @@ -298,6 +299,13 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, For diploid organisms: whether this optimization is inferring a "simple diploid" structure in which homologs are assumed to be identical and completely overlapping with one another. + restart_struct : str + The structure to restart inference from (used as the initialization). + Number of beads per homolog of each chromosome, or hiclib .bed file with + lengths data. + restart_iter : int + The number of iterations to restart from (corresponds to the + restart_struct file). Returns ------- @@ -429,15 +437,18 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, print( 'INITIALIZATION: initializing with true structure', flush=True) init = struct_true - """ - struct_init = initialize( - counts=counts, lengths=lengths, init=init, ploidy=ploidy, - random_state=random_state, - alpha=alpha_init if alpha_ is None else alpha_, - bias=bias, multiscale_factor=multiscale_factor, reorienter=reorienter, - mixture_coefs=mixture_coefs, verbose=verbose) - """ - struct_init = np.loadtxt("./results_4DNFI9YAVTI1/inferred_structure.epoch_0012000.txt") + + if restart_struct is None: + struct_init = initialize( + counts=counts, lengths=lengths, init=init, ploidy=ploidy, + random_state=random_state, + alpha=alpha_init if alpha_ is None else alpha_, + bias=bias, multiscale_factor=multiscale_factor, reorienter=reorienter, + mixture_coefs=mixture_coefs, verbose=verbose) + else: + if not outdir.endswith("/"): + outdir += "/" + struct_init = np.loadtxt(outdir + restart_struct) # HOMOLOG-SEPARATING CONSTRAINT if ploidy == 1 and (hsc_lambda > 0 or mhs_lambda > 0): @@ -496,7 +507,8 @@ def infer(counts_raw, lengths, ploidy, outdir='', alpha=None, seed=0, multiscale_factor=multiscale_factor, analysis_function=callback_function, frequency=callback_freq, directory=outdir, - struct_true=struct_true, alpha_true=alpha_true) + struct_true=struct_true, alpha_true=alpha_true, + restart_iter=restart_iter) # INFER STRUCTURE pm = PastisPM(counts=counts, lengths=lengths, ploidy=ploidy, @@ -745,7 +757,8 @@ def pastis_poisson(counts, lengths, ploidy, outdir='', chromosomes=None, callback_function=callback_function, callback_freq=callback_freq, alpha_true=alpha_true, struct_true=struct_true, input_weight=input_weight, exclude_zeros=exclude_zeros, - null=null, mixture_coefs=mixture_coefs, verbose=verbose) + null=null, mixture_coefs=mixture_coefs, verbose=verbose, + restart_struct=restart_struct, restart_iter=restart_iter) else: from .piecewise_whole_genome import infer_piecewise From ad6f5396cd4833f33a899e57ed61963acc6361af Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Wed, 23 Feb 2022 12:54:17 -0800 Subject: [PATCH 7/9] fixed some bugs --- pastis/optimization/callbacks.py | 7 ++++--- pastis/optimization/pastis_algorithms.py | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pastis/optimization/callbacks.py b/pastis/optimization/callbacks.py index c498f0155..030342640 100644 --- a/pastis/optimization/callbacks.py +++ b/pastis/optimization/callbacks.py @@ -174,7 +174,8 @@ def __init__(self, lengths, ploidy, counts=None, multiscale_factor=1, self.alpha_loop = None self.epoch = -1 if restart_iter is not None: - self.epoch = restart_iter + self.restart_iter = restart_iter + self.epoch = restart_iter - 1 self.time = '0:00:00.0' self.structures = None self.alpha = None @@ -199,7 +200,6 @@ def _check_frequency(self, frequency, last_epoch=False): def _print(self, last_epoch=False): """Prints loss every given number of epochs.""" - if self._check_frequency(self.frequency['print'], last_epoch): info_dict = {'At iterate': ' ' * (6 - len(str(self.epoch))) + str( self.epoch), 'f= ': '%.6g' % self.obj['obj'], @@ -276,7 +276,8 @@ def on_training_begin(self, opt_type=None, alpha_loop=None): else: self.opt_type = opt_type self.alpha_loop = alpha_loop - self.epoch = -1 + if self.restart_iter is None: + self.epoch = -1 self.seconds = 0 self.time = '0:00:00.0' self.structures = None diff --git a/pastis/optimization/pastis_algorithms.py b/pastis/optimization/pastis_algorithms.py index 385033969..33d895245 100644 --- a/pastis/optimization/pastis_algorithms.py +++ b/pastis/optimization/pastis_algorithms.py @@ -620,8 +620,7 @@ def pastis_poisson(counts, lengths, ploidy, outdir='', chromosomes=None, piecewise_step1_accuracy=1, alpha_true=None, struct_true=None, init='mds', input_weight=None, exclude_zeros=False, null=False, mixture_coefs=None, - verbose=True, save_freq=None, restart_struct=None, - restart_iter=None): + verbose=True, restart_struct=None, restart_iter=None): """Infer 3D structures with PASTIS via Poisson model. Infer 3D structure from Hi-C contact counts data for haploid or diploid From 8181b4d408e552d51b13ad2891c66bb8b9d7d1a1 Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Wed, 23 Feb 2022 13:13:39 -0800 Subject: [PATCH 8/9] fixed a bug with parameter restart_iter --- pastis/optimization/callbacks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pastis/optimization/callbacks.py b/pastis/optimization/callbacks.py index 030342640..27efe3f14 100644 --- a/pastis/optimization/callbacks.py +++ b/pastis/optimization/callbacks.py @@ -127,6 +127,7 @@ def __init__(self, lengths, ploidy, counts=None, multiscale_factor=1, on_training_begin=None, on_training_end=None, on_epoch_end=None, directory=None, struct_true=None, alpha_true=None, verbose=False, restart_iter=None): + self.restart_iter = restart_iter self.ploidy = ploidy self.multiscale_factor = multiscale_factor self.lengths = decrease_lengths_res(lengths, multiscale_factor) @@ -173,9 +174,8 @@ def __init__(self, lengths, ploidy, counts=None, multiscale_factor=1, self.opt_type = None self.alpha_loop = None self.epoch = -1 - if restart_iter is not None: - self.restart_iter = restart_iter - self.epoch = restart_iter - 1 + if self.restart_iter is not None: + self.epoch = self.restart_iter - 1 self.time = '0:00:00.0' self.structures = None self.alpha = None From ad7fb4294b81369fcd0e6e56f932855ef5a998e3 Mon Sep 17 00:00:00 2001 From: Mozes Jacobs Date: Wed, 23 Feb 2022 13:21:05 -0800 Subject: [PATCH 9/9] ready to be looked at --- pastis/optimization/callbacks.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pastis/optimization/callbacks.py b/pastis/optimization/callbacks.py index 27efe3f14..36bd2baef 100644 --- a/pastis/optimization/callbacks.py +++ b/pastis/optimization/callbacks.py @@ -276,8 +276,9 @@ def on_training_begin(self, opt_type=None, alpha_loop=None): else: self.opt_type = opt_type self.alpha_loop = alpha_loop - if self.restart_iter is None: - self.epoch = -1 + self.epoch = -1 + if self.restart_iter is not None: + self.epoch = self.restart_iter - 1 self.seconds = 0 self.time = '0:00:00.0' self.structures = None