Skip to content

Commit

Permalink
changed to linear transformation and fixed support on uniform prior
Browse files Browse the repository at this point in the history
  • Loading branch information
kylajones committed Mar 28, 2024
1 parent b77eae5 commit a3beb4c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions linfa/tests/TP1_uniform_prior.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions linfa/tests/TP1_uniform_prior_no_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions run_plot_res.sh
Original file line number Diff line number Diff line change
@@ -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



Expand Down

0 comments on commit a3beb4c

Please sign in to comment.