Merged
Conversation
This was referenced Jul 31, 2024
Collaborator
Author
rhayes777
approved these changes
Aug 5, 2024
autofit/non_linear/initializer.py
Outdated
Comment on lines
+260
to
+264
| info += f"{key}: Start[{value}]\n" | ||
|
|
||
| except KeyError: | ||
|
|
||
| info += f"{key} : {prior})\n" |
Collaborator
There was a problem hiding this comment.
Inconsistent spacing before the :
| info_start = self.search.initializer.info_from_model(model=self.model) | ||
| self._save_model_start_point(info=info_start) | ||
| except (NotImplementedError, AttributeError): | ||
| pass |
Collaborator
There was a problem hiding this comment.
Could be worth logging something here as these errors may cover up code mistakes
| self.logger.debug("Visualizing") | ||
|
|
||
| if analysis.should_visualize(paths=self.paths, during_analysis=during_analysis): | ||
| if paths_override is None: |
Collaborator
There was a problem hiding this comment.
paths = paths_override or self.paths|
|
||
|
|
||
| class AbstractBFGS(AbstractMLE): | ||
| __identifier_fields__ = () |
Collaborator
There was a problem hiding this comment.
Probably best not to define an empty identifier_fields - I think as it stands it would mean attributes would be ignored when creating an identifier for an AbstractBFGS meaning all AbstractBFGS runs of the same type would have the same identifier
Comment on lines
+20
to
+56
| def test__priors__samples_from_model(): | ||
| model = af.Model(af.m.MockClassx4) | ||
| model.one = af.UniformPrior(lower_limit=0.099, upper_limit=0.101) | ||
| model.two = af.UniformPrior(lower_limit=0.199, upper_limit=0.201) | ||
| model.three = af.UniformPrior(lower_limit=0.299, upper_limit=0.301) | ||
| model.four = af.UniformPrior(lower_limit=0.399, upper_limit=0.401) | ||
|
|
||
| initializer = af.InitializerPrior() | ||
|
|
||
| ( | ||
| unit_parameter_lists, | ||
| parameter_lists, | ||
| figure_of_merit_list, | ||
| ) = initializer.samples_from_model( | ||
| total_points=2, | ||
| model=model, | ||
| fitness=MockFitness(), | ||
| paths=af.DirectoryPaths(), | ||
| ) | ||
|
|
||
| assert 0.0 < unit_parameter_lists[0][0] < 1.0 | ||
| assert 0.0 < unit_parameter_lists[1][0] < 1.0 | ||
| assert 0.0 < unit_parameter_lists[0][1] < 1.0 | ||
| assert 0.0 < unit_parameter_lists[1][1] < 1.0 | ||
| assert 0.0 < unit_parameter_lists[0][2] < 1.0 | ||
| assert 0.0 < unit_parameter_lists[1][2] < 1.0 | ||
| assert 0.0 < unit_parameter_lists[0][3] < 1.0 | ||
| assert 0.0 < unit_parameter_lists[1][3] < 1.0 | ||
|
|
||
| assert 0.099 < parameter_lists[0][0] < 0.101 | ||
| assert 0.099 < parameter_lists[1][0] < 0.101 | ||
| assert 0.199 < parameter_lists[0][1] < 0.201 | ||
| assert 0.199 < parameter_lists[1][1] < 0.201 | ||
| assert 0.299 < parameter_lists[0][2] < 0.301 | ||
| assert 0.299 < parameter_lists[1][2] < 0.301 | ||
| assert 0.399 < parameter_lists[0][3] < 0.401 | ||
| assert 0.399 < parameter_lists[1][3] < 0.401 |
Collaborator
There was a problem hiding this comment.
@pytest.fixture
def model_and_samples():
model = af.Model(af.m.MockClassx4)
model.one = af.UniformPrior(lower_limit=0.099, upper_limit=0.101)
model.two = af.UniformPrior(lower_limit=0.199, upper_limit=0.201)
model.three = af.UniformPrior(lower_limit=0.299, upper_limit=0.301)
model.four = af.UniformPrior(lower_limit=0.399, upper_limit=0.401)
initializer = af.InitializerPrior()
unit_parameter_lists, parameter_lists, _ = initializer.samples_from_model(
total_points=2,
model=model,
fitness=MockFitness(),
paths=af.DirectoryPaths(),
)
return unit_parameter_lists, parameter_lists
@pytest.mark.parametrize("index, param_index, lower, upper", [
(0, 0, 0.0, 1.0),
(1, 0, 0.0, 1.0),
(0, 1, 0.0, 1.0),
(1, 1, 0.0, 1.0),
(0, 2, 0.0, 1.0),
(1, 2, 0.0, 1.0),
(0, 3, 0.0, 1.0),
(1, 3, 0.0, 1.0),
])
def test_unit_parameter_lists(model_and_samples, index, param_index, lower, upper):
unit_parameter_lists, _ = model_and_samples
assert lower < unit_parameter_lists[index][param_index] < upper
@pytest.mark.parametrize("index, param_index, lower, upper", [
(0, 0, 0.099, 0.101),
(1, 0, 0.099, 0.101),
(0, 1, 0.199, 0.201),
(1, 1, 0.199, 0.201),
(0, 2, 0.299, 0.301),
(1, 2, 0.299, 0.301),
(0, 3, 0.399, 0.401),
(1, 3, 0.399, 0.401),
])
def test_parameter_lists(model_and_samples, index, param_index, lower, upper):
_, parameter_lists = model_and_samples
assert lower < parameter_lists[index][param_index] < upper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Methods which found the maximum likelihood model were previously called
optimize, which this PR renames to MLE (maximum likelihood estimator).This PR improves the MLE methods with functionality including:
InitializerAPI.The
BFGSandLBFGSMLE searches have been improved in this PR, including visualization.The main use case is fits where a good starting point is known and simple gradient descent can find the maximum likelihood solution.
The intent is to use this for strong lens sensitivity mapping.