nonlinear spline fit with unknown upper bound of interpolation domain

124 ビュー (過去 30 日間)
SA-W
SA-W 2025 年 2 月 19 日 7:42
編集済み: Matt J 2025 年 2 月 24 日 18:27
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:
  1. 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.
  2. 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: %.4f\n', 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
  6 件のコメント
Matt J
Matt J 2025 年 2 月 19 日 13:34
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
What does "good" mean in this context? Why do you care what the values for x>6 are if they don't impact your objective function?
SA-W
SA-W 2025 年 2 月 19 日 14:08
What does "good" mean in this context?
That the initial guess of the interpolation domain is not appropriate for the final model.
Why do you care what the values for x>6 are if they don't impact your objective function?
You are right that the objective function is not impacted much by what is happening after x > 6. But the optimizer sets the parameters at x > 6 to values near the upper bound I am passing to the optimizer. The upper bound is way larger than the fitted parameters at x < 6, causing an extremly large curvature at x > 6 which makes the spline unemanable for evaluation beyond x > 6. When I use the trained model after optimizing, I may have to evaluate at x > 6 where the spline interpolates non-sense values.
Ideally, I would crop the spline after x > 6 by discarding the parameters defined at those points, but the thus obtained spline is of course different from the original one.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2025 年 2 月 19 日 14:28
編集済み: Matt J 2025 年 2 月 19 日 15:01
The upper bound is way larger than the fitted parameters at x < 6, causing an extremly large curvature at x > 6 which makes the spline unemanable for evaluation beyond x > 6.
If high curvature is the problem, perhaps put a penalty on curvature,
% Evaluate the spline at xq
spline_values = fnval(f, xq);
curv_values = fnval(fnder(f,2), x );
%Penalized objective
obj_val = norm( spline_values - mean(spline_values) ).^2 + weight*norm(curv_values).^2;
However, I find it strange that you cannot dictate xq (or at least min(xq), max(xq) ) to your PDE solver. I also find it strange that your PDE residual term has no dependence on any measured data.
  25 件のコメント
SA-W
SA-W 2025 年 2 月 21 日 17:13
Interesting. I am not really sure about the smoothness of dx/dy since I only have it available at discrete points xq: dxq(1)/dy, ..., dxq(m)/dy. Thats also why i wanted to express
dxact/dy = -sum_i dF(xact,xq)/dxq(i) *dxq(i)/dy / f(xact)
solely in terms of dxq(i)/dy.
So given a vector of dxq(i)/dy, are there built-in functions to assess the smoothness of the data?
Matt J
Matt J 2025 年 2 月 21 日 18:00
編集済み: Matt J 約10時間 前
If there is anything to do an analytical continuity assessment, it would be in the Symbolic Toolbox, though I am not familiar enough with it to know if you'd find something appropriate there.
You could measure compute derivatives and make some kind of assessment of how rapidly they change...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by