Opened 8 years ago

Closed 5 years ago

#2969 closed defect (fixed)

r.series: wrong usage of weights

Reported by: mmetz Owned by: grass-dev@…
Priority: normal Milestone: 7.0.7
Component: Raster Version: 7.0.3
Keywords: r.series, weights Cc:
CPU: Unspecified Platform: All

Description

A weighted average is calculated with

avg = sum(w[i] * x[i]) / sum(w[i])

r.series calculates weighted averages with

avg = sum(w[i] * x[i]) / count

r.series should instead behave like r.neighbors and use the corresponding weighing functions from libstats if available.

Test commands:

# set the region
g.region -p n=10 s=0 w=0 e=10 res=1
# create identical input maps
r.mapcalc "input1 = 1"
r.mapcalc "input2 = 1"
r.mapcalc "input3 = 1"
r.mapcalc "input4 = 1"
r.mapcalc "input5 = 1"

# average
r.series in=input1,input2,input3,input4,input5 method=average out=avg
# weighted average
r.series in=input1,input2,input3,input4,input5 method=average out=avg_w weights=0.1,0.2,0.3,0.2,0.1

Without weights the result is 1, with weights the result is 0.18 instead of 1. Weights have been added to r.series in r49946. I am going to change r.series in trunk and relbr70.

Change History (6)

comment:1 by mmetz, 8 years ago

Fixed in r68124,5 (trunk, relbr70).

comment:2 by marisn, 8 years ago

A second candidate for erratum as the wrong result might slip unnoticed for not so trivial cases?

Affected releases: 7.0.0-7.0.3

comment:3 by martinl, 8 years ago

Milestone: 7.0.47.0.5

comment:4 by neteler, 8 years ago

Milestone: 7.0.57.0.6

comment:5 by neteler, 6 years ago

Milestone: 7.0.67.0.7

comment:6 by martinl, 5 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.