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
18 changes: 14 additions & 4 deletions autofit/mapper/prior_model/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import inspect
import json
import logging
import random
import types
from collections import defaultdict
from functools import wraps
import random
from typing import Tuple, Optional, Dict, List, Iterable, Generator

import numpy as np
Expand All @@ -32,6 +32,8 @@
__name__
)

LINE_LENGTH = 80


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

for t in self.path_instance_tuples_for_class(
(
Expand All @@ -1562,7 +1566,11 @@ def info(self) -> str:
):
formatter.add(*t)

return formatter.text
return '\n\n'.join([
f"Total Free Parameters = {self.prior_count}",
f"{self.parameterization}",
formatter.text
])

@property
def order_no(self) -> str:
Expand Down Expand Up @@ -1594,7 +1602,9 @@ def parameterization(self) -> str:
"""
from .prior_model import PriorModel

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

for t in self.path_instance_tuples_for_class(
(
Expand Down
2 changes: 0 additions & 2 deletions autofit/non_linear/paths/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ def _save_model_info(self, model):
self.output_path,
"model.info"
), "w+") as f:
f.write(f"Total Free Parameters = {model.prior_count} \n\n")
f.write(f"{model.parameterization} \n\n")
f.write(model.info)

def _save_parameter_names_file(self, model):
Expand Down
10 changes: 7 additions & 3 deletions test_autofit/graphical/functionality/test_model_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ def make_analysis_factor():
def make_info():
return """AnalysisFactor0

centre UniformPrior, lower_limit = 0.0, upper_limit = 1.0
normalization UniformPrior, lower_limit = 0.0, upper_limit = 1.0
sigma UniformPrior, lower_limit = 0.0, upper_limit = 1.0"""
Total Free Parameters = 3

model Gaussian (N=3)

centre UniformPrior, lower_limit = 0.0, upper_limit = 1.0
normalization UniformPrior, lower_limit = 0.0, upper_limit = 1.0
sigma UniformPrior, lower_limit = 0.0, upper_limit = 1.0"""


def test_analysis_factor(
Expand Down
7 changes: 6 additions & 1 deletion test_autofit/mapper/model/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ def test_as_model_tuples():
instance
)
assert model.tup == (0.5, 0.5)
assert model.info == """tup (0.5, 0.5)"""
assert """tup (0.5, 0.5)""" in model.info


def test_info_prints_number_of_parameters():
model = af.Model(af.Gaussian)
assert "Total Free Parameters" in model.info


def test_set_centre():
Expand Down
44 changes: 29 additions & 15 deletions test_autofit/mapper/test_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def test_parameterization():

parameterization = model.parameterization
assert parameterization == (
"""model CollectionPriorModel (N=3)
collection CollectionPriorModel (N=3)
gaussian Gaussian (N=3)"""
"""model CollectionPriorModel (N=3)
collection CollectionPriorModel (N=3)
gaussian Gaussian (N=3)"""
)


def test_root():
model = af.Model(af.Gaussian)
parameterization = model.parameterization
assert parameterization == (
'model Gaussian (N=3)'
'model Gaussian (N=3)'
)


Expand All @@ -37,9 +37,9 @@ def test_instance():

parameterization = model.parameterization
assert parameterization == (
"""model CollectionPriorModel (N=0)
collection CollectionPriorModel (N=0)
gaussian Gaussian (N=0)"""
"""model CollectionPriorModel (N=0)
collection CollectionPriorModel (N=0)
gaussian Gaussian (N=0)"""
)


Expand All @@ -54,7 +54,7 @@ def test_tuple_prior():
)
parameterization = model.parameterization
assert parameterization == (
'model Gaussian (N=4)'
'model Gaussian (N=4)'
)


Expand Down Expand Up @@ -89,9 +89,14 @@ def test_basic(self):

assert (
model_info
== """mock_class
one UniformPrior, lower_limit = 0.0, upper_limit = 1.0
two UniformPrior, lower_limit = 0.0, upper_limit = 2.0"""
== """Total Free Parameters = 2

model ModelMapper (N=2)
mock_class MockClassx2 (N=2)

mock_class
one UniformPrior, lower_limit = 0.0, upper_limit = 1.0
two UniformPrior, lower_limit = 0.0, upper_limit = 2.0"""
)

def test_with_instance(self):
Expand All @@ -104,9 +109,14 @@ def test_with_instance(self):

assert (
model_info
== """mock_class
one UniformPrior, lower_limit = 0.0, upper_limit = 1.0
two 1.0"""
== """Total Free Parameters = 1

model ModelMapper (N=1)
mock_class MockClassx2 (N=1)

mock_class
one UniformPrior, lower_limit = 0.0, upper_limit = 1.0
two 1.0"""
)

def test_with_tuple(self):
Expand All @@ -115,7 +125,11 @@ def test_with_tuple(self):

assert (
mm.info
== "tuple (0, 1)"
== """Total Free Parameters = 0

model ModelMapper (N=0)

tuple (0, 1)"""
)

# noinspection PyUnresolvedReferences
Expand Down