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.

BUG: MultivariateNormalQMC with specific QMCEngine and d == 1 erroneously throws exception

See original GitHub issue

Describe your issue.

With the way the conditional is written in the lines below https://github.com/scipy/scipy/blob/838cfbe51a2aecaba19b24813769ef5aeebfe056/scipy/stats/_qmc.py#L1548 when initializing an MultivariateNormalQMC instance with d == 1 and an engine that is unquestionably an instance of scipy.stats.qmc.QMCEngine, we get the ValueError below. Works fine for d > 1.

Reproducing Code Example

from scipy.stats.qmc import MultivariateNormalQMC, Sobol

input_dim = 1
engine = Sobol(d=input_dim)
sampler = MultivariateNormalQMC(mean=np.zeros(input_dim), engine=engine)

Error message

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-f2da58e7ebf7> in <module>
----> 1 sampler = MultivariateNormalQMC(mean=np.zeros(1), engine=engine)

~/.virtualenvs/foo/lib/python3.8/site-packages/scipy/stats/_qmc.py in __init__(self, mean, cov, cov_root, inv_transform, engine, seed)
   1248             self.engine = engine
   1249         else:
-> 1250             raise ValueError("`engine` must be an instance of "
   1251                              "`scipy.stats.qmc.QMCEngine` or `None`.")
   1252 

ValueError: `engine` must be an instance of `scipy.stats.qmc.QMCEngine` or `None`.

SciPy/NumPy/Python version information

1.7.1 1.19.5 sys.version_info(major=3, minor=8, micro=10, releaselevel=‘final’, serial=0)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ltiaocommented, Oct 30, 2021

Thanks @tupui for taking a look at this. I understand your previous point and think there is probably a case to be made for both approaches. Ultimately, I’d be happy with either option. Unfortunately, I am not participating in the PyData Sprint and also won’t have much time these days to contribute. Thanks for maintaining the project and keep up the good work!

0reactions
reshamascommented, Oct 30, 2021

current:

       if engine is None:
            self.engine = Sobol(d=engine_dim, scramble=True, seed=seed)  # type: QMCEngine
        elif isinstance(engine, QMCEngine) and engine.d != 1:
            if engine.d != d:
                raise ValueError("Dimension of `engine` must be consistent"
                                 " with dimensions of mean and covariance.")
            self.engine = engine
        else:
            raise ValueError("`engine` must be an instance of "
                             "`scipy.stats.qmc.QMCEngine` or `None`.")

proposed:

       if engine is None:
            self.engine = Sobol(d=engine_dim, scramble=True, seed=seed)  # type: QMCEngine
    
        elif isinstance(engine, QMCEngine):
            if engine.d != d:
                raise ValueError("Dimension of `engine` must be consistent"
                                 " with dimensions of mean and covariance.")
            self.engine = engine
            if engine.d == 0:
              raise ValueError("xxx  0 not valid")
            if engine.d == 1:
              raise ValueError("xxx  1 not valid")
        else:
            raise ValueError("`engine` must be an instance of "
                             "`scipy.stats.qmc.QMCEngine` or `None`.")
         

if d=0, d=1, are there tests?

Read more comments on GitHub >

github_iconTop Results From Across the Web

scipy.stats.qmc.MultivariateNormalQMC — SciPy v1.9.3 Manual
A root decomposition of the covariance matrix, where d' may be less than d if the covariance is not full rank. If omitted,...
Read more >
Mailman 3 ANN: SciPy 1.9.0 - NumPy-Discussion - python.org
Several BSpline methods now raise an error if inputs have ``ndim > 1``. ... inheritance to `QMCEngine` in `MultinomialQMC` and `MultivariateNormalQMC`.
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