Generate new samples from available data

Hi I have three variables (a,b,c) as input and their output is a variable d. I have generated 30 samples by varying inputs and getting output. Now i want to generate new samples using the data of available samples. Please guide me how to do this in Matlab. These are not random data samples.

 Réponse acceptée

Star Strider
Star Strider le 20 Jan 2022

0 votes

This seems to be an interpolation problem, such that the original data are created by the original values, and the desire is then to interpolate within the ranges of ‘a’, ‘b’, and ‘c’ to get new values.
If this is correct, use the scatteredInterpolant function to find the new values.

6 commentaires

Haris Hameed
Haris Hameed le 20 Jan 2022
Can you show how to use it if
a = [100 200 300] b = [11 12 13] c = [600 900 1200]
d = [0.25 O.12 .... 0.67] total 27 values. These i got by varying a,b and c. Now i want some sampling method that generate new values of "d" for input values of a,b and c.
I need to understand how ‘d’ was created (what function created it) and then reproduce that calculation with the vectors in order to create the appropriate arrays for the interpolation. After that, it should be straightforward.
EDIT — (20 Jan 2022 at 14:28)
An example to demonstrate the reason the information I requested is important and necessary to solve the problem —
a = [100 200 300];
b = [11 12 13];
c = [600 900 1200];
[Am,Bm,Cm] = ndgrid(a,b,c);
d_fcn = @(a,b,c) a.^2 + 2*a.*b + c.^2; % Create Function To Calculate 'd'
Dm = d_fcn(Am,Bm,Cm);
F = scatteredInterpolant(Am(:),Bm(:),Cm(:),Dm(:)) % Interpolation Function
F =
scatteredInterpolant with properties: Points: [27×3 double] Values: [27×1 double] Method: 'linear' ExtrapolationMethod: 'linear'
d_cal_1 = d_fcn(200,12,900) % Calculated Value
d_cal_1 = 854800
d_itp_1 = F(200,12,900) % Interpolated Value
d_itp_1 = 854800
d_itp_2 = F(150,12.5,1000) % Different Interpolated Value
d_itp_2 = 1048700
Substitute whatever function creates ‘d’ in your code for my ‘d_fcn’ with your data, then test it as I did here to be certain that it works correctly (as it does here).
That should work.
.
Haris Hameed
Haris Hameed le 20 Jan 2022
Modifié(e) : Haris Hameed le 20 Jan 2022
a,b, c are geometric parameters, That i change to calculate the drag values "d" from CFD code.
Star Strider
Star Strider le 20 Jan 2022
I have no idea what that means or what the variables are.
See the EDIT in my Comment and try it with your data to see if it works correctly with them. You will need to use my entire code (except for ‘d_fcn’) for it to work correctly. Also, replace my ‘Dm’ with your ‘d’.
Note — The ‘d’ vector must correspond to the values of the ‘a’, ‘b’, and ‘c’ vectors (as in my code) for my code to work correctly.
.
Haris Hameed
Haris Hameed le 20 Jan 2022
Okk will try it. Thank you
Star Strider
Star Strider le 20 Jan 2022
Modifié(e) : Star Strider le 20 Jan 2022
My pleasure!
It may be necessary to re-calculate ‘d’ using the ndgrid matrices in order for it to work with my code.
EDIT — (20 Jan 2022 at 16:52)
To calculate ‘d’ and use my code to interpolate values from it, it would be necessary to use the ‘Am’, ‘Bm’, and ‘Cm’ matrices to calculate it, using element-wise operations. (See Array vs. Matrix Operations for the necessary information on that.)
That will create a ‘Dm’ matrix output. Then use the rest of my code to interpolate values of ‘d’ for the desired ‘a’, ‘b’, and ‘c’ inputs, using the scatteredInterpolant code in my earlier Comment.
Calculating it in a loop using the vectors may not produce the correct result if the loop calculations produce something different from what ‘Dm’ would be in my code.
I can write specific code to do that if I have the function that creates ‘d’.
.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 20 Jan 2022
How about just getting a random number from each of your input ranges. Like:
a = [100 200 300];
b = [11 12 13];
c = [600 900 1200];
numPointsNeeded = 4 % Or 1 or 30 or however many you need.
aNew = a(1) + (a(3) - a(1)) * rand(1, numPointsNeeded)
bNew = b(1) + (b(3) - b(1)) * rand(1, numPointsNeeded)
cNew = c(1) + (c(3) - c(1)) * rand(1, numPointsNeeded)

4 commentaires

Haris Hameed
Haris Hameed le 20 Jan 2022
But actually in my case d is not a random number but depends on variable a,b and c.
I didn't say d was a random number. All I said was to generate some new a,b, and c and then use those to computer your new d using your non-random formula or function.
Sure, the a, b, and c were randomly picked from the range you gave, but only they are random, not the d that is computed from them.
If you need a more systematic way of generating new a,b,c values, then tell us what it is. Like maybe you want every value with the middle value being the step size. You can do that with a nested for loop:
a = [100, 200, 300];
b = [11, 12, 13];
c = [600, 900, 1200];
for ka = a(1) : a(2) : a(3)
for kb = b(1) : b(2) : b(3)
for kc = c(1) : c(2) : c(3)
d = MyFunctionForD(ka, kb, kc);
end
end
end
Haris Hameed
Haris Hameed le 20 Jan 2022
a,b,c are geometric parameters like radius, diameter and lenght. Now for different values of these i calculate aerodynamic drag that is "d" using a separate code (computational fluid dynamics). Now since i have manually calculated 28 points, i want to generate more data using these 28 calculated points. For this i am asking some method.
Image Analyst
Image Analyst le 20 Jan 2022
Not sure how the existing 28 d values will enable you to get more values for d.
if d1 = function(a, b, c) and you want a new set d2. I don't see how you can get new d2 only from d1 (the "calculated 28 points"), while not using new a,b,c values, unless you just create a distribution of d1 and try to get random values from it. Like a statistical estimation/prediction.
I think the best way would be to get some more values for a, b, and c and compute your new d values. So you can either get random a, b, c values, OR you can do it in some systematic way (like doing all values of a, b, and c). I showed you both ways.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by