polychron.models.MCMCData
Module
MCMCData
dataclass
Dataclass containing all of the MCMC results.
This enables lighter-weight "save" behavior
Note
Optional[foo]
must be used rather than from __future__ import annotations
and foo | None
in python 3.9 due to use of get_type_hints
contexts
class-attribute
instance-attribute
contexts: List[str] = field(default_factory=list)
List of contexts passed in to and returned by run_MCMC, stored in topological order
accept_samples_context
class-attribute
instance-attribute
accept_samples_context: List[List[float]] = field(default_factory=list)
A list of accepted samples from the MCMC process.
The number of accepted samples is important.
Formerly StartPage.ACCEPT
accept_samples_phi
class-attribute
instance-attribute
accept_samples_phi: List[List[float]] = field(default_factory=list)
Accepted group boundaries from MCMC simulation
Formerly StartPage.PHI_ACCEPT
A
class-attribute
instance-attribute
A: int = field(default=0)
The newer limit for the Cal BP range to be considered considered during MCMC, denoting the most recent time.
Formerly StartPage.A
P
class-attribute
instance-attribute
P: int = field(default=0)
The older limit for the Cal BP range to be considered considered during MCMC
Formerly StartPage.P
all_samples_context
class-attribute
instance-attribute
all_samples_context: List[List[float]] = field(default_factory=list)
A list of lists containing all samples for contexts from MCMC, including rejected samples.
I.e. accept_samples_context is a subset of this.
Formerly StartPage.ALL_SAMPS_CONT
all_samples_phi
class-attribute
instance-attribute
all_samples_phi: List[List[float]] = field(default_factory=list)
A list of lists, containing all samples for group boundaries from MCMC, including rejected samples.
I.e. accept_samples_phi is a subset of this.
Formerly StartPage.ALL_SAMPS_PHI
accept_group_limits
class-attribute
instance-attribute
accept_group_limits: Dict[str, List[float]] = field(default_factory=dict)
A dictionary of group limits from accepted phi samples. Produced in phase_labels
.
Formerly StartPage.resultsdict
all_group_limits
class-attribute
instance-attribute
all_group_limits: Dict[str, List[float]] = field(default_factory=dict)
A dictionary of all_results? returned by MCMC_func, which is used to find the phase lengths during node finding on the results page.
Formerly StartPage.all_results_dict
save_results_dataframes
save_results_dataframes(path: Path, group_df: DataFrame) -> None
Save some MCMC data to disk, separately from the serialised version of this class
Formerly part of StartPage.save_state_1
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The path to the directory in which files should be created |
required |
group_df
|
DataFrame
|
A pandas dataframe containing context group information. |
required |
Todo
- Check if
full_results_df
include the first 10000 elements or not?
to_json
to_json(pretty: bool = False) -> str
Serialise this object to JSON
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty
|
bool
|
If the json should be prettified or not. |
False
|
Return
JSON string representing the MCMCData instance
save
save(path: Path, group_df: DataFrame, verbose: bool = False) -> None
Save the current state of this file to the specified path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The directory in which the files will be saved. |
required |
group_df
|
DataFrame
|
A pandas dataframe containing context group information |
required |
verbose
|
bool
|
If verbose output should be used |
False
|
Raises:
Type | Description |
---|---|
RuntimeError
|
If the provided path is not a directory |
Exception
|
If other exceptions are raised during saving of files to disk |
load_from_disk
classmethod
load_from_disk(json_path: Path) -> MCMCData
Get an instance of the MCMCData from serialised json on disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_path
|
Path
|
Path to json file to load it from |
required |
Returns:
Type | Description |
---|---|
MCMCData
|
MCMCData instance |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the json_path is not an existing file; or the 'polychron_version' key is missing from the json file'; or the 'mcmc_data' key is missing from the json file |
JSONDecodeError
|
If the json_path does not point to a valid json file |