Interpolation problems in multidimensional space

6 visualizaciones (últimos 30 días)
Jan
Jan el 17 de Mzo. de 2025
Editada: Stephen23 el 17 de Mzo. de 2025
In the problem I have, I need to apply multidimensional interpolation. My goal is to apply spline interpolation first, and then, if not possible, fitnet or something similar.
I have 16 variants, each of which is determined by 6 dimensions (width, length,...). Each combination of dimensions out of those 16 is different (each row is one variant, and each row is different), but certain dimensions, e.g. diameter=100mm (second column) repeat in different combinations. For each of these 16 variants I have 9x11 size results. I am writing a program which, when I select specific values ​​for each of the 6 dimensions (width, length,...), gives the appropriate result with dimension 9x11, by interpolation between known data.
I am citing cases that I have tried and none of them work, I don't know why.
clear all; clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THE FIRST TRY
dimensions1 = [95, 100, 300, 2000, 200, 200;
85, 100, 300, 2000, 200, 200;
70, 100, 300, 2000, 200, 200;
95, 150, 300, 2000, 200, 200;
85, 150, 300, 2000, 200, 200;
95, 100, 300, 1000, 200, 200;
95, 100, 500, 2000, 200, 200;
95, 100, 300, 2000, 100, 200;
95, 100, 300, 2000, 200, 300;
0, 0, 300, 2000, 200, 200;
0, 0, 300, 1000, 200, 200;
0, 0, 500, 2000, 200, 200;
0, 0, 300, 2000, 100, 200;
0, 0, 300, 2000, 200, 300;
90, 125, 400, 1500, 150, 250;
0, 0, 400, 1500, 150, 250;];
results = cell(16,1);
results{1} = rand(9,11);
results{2} = rand(9,11);
results{3} = rand(9,11);
results{4} = rand(9,11);
results{5} = rand(9,11);
results{6} = rand(9,11);
results{7} = rand(9,11);
results{8} = rand(9,11);
results{9} = rand(9,11);
results{10} = rand(9,11);
results{11} = rand(9,11);
results{12} = rand(9,11);
results{13} = rand(9,11);
results{14} = rand(9,11);
results{15} = rand(9,11);
results{16} = rand(9,11);
results_array = cat(3, results{:});
disp(class(results_array));
disp(size(results_array));
disp(class(results{1}));
% results_numeric = cellfun(@table2array, results);
% results_numeric(1,:) = cellfun(@table2array, results);
f = griddedInterpolant({dimensions1(:,1), dimensions1(:,2), dimensions1(:,3), dimensions1(:,4), dimensions1(:,5), dimensions1(:,6)}, [results{1}, results{2}, results{3}, results{4}...
results{5}, results{6}, results{7}, results{8}, results{9}, results{10}, results{11}, results{12}, results{13}, results{14}, results{15}, results{16}], 'spline');
% f = griddedInterpolant({dimensions1(:,1), dimensions1(:,2), dimensions1(:,3), dimensions1(:,4), dimensions1(:,5), dimensions1(:,6)}, results, 'spline');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THE SECOND TRY
x1 = [95,85,70,95,85,95,95,95,95,0,0,0,0,0,90,0];
x2 = [100,100,100,150,150,100,100,100,100,0,0,0,0,0,125,0];
x3 = [300,300,300,300,300,300,500,300,300,300,300,500,300,300,400,400];
x4 = [2000,2000,2000,2000,2000,1000,2000,2000,2000,2000,1000,2000,2000,2000,1500,1500];
x5 = [200,200,200,200,200,200,200,100,200,200,200,200,100,200,150,150];
x6 = [200,200,200,200,200,200,200,200,300,200,200,200,200,300,250,250];
% disp(size(x1));
% disp(size(x2));
% disp(size(x3));
% disp(size(x4));
% disp(size(x5));
% disp(size(x6));
dim_comb = [x1',x2',x3',x4',x5',x6']
% res_interp = interpn(x1,x2,x3,x4,x5,x6,results_array,[80, 115, 450, 1750, 175, 225]);
f = griddedInterpolant(dim_comb(:,1), dim_comb(:,2), dim_comb(:,3), dim_comb(:,4), dim_comb(:,5), dim_comb(:,6), results_array, 'spline');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THE THIRD TRY
[x1grid, x2grid, x3grid, x4grid, x5grid, x6grid,] = ndgrid(x1,x2,x3,x4,x5,x6);
f3 = griddedInterpolant(x1grid(:),x2grid(:),x3grid(:),x4grid(:),x5grid(:),x6grid(:),results_array,'spline');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THE FOURTH TRY
net = fitnet(10, 'trainlm');
net = train(net, dimensions1, results);
net = train(net, dimensions1', results');
% net = newrbe(dimensions1', results', spread)
% net = train(net, [95, 100, 300, 2000, 200, 200], results{1})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THE FIFTH TRY
layers = [featureInputLayer(16, 'Name', 'input'),...
fullyConnectedLayer(50, 'Name', 'fc1'),...
reluLayer('Name', 'relu1'),...
fullyConnectedLayer(99,'Name','output'), regressionLayer('Name','regressionOutput')];
options = trainigOptions('adam', 'MaxEpochs',100,'Plots','training-progress');
net = trainNetwork(dimensions1', reshape(results, [], 16)', layers, options);
  2 comentarios
