0

I want to use GPR to predict RSS from a deployed access point (AP). Since GPR gives mean RSS and its variance too, GPR could be very useful in positioning and navigation system. I read the GPR related published journals and got the theoretical insight of it. Now, I want to implement it with real data (RSS). In my system, the input and corresponding outputs (observations) are:

X: 2D cartesian coordinates points

y: an array of RSS (-dBm) at the corresponding coordinates

After searching online, I found that I can use sklearn software (using python). I installed sklearn and successfully tested the sample codes. The sample python scripts are for 1D GPR. Since my input sets are 2D coordinates, I wanted to modify the sample code. I found that other people have also tried to do the same, for example : How to correctly use scikit-learn's Gaussian Process for a 2D-inputs, 1D-output regression?, How to make a 2D Gaussian Process Using GPML (Matlab) for regression?, and Is kringing suitable for high dimensional regression problems?.

The expected (predicted) values should be similar to y. The value I got is very different. The size of the testbed where I want to predict the RSS is 16*16 sq.meters. I want to predict RSS at every meter apart. I assume that the Gaussian Process predictor is trained with the Gaussian Decent algorithm in the sample code. I want to optimize the hyperparameter (theta: trained by using y and X) with Firefly algorithm.

In order to use my own data (2D input), in which line of code am I suppose to edit? Similarly, how can I implement Firefly algorithm (I've installed firefly algorithm using pip)?

Please help me with your kind suggestions and comments.

Thank you very much.

Community
  • 1
  • 1
santobedi
  • 866
  • 3
  • 17
  • 39

1 Answers1

1

I have simplified the code a bit to illustrate potential issues:

import numpy as np
from sklearn.gaussian_process import GaussianProcessRegressor

x_train = np.array([[0,0],[2,0],[4,0],[6,0],[8,0],[10,0],[12,0],[14,0],[16,0],[0,2],
                    [2,2],[4,2],[6,2],[8,2],[10,2],[12,2],[14,2],[16,2]])

y_train = np.array([-54,-60,-62,-64,-66,-68,-70,-72,-74,-60,-62,-64,-66,
                    -68,-70,-72,-74,-76])

# This is a test set?
x1min = 0
x1max = 16
x2min = 0
x2max = 16
x1 = np.linspace(x1min, x1max)
x2 = np.linspace(x2min, x2max)
x_test =(np.array([x1, x2])).T

gp = GaussianProcessRegressor()
gp.fit(x_train, y_train)

# predict on training data 
y_pred_train = gp.predict(x_train)
print('Avg MSE: ', ((y_train - y_pred_train)**2).mean()) # MSE is 0

# predict on test (?) data 
y_pred_test = gp.predict(x_test)
# it is unclear how good this result without y_test (e.g., held out labeled test samples)

The expected (predicted) values should be similar to y.

Here, I have renamed y to y_train for clarity. After fitting the GP and predicting on x_train, we see that the model perfectly predicts the training samples, which is possibly what you meant. I am not sure if you mistakenly wrote lowercase x which I call x_test (instead of uppercase X which I call x_train) in the question. If we predict on x_test, we cannot really know how good the prediction is without the corresponding y_test values. So, this basic example is working as I would expect.

It also appears you are trying to create a grid for x_test, however the current code does not do that. Here, x1 and x2 are always the same for each position. If you want a grid, take a look at np.meshgrid.

BradMcDanel
  • 543
  • 3
  • 15
  • x1(2)min(max) are size of 2D testbed.I want to predict mean and covariance RSS inside the grids of testbed.I want to use karnel function (eg. squared exponential) in GPR.Is MSE 0 due to absence of Karnel function?x_train is the coordinates of grid points and y_train is the observed RSS at respective grid points. Using this training data, how can I predict mean and covariance RSS in remaining grids in the testbed? Thanks a lot. – santobedi Apr 17 '18 at 05:54
  • MSE is 0 because we are predicting on the training data, so it fits it perfectly. I realize now in your original example you have function `f`, is that the function you are trying to estimate? – BradMcDanel Apr 17 '18 at 06:01
  • Yes. The function is the sum of observed RSS and physical noise (follows Gaussian distribution). – santobedi Apr 17 '18 at 06:52
  • Your edit makes it more confusing for me. If f(x) = y, then there is no need to do prediction :). – BradMcDanel Apr 17 '18 at 17:10
  • Theoretically, function fn(xi) is RSS at 2-D location xi from transmitter n.I want to make prediction of RSS fn(x*) for all possible 2-D inputs x*. For this, we need to model fn(xi): A-->R as a GP. A is 2-D area, R is real number. n and i are subscripted. – santobedi Apr 18 '18 at 00:46
  • 1
    In this case, in order to really evaluate how good a fit the GP is, you must collect a training and validation set, fit on the training set, and then evaluate on the held out validation set. Basically, you need groundtruth x_test and y_test like x_train and y_train in my modified answer. – BradMcDanel Apr 18 '18 at 01:05
  • Now, I'm able to predict the RSS in my testbed with the Kernel available in sample code [kernel = C(1.0, (1e-3, 1e3)) * RBF([5,5], (1e-2, 1e2))]. I want to use different Kernels. However, I don't know the meaning of arguments used in sample Kernel definition code. I also want to use optimize hyperparameter (theta) with different algorithms. Any idea? – santobedi Apr 18 '18 at 11:04
  • @ BradMcDanel The syntax [y_pred_test = gp.predict(x_test)] gives the predicted mean RSS.However, I couldn't find the syntax for the variance. Do I need to code the mathematical equation for variance? Thank you. – santobedi Apr 18 '18 at 11:24
  • 1
    Please refer to the sklearn docs for details. You can return the std and covariance using the following, gp.predict(x_test, return_std=True, return_cov=True) – BradMcDanel Apr 18 '18 at 14:52