Skip to content

Commit

Permalink
Change model module names.giti
Browse files Browse the repository at this point in the history
  • Loading branch information
alicjapolanska committed Nov 2, 2023
1 parent c8e0f1c commit 71d5a36
Show file tree
Hide file tree
Showing 28 changed files with 747 additions and 651 deletions.
2 changes: 1 addition & 1 deletion examples/gaussian_diagcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def run_example(
# ======================================================================
# Train hyper-spherical model
# ======================================================================
model = hm.model.HyperSphere(ndim, domains_sphere)
model = hm.model_legacy.HyperSphere(ndim, domains_sphere)
model.set_R(max_r_prob)
model.fitted = True

Expand Down
2 changes: 1 addition & 1 deletion examples/gaussian_nondiagcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def run_example(
hm.logs.debug_log("r scale = {}".format(r_scale))
domains = [r_scale * np.array([1e-1, 1e0])]
hm.logs.debug_log("Domain = {}".format(domains))
model = hm.model.HyperSphere(ndim, domains)
model = hm.model_legacy.HyperSphere(ndim, domains)
fit_success, objective = model.fit(
chains_train.samples, chains_train.ln_posterior
)
Expand Down
6 changes: 2 additions & 4 deletions examples/gaussian_nondiagcov_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import utils

sys.path.append("harmonic")
import model_nf
import model as md


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

# Use chains and model to compute inverse evidence.
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 @@ -13,7 +13,7 @@
import utils

sys.path.append("harmonic")
from harmonic import model_nf
from harmonic import model as md
import jax
import jax.numpy as jnp

Expand Down Expand Up @@ -150,7 +150,7 @@ def run_example(ndim=2, nchains=100, samples_per_chain=1000, plot_corner=False):
# Fit model
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RQSplineModel(
model = md.RQSplineModel(
ndim,
n_layers=n_layers,
n_bins=n_bins,
Expand Down
8 changes: 4 additions & 4 deletions examples/normal_gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def run_example(
domains_MGMM,
hyper_parameters_MGMM,
nfold=nfold,
modelClass=hm.model.ModifiedGaussianMixtureModel,
modelClass=hm.model_legacy.ModifiedGaussianMixtureModel,
seed=0,
)
hm.logs.debug_log(
Expand All @@ -293,7 +293,7 @@ def run_example(
domains_sphere,
hyper_parameters_sphere,
nfold=nfold,
modelClass=hm.model.HyperSphere,
modelClass=hm.model_legacy.HyperSphere,
seed=0,
)
hm.logs.debug_log(
Expand All @@ -316,12 +316,12 @@ def run_example(
hm.logs.debug_log(
"Using MGMM with hyper_parameters = {}".format(best_hyper_param_MGMM)
)
model = hm.model.ModifiedGaussianMixtureModel(
model = hm.model_legacy.ModifiedGaussianMixtureModel(
ndim, domains_MGMM, hyper_parameters=best_hyper_param_MGMM
)
else:
hm.logs.debug_log("Using HyperSphere")
model = hm.model.HyperSphere(
model = hm.model_legacy.HyperSphere(
ndim, domains_sphere, hyper_parameters=best_hyper_param_sphere
)
fit_success = model.fit(chains_train.samples, chains_train.ln_posterior)
Expand Down
6 changes: 2 additions & 4 deletions examples/normal_gamma_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import utils

sys.path.append("harmonic")
import model_nf
import model as md


def ln_likelihood(x_mean, x_std, x_n, mu, tau):
Expand Down Expand Up @@ -268,9 +268,7 @@ def run_example(
# Fit model
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RealNVPModel(
ndim, standardize=standardize, temperature=temperature
)
model = md.RealNVPModel(ndim, standardize=standardize, temperature=temperature)
model.fit(chains_train.samples, epochs=epochs_num)

# ===================================================================
Expand Down
6 changes: 2 additions & 4 deletions examples/normal_gamma_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import utils

sys.path.append("harmonic")
import model_nf
import model as md


def ln_likelihood(x_mean, x_std, x_n, mu, tau):
Expand Down Expand Up @@ -268,9 +268,7 @@ def run_example(
# Fit model
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RQSplineModel(
ndim, standardize=standardize, temperature=temperature
)
model = md.RQSplineModel(ndim, standardize=standardize, temperature=temperature)
model.fit(chains_train.samples, epochs=epochs_num)

# ===================================================================
Expand Down
8 changes: 4 additions & 4 deletions examples/pima_indian.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def run_example(
domains_MGMM,
hyper_parameters_MGMM,
nfold=nfold,
modelClass=hm.model.ModifiedGaussianMixtureModel,
modelClass=hm.model_legacy.ModifiedGaussianMixtureModel,
seed=0,
)
hm.logs.debug_log(
Expand All @@ -275,7 +275,7 @@ def run_example(
domains_sphere,
hyper_parameters_sphere,
nfold=nfold,
modelClass=hm.model.HyperSphere,
modelClass=hm.model_legacy.HyperSphere,
seed=0,
)
hm.logs.debug_log(
Expand All @@ -298,12 +298,12 @@ def run_example(
hm.logs.info_log(
"Using MGMM with hyper_parameters = {}".format(best_hyper_param_MGMM)
)
model = hm.model.ModifiedGaussianMixtureModel(
model = hm.model_legacy.ModifiedGaussianMixtureModel(
ndim, domains_MGMM, hyper_parameters=best_hyper_param_MGMM
)
else:
hm.logs.info_log("Using HyperSphere")
model = hm.model.HyperSphere(
model = hm.model_legacy.HyperSphere(
ndim, domains_sphere, hyper_parameters=best_hyper_param_sphere
)

Expand Down
4 changes: 2 additions & 2 deletions examples/pima_indian_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import utils

sys.path.append("harmonic")
import model_nf
import model as md
import flows


Expand Down Expand Up @@ -255,7 +255,7 @@ def run_example(
minimises the validation variances.
"""

model = model_nf.RealNVPModel(
model = md.RealNVPModel(
ndim,
n_scaled_layers=n_scaled,
n_unscaled_layers=n_unscaled,
Expand Down
2 changes: 1 addition & 1 deletion examples/radiata_pine.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def run_example(
"""

hm.logs.info_log("Using HyperSphere")
model = hm.model.HyperSphere(ndim, domains_sphere, hyper_parameters=None)
model = hm.model_legacy.HyperSphere(ndim, domains_sphere, hyper_parameters=None)

fit_success = model.fit(chains_train.samples, chains_train.ln_posterior)
hm.logs.debug_log("fit_success = {}".format(fit_success))
Expand Down
6 changes: 3 additions & 3 deletions examples/radiata_pine_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import utils

sys.path.append("harmonic")
import model_nf
import model as md
import flows


Expand Down Expand Up @@ -436,15 +436,15 @@ def run_example(
Fit model by selecing the configuration of hyper-parameters which
minimises the validation variances.
"""
model = model_nf.RealNVPModel(
model = md.RealNVPModel(
ndim,
n_scaled_layers=n_scaled,
n_unscaled_layers=n_unscaled,
learning_rate=learning_rate,
standardize=standardize,
temperature=temperature,
)
# model = model_nf.RQSplineFlow(ndim)
# model = md.RQSplineFlow(ndim)
model.fit(chains_train.samples, epochs=epochs_num)

# ===========================================================================
Expand Down
6 changes: 2 additions & 4 deletions examples/radiata_pine_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import utils

sys.path.append("harmonic")
import model_nf
import model as md
import flows


Expand Down Expand Up @@ -433,9 +433,7 @@ 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=temperature
)
model = md.RQSplineModel(ndim, standardize=standardize, temperature=temperature)
model.fit(chains_train.samples, epochs=epochs_num)

# ===========================================================================
Expand Down
4 changes: 2 additions & 2 deletions examples/rastrigin.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def run_example(
domain,
hyper_parameters,
nfold=nfold,
modelClass=hm.model.KernelDensityEstimate,
modelClass=hm.model_legacy.KernelDensityEstimate,
seed=0,
)

Expand All @@ -215,7 +215,7 @@ def run_example(
Fit model by selecing the configuration of hyper-parameters which
minimises the validation variances.
"""
model = hm.model.KernelDensityEstimate(
model = hm.model_legacy.KernelDensityEstimate(
ndim, domain, hyper_parameters=best_hyper_param
)
fit_success = model.fit(chains_train.samples, chains_train.ln_posterior)
Expand Down
4 changes: 2 additions & 2 deletions examples/rastrigin_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import utils

sys.path.append("harmonic")
import model_nf
import model as md
import flows


Expand Down Expand Up @@ -200,7 +200,7 @@ def run_example(
"""
Fit model.
"""
model = model_nf.RQSplineModel(
model = md.RQSplineModel(
ndim,
n_layers=n_layers,
n_bins=n_bins,
Expand Down
4 changes: 2 additions & 2 deletions examples/rosenbrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def run_example(
domain,
hyper_parameters,
nfold=nfold,
modelClass=hm.model.KernelDensityEstimate,
modelClass=hm.model_legacy.KernelDensityEstimate,
seed=0,
)
hm.logs.debug_log("validation_variances = {}".format(validation_variances))
Expand All @@ -253,7 +253,7 @@ def run_example(
Fit model by selecing the configuration of hyper-parameters which
minimises the validation variances.
"""
model = hm.model.KernelDensityEstimate(
model = hm.model_legacy.KernelDensityEstimate(
ndim, domain, hyper_parameters=best_hyper_param
)
fit_success = model.fit(chains_train.samples, chains_train.ln_posterior)
Expand Down
6 changes: 2 additions & 4 deletions examples/rosenbrock_nvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

sys.path.append("examples")
import utils
from harmonic import model_nf
from harmonic import model as md


def ln_prior_uniform(x, xmin=-10.0, xmax=10.0, ymin=-5.0, ymax=15.0):
Expand Down Expand Up @@ -220,9 +220,7 @@ def run_example(
# Fit model
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RealNVPModel(
ndim, standardize=standardize, temperature=temperature
)
model = md.RealNVPModel(ndim, standardize=standardize, temperature=temperature)
model.fit(chains_train.samples, epochs=epochs_num)

# =======================================================================
Expand Down
6 changes: 2 additions & 4 deletions examples/rosenbrock_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

sys.path.append("examples")
import utils
from harmonic import model_nf
from harmonic import model as md


def ln_prior_uniform(x, xmin=-10.0, xmax=10.0, ymin=-5.0, ymax=15.0):
Expand Down Expand Up @@ -220,9 +220,7 @@ def run_example(
# Fit model
# =======================================================================
hm.logs.info_log("Fit model for {} epochs...".format(epochs_num))
model = model_nf.RQSplineModel(
ndim, standardize=standardize, temperature=temperature
)
model = md.RQSplineModel(ndim, standardize=standardize, temperature=temperature)
model.fit(chains_train.samples, epochs=epochs_num)

# =======================================================================
Expand Down
4 changes: 2 additions & 2 deletions examples/temperature_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
tfp = tfp.substrates.jax
tfd = tfp.distributions
tfb = tfp.bijectors
from harmonic import model_nf
from harmonic import model as md
from harmonic import flows


Expand Down Expand Up @@ -101,7 +101,7 @@ def get_batch(seed):
epochs_num = 300

posterior_samples = np.array(get_moon(0.05).sample(batch_size, seed=seed))
model = model_nf.RealNVPModel(
model = md.RealNVPModel(
ndim,
flow=flows.RealNVP(ndim, n_scaled_layers=n_scaled, n_unscaled_layers=n_unscaled),
)
Expand Down
3 changes: 2 additions & 1 deletion harmonic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .chains import Chains
from . import evidence
from .evidence import Evidence, Shifting
from . import model

# from . import model
from . import utils
from . import logs
4 changes: 2 additions & 2 deletions harmonic/model_nf.py → harmonic/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Sequence, Union
from harmonic import model as md
from harmonic import model_abstract as mda
from harmonic import flows
import jax
import jax.numpy as jnp
Expand Down Expand Up @@ -94,7 +94,7 @@ def train_flow(
return train_flow, train_epoch, train_step


class FlowModel(md.Model):
class FlowModel(mda.Model):
"""Normalizing flow model to approximate the log_e posterior by a normalizing flow."""

def __init__(
Expand Down
Loading

0 comments on commit 71d5a36

Please sign in to comment.