How do I get some sampling points from a 4 dimentional function at LHS(Latin Hypercube Sampling)?
29 views (last 30 days)
Show older comments
function scores = rosenbrockfcn(x)
scores = 0;
n = size(x, 2);
assert(n >= 1, 'Given input X cannot be empty');
a = 1;
b = 100;
for i = 1 : (n-1)
scores = scores + (b * ((x(:, i+1) - (x(:, i).^2)) .^ 2)) + ((a - x(:, i)) .^ 2);
end
This is Rosenbrock function.
I want to get some samples from a 4 dimentional rosenbrock function.
like [x1 x2 x3 x4] and f(x)
Boundary conditions are [-10 10]
Please let me know. Thank you!
0 Comments
Answers (1)
Zuber Khan
on 9 May 2024
Hi,
To obtain Latin Hypercube Sampling (LHS) points from a 4-dimensional Rosenbrock function, you can use the "lhsdesign" function in MATLAB. The function as used below,
X = lhsdesign(n,p)
returns a Latin hypercube sample matrix of size n-by-p. For each column of 'X', the 'n' values are randomly distributed with one from each interval (0,1/n), (1/n,2/n), ..., (1 - 1/n,1), and randomly permuted.
You can generate LHS samples and evaluate the Rosenbrock function at sampled points as follows:
numSamples = 10; % Assuming there are 10 sample points
numDims = 4; % Number of dimensions
% Generate Latin Hypercube Samples in the range [0, 1]
lhsSamples = lhsdesign(numSamples, numDims);
% Scale samples to the range [-10, 10]
lowerBound = -10;
upperBound = 10;
scaledPoints = lowerBound + (upperBound - lowerBound) * lhsSamples; % Transform [0, 1] to [-10, 10]
% Evaluate the Rosenbrock function at the LHS points
scores = rosenbrockfcn(scaledPoints);
% Combine the sampled points and corresponding function values if you want
% better visibility
sampledData = [scaledPoints, scores];
I hope this will resolve your query.
Regards,
Zuber
0 Comments
See Also
Categories
Find more on Industrial Statistics 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!