From a3beb4c1fcd46b4426adf64dfd52c368e328d34a Mon Sep 17 00:00:00 2001 From: kylajones Date: Thu, 28 Mar 2024 11:34:27 -0400 Subject: [PATCH] changed to linear transformation and fixed support on uniform prior --- linfa/tests/TP1_uniform_prior.py | 4 ++-- linfa/tests/TP1_uniform_prior_no_disc.py | 25 +++++++++++++++++------- run_plot_res.sh | 4 ++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/linfa/tests/TP1_uniform_prior.py b/linfa/tests/TP1_uniform_prior.py index 6c5b80c..6f76c30 100644 --- a/linfa/tests/TP1_uniform_prior.py +++ b/linfa/tests/TP1_uniform_prior.py @@ -53,8 +53,8 @@ def run_test(): exp.device = torch.device('cuda:0' if torch.cuda.is_available() and not exp.no_cuda else 'cpu') # Define transformation - trsf_info = [['tanh', -20.0, 20.0, 500.0, 1500.0], - ['tanh', -20.0, 20.0, -30000.0, -15000.0]] + trsf_info = [['linear', -20.0, 20.0, 500.0, 1500.0], + ['linear', -20.0, 20.0, -30000.0, -15000.0]] trsf = Transformation(trsf_info) # Apply the transformation diff --git a/linfa/tests/TP1_uniform_prior_no_disc.py b/linfa/tests/TP1_uniform_prior_no_disc.py index ad8d00f..791f585 100644 --- a/linfa/tests/TP1_uniform_prior_no_disc.py +++ b/linfa/tests/TP1_uniform_prior_no_disc.py @@ -53,8 +53,8 @@ def run_test(): exp.device = torch.device('cuda:0' if torch.cuda.is_available() and not exp.no_cuda else 'cpu') # Define transformation - trsf_info = [['tanh', -20.0, 20.0, 500.0, 1500.0], - ['tanh', -20.0, 20.0, -30000.0, -15000.0]] + trsf_info = [['linear', -20.0, 20.0, 500.0, 1500.0], + ['linear', -20.0, 20.0, -30000.0, -15000.0]] trsf = Transformation(trsf_info) # Apply the transformation @@ -163,14 +163,25 @@ def log_prior(calib_inputs, transform): adjust = transform.compute_log_jacob_func(calib_inputs) # Compute the calibration inputs in the physical domain phys_inputs = transform.forward(calib_inputs) - # Define prior moments for uniform distribution + # Define upper and lower bounds for uniform distribution low = torch.tensor([500, -35.0E3]) high = torch.tensor([1500, -10.0E3]) + res = [] # Initialize # Eval log prior - l1 = -np.log((high[0] - low[0])*(high[1] - low[1])) - # Return - res = l1 + adjust - return res + for loopA, param_pairs in enumerate(phys_inputs): + if param_pairs[0] < low[0]: + l1 = 0 + elif param_pairs[0] > high[0]: + l1 = 0 + elif param_pairs[1] < low[1]: + l1 = 0 + elif param_pairs[1] > high[1]: + l1 = 0 + else: + l1 = -np.log((high[0] - low[0])*(high[1] - low[1])) + # Return + res.append(l1 + adjust[loopA]) + return torch.tensor(res) exp.model_logprior = lambda x: log_prior(x, exp.transform) diff --git a/run_plot_res.sh b/run_plot_res.sh index bbf14e4..46b4149 100644 --- a/run_plot_res.sh +++ b/run_plot_res.sh @@ -1,8 +1,8 @@ -python3 linfa/plot_res.py --folder results/ --name TP_15_uniform_prior --iter 25000 --picformat png +python3 linfa/plot_res.py --folder results/ --name TP1_uniform_prior_no_disc --iter 5000 --picformat png # python3 linfa/plot_disc.py --folder results/ --name test_08_lf_w_disc_TP1_uniform_prior --iter 25000 --picformat png --mode histograms --num_points 10 --limfactor 1.0 --saveinterval 1000 --dropouts 10 # python3 linfa/plot_disc.py --folder results/ --name test_19_lf_w_disc_TP15_rep_meas_dropout --iter 10000 --picformat png --mode discr_surface --num_points 10 --limfactor 1.0 --saveinterval 1000 # python3 linfa/plot_disc.py --folder results/ --name test_08_lf_w_disc_TP1_uniform_prior --iter 25000 --picformat png --mode marginal_stats --num_points 10 --limfactor 1.0 --saveinterval 1000 -python3 linfa/plot_disc.py --folder results/ --name TP_15_uniform_prior --iter 25000 --picformat png --mode marginal_posterior --num_points 10 --limfactor 1.0 --saveinterval 1000 +python3 linfa/plot_disc.py --folder results/ --name TP1_uniform_prior_no_disc --iter 5000 --picformat png --mode marginal_posterior --num_points 10 --limfactor 1.0 --saveinterval 1000