'error with SAlib library for Sensitivity analysis in python

I am trying to perform sensitivity analysis using Sobol`s method. I always get an error which i can not solve. the code and the result are below. the input variable ranges are identified in problem and the output of the model are saved in sens_out.txt

from SALib.sample import saltelli
from SALib.analyze import sobol
from SALib.test_functions import Ishigami
import numpy as np
import subprocess

problem = {
    'num_vars': 30,
    'names': ['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9', 'x10',
              'x11', 'x12', 'x13', 'x14', 'x15', 'x16', 'x17', 'x18', 'x19',
              'x20', 'x21', 'x22', 'x23', 'x24', 'x25', 'x26', 'x27', 'x28',
              'x29', 'x30'],
    'bounds': [[2, 6],
               [20, 30],
               [600, 900],
               [800, 1300],
               [0.01, 0.05],
               [0.1, 0.2],
               [30, 35],
               [0.0015, 0.003],
               [0.001, 0.0015],
               [0.50, 0.70],
               [0.50, 0.70],
               [0.50, 0.70],
               [0.25, 0.50],
               [0.0, 0.25],
               [0.4, 0.5],
               [0.5, 0.7],
               [0.5, 0.7],
               [0.5, 0.7],
               [0.55, 0.7],
               [0.6, 0.7],
               [0.013, 0.017],
               [0.027, 0.032],
               [0.17, 0.21],
               [0.007, 0.012],
               [0.01, 0.016],
               [0.02, 0.04],
               [0.8, 1.2],
               [2.0, 2.5],
               [8, 12],
               [90, 110]]
}

param_values = saltelli.sample(problem, 1000, calc_second_order=True)

#np.savetxt("/home/omar/Desktop/param_values.txt", param_values)

Y = np.loadtxt("/home/omar/Desktop/sens_out.txt", float)

Si = sobol.analyze(problem, Y, print_to_console=True)

Result = error message

    Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
    execfile(filename, namespace)
  File "/home/omar/Desktop/untitled0.py", line 58, in <module>
    Si = sobol.analyze(problem, Y, print_to_console=True)
  File "/home/omar/SALib/SALib/analyze/sobol.py", line 81, in analyze
    A,B,AB,BA = separate_output_values(Y, D, N, calc_second_order)
  File "/home/omar/SALib/SALib/analyze/sobol.py", line 164, in separate_output_values
    AB[:, j] = Y[(j + 1):Y.size:step]
ValueError: could not broadcast input array from shape (1000,14) into shape (14000)


Solution 1:[1]

What is the dimension of Y? To use the sobol.analyze function, Y must be a column vector. In this case it appears that you're passing in a matrix rather than a vector, which seems to to be the problem.

Also if you are calculating second-order indices, your sample size will be N(k+2), or in this case, 32,000. If the model is only returning 14,000 values, that will cause another problem with the dimension of the array.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ah bon