Error in inversion algorithm for PGI inversion when setting GMM update = True

Greetings,
As a young researcher being in initial days of work, I was working on exploring the PGI inversion of Gravity data.
I have been stuck to a point where the inversion code interrupts saying:

ValueError Traceback (most recent call last)
in <cell line: 101>()
99
100 # Run the inversion
→ 101 inverted_model = inversion_algo.run(initial_model)

13 frames
/usr/local/lib/python3.10/dist-packages/simpeg/utils/pgi_utils.py in _check_weights(self, weights, n_components, n_samples)
220
221 # check range
→ 222 if any(np.less(weights, 0.0)) or any(np.greater(weights, 1.0)):
223 raise ValueError(
224 "The parameter ‘weights’ should be in the range "

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I have checked the weights (it sums to a total of 1), and also looked for solutions here and there but nothing works.
Also when I change the
update_gmm=True —> update_gmm=False, after this the inversion runs successfully, but the learned GMM after iterations in inversion comes out to be faulty as the GMM peaks doesnt collide with the new peaks generated.

I am hoping to see your response.
Mridul Chawla

Hi Mridul. Thanks for reporting this issue.

The reason why the code is failing on you is because in your case the weights array that is being passed to _check_weights is a 2d array. When running np.less(weights, 0.0) we obtain a 2d array of bools, and running any() on this array will raise the ValueError you are experiencing.

Luckily we can easily solve that by using Numpy’s a.any() method instead of the Python built-in any() function.

I’ll open a PR to fix this and to add tests that catches this bug. I’ll post a link to it here once it’s opened.

Thanks again for reporting this issue!

BTW, here’s a link to the offending _check_weights method:

Here’s a link to the PullRequest I opened to fix this bug: Fix bug in GMM's `_check_weights` by santisoler · Pull Request #1526 · simpeg/simpeg · GitHub