WentaoZhan1998 / geospaNN

MIT License
5 stars 1 forks source link

A different way of using geospaNN for prediction #3

Open ShinyFabio opened 1 week ago

ShinyFabio commented 1 week ago

Hi, I checked your real data example and didn't understand why you first trained the mlp_nn and then the mlp_nngls. It seems that you used the first NN just to pre-train the theta values (with the geospaNN.theta_update() function), but those values are updated again in the gls model. So what's the difference in using the stock theta values directly in the geospaNN.nngls() function and let the gls update the thetas?

Then a question regarding my application. So basically I'm dealing with something similar to the PM2.5 example with some temperature values on an irregular grid (like your ground stations) and I want to convert them to a regular grid. Currently, I'm training an ML model using some covariates colocalized both spatially and temporally to my temperature observations (so should be similar to your PM2.5 training). My problem is in the prediction because I use another dataset (with the same covariates but colocalized to a finer regular grid) to predict the temperatures on a regular grid. In my case, I simply use the new dataset as input for the trained ML model to have the prediction, but here, from what I understood, your model.predict() function uses both training and testing datasets for the prediction. So basically is like predicting the PM2.5 for the whole US area using just the original covariates dataset of 7706 pixels (so without running the interpolate.CloughTocher2DInterpolator function).

WentaoZhan1998 commented 2 days ago

Hello, sorry about the delayed response.

For your first question, directly using the stock theta for geospaNN.nngls should give a similar result. Our point is that, NN-GLS requires some rough guess (theta0 here) on the initial value for theta's estimation. It can either come from the residual of a NN fit or any other reasonable approaches.

For your second question, we are sorry about the confusion. Actually, model.predict(data_train, data_test) allows you to compose your own data_test without knowing Y_test. In your case, you can create data_train = geospaNN.make_graph(X_train, Y_train, coord_train, nn), and data_test = geospaNN.make_graph(X_test, Null, coord_test, nn), where X_test is the covariates colocalized to a finer regular grid (the other dataset you have), and Y_test = Null is unknown. After training the model, model.predict(data_train, data_test) should work as desired.

We will update the example in the next few days to deliver the above steps more clearly. Please let me know if you have any further questions.

ShinyFabio commented 2 days ago

Okay thank you. And let's say I want to compute the residuals on the training dataset. Since model.predict() requires both training and test set, can I do something like model.predict(data_train, data_train)? Or is it wrong and there is a better way?

P.S. I think there's an error in the code in the main.py at line 257. It should be "if data_test is not None:" otherwise it will try to compute the test estimate with None. Also at lines 84 and 110 I think there's something weird because if I don't want to use the test set, you use the training set as test set (line 84), and then you try to compute the estimate only if data_test is None (line 110).