-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consolidate MGWR #5
Conversation
comment out ac in gs
Speed-up GWR
add scipy optimization and some exploratory demonstrations.
Solving divided by zero issue
It should be noted, that the MGWR routine we used for the GA paper had changed the initial bandwidth parameterization so that line 331 in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job! good to me.
gwr/sel_bw.py
Outdated
def _mbw(self): | ||
y = self.y | ||
if self.constant: | ||
X = USER.check_constant(self.X_loc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is not consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be consistent now.
bw_max = self.bw_max | ||
interval = self.interval | ||
tol = self.tol | ||
max_iter = self.max_iter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether there is a need to define new variables since they are not transformed in any way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not, but I am going to leave them for now for the sake of getting a canonical version of MGWR set up - any PR's cleaning it up are welcome!
gwr/search.py
Outdated
err = optim_model.resid_response.reshape((-1,1)) | ||
est = optim_model.params | ||
else: | ||
model = GLM(y, X, family=self.family, constant=False).fit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no self.family
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it should just be family=family
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its now just family. Should we think about taking out the GLM initialization?
The interpretation of the optimal bandwidths produced from MGWR calibration depends on the magnitude of the independent variables (both mean and variance). A suggestion has been made in Note 5 of the MGWR paper (AAAG) to standardize them before calibrating an MGWR model to facilitate interpretation in terms of linking the values of the optimal bandwidths to the spatial scales of conditional relationships. I am just wondering if we are going to add some optional parameters to standardize |
Yup, that's the plan! Been doing it manually, but will be helpful to have
an option hat does it automatically.
…On Wed, Mar 14, 2018 at 6:04 PM Wei Kang ***@***.***> wrote:
The interpretation of the optimal bandwidths produced from MGWR
calibration depends on the magnitude of the independent variables (both
mean and variance). A suggestion has been made in Note 5 of the MGWR paper
(AAAG) to standardize them before calibrating an MGWR model to facilitate
interpretation in terms of linking the values of the optimal bandwidths to
the spatial scales of conditional relationships. I am just wondering if we
are going to add some optional parameters to standardize X.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHvdzZ3IjRi5X1n29_tQsDmQzg770is6ks5teb4XgaJpZM4SrRpF>
.
|
While an option for mean/variance standardization important, I think we would definitely need to make sure a "summary" function or the MGWR I wrestled with this same question in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor changes/tiny questions.
gwr/diagnostics.py
Outdated
@@ -1,5 +1,5 @@ | |||
""" | |||
Diagnostics for estimated gwr models | |||
Diagnostics for estimated gwr modesl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
models.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed it up.
gwr/search.py
Outdated
err = optim_model.resid_response.reshape((-1,1)) | ||
est = optim_model.params | ||
else: | ||
model = GLM(y, X, family=self.family, constant=False).fit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it should just be family=family
.
gwr/gwr.py
Outdated
@cache_readonly | ||
def predictions(self): | ||
P = self.model.P | ||
if P is None: | ||
raise NotImplementedError('predictions only avaialble if predict' | ||
'method called on GWR model') | ||
raise NotImplementedError('predictions only avaialble if predict' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a TypeError
or Exception
? feels weird to call it a NotImplementedError
, since it's only possible to predict if you've fit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, TypeError makes a bit more sense. Might be a better way to implement in this in the future that avoids an ambiguous error. But just want to make sure the user gets some sort of message that indicates that GWRResults will only provide predictions if you've run gwr_model.predict() prior.
I agree. The summary output for MGWR definitely needs to incorporate such standardization if it has been made (either it is made by default or not). Even if the users choose not to standardize, I think it is still important to remind them of a different interpretation of the optimal bandwidths in the summary output. |
@weikang9009 that can be easily done in the GUI's summary output, but for the console, we don't currently have a summary output unless do something like what |
Perhaps can just do like |
+1. A summary output similar to |
I've migrated the conversation about standardization to #6 where we can keep discussing, but I was hoping not to hamstring this PR on that issue. Also fixed up a bunch of minor revisions suggest over review, so I think this is ready to merge and become the up-to-date version of gwr/mgwr. |
I also added a PR so that if a user manually inputs min or max bandwidth search parameters, then those are automatically set to the starting points of the search procedure. As it currently stands the default min/max are both zero and then this value is compared to the "rule of thumb" min/max and depending on if the manual min is lower than the standard min then the manual min becomes the min. However, this causes issues depending on whether the use wants to set a manual bandwidth that is smaller/larger than the standard min. So now the default is |
This PR:
(1) Merges together several copies of MGWR that were beginning to diverge from each other.
(2) Merges in several updates to the underlying GWR routines to the MGWR codebase
(3) Adds additional code to estimate a hat matrix in parallel with estimating the MGWR parameters.
(4) Adds some basic tests for MGWR (not including the hat matrix)
It would be good for everyone to a close look at this and make sure your favorite edits to the MGWR code are still here. I did my best to make sure everything was going in, but could have accidentally deleted something.
This should be seen as the starting point for the MGWR code that will underly the GUI and be released to the public, rather than a finished product. Still need to clean code up, add diagnostics, and more tests.