Skip to content

Enhanced HDMR, error with max_order = 3 #667

Description

@ddanaci

The following error is returned when I attempt to run enhanced_hdmr with an order of 3.

  File "/home/david/miniforge3/envs/GSA/lib/python3.14/site-packages/SALib/analyze/enhanced_hdmr.py", line 232, in analyze
    Si = _finalize(hdmr, Si, alpha, return_emulator)
  File "/home/david/miniforge3/envs/GSA/lib/python3.14/site-packages/SALib/analyze/enhanced_hdmr.py", line 1445, in _finalize
    ijk = hdmr.d + hdmr.nc2 + np.where(np.sum(hdmr.nc3 == r, axis=1) == 1)[0]
                                       ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/david/miniforge3/envs/GSA/lib/python3.14/site-packages/numpy/_core/fromnumeric.py", line 2466, in sum
    return _wrapreduction(
        a, np.add, 'sum', axis, dtype, out,
        keepdims=keepdims, initial=initial, where=where
    )
  File "/home/david/miniforge3/envs/GSA/lib/python3.14/site-packages/numpy/_core/fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 0

enhanced_hdmr with order of 1 or 2 works fine.
"regular" hdmr with order 1, 2, or 3, also works fine.

Looking at enhanced_hdmr.py, line 1445:
ijk = hdmr.d + hdmr.nc2 + np.where(np.sum(hdmr.nc3 == r, axis=1) == 1)[0]
hdmr.nc3 is a scalar value.

Comparing to hdmr.py, line 755:
ijk = Em["n1"] + Em["n2"] + np.where(np.sum(Em["c3"] == r, axis=1) == 1)[0]
Em["c3"] is an array.

In the case of enhanced_hdmr, I think "hdmr.nc3" might have to be "hdmr.gamma"?
If I make that change, it runs, and the results don't seem crazy.
The sum of indices using enhanced_hdmr is less than 1, whereas with hdmr.py it does sum to 1. Not sure if there is some other methodological reason for the difference.

SALib version: 1.5.2
Python version: 3.14.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions