Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autofit/config/general.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ log_file=output.log
log_level=INFO
samples_to_csv=False
model_results_decimal_places=3
info_whitespace_length=80
remove_files=False
force_pickle_overwrite=False
identifier_version=4
Expand Down
8 changes: 4 additions & 4 deletions autofit/mapper/prior_model/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@
from autofit.text import formatter as frm
from autofit.text.formatter import TextFormatter
from autofit.tools.util import split_paths
from autofit.tools.util import info_whitespace

logger = logging.getLogger(
__name__
)

LINE_LENGTH = 80


class Limits:
@staticmethod
Expand Down Expand Up @@ -1554,8 +1553,9 @@ def info(self) -> str:
parameter of the overall model.
This information is extracted from each priors *model_info* property.
"""

formatter = TextFormatter(
line_length=LINE_LENGTH
line_length=info_whitespace()
)

for t in self.path_instance_tuples_for_class(
Expand Down Expand Up @@ -1603,7 +1603,7 @@ def parameterization(self) -> str:
from .prior_model import PriorModel

formatter = TextFormatter(
line_length=LINE_LENGTH
line_length=info_whitespace()
)

for t in self.path_instance_tuples_for_class(
Expand Down
4 changes: 2 additions & 2 deletions autofit/text/samples_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

logger = logging.getLogger(__name__)


def values_from_samples(samples, median_pdf_model):

if median_pdf_model:
Expand All @@ -15,7 +14,8 @@ def values_from_samples(samples, median_pdf_model):
def summary(
samples, sigma=3.0, median_pdf_model=True, indent=1, line_length=None
) -> str:
""" Create a string summarizing the results of the `NonLinearSearch` at an input sigma value.
"""
Create a string summarizing the results of the `NonLinearSearch` at an input sigma value.

This function is used for creating the model.results files of a non-linear search.

Expand Down
19 changes: 9 additions & 10 deletions autofit/text/text_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from autoconf import conf
from autofit.text import formatter as frm, samples_text

from autofit.tools.util import info_whitespace

def padding(item, target=6):
string = str(item)
Expand All @@ -14,7 +14,6 @@ def result_info_from(samples) -> str:
Output the full model.results file, which include the most-likely model, most-probable model at 1 and 3
sigma confidence and information on the maximum log likelihood.
"""

results = []

if hasattr(samples, "log_evidence"):
Expand All @@ -24,7 +23,7 @@ def result_info_from(samples) -> str:
frm.add_whitespace(
str0="Bayesian Evidence ",
str1="{:.8f}".format(samples.log_evidence),
whitespace=90
whitespace=info_whitespace()
)
]
results += ["\n"]
Expand All @@ -33,15 +32,15 @@ def result_info_from(samples) -> str:
frm.add_whitespace(
str0="Maximum Log Likelihood ",
str1="{:.8f}".format(max(samples.log_likelihood_list)),
whitespace=90
whitespace=info_whitespace()
)
]
results += ["\n"]
results += [
frm.add_whitespace(
str0="Maximum Log Posterior ",
str1="{:.8f}".format(max(samples.log_posterior_list)),
whitespace=90
whitespace=info_whitespace()
)
]
results += ["\n"]
Expand All @@ -50,7 +49,7 @@ def result_info_from(samples) -> str:

results += ["Maximum Log Likelihood Model:\n\n"]

formatter = frm.TextFormatter()
formatter = frm.TextFormatter(line_length=info_whitespace())

for i, prior_path in enumerate(samples.model.unique_prior_paths):
formatter.add(
Expand All @@ -62,21 +61,21 @@ def result_info_from(samples) -> str:

if samples.pdf_converged:

results += samples_text.summary(samples=samples, sigma=3.0, indent=4, line_length=90)
results += samples_text.summary(samples=samples, sigma=3.0, indent=4, line_length=info_whitespace())
results += ["\n"]
results += samples_text.summary(samples=samples, sigma=1.0, indent=4, line_length=90)
results += samples_text.summary(samples=samples, sigma=1.0, indent=4, line_length=info_whitespace())

else:

results += [
"\n WARNING: The samples have not converged enough to compute a PDF and model errors. \n "
"The model below over estimates errors. \n\n"
]
results += samples_text.summary(samples=samples, sigma=1.0, indent=4, line_length=90)
results += samples_text.summary(samples=samples, sigma=1.0, indent=4, line_length=info_whitespace())

results += ["\n\ninstances\n"]

formatter = frm.TextFormatter()
formatter = frm.TextFormatter(line_length=info_whitespace())

for t in samples.model.path_float_tuples:
formatter.add(*t)
Expand Down
5 changes: 5 additions & 0 deletions autofit/tools/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as np

from autoconf import conf

def split_paths(func):
"""
Expand Down Expand Up @@ -141,3 +142,7 @@ def numpy_array_from_json(file_path: str):
"""
with open(file_path, "r") as f:
return np.asarray(json.load(f))


def info_whitespace():
return conf.instance["general"]["output"]["info_whitespace_length"]
1 change: 1 addition & 0 deletions test_autofit/config/general.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ log_file=output.log
log_level=INFO
samples_to_csv=False
model_results_decimal_places=3
info_whitespace_length=80
remove_files=True
force_pickle_overwrite=False
identifier_version=3
Expand Down
2 changes: 1 addition & 1 deletion test_autofit/non_linear/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_set_number_of_cores(
multi_analysis.n_cores = 1
assert multi_analysis._log_likelihood_function.__name__ == "_summed_log_likelihood"

multi_analysis.n_cores = 1
multi_analysis.n_cores = 2
assert isinstance(
multi_analysis._log_likelihood_function,
AnalysisPool
Expand Down
2 changes: 1 addition & 1 deletion test_autofit/text/test_text_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test__results_to_file(samples):
samples=samples,
)

assert "Maximum Log Likelihood 1.00000000\n" in result_info
assert "Maximum Log Likelihood 1.00000000\n" in result_info

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth making this test dynamic

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so, the config is a tesrt specific one. Worry that dynamic might miss changes to source code.


def test__search_summary_to_file(model):
file_search_summary = path.join(text_path, "search.summary")
Expand Down