Adds method to get bayes result procedure and bumps version to dev10 by StephenNneji · Pull Request #192 · RascalSoftware/python-RAT · GitHub
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
2 changes: 1 addition & 1 deletion pyproject.toml
13 changes: 13 additions & 0 deletions ratapi/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,19 @@ class BayesResults(Results):
nestedSamplerOutput: NestedSamplerOutput
chain: np.ndarray

def from_procedure(self) -> Procedures:
"""Return the procedure that created the result.

Returns
-------
procedure: Procedures
The procedure that created the result.
"""
samples = self.nestedSamplerOutput.nestSamples
if samples.shape == (1, 2) and not np.any(samples):
return Procedures.DREAM
return Procedures.NS

def save(self, filepath: str | Path = "./results.json"):
"""Save the BayesResults object to a JSON file.

Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6546,6 +6546,18 @@ def dream_results():
)


@pytest.fixture
def nested_sampler_results(dream_results):
results = dream_results
results.nestedSamplerOutput = ratapi.outputs.NestedSamplerOutput(
logZ=-28.99992503667041,
logZErr=0.3391187711291207,
nestSamples=np.ones((100, 9)),
postSamples=np.ones((100, 10)),
)
return results


@pytest.fixture
def r1_default_project():
"""The Project corresponding to the data in R1defaultProject.mat."""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_outputs.py