Skip to content
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

r.vif: bugfix #1228

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/raster/r.vif/r.vif.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# VIF. This will be repeated till the VIF falls below the user
# defined VIF threshold value.
#
# COPYRIGHT: (C) 2015 - 2022 Paulo van Breugel and the GRASS Development Team
# COPYRIGHT: (C) 2015 - 2024 Paulo van Breugel and the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
Expand Down Expand Up @@ -215,8 +215,10 @@ def compute_vif(mapx, mapy):
x_i = np.hstack((mapx, np.ones((mapx.shape[0], 1))))
unused, resid = np.linalg.lstsq(x_i, mapy, rcond=None)[:2]
if resid.size == 0:
resid = 0
r2 = float(1 - resid[0] / (mapy.size * mapy.var()))
resid_value = 0
else:
resid_value = resid[0]
r2 = float(1 - resid_value / (mapy.size * mapy.var()))
if float(r2) > 0.9999999999:
vif = float("inf")
sqrtvif = float("inf")
Expand Down