-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make a triangular plot with different data sets, starting with a data set that contains fewer cosmological parameters in the sample? #116
Comments
At the moment, the first chain determines the parameters that are used. Happy to look at a PR if you want to try to implement more flexibility. |
Thank you for your attention. |
Hi, It's all about modifying the GetDistPlotter.get_param_array method to take a list of roots instead of a single one. A ParamNames object is created with the first root. And then the extra parameters of the other roots are appended. My implementation works only for triangle plots (these were my needs), but generalising it should not be difficult |
I'm grateful for the contribution, but in my case there is still a problem and the version that worked also presents the same problem now with this modification "paramNames size (45) does not match number of parameters in samples (43)". But I thank you in advance for your contribution. |
The following function merges what is common between the chains, but still does not solve the complete problem. #funcão de mescla o tem de comum entre as amostras / function of merging the common elements between the samples
def get_param_array(self, roots, params: Union[None, str, Sequence] = None, renames: Mapping = None):
"""
Gets an array of :class:`~.paramnames.ParamInfo` for named params
in the given `root`.
If a parameter is not found in `root`, returns the original ParamInfo if ParamInfo
was passed, or fails otherwise.
:param roots: The root name of the samples to use
:param params: the parameter names (if not specified, get all)
:param renames: optional dictionary mapping input names and equivalent names
used by the samples
:return: list of :class:`~.paramnames.ParamInfo` instances for the parameters
"""
if not isinstance(roots, list):
roots = [roots]
# Get parameter names from the first root
if hasattr(roots[0], 'param_names'):
names = roots[0].param_names
elif hasattr(roots[0], 'paramNames'):
names = roots[0].paramNames
elif hasattr(roots[0], 'names'):
names = ParamNames(names=roots[0].names, default=getattr(roots[0], 'dim', 0))
else:
names = self.param_names_for_root(roots[0])
# Collect common parameters across all roots
common_param_names = set(name.name for name in names.names)
for root in roots[1:]:
if hasattr(root, 'param_names'):
names_part = root.param_names
elif hasattr(root, 'paramNames'):
names_part = root.paramNames
elif hasattr(root, 'names'):
names_part = ParamNames(names=root.names, default=getattr(root, 'dim', 0))
else:
names_part = self.param_names_for_root(root)
current_param_names = set(name.name for name in names_part.names)
common_param_names.intersection_update(current_param_names)
# Filter out the common parameters
common_names = [name for name in names.names if name.name in common_param_names]
if params is None or len(params) == 0:
return common_names
if isinstance(params, str):
if params in common_param_names:
return [name for name in common_names if name.name == params]
else:
raise Exception(f"parameter name not found: {params}")
else:
filtered_params = [param for param in params if (param if isinstance(param, str) else param.name) in common_param_names]
if not filtered_params:
raise Exception("No common parameters found in the provided roots.")
is_param_info = [isinstance(param, ParamInfo) for param in filtered_params]
error = [not a for a in is_param_info]
renames_from_param_info = {param.name: getattr(param, "renames", []) for i, param in enumerate(filtered_params) if is_param_info[i]}
if renames:
renames = mergeRenames(renames, renames_from_param_info)
else:
renames = renames_from_param_info
params_names = [getattr(param, "name", param) for param in filtered_params]
old = [(old if isinstance(old, ParamInfo) else ParamInfo(old)) for old in filtered_params]
new_params = names.parsWithNames(params_names, error=error, renames=renames)
return [new if new else old for new, old in zip(new_params, old)] |
This is my attempt, seems to work at least for a simple triangle plot: #117 |
I'm very grateful for the solution...it really works now |
If I do the plot
roots_data=[IDEM2_sample5, IDEM2_sample2, IDEM2_sample3, IDEM2_sample4,IDEM2_sample1]
works, but I do:
roots_data=[IDEM2_sample1, IDEM2_sample2, IDEM2_sample3, IDEM2_sample4,IDEM2_sample5]
It doesn't work, how to solve it?
The IDEM2_sample1, IDEM2_sample2 strings have fewer parameters in the sample than the other data.
Att. Jaelsson
The text was updated successfully, but these errors were encountered: