Skip to content

Add heterogeneity indices, printing indices/legend, fix index.html.#56

Open
justushelo wants to merge 1 commit intoSimulation-Decomposition:mainfrom
justushelo:heterogeneity-index
Open

Add heterogeneity indices, printing indices/legend, fix index.html.#56
justushelo wants to merge 1 commit intoSimulation-Decomposition:mainfrom
justushelo:heterogeneity-index

Conversation

@justushelo
Copy link
Copy Markdown
Contributor

  • Add heterogeneity indices function.
  • Add functionality for printing indices and legend. sensitivity_indices.py edited to get var_names for printing.
  • Added guardrails for output parameter in decomposition.py
  • Added tests for printing legend.
  • Initialize decomposition in dashboard with 0.8*sum(si). Other variables still can be chosen after this.
  • Updated docs to print correct second-order effects.
    Closes Automatic printing of indices #46, Closes Automatic legend #47

- Add heterogeneity indices function.
- Add functionality for printing indices and legend. sensitivity_indices.py edited to get var_names for printing.
- Added guardrails for output parameter in decomposition.py
- Added tests for printing legend.
- Initialize decomposition in dashboard with 0.8*sum(si). Other variables still can be chosen after this.
- Updated docs to print correct second-order effects.
Closes Simulation-Decomposition#46, Closes Simulation-Decomposition#47
@netlify
Copy link
Copy Markdown

netlify Bot commented May 9, 2026

Deploy Preview for simdec-io ready!

Name Link
🔨 Latest commit 084ea22
🔍 Latest deploy log https://app.netlify.com/projects/simdec-io/deploys/69fec7d022aa340008ea75ff
😎 Deploy Preview https://deploy-preview-56--simdec-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Good start, I left some comments. We will also be missing a test for heterogeneity_indices

def decomposition(
inputs: pd.DataFrame,
output: pd.DataFrame,
output: pd.DataFrame | np.ndarray,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a fan of adding this just on 1 parameters as we are not consistent then. Either we allow this on both or none. This is more done on the user side IMO.

What we can consider in the future is to be actually dataframe agnostic and use Narwhal. This is a great way to support multiple format at once as it supports the data API.

Comment on lines +201 to +203
print(f"{'-'*69}")
print(df_indices)
print(f"{'-'*69}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's use one print with \n or we can even consider template strings.

kind: Literal["histogram", "boxplot"] = "histogram",
ax=None,
print_legend: bool = False,
decomposition=None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing the typing info.

Matplotlib axis.
print_legend: Boolean, optional
Prints plot legend.
decomposition: Object, optional
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should specify the type, not just Object

raise ValueError("'kind' can only be 'histogram' or 'boxplot'")

if print_legend:
from IPython.display import display
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we have it declared as a dependency. This has to be added in pyproject.toml as optional and here we have to guard the input. Usually we do this at the top and use a flag to activate or not a feature.

You can also consider the new lazy import if we update the Python version.

f"{valid}/{total_regions} regions passed all checks for '{split_name}'.\n"
f"Skipped regions:\n"
+ "\n".join(f" {r!r}: n={n}, {reason}" for r, n, reason in skipped)
+ "\n\nTry: (1) reducing n_subdivisions, "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

don't need the + there

continue

if skipped:
print(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Really not a fan of using any print. We should use the logging if we must. People using the library have no control on prints vs logging which they can properly capture and filter. That's the main reason.

If True, displays a stacked bar chart of regional sensitivities.

Returns
----------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some nits

Comment on lines +16 to +17
"""
Compute sensitivity-based heterogeneity across subdivisions of a variable.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A nits but the format is actually to always write on the first line the sentence ending with a point. If too long, we make two sentences leaving a blank line.

@@ -0,0 +1,171 @@
from .sensitivity_indices import sensitivity_indices
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Import order matters (also sorting m before n, p) this should go at the bottom (with a blank line to separate) as this is coming from our library. Order is, std lib, 3rd party deps, dependencies from our own other packages, then the current package.

Also prefer to always use absolute import using our namespace simdec. ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatic legend Automatic printing of indices

2 participants