Having errors in retrieving the m-file handle for a developed PCE metamodel. Error shows that ‘The model does not seem to be properly initialized! Internal field fHandle is missing’. Thank you
Dear @Abraham
Can you please provide a minimal reproducible example? This will make it easier for us to assist you with your problem.
Best regards
Styfen
Dear @styfen.schaer
Good to hear from you.
I developed a PCE-based model and saved it as an m-file, say ‘myPCE_sparseLARS’.
myPCE_sparseLARS.m (7.0 KB)
The PCE model was developed from design of experiments from a numerical model.
To treat it as computational model, the mFile, the random filed parameters were assigned to it as shown below:
ModelOpts.mFile = 'myPCE_sparseLARS';
ModelOpts.isVectorized = true;
ModelOpts.Parameters = myRFInput1 ;
myModel = uq_createModel(ModelOpts);
MetaOpts.FullModel = myModel; uq_mergeInputs(myInput, myRFInput5.UnderlyingGaussian) ;
The challenge occurred when generating the response, Ym in the experimental design over the discretisation domain.
Xm = uq_getSample(myFullInput, 360, 'LHS') ;
fprintf('Evaluating the experimental design...')
Ym = uq_evalModel(myModel, Xm) ;
fprintf(' done!\n\n')
The Error using uq_eval_uq_default_model shows:
‘Execution of script myPCE_sparseLARS as a function is not supported’
Grateful to receive the necessary clarification on how to use the myPCE_sparseLARS as a function.
Thank you.
Dear @Abraham
The myPCE_sparseLARS.m
file is not a valid model. You can check out Section 2.1.1 in the manual to see how to define a model that is based on an m-file:
Best regards
Styfen
Thank you @styfen.schaer .
Dear @styfen.schaer
Thank you for the prompt response.
Is it possible to use a developed PCE surrogate model instead of a computational model defined by a Matlab handle function or a Matlab m-file for this type of analysis?
If possible, can you please provide me with some insight.
Thank you.
Kind regards,
Abraham
Dear @Abraham
Yes, it is possible. If you want to have the model as m-file, you have to wrap the model in a function with the following signature, as described in the manual:
function Y = myPCE_sparseLARS(X)
Y = uq_evalModel(myModel, X);
end
Of course, in this case myModel
must be visible within the function scope. For example, you can load a saved model, create the model, or use a model from the workspace.
Alternatively, you can provide the model as a function handle as follows:
ModelOpts.mHandle = @(X) uq_evalModel(myModel, X)
Best regards
Styfen
Thank you @styfen.schaer .
Hello @styfen.schaer,
I managed to use the function handle to provide the PCE surrogate model. Thank you.
myFullInput = uq_mergeInputs(myScalarInput, myRFInput.UnderlyingGaussian) ;
ModelOpts.mHandle = @(X) uq_evalModel(myPCE_LARSa, X);
ModelOpts.Parameters = myRFInput ;
myModel = uq_createModel(ModelOpts);
X = uq_getSample(myFullInput, 120, ‘LHS’) ;
fprintf(‘Evaluating the experimental design…’)
Y = uq_evalModel(myModel, X) ;
fprintf(’ done!\n\n’)
However, in evaluating the model response over a discretisation domain, it gives an error of ‘too many input arguments’. Is there a limit to the number of input arguments in UQlab ?
Thank you.
Dear @Abraham
Where in your code does the error occur and can you share the full error message? Can you give a minimal reproducible example?
Best regards
Styfen
Dear @styfen.schaer
The error occurs in calculating the model response over the discretised domain.
Y = uq_evalModel(myModel, X) ;
fprintf(’ done!\n\n’)
Evaluating the experimental design…Error using uq_eval_uq_default_model
Too many input arguments.
Error in uq_evalModel (line 121)
** [varargout{1:nargout}] = current_model.eval(current_model,varargin{:});**
sfermuqlab.m (3.2 KB)
Thank you for the prompt response. Hope this helps.
Dear @Abraham
In order for us to run your code, you also need to provide all the data and models, e.g. myPCE_LARSa
.
However, I think the problem is that you specify ModelOpts.Parameters = myRFInput
and therefore the function handle assigned to ModelOpts.mHandle
must take this additional argument, as described in the manual. I recommend you to take another close look at the manual (section 2.1.1):
And are you sure you really want the ModelOpts.Parameters
? From the code you showed me, it looks like myPCE_LARSa
wouldn’t do anything with this additional argument.
Best regards
Styfen
Thank you @styfen.schaer
Dear @styfen.schaer
Thank you for the response.
Kindly find attached the full model including the data as an example.
sfermuqlabpractise.m (18.7 KB)
I was expecting to get the model response , Y over the discretisation domain (360 months). In this case, I will have the experimental design for the 30 years, from which I can further use for reliability analysis.
Thank you.