Skip to content
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

Optimization fails for selected_times is not None (i.e. a subset time range) #540

Open
rajabell opened this issue Feb 27, 2025 · 0 comments

Comments

@rajabell
Copy link
Collaborator

We are encountering an issue when trying to optimize for a subset of data:

When setting a time window that does not contain data for all of the channels in the model, the Summerizer works fine but the Optimizer frequently fails. It doesn't seem to matter if we force any channels to zero in the constraints:

[/usr/local/lib/python3.11/dist-packages/meridian/analysis/optimizer.py](https://localhost:8080/#) in _create_response_curves_section(self)
    867     response_curves = formatter.ChartSpec(
    868         id=summary_text.OPTIMIZED_RESPONSE_CURVES_CHART_ID,
--> 869         chart_json=self.plot_response_curves(
    870             n_top_channels=n_channels
    871         ).to_json(),

[/usr/local/lib/python3.11/dist-packages/meridian/analysis/optimizer.py](https://localhost:8080/#) in plot_response_curves(self, n_top_channels)
    418     else:
    419       title = summary_text.INC_KPI_LABEL
--> 420     df = self._get_plottable_response_curves_df(n_top_channels=n_top_channels)
    421     base = (
    422         alt.Chart(df)

[/usr/local/lib/python3.11/dist-packages/meridian/analysis/optimizer.py](https://localhost:8080/#) in _get_plottable_response_curves_df(self, n_top_channels)
    577     })
    578 
--> 579     response_curves_ds = self.get_response_curves()
    580     response_curves_df = (
    581         response_curves_ds.to_dataframe()

[/usr/local/lib/python3.11/dist-packages/meridian/analysis/optimizer.py](https://localhost:8080/#) in get_response_curves(self)
    536     # max upper spend constraint + padding.
    537     upper_limit = max(max(upper_bound) + c.SPEND_CONSTRAINT_PADDING, 2)
--> 538     spend_multiplier = np.arange(0, upper_limit, c.RESPONSE_CURVE_STEP_SIZE)
    539     # WARN: If `selected_times` is not None (i.e. a subset time range), this
    540     # response curve computation might take a significant amount of time.

ValueError: arange: cannot compute length
``

The error "ValueError: arange: cannot compute length" arises when np.arange cannot determine the number of elements to generate because the step size is zero or leads to an infinite loop. In this context, within the _get_plottable_response_curves_df method of the BudgetOptimizer class, the code uses np.arange(0, upper_limit, c.RESPONSE_CURVE_STEP_SIZE) to generate spend multipliers for plotting response curves. The error suggests that c.RESPONSE_CURVE_STEP_SIZE is likely zero or leading to an infinite loop, preventing the calculation of the range length.

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

No branches or pull requests

1 participant