Specifying a cost function to optimize a simbiology model response to plausible ranges
Show older comments
I am trying to generate a virual population simulation for my model using a uniform distribution for some parameter set from my simbiology model. Then I specify some if statements to reduce the simdata to fall within biological bounds and perform some calculations such as: mean, median, max, and min. Next, I would like to speicfy the cost funciton to optimize my model response with respect to the chosen parameter set. How can I correctly specify the cost function in terms of the simulaiton data? The cost functions is given as:
and
; where l and u are lower and upper bounds for plausible ranges of model states. I've provided the simdataReduced and timeVector to help with solving the problem. How can I specify Mi(p) in this case?
and %% New script to perform analysis on the simdataReduced
stopTime = simdataReduced(1).Time(end);
timeVector = linspace(0,stopTime,700);
simdataResampled = resample(simdataReduced, timeVector);
% "Stack" the matrices of simulation results and average them
% Calculate the 25th and 75th percentiles
stackedData = cat(3, simdataResampled.Data);
meanData = mean(stackedData, 3);
maxData = max(stackedData, [],3);
minData = min(stackedData, [],3);
medianData= median(stackedData, 3);
prc75= prctile(stackedData, 75, 3);
prc25= prctile(stackedData, 25, 3);
%%--------------- function script---------------------------------------------------
function J = computeCost(X, y, theta)
%COMPUTECOST Compute cost for linear regression
% J = COMPUTECOST(X, y, theta) computes the cost of using theta as the
% parameter for linear regression to fit the data points in X and y
% Initialize some useful values
m = length(y); % number of training examples (length of simdataResampled)
% You need to return the following variables correctly
J = 0;
% ====================== YOUR CODE HERE ======================
% Instructions: Compute the cost of a particular choice of theta
% You should set J to the cost.
prediction = X.*theta;
%sqrError = (prediction - y).^2;
c= 0.5*(lb+up)
sqrError= (((prediction- c).^2) - (ub-c).^2);
J = sum(max(sqrError), 0);
% =========================================================================
end
3 Comments
Arthur Goldsipe
on 27 May 2022
Can you provide more context for this cost function? What is
supposed to represent?
supposed to represent?
Fearass Zieneddin
on 27 May 2022
Arthur Goldsipe
on 27 May 2022
I think I'm still missing something. It sounds to me like
is some particular simulation result (a particular simulated state value at a particular time) for a parameter set P. But I think you've already figured out how to do that by looking at simdataResampled.Data. More specifically, it looks like simdataResampled(p).Data(t,i) would be timepoint t for state i and parameter sample p. But if that's not what you intend, I think it might be easiest to talk through this "live." If you want to do that, please contact me directly on MATLAB Answers, or reach out to Technical Support.
is some particular simulation result (a particular simulated state value at a particular time) for a parameter set P. But I think you've already figured out how to do that by looking at simdataResampled.Data. More specifically, it looks like simdataResampled(p).Data(t,i) would be timepoint t for state i and parameter sample p. But if that's not what you intend, I think it might be easiest to talk through this "live." If you want to do that, please contact me directly on MATLAB Answers, or reach out to Technical Support.Accepted Answer
More Answers (0)
Communities
More Answers in the SimBiology Community
Categories
Find more on Import Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


