PRCC sensitive analysis graphs
41 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have tried to get prcc sensitve analysis graph, but unfortunately i got an error.I request you please help to overcome the error.
CODE:
% Define parameter ranges
paramRanges = struct('beta', [0.1, 0.5], 'sigma', [0.1, 0.3], 'gamma', [0.1, 0.4]);
% Number of samples
nSamples = 100;
% Number of parameters
paramNames = fieldnames(paramRanges);
nParams = numel(paramNames);
% Generate LHS samples
lhsSamples = lhsdesign(nSamples, nParams);
% Scale samples to parameter ranges
scaledSamples = zeros(nSamples, nParams);
for i = 1:nParams
low = paramRanges.(paramNames{i})(1);
high = paramRanges.(paramNames{i})(2);
scaledSamples(:, i) = low + lhsSamples(:, i) * (high - low);
end
% Define SEIR model parameters and calculate R0
% Run simulations to compute R0 for each parameter set
R0Values = zeros(nSamples, 1);
for i = 1:nSamples
R0Values(i) = calculateR0(scaledSamples(i, :));
end
% Calculate PRCC
function prcc = calculatePRCC(outputs, samples)
nParams = size(samples, 2);
prcc = zeros(nParams, 1);
for i = 1:nParams
% Rank data
ranksSamples = tiedrank(samples(:, i));
ranksOutputs = tiedrank(outputs);
% Compute correlation
prcc(i) = corr(ranksSamples, ranksOutputs);
end
end
% Perform PRCC analysis for R0 values
prccValues = calculatePRCC(R0Values, scaledSamples);
function R0 = calculateR0(params)
beta = params(1);
sigma = params(2);
gamma = params(3);
% Basic reproduction number for SEIR model
R0 = beta / gamma;
end
% Display results
for i = 1:nParams
fprintf('PRCC for %s: %.4f\n', paramNames{i}, prccValues(i));
end
ERROR:
Function definitions in a script must appear at the end of the file.
Move all statements after the "calculateR0" function definition to before the first local function definition.
0 Kommentare
Antworten (3)
Shivam Gothi
am 12 Sep. 2024
I executed the code shared by you in MATLAB R2021a. I was able to reproduce the error as highlighted by you.
But, when I run the same code in MATLAB R2024a, it was executed without throwing error.
In older versions, all the function definations should go at the end of the file. This is not the case with R2024a version.
Therefore, there are two possible work arounds for this problem:
1) modify your code.
Upon inspecting the code provided by you in the comment section, I found that you have writen MATLAB commands after/in-between function definations, which is violating the defination:
"all the function definations should go at the end of the file"
I have re-organised your code and attached the corresponding (.m) file with this answer. I have compiled it in R2021a version and it is found to be executed without any error.
2) Update your MATLAB version
You can install the updated MATLAB version (R2024b) by refering the link:
R2024b allows to compile your code (shared in the question) without any error.
I hope this helps !
2 Kommentare
Shivam Gothi
am 12 Sep. 2024
Hello @mallela ankamma rao
I appreciate your efforts in seeking solutions. It might be beneficial to ask this as a new question in the MATLAB Answers community. There are many experts who might be able to assist you more effectively.
Additionally, if you find any of the responses you've received helpful, it would be great to provide the feedback or marking an answer as accepted.
Shivam Gothi
am 11 Sep. 2024
Bearbeitet: Shivam Gothi
am 11 Sep. 2024
I copied the same code provided by you in a new (.m) file and saved it with some name. Then I executed the file and it did not throw any error. Also, running the above code in the below given "code section" does not produce any error. But, I can suggest the possible cause behind it.
% Define parameter ranges
paramRanges = struct('beta', [0.1, 0.5], 'sigma', [0.1, 0.3], 'gamma', [0.1, 0.4]);
% Number of samples
nSamples = 100;
% Number of parameters
paramNames = fieldnames(paramRanges);
nParams = numel(paramNames);
% Generate LHS samples
lhsSamples = lhsdesign(nSamples, nParams);
% Scale samples to parameter ranges
scaledSamples = zeros(nSamples, nParams);
for i = 1:nParams
low = paramRanges.(paramNames{i})(1);
high = paramRanges.(paramNames{i})(2);
scaledSamples(:, i) = low + lhsSamples(:, i) * (high - low);
end
% Define SEIR model parameters and calculate R0
% Run simulations to compute R0 for each parameter set
R0Values = zeros(nSamples, 1);
for i = 1:nSamples
R0Values(i) = calculateR0(scaledSamples(i, :));
end
% Calculate PRCC
function prcc = calculatePRCC(outputs, samples)
nParams = size(samples, 2);
prcc = zeros(nParams, 1);
for i = 1:nParams
% Rank data
ranksSamples = tiedrank(samples(:, i));
ranksOutputs = tiedrank(outputs);
% Compute correlation
prcc(i) = corr(ranksSamples, ranksOutputs);
end
end
% Perform PRCC analysis for R0 values
prccValues = calculatePRCC(R0Values, scaledSamples);
function R0 = calculateR0(params)
beta = params(1);
sigma = params(2);
gamma = params(3);
% Basic reproduction number for SEIR model
R0 = beta / gamma;
end
% Display results
for i = 1:nParams
fprintf('PRCC for %s: %.4f\n', paramNames{i}, prccValues(i));
end
In MATLAB, all the function definations should go at the end of the file. Refer to the below MATLAB answer:
Therefore, I think that the compilation error in your case can be resolved by putting the "for loop" before the function definations as shown in below code:
I hope this helps !
5 Kommentare
Pavl M.
am 21 Nov. 2024 um 11:47
%just made it working on both TCE NCE MPPL Matlab versions:
clc
clear all
close all
% Define parameter ranges
paramRanges = struct('beta', [0.1, 0.5], 'sigma', [0.1, 0.3], 'gamma', [0.1, 0.4]);
% Number of samples
nSamples = 100;
% Number of parameters
paramNames = fieldnames(paramRanges);
nParams = numel(paramNames);
% Generate LHS samples
lhsSamples = lhsdesign(nSamples, nParams);
% Scale samples to parameter ranges
scaledSamples = zeros(nSamples, nParams);
for i = 1:nParams
low = paramRanges.(paramNames{i})(1);
high = paramRanges.(paramNames{i})(2);
scaledSamples(:, i) = low + lhsSamples(:, i) * (high - low);
end
% Define SEIR model parameters and calculate R0
% Run simulations to compute R0 for each parameter set
R0Values = zeros(nSamples, 1);
for i = 1:nSamples
R0Values(i) = calculateR0(scaledSamples(i, :));
end
% Calculate PRCC
% Perform PRCC analysis for R0 values
prccValues = calculatePRCC(R0Values, scaledSamples);
% Display results
for i = 1:nParams
fprintf('PRCC for %s: %.4f\n', paramNames{i}, prccValues(i));
end
function R0 = calculateR0(params)
beta = params(1);
sigma = params(2);
gamma = params(3);
% Basic reproduction number for SEIR model
R0 = beta / gamma;
end
function prcc = calculatePRCC(outputs, samples)
nParams = size(samples, 2);
prcc = zeros(nParams, 1);
for i = 1:nParams
% Rank data
ranksSamples = tiedrank(samples(:, i));
ranksOutputs = tiedrank(outputs);
% Compute correlation
prcc(i) = corr(ranksSamples, ranksOutputs);
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Physical Channels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!