question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting priors raises ValueError: need at least one array to concatenate

See original GitHub issue

Hi! I was trying to follow the docs to set custom priors on some made up data but kept hitting this numpy error in weird places. Including an example, diagnostics, and the results of my investigation here:

Example:

import bambi as bmb
import pandas as pd
import numpy as np

df = pd.DataFrame(
    dict(y=[0, 1, 0, 0, 1, 0], x_1=np.random.uniform(size=(6,)), x_2=np.random.uniform(size=(6,))),
)


priors = {
    "x_1": bmb.Prior("TruncatedNormal", sigma=1, mu=0, lower=0),
    "x_2": bmb.Prior("TruncatedNormal", sigma=1, mu=0, upper=0),
}
model = bmb.Model(
    formula="y ~ x_1 + x_2", data=df, family="bernoulli", priors=priors
)

model.build()
...
~/.pyenv/versions/3.8.10/envs/jupyter/lib/python3.8/site-packages/numpy/core/shape_base.py in hstack(tup)
    343         return _nx.concatenate(arrs, 0)
    344     else:
--> 345         return _nx.concatenate(arrs, 1)
    346 
    347 

<__array_function__ internals> in concatenate(*args, **kwargs)

ValueError: need at least one array to concatenate

Diagnostics:

import sys

print("sys: ", sys.version)
print("np: ", np.__version__)
print("pd: ", pd.__version__)
print("bmb: ", bmb.__version__)
sys:  3.8.10 (default, Jun 24 2021, 16:50:28) 
[Clang 12.0.5 (clang-1205.0.22.11)]
np:  1.21.2
pd:  1.3.3
bmb:  0.6.3

What i tried

  1. no results in project tracker
  2. Added/removed/changed the automatic_priors setting.
  3. Added/removed/changed the auto_scale setting.
  4. I put one term’s prior into a tuple, and then the model built, but it does not look like the prior took:
priors = {
    ("x_1",): bmb.Prior("TruncatedNormal", sigma=1, mu=0, lower=0),
    "x_2": bmb.Prior("TruncatedNormal", sigma=1, mu=0, upper=0),
}
model = bmb.Model(
    formula="y ~ x_1 + x_2", data=df, family="bernoulli", priors=priors
)

model.build()
model.plot_priors()

image

You can see that x_1 is not given the correct prior whereas x_2 is.

  1. Setting auto_scale=False on the model allows everything to build, but the priors are not correct:
model = bmb.Model(
    formula="y ~ x_1 + x_2", data=df, family="bernoulli", priors=priors, auto_scale=False
)
model.build()
model.plot_priors()

image

This feels like a numpy incompatibility- are these any known such issues?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tomicaprettocommented, Nov 26, 2021

This is fixed in #430

2reactions
tomicaprettocommented, Nov 2, 2021

Glad it helped! And thanks for raising this issue. I wasn’t aware of it. I’ll try to fix it for the next release 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: need at least one array to concatenate
The problem seems to be in np.concatenate where it expects an array of arrays and it's not receiving ...
Read more >
ValueError: need at least one array to concatenate · Issue #3628
Hi, concatenation from an empty array will raise this error, and there is size mismatch between your model and loaded state dict (e.g.,...
Read more >
Merge, join, concatenate and compare - Pandas
Merge, join, concatenate and compare#. pandas provides various facilities for easily combining together Series or DataFrame with various kinds of set logic ...
Read more >
solution-dsa01 | Kaggle
... FileNotFoundError Traceback (most recent call last) ... internals> in concatenate(*args, **kwargs) ValueError: need at least one array to concatenate.
Read more >
ValueError: Not enough samples to build a trace - Questions
I keep getting an error on a small test case. ... line 1530, in _choose_chains raise ValueError("Not enough samples to build a trace....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found