Skip to content

Commit

Permalink
SpecificRangeInitializer -> InitializerParamBounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Jul 31, 2024
1 parent 52808e5 commit ee45a3e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion autofit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
from .non_linear.grid.sensitivity import Sensitivity
from .non_linear.initializer import InitializerBall
from .non_linear.initializer import InitializerPrior
from .non_linear.initializer import SpecificRangeInitializer
from .non_linear.initializer import InitializerParamBounds
from .non_linear.search.mcmc.auto_correlations import AutoCorrelationsSettings
from .non_linear.search.mcmc.emcee.search import Emcee
from .non_linear.search.mcmc.zeus.search import Zeus
Expand Down
8 changes: 8 additions & 0 deletions autofit/mapper/prior_model/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,14 @@ def paths(self) -> List[Path]:
"""
return [path for path, _ in self.path_priors_tuples]

@property
def paths_formatted(self) -> List[Path]:
"""
A list of paths to all the priors in the model, ordered by their
ids
"""
return [path for path, _ in self.path_priors_tuples]

@property
def composition(self):
return [".".join(path) for path in self.paths]
Expand Down
2 changes: 2 additions & 0 deletions autofit/non_linear/fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def __call__(self, parameters, *kwargs):
instance = self.model.instance_from_vector(vector=parameters)
log_likelihood = self.log_likelihood_function(instance=instance)

print(log_likelihood)

if np.isnan(log_likelihood):
return self.resample_figure_of_merit

Expand Down
4 changes: 2 additions & 2 deletions autofit/non_linear/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def samples_in_test_mode(self, total_points: int, model: AbstractPriorModel):
return unit_parameter_lists, parameter_lists, figure_of_merit_list


class SpecificRangeInitializer(AbstractInitializer):
class InitializerParamBounds(AbstractInitializer):
def __init__(
self,
parameter_dict: Dict[Prior, Tuple[float, float]],
Expand Down Expand Up @@ -226,7 +226,7 @@ def _generate_unit_parameter_list(self, model: AbstractPriorModel) -> List[float
key = ".".join(model.path_for_prior(prior))
if key not in self._generated_warnings:
logger.warning(
f"Range for {key} not set in the SpecificRangeInitializer. "
f"Range for {key} not set in the InitializerParamBounds. "
f"Using defaults."
)
self._generated_warnings.add(key)
Expand Down
6 changes: 3 additions & 3 deletions autofit/non_linear/search/nest/abstract_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from autofit.non_linear.initializer import (
InitializerPrior,
AbstractInitializer,
SpecificRangeInitializer,
InitializerParamBounds,
)
from autofit.non_linear.samples import SamplesNest
from autofit.non_linear.plot.nest_plotters import NestPlotter
Expand Down Expand Up @@ -44,9 +44,9 @@ def __init__(
session
An SQLAlchemy session instance so the results of the model-fit are written to an SQLite database.
"""
if isinstance(initializer, SpecificRangeInitializer):
if isinstance(initializer, InitializerParamBounds):
raise ValueError(
"SpecificRangeInitializer cannot be used for nested sampling"
"InitializerParamBounds cannot be used for nested sampling"
)

super().__init__(
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ We now define the start point of certain parameters in the model as follows.

.. code-block:: python
initializer = af.SpecificRangeInitializer(
initializer = af.InitializerParamBounds(
{
model.centre: (49.0, 51.0),
model.normalization: (4.0, 6.0),
Expand Down
6 changes: 3 additions & 3 deletions test_autofit/non_linear/test_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def make_model():


def test_starting_point_initializer(model):
initializer = af.SpecificRangeInitializer(
initializer = af.InitializerParamBounds(
{
model.centre: (1.0, 2.0),
model.normalization: (2.0, 3.0),
Expand All @@ -250,7 +250,7 @@ def test_starting_point_initializer(model):


def test_offset(model):
initializer = af.SpecificRangeInitializer(
initializer = af.InitializerParamBounds(
{
model.centre: (1.5, 2.0),
model.normalization: (2.5, 3.0),
Expand All @@ -265,7 +265,7 @@ def test_offset(model):


def test_missing_parameter(model):
initializer = af.SpecificRangeInitializer(
initializer = af.InitializerParamBounds(
{
model.centre: (1.5, 2.0),
model.normalization: (2.5, 3.0),
Expand Down

0 comments on commit ee45a3e

Please sign in to comment.