Error: uq_gradient (line 180) ExpDesign(ii).Y = fun(ExpDesign(ii).X);

clc
clear all
format long
%% 
mu_x = [3 15 125 5 48 22];
sig_x = [0.00015 0.00075 0.000625 0.0025 0.24 0.0011];
rA =1.43e4;
h = 3.78;
ns = length(mu_x);
uqlab;
%% 
G = @(mu_x)rA-(mu_x(:,1).*mu_x(:,2).*mu_x(:,3).*mu_x(:,4).*(0.5.*(cos(mu_x(:,5).*pi./180)-cos(mu_x(:,6).*pi./180))));
n=100;
X1=lhsnorm(mu_x,diag(sig_x.^2),n);Y1=G(X1);
MetaOpts.Type='Metamodel';
MetaOpts.MetaType='SVR';
MetaOpts.ExpDesign.X=X1;
MetaOpts.ExpDesign.Y=Y1;
MetaOpts.Kernel.Family='Exponential';  
MetaOpts.QPSolver='SMO';
MetaOpts.Loss='l1-eps';
MetaOpts.EstimMethod='CV';
MetaOpts.Optim.Method='GA';
mySVR=uq_createModel(MetaOpts);
BHgx1 = uq_gradient(mu_x,mySVR);
BHgx1 = uq_gradient(mu_x,mySVR);
The array index must be a positive integer or logical value
error uq_gradient (line 180)
                    ExpDesign(ii).Y = fun(ExpDesign(ii).X);

What should X be when you use uq_gradient(X, fun, GradientMethod, FDStep, GivenH, KnownX, Marginals) to solve for a gradient?

Dear @koumm152

You need to wrap your SVR model in a function to make it work, e.g.:

func = @(X) uq_evalModel(mySVR, X);
BHgx1 = uq_gradient(X1, func);

Best regards
Styfen

1 Like

Thank you for your reply. This problem has been solved perfectly with your help.

Best regard
Maomao Kou