nonlinear spline fit with unknown upper bound of interpolation domain
I want to fit the interpolation values of a spline, but I can not provide a good guess for the upper bound of the interpolation domain. That is, x(end) is so to speek an unknown too.
The value of the objective function is a pde residual and to compute it, the spline needs to be evaluated at certain points which can change during iterations. In the toy code below, I mock this by shrinking the interpolation domain over the iterations. For example, when fmincon does the last iteration, the spline was only evaluated at points xq in [0, 6] and the initial guess for the interpolation domain (x = linspace(3, 10, 5)) is not good anymore because the interpolation values defined at x > 6 have not been activated in the forward solve. As a consequence, no meaningful parameters are assigned at points x > 6.
So far, I did a multi-stage optimization: Optimizing with fixed points x, checking the final evaluation points, refining the points, optimizing again, etc. But this is very costly.
My ideas are the following:
Changing the interpolation points in some iterations (if required): At iteration k, the sampled points xq are in [0, 5]. So the initial points (x = linspace(3, 10, 5)) are changed to x = linspace(3, 5, 5)) in the next iteration. With this strategy I am keeping the number of parameters constant (there is probably no chance to dynamically change the number of parameters for any solver?) I am not sure if this violates differentiability assumptions of the solvers.
Since I really know x(end) roughly only, I may treat it as an unknown too. So the new parameter vector represents [y; x(end)]. However, in this strategy I want to guide the optimizer (via a penalty or so) in a way that it moves the current x(end) to the current active region. What I can do for instance is to compute the min/max of the evaluation points in every iteration. But I am not sure how to translate this into a penalty term since the min/max evaluation points are not constants.
Can you think of smarter ways to handle this? Maybe spline fit with unknown domain is a known problem.
% Define initial parameters
x = linspace(3, 10, 5); % Interpolation points
y0 = rand(size(x)); % Initial interpolation values
% Define optimization problem
options = optimoptions(‘fmincon’, ‘OutputFcn’, @output_function); % Track iteration count
% Call fmincon optimizer
global iter_count;
iter_count = 0; % Iteration counter
[y_opt, fval] = fmincon(@objective_func, y0, [], [], [], [], [], [], [], options);
% Display results
fprintf(‘Optimized objective function value: %.4fn’, fval);
fprintf(‘Optimized spline values: [%s]n’, num2str(y_opt, ‘%.2f ‘));
function obj_val = objective_func(y)
global iter_count;
% Re-compute interpolation points
x = linspace(3, 10, numel(y));
% Create spline f
f = spapi(4, x, y);
% Mock shrinking of evaluation domain
shrink_factor = 1 – exp(-0.1 * iter_count); % Exponential decay
shrinked_domain = 5 + (10 – 5) * (1 – shrink_factor); % Starts at 10, slowly shrinks to 5
xq = linspace(3, shrinked_domain, 10); % PDE evaluation points
% Evaluate the spline at xq
spline_values = fnval(f, xq);
% Compute mock PDE residual (sum of squared differences)
obj_val = sum((spline_values – mean(spline_values)).^2);
% Debug print
% fprintf(‘Iter %d – Eval points: [%s]n’, iter_count, num2str(xq, ‘%.2f ‘));
end
function stop = output_function(~, ~, state)
global iter_count;
if strcmp(state, ‘iter’)
iter_count = iter_count + 1; % Update iteration count
end
stop = false; % Continue optimization
endI want to fit the interpolation values of a spline, but I can not provide a good guess for the upper bound of the interpolation domain. That is, x(end) is so to speek an unknown too.
The value of the objective function is a pde residual and to compute it, the spline needs to be evaluated at certain points which can change during iterations. In the toy code below, I mock this by shrinking the interpolation domain over the iterations. For example, when fmincon does the last iteration, the spline was only evaluated at points xq in [0, 6] and the initial guess for the interpolation domain (x = linspace(3, 10, 5)) is not good anymore because the interpolation values defined at x > 6 have not been activated in the forward solve. As a consequence, no meaningful parameters are assigned at points x > 6.
So far, I did a multi-stage optimization: Optimizing with fixed points x, checking the final evaluation points, refining the points, optimizing again, etc. But this is very costly.
My ideas are the following:
Changing the interpolation points in some iterations (if required): At iteration k, the sampled points xq are in [0, 5]. So the initial points (x = linspace(3, 10, 5)) are changed to x = linspace(3, 5, 5)) in the next iteration. With this strategy I am keeping the number of parameters constant (there is probably no chance to dynamically change the number of parameters for any solver?) I am not sure if this violates differentiability assumptions of the solvers.
Since I really know x(end) roughly only, I may treat it as an unknown too. So the new parameter vector represents [y; x(end)]. However, in this strategy I want to guide the optimizer (via a penalty or so) in a way that it moves the current x(end) to the current active region. What I can do for instance is to compute the min/max of the evaluation points in every iteration. But I am not sure how to translate this into a penalty term since the min/max evaluation points are not constants.
Can you think of smarter ways to handle this? Maybe spline fit with unknown domain is a known problem.
% Define initial parameters
x = linspace(3, 10, 5); % Interpolation points
y0 = rand(size(x)); % Initial interpolation values
% Define optimization problem
options = optimoptions(‘fmincon’, ‘OutputFcn’, @output_function); % Track iteration count
% Call fmincon optimizer
global iter_count;
iter_count = 0; % Iteration counter
[y_opt, fval] = fmincon(@objective_func, y0, [], [], [], [], [], [], [], options);
% Display results
fprintf(‘Optimized objective function value: %.4fn’, fval);
fprintf(‘Optimized spline values: [%s]n’, num2str(y_opt, ‘%.2f ‘));
function obj_val = objective_func(y)
global iter_count;
% Re-compute interpolation points
x = linspace(3, 10, numel(y));
% Create spline f
f = spapi(4, x, y);
% Mock shrinking of evaluation domain
shrink_factor = 1 – exp(-0.1 * iter_count); % Exponential decay
shrinked_domain = 5 + (10 – 5) * (1 – shrink_factor); % Starts at 10, slowly shrinks to 5
xq = linspace(3, shrinked_domain, 10); % PDE evaluation points
% Evaluate the spline at xq
spline_values = fnval(f, xq);
% Compute mock PDE residual (sum of squared differences)
obj_val = sum((spline_values – mean(spline_values)).^2);
% Debug print
% fprintf(‘Iter %d – Eval points: [%s]n’, iter_count, num2str(xq, ‘%.2f ‘));
end
function stop = output_function(~, ~, state)
global iter_count;
if strcmp(state, ‘iter’)
iter_count = iter_count + 1; % Update iteration count
end
stop = false; % Continue optimization
end I want to fit the interpolation values of a spline, but I can not provide a good guess for the upper bound of the interpolation domain. That is, x(end) is so to speek an unknown too.
The value of the objective function is a pde residual and to compute it, the spline needs to be evaluated at certain points which can change during iterations. In the toy code below, I mock this by shrinking the interpolation domain over the iterations. For example, when fmincon does the last iteration, the spline was only evaluated at points xq in [0, 6] and the initial guess for the interpolation domain (x = linspace(3, 10, 5)) is not good anymore because the interpolation values defined at x > 6 have not been activated in the forward solve. As a consequence, no meaningful parameters are assigned at points x > 6.
So far, I did a multi-stage optimization: Optimizing with fixed points x, checking the final evaluation points, refining the points, optimizing again, etc. But this is very costly.
My ideas are the following:
Changing the interpolation points in some iterations (if required): At iteration k, the sampled points xq are in [0, 5]. So the initial points (x = linspace(3, 10, 5)) are changed to x = linspace(3, 5, 5)) in the next iteration. With this strategy I am keeping the number of parameters constant (there is probably no chance to dynamically change the number of parameters for any solver?) I am not sure if this violates differentiability assumptions of the solvers.
Since I really know x(end) roughly only, I may treat it as an unknown too. So the new parameter vector represents [y; x(end)]. However, in this strategy I want to guide the optimizer (via a penalty or so) in a way that it moves the current x(end) to the current active region. What I can do for instance is to compute the min/max of the evaluation points in every iteration. But I am not sure how to translate this into a penalty term since the min/max evaluation points are not constants.
Can you think of smarter ways to handle this? Maybe spline fit with unknown domain is a known problem.
% Define initial parameters
x = linspace(3, 10, 5); % Interpolation points
y0 = rand(size(x)); % Initial interpolation values
% Define optimization problem
options = optimoptions(‘fmincon’, ‘OutputFcn’, @output_function); % Track iteration count
% Call fmincon optimizer
global iter_count;
iter_count = 0; % Iteration counter
[y_opt, fval] = fmincon(@objective_func, y0, [], [], [], [], [], [], [], options);
% Display results
fprintf(‘Optimized objective function value: %.4fn’, fval);
fprintf(‘Optimized spline values: [%s]n’, num2str(y_opt, ‘%.2f ‘));
function obj_val = objective_func(y)
global iter_count;
% Re-compute interpolation points
x = linspace(3, 10, numel(y));
% Create spline f
f = spapi(4, x, y);
% Mock shrinking of evaluation domain
shrink_factor = 1 – exp(-0.1 * iter_count); % Exponential decay
shrinked_domain = 5 + (10 – 5) * (1 – shrink_factor); % Starts at 10, slowly shrinks to 5
xq = linspace(3, shrinked_domain, 10); % PDE evaluation points
% Evaluate the spline at xq
spline_values = fnval(f, xq);
% Compute mock PDE residual (sum of squared differences)
obj_val = sum((spline_values – mean(spline_values)).^2);
% Debug print
% fprintf(‘Iter %d – Eval points: [%s]n’, iter_count, num2str(xq, ‘%.2f ‘));
end
function stop = output_function(~, ~, state)
global iter_count;
if strcmp(state, ‘iter’)
iter_count = iter_count + 1; % Update iteration count
end
stop = false; % Continue optimization
end optimization, fmincon, spline, lsqnonlin MATLAB Answers — New Questions