cbergmeir / RSNNS

RSNNS: Neural Networks in R using the Stuttgart Neural Network Simulator (SNNS)
26 stars 5 forks source link

Is it possible to use the RSNNS library to perform RBF interpolation when the target output is longer than the input? #22

Open Jsalas424 opened 1 year ago

Jsalas424 commented 1 year ago

Is it possible to use the RSNNS library to perform RBF interpolation when the target output is longer than the input?

There are 4 columns, "fitted" which stands for a value for each surf_x, surf_y, and surf_z value. surf_x etc. and all values of "outputs" all represent a coordinate in 3D space.

The goal is to use RBF interpolation to find the "fitted" value corresponding to the coordinates found in "outputs" where all values of surf_x in "inputs" can be found in column [,1] of "outputs".

library(RSNNS)

> dim(inputs)
[1] 2312    4

> head(inputs)
      fitted    surf_x    surf_y   surf_z
1 -2.0260418 -64.20550 -84.79310 219.4273
2  1.2358981 -67.00667 -79.65610 227.9487
3 -1.3667838 -62.88993 -86.83528 218.1500
4  0.1172459 -66.91177 -79.44738 227.0095
5  1.1278194 -67.30763 -80.56429 226.5518
6 -2.7412495 -62.88353 -85.40290 218.0784

> dim(outputs)
[1] 6971    3

> head(outputs)
        [,1]    [,2]    [,3]
[1,] -38.000 -41.794 180.858
[2,] -39.542 -50.167 175.664
[3,] -33.440 -56.959 173.340
[4,] -17.804 -60.643 181.561
[5,]  -8.156 -50.190 201.004
[6,] -23.019 -36.171 196.698

rbf_res <- RSNNS::rbf(x = inputs,
               y = outputs)

Error in checkInput(x, y) : nrows of 'x' and 'y' must match
cbergmeir commented 1 year ago

Hi, I'm not sure if I understand correctly what you try to do, but it seems this is a quite standard regression problem where what you call inputs is the training set and what you call outputs is a test set. Your actual inputs in training are surf_x, surf_y, and surf_z, and fitted is the target. Then, in testing, in your "outputs" dataset, you only have surf_x, surf_y, and surf_z and want to find the "fitted" values. So what you need is something like the following to train the model:

rbf_res <- RSNNS::rbf(x = inputs[,c("surf_x","surf_y","surf_z")],
               y = inputs[,"fitted"])

Then, to predict on your new data, you need:

res = predict(rbf_res, newdata=outputs)

Any particular reason to use RBF for this? Otherwise I'd use any standard Machine Learning algorithm like a random forest or so.

Jsalas424 commented 1 year ago

@cbergmeir

Cubic RBF interpolation has been specifically validated for my goal: https://ieeexplore.ieee.org/document/5626616

Relevant excerpt: image

I'm about to leave on an extended vacation and will test this when I return, thank you!

cbergmeir commented 1 year ago

Sure, give it a go and let me know if it works (or not).

Jsalas424 commented 1 year ago

Can this be used to fit a cubic or multiquadric RBF?

cbergmeir commented 1 year ago

It seems to have Multiquadratic, yes. Best you check in the SNNS Manual, page 175ff for the details: http://gentoo.osuosl.org/distfiles/SNNSv4.2.Manual.pdf

cbergmeir commented 1 year ago

There are some demos in RSNNS that should allow you to figure out how to use these parameters from SNNS in RSNNS. They are in the demo folder in the package.