Function File: param_idx = doe_res_idx_to_param_idx(parameter_dim, result_index)

This function is useful to distribute DOE’s to multiple processes with run_parallel. For example we have a scalar function y = f(x_1, x_2, …, x_N) which depends on N scalar parameters. For each parameter x_i the function f should be evaluated for parameter_dim(i) different values. In this case the total number of function evaluations to be executed by run_parallel will be number_of_parameters = doe_param_dim_to_res_dim(parameter_dim). Run_parallel will pass result_index as the first argument to the user supplied callback function func. Then the callback function func can use the return value param_idx from doe_res_idx_to_param_idx(parameter_dim, result_index) to evaluate x_i.

y{result_index} = f(x_1(param_idx(1)), x_2(param_idx(2)), …, x_N(param_idx(N)))

parameter_dim … array containing the number of different values for each parameter in the DOE

result_index … index of the function call (e.g. the first argument passed to a user function by run_parallel)

See also: run_parallel, doe_param_dim_to_res_dim.

Demonstration 1

The following code

 x = linspace(-pi / 2, pi / 2, 30);
 y = linspace(-pi / 3, pi / 3, 25);
 dim = int32([numel(x), numel(y)]);
 options.number_of_parameters = doe_param_dim_to_res_dim(dim);
 options.number_of_processors = int32(4);
 options.verbose = false;
 x_idx = @(i) doe_res_idx_to_param_idx(dim, i)(1);
 y_idx = @(i) doe_res_idx_to_param_idx(dim, i)(2);
 func = @(i, x, y) sin(x(x_idx(i))^2 + y(y_idx(i))^2);
 res = run_parallel(options, func, x, y);
 z = zeros(numel(x), numel(y));
 for i=1:numel(res)
  idx = doe_res_idx_to_param_idx(dim, i);
  z(idx(1), idx(2)) = res{i};
 endfor
 for i=1:numel(x)
  for j=1:numel(y)
    assert(z(i, j), sin(x(i)^2 + y(j)^2));
  endfor
 endfor
 figure("visible", "off");
 [xx, yy] = meshgrid(x, y);
 contourf(xx, yy, z.');
 colormap("jet");
 colorbar();
 xlabel("x");
 ylabel("y");
 title("f(x,y) = sin(x^2 + y^2)");

Produces the following figure

Figure 1

Package: mboct-octave-pkg