Torsten
Torsten el 17 de Mzo. de 2025
Editada: Torsten el 17 de Mzo. de 2025
Given a 1x6 vector of values for the 6 dimensions, what is your criterion to determine the rows of "dimension1" between which you want to interpolate ? Some distance norm to the row vectors of "dimension1" ?
Jan
Jan el 17 de Mzo. de 2025
Editada: Jan el 17 de Mzo. de 2025
Well, I created program for linear interpolation, and firstly I am looking for range where is my first dimension in the first column, then I interpolate between that two rows and get result of size 9x11. After that, I am looking for range for my second dimension, it means in the second column. On the value which I got from the first interpolation (size 9x11) I add the part that I get by determining the weighting factor, i.e. how much the value I'm looking for increases or decreases in this interval and apply it to my results from the first column, according to given dimension (second). I go through all the other columns in the same way.
I am not sure this will work for other types of interpolation.

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 17 de Mzo. de 2025
Editada: Stephen23 el 17 de Mzo. de 2025
You do not have gridded data, so all of the attempts with GRIDDEDINTERPOLANT will not work. Using NDGRID does create gridded data, but you will end up with 16^6 data points... way more than the 16 data points that you actually have. So that won't work either. What is more likely to work:
  • your data is irregular (scattered) in 6D space, so use methods designed for scattered data interpolation.
  • neural networks are well-suited for this kind of high-dimensional regression problem... but they need to correct input arrays. A bit tricky.
D = [95,100,300,2000,200,200; 85,100,300,2000,200,200; 70,100,300,2000,200,200; 95,150,300,2000,200,200; 85,150,300,2000,200,200; 95,100,300,1000,200,200; 95,100,500,2000,200,200; 95,100,300,2000,100,200; 95,100,300,2000,200,300; 0,0,300,2000,200,200; 0,0,300,1000,200,200; 0,0,500,2000,200,200; 0,0,300,2000,100,200; 0,0,300,2000,200,300; 90,125,400,1500,150,250; 0,0,400,1500,150,250]
D = 16×6
95 100 300 2000 200 200 85 100 300 2000 200 200 70 100 300 2000 200 200 95 150 300 2000 200 200 85 150 300 2000 200 200 95 100 300 1000 200 200 95 100 500 2000 200 200 95 100 300 2000 100 200 95 100 300 2000 200 300 0 0 300 2000 200 200
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
R = rand(9,11,16); % one array
S = size(R);
Using FITRGP from Statistics and Machine Learning toolbox:
F = cell(S(1:2));
for ii = 1:S(1)
for jj = 1:S(2)
V = reshape(R(ii,jj,:),[],1);
F{ii,jj} = fitrgp(D,V, 'KernelFunction','squaredexponential');
end
end
FITRGP is a Gaussian Process Regression function, well-suited for this task because:
  • It's designed specifically for scattered data interpolation in multi-dimensional spaces
  • It creates a smooth interpolation by modeling the data as a Gaussian process
  • It automatically handles the irregular spacing of your 6D data points
  • It's robust to noise and can avoid overfitting with proper kernel selection
  • It provides uncertainty estimates for predictions (though we're not using this feature)
The function works by fitting a statistical model to your data that represents the underlying function. It uses a kernel function (in our case 'squaredexponential') to measure similarity between data points, which enables it to generate smooth interpolations between known points, even in high-dimensional spaces like your 6D parameter space. To interpolate some query points using those models:
Q = [80,115,450,1750,175,225]; % some random query values
Z = nan(S(1:2));
for ii = 1:S(1)
for jj = 1:S(2)
Z(ii,jj) = predict(F{ii,jj},Q);
end
end
display(Z)
Z = 9×11
0.4307 0.5286 0.5157 0.4029 0.4506 0.5029 0.4704 0.3727 0.3498 0.5360 0.5165 0.4844 0.4876 0.5293 0.4484 0.3677 0.4481 0.4470 0.4332 0.4406 0.4234 0.4339 0.5627 0.5197 0.3706 0.5442 0.4074 0.4473 0.5253 0.4547 0.4862 0.4913 0.4941 0.5610 0.5612 0.4509 0.3412 0.4531 0.4626 0.4232 0.4903 0.5931 0.5211 0.5342 0.4786 0.5224 0.5154 0.4390 0.4663 0.5342 0.4808 0.3736 0.4426 0.6238 0.5588 0.4915 0.5409 0.4454 0.6424 0.5593 0.4827 0.4130 0.6550 0.4303 0.5231 0.3986 0.4646 0.6434 0.5305 0.4618 0.4341 0.4078 0.4695 0.4411 0.5463 0.6933 0.5486 0.5524 0.6026 0.5221 0.4748 0.4576 0.5017 0.5425 0.4436 0.5393 0.4669 0.6412 0.4932 0.5953 0.5511 0.4240 0.6130 0.5464 0.5381 0.4510 0.4693 0.5358 0.4342
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  2 comentarios
Jan
Jan el 17 de Mzo. de 2025
Can you please explain me how to use this result? For example how should I use it if I would like to interpolate for this 6D values [90, 125, 475, 1100, 110, 260]?
Stephen23
Stephen23 el 17 de Mzo. de 2025
"For example how should I use it if I would like to interpolate for this 6D values [90, 125, 475, 1100, 110, 260]?"
Q = [90, 125, 475, 1100, 110, 260];
etc.

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by