Interpolation problems in multidimensional space
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (1)
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]
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)
2 comentarios
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.
Ver también
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!