jeudi 5 avril 2018

Sensitivity analysis of upper bound within linear interpolation in Python

I wrote a parameter sensitivity analysis in SALib. One of the parameters I would like to test is used within a linear interpolation. Here, I encounter a ValueError as opposed to the other parameters an inclusion of the sampled-sequence is not feasible. Hence, the solution would randomly sample 1,000 values for the parameter and the interpolation would only use one value at a time (in turn the model runs 1,000 times). I try to provide a simple working example below that illustrates the problem. The actual model is longer and has more stochastic parameters (this is the reason I call [:, column] when unwrapping the param_values within the model)

from scipy.interpolate import InterpolatedUnivariateSpline as Interpolate
import numpy as np
from SALib.sample import saltelli
from SALib.analyze import sobol  

# First define the model subject to the analysis
def model(param_values):
    # Stochastic parameters
    fbY = param_values[:, 0]
    # Linear interpolation 
    a1, a1_ = np.array([0, 15, 39, 49]), np.linspace(0, 49, 50)
    Y1 = np.array([0, fbY, fbY, fbY*0.5])
    Y_int = Interpolate(a1, Y1, k=1)
    return Y_int

# Generate stochastic parameters
stochastic = {
'num_vars': 1,
'names': ['fbY'],
'bounds': [[2, 0.16]],
'dists': ['norm']
}
# Sample parameter
param_values = saltelli.sample(stochastic, 1000, calc_second_order=True)

# Run model
Y = model(param_values)

# Analyze
Si = sobol.analyze(stochastic, Y)

This should result in

"ValueError: setting an array element with a sequence."

The desired result would use one value at a time, within the interpolation, out of the array of possible parameter values generated via the saltelli sampler.




Aucun commentaire:

Enregistrer un commentaire