Skip to content

Commit

Permalink
Rename var_scale temperature everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
alicjapolanska committed Oct 26, 2023
1 parent ab9e61b commit 9ec595d
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 87 deletions.
6 changes: 3 additions & 3 deletions examples/gaussian_nondiagcov_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def run_example(
cov = init_cov(ndim)
inv_cov = np.linalg.inv(cov)
training_proportion = 0.5
epochs_num = 50
var_scale = 0.9
epochs_num = 5
temperature = 0.9
standardize = True
verbose = True

Expand Down Expand Up @@ -145,7 +145,7 @@ def run_example(
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RealNVPModel(
ndim, standardize=standardize, temperature=var_scale
ndim, standardize=standardize, temperature=temperature
)
model.fit(chains_train.samples, epochs=epochs_num, verbose=verbose)

Expand Down
4 changes: 2 additions & 2 deletions examples/gaussian_nondiagcov_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run_example(ndim=2, nchains=100, samples_per_chain=1000, plot_corner=False):
inv_cov = jnp.linalg.inv(cov)
training_proportion = 0.5
epochs_num = 80
var_scale = 0.8
temperature = 0.8
standardize = True
verbose = True

Expand Down Expand Up @@ -157,7 +157,7 @@ def run_example(ndim=2, nchains=100, samples_per_chain=1000, plot_corner=False):
hidden_size=hidden_size,
spline_range=spline_range,
standardize=standardize,
temperature=var_scale,
temperature=temperature,
)
model.fit(jnp.array(chains_train.samples), epochs=epochs_num, verbose=verbose)

Expand Down
20 changes: 10 additions & 10 deletions examples/normal_gamma_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def run_example(
created_plots = False

training_proportion = 0.5
var_scale = 0.9
temperature = 0.9
epochs_num = 100
standardize = False

plot_comparison_2var = True
var_scale_2 = 0.95
temperature_2 = 0.95

# ===========================================================================
# Simulate data
Expand Down Expand Up @@ -269,7 +269,7 @@ def run_example(
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RealNVPModel(
ndim, standardize=standardize, temperature=var_scale
ndim, standardize=standardize, temperature=temperature
)
model.fit(chains_train.samples, epochs=epochs_num)

Expand Down Expand Up @@ -299,7 +299,7 @@ def run_example(

if plot_comparison_2var:
model2 = model
model2.temperature = var_scale_2
model2.temperature = temperature_2
ev_2 = hm.Evidence(chains_test.nchains, model)
ev_2.add_chains(chains_test)
ln_evidence_2, ln_evidence_std_2 = ev_2.compute_ln_evidence()
Expand Down Expand Up @@ -411,7 +411,7 @@ def run_example(
if savefigs:
plt.savefig(
"examples/plots/nvp_normalgamma_corner_all_"
+ str(var_scale)
+ str(temperature)
+ "tau"
+ str(tau_prior)
+ ".png",
Expand Down Expand Up @@ -448,7 +448,7 @@ def run_example(
)
if savefigs:
plt.savefig(
"examples/plots/nvp_normalgamma_comparison" + str(var_scale) + ".pdf",
"examples/plots/nvp_normalgamma_comparison" + str(temperature) + ".pdf",
bbox_inches="tight",
)
plt.show(block=False)
Expand All @@ -472,7 +472,7 @@ def run_example(
capsize=4,
capthick=2,
elinewidth=2,
label="T=" + str(var_scale),
label="T=" + str(temperature),
)
ax.errorbar(
np.array(tau_array) * 1.13,
Expand All @@ -482,15 +482,15 @@ def run_example(
capsize=4,
capthick=2,
elinewidth=2,
label="T=" + str(var_scale_2),
label="T=" + str(temperature_2),
)
ax.legend(loc="lower right")
if savefigs:
plt.savefig(
"examples/plots/nvp_normalgamma_comparison_"
+ str(var_scale)
+ str(temperature)
+ "_"
+ str(var_scale_2)
+ str(temperature_2)
+ ".pdf",
bbox_inches="tight",
dpi=3000,
Expand Down
20 changes: 10 additions & 10 deletions examples/normal_gamma_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def run_example(
created_plots = False

training_proportion = 0.5
var_scale = 0.8
temperature = 0.8
epochs_num = 10
standardize = False

plot_comparison_2var = False
var_scale_2 = 0.95
temperature_2 = 0.95

# ===========================================================================
# Simulate data
Expand Down Expand Up @@ -269,7 +269,7 @@ def run_example(
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RQSplineModel(
ndim, standardize=standardize, temperature=var_scale
ndim, standardize=standardize, temperature=temperature
)
model.fit(chains_train.samples, epochs=epochs_num)

Expand Down Expand Up @@ -299,7 +299,7 @@ def run_example(

if plot_comparison_2var:
model2 = model
model2.temperature = var_scale_2 # double check this doesn't modify model
model2.temperature = temperature_2 # double check this doesn't modify model
ev_2 = hm.Evidence(chains_test.nchains, model)
ev_2.add_chains(chains_test)
ln_evidence_2, ln_evidence_std_2 = ev_2.compute_ln_evidence()
Expand Down Expand Up @@ -411,7 +411,7 @@ def run_example(
if savefigs:
plt.savefig(
"examples/plots/splines_normalgamma_corner_all_"
+ str(var_scale)
+ str(temperature)
+ "tau"
+ str(tau_prior)
+ ".png",
Expand Down Expand Up @@ -449,7 +449,7 @@ def run_example(
if savefigs:
plt.savefig(
"examples/plots/splines_normalgamma_comparison"
+ str(var_scale)
+ str(temperature)
+ ".pdf",
bbox_inches="tight",
)
Expand All @@ -474,7 +474,7 @@ def run_example(
capsize=4,
capthick=2,
elinewidth=2,
label="T=" + str(var_scale),
label="T=" + str(temperature),
)
ax.errorbar(
np.array(tau_array) * 1.13,
Expand All @@ -484,15 +484,15 @@ def run_example(
capsize=4,
capthick=2,
elinewidth=2,
label="T=" + str(var_scale_2),
label="T=" + str(temperature_2),
)
ax.legend(loc="lower right")
if savefigs:
plt.savefig(
"examples/plots/splines_normalgamma_comparison_"
+ str(var_scale)
+ str(temperature)
+ "_"
+ str(var_scale_2)
+ str(temperature_2)
+ ".pdf",
bbox_inches="tight",
dpi=3000,
Expand Down
8 changes: 4 additions & 4 deletions examples/pima_indian_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def run_example(
"""

training_proportion = 0.5
var_scale = 0.9
temperature = 0.9
epochs_num = 50
n_scaled = 6
n_unscaled = 2
Expand Down Expand Up @@ -259,7 +259,7 @@ def run_example(
ndim,
n_scaled_layers=n_scaled,
n_unscaled_layers=n_unscaled,
temperature=var_scale,
temperature=temperature,
)
model.fit(chains_train.samples, epochs=epochs_num)

Expand All @@ -268,7 +268,7 @@ def run_example(
# =======================================================================

num_samp = chains_train.samples.shape[0]
# samps = np.array(model.sample(num_samp, var_scale=1.))
# samps = np.array(model.sample(num_samp, temperature=1.))
samps_compressed = np.array(model.sample(num_samp))

labels = ["Bias", "NP", "PGC", "BMI", "DP", "AGE"]
Expand All @@ -286,7 +286,7 @@ def run_example(
if savefigs:
plt.savefig(
"examples/plots/nvp_pima_indian_corner_all_{}_T{}_tau{}_".format(
n_scaled + n_unscaled, var_scale, tau
n_scaled + n_unscaled, temperature, tau
)
+ model_lab
+ ".png",
Expand Down
8 changes: 4 additions & 4 deletions examples/radiata_pine_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def run_example(
savefigs = True

training_proportion = 0.5
var_scale = 0.9
temperature = 0.9
epochs_num = 50
n_scaled = 3
n_unscaled = 3
Expand Down Expand Up @@ -442,7 +442,7 @@ def run_example(
n_unscaled_layers=n_unscaled,
learning_rate=learning_rate,
standardize=standardize,
temperature=var_scale,
temperature=temperature,
)
# model = model_nf.RQSplineFlow(ndim)
model.fit(chains_train.samples, epochs=epochs_num)
Expand Down Expand Up @@ -537,8 +537,8 @@ def run_example(
# =======================================================================

num_samp = chains_train.samples.shape[0]
# samps = np.array(model.sample(num_samp, var_scale=1.))
samps_compressed = np.array(model.sample(num_samp, var_scale=var_scale))
# samps = np.array(model.sample(num_samp, temperature=1.))
samps_compressed = np.array(model.sample(num_samp, temperature=temperature))

utils.plot_getdist_compare(chains_train.samples, samps_compressed)
if savefigs:
Expand Down
8 changes: 5 additions & 3 deletions examples/radiata_pine_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def run_example(
savefigs = True

training_proportion = 0.5
var_scale = 0.8
temperature = 0.8
epochs_num = 30
standardize = True

Expand Down Expand Up @@ -433,7 +433,9 @@ def run_example(
Fit model by selecing the configuration of hyper-parameters which
minimises the validation variances.
"""
model = model_nf.RQSplineModel(ndim, standardize=standardize, temperature=var_scale)
model = model_nf.RQSplineModel(
ndim, standardize=standardize, temperature=temperature
)
model.fit(chains_train.samples, epochs=epochs_num)

# ===========================================================================
Expand Down Expand Up @@ -526,7 +528,7 @@ def run_example(
# =======================================================================

num_samp = chains_train.samples.shape[0]
# samps = np.array(model.sample(num_samp, var_scale=1.))
# samps = np.array(model.sample(num_samp, temperature=1.))
samps_compressed = np.array(model.sample(num_samp))

utils.plot_getdist_compare(chains_train.samples, samps_compressed)
Expand Down
4 changes: 2 additions & 2 deletions examples/rastrigin_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def run_example(
hyper_parameters = [[10 ** (R)] for R in range(-nhyper + step, step)]
hm.logs.debug_log("Hyper-parameters = {}".format(hyper_parameters))

var_scale = 0.8
temperature = 0.8
epochs_num = 30

# Spline params
Expand Down Expand Up @@ -209,7 +209,7 @@ def run_example(
standardize=standardize,
learning_rate=learning_rate,
momentum=momentum,
temperature=var_scale,
temperature=temperature,
)
model.fit(chains_train.samples, epochs=epochs_num)

Expand Down
8 changes: 4 additions & 4 deletions examples/rosenbrock_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def run_example(
a = 1.0
b = 100.0
epochs_num = 8
var_scale = 0.9
temperature = 0.9
training_proportion = 0.5
standardize = False
"""
Expand Down Expand Up @@ -221,7 +221,7 @@ def run_example(
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RealNVPModel(
ndim, standardize=standardize, temperature=var_scale
ndim, standardize=standardize, temperature=temperature
)
model.fit(chains_train.samples, epochs=epochs_num)

Expand Down Expand Up @@ -364,7 +364,7 @@ def run_example(
if savefigs:
plt.savefig(
"examples/plots/nvp_rosenbrock_corner_all_T"
+ str(var_scale)
+ str(temperature)
+ ".png",
bbox_inches="tight",
dpi=300,
Expand All @@ -388,7 +388,7 @@ def run_example(
if n_realisations > 1:
np.savetxt(
"examples/data/nvp_rosenbrock_evidence_inv_T"
+ str(var_scale)
+ str(temperature)
+ "_realisations.dat",
evidence_inv_summary,
)
Expand Down
8 changes: 4 additions & 4 deletions examples/rosenbrock_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def run_example(
a = 1.0
b = 100.0
epochs_num = 5
var_scale = 0.8
temperature = 0.8
training_proportion = 0.5
standardize = True
"""
Expand Down Expand Up @@ -221,7 +221,7 @@ def run_example(
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RQSplineModel(
ndim, standardize=standardize, temperature=var_scale
ndim, standardize=standardize, temperature=temperature
)
model.fit(chains_train.samples, epochs=epochs_num)

Expand Down Expand Up @@ -356,7 +356,7 @@ def run_example(
if savefigs:
plt.savefig(
"examples/plots/spline_rosenbrock_corner_all_T"
+ str(var_scale)
+ str(temperature)
+ ".png",
bbox_inches="tight",
dpi=300,
Expand All @@ -378,7 +378,7 @@ def run_example(
if n_realisations > 1:
np.savetxt(
"examples/data/spline_rosenbrock_evidence_inv_T"
+ str(var_scale)
+ str(temperature)
+ "_realisations.dat",
evidence_inv_summary,
)
Expand Down
6 changes: 3 additions & 3 deletions examples/temperature_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def get_batch(seed):

num_samp = batch_size * 5

# samps = np.array(model.sample(num_samp, var_scale=1.))
samps2 = np.array(model.sample(num_samp, var_scale=0.7))
samps3 = np.array(model.sample(num_samp, var_scale=0.4))
# samps = np.array(model.sample(num_samp, temperature=1.))
samps2 = np.array(model.sample(num_samp, temperature=0.7))
samps3 = np.array(model.sample(num_samp, temperature=0.4))

# Get the getdist MCSamples objects for the samples, specifying same parameter
# names and labels; if not specified weights are assumed to all be unity
Expand Down
Loading

0 comments on commit 9ec595d

Please sign in to comment.