comparison pkg/common/nashsutcliffe.go @ 3097:e6ba32b060df

Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 23 Apr 2019 18:10:19 +0200
parents cb3360653652
children 8f2ac24b0cb3
comparison
equal deleted inserted replaced
3096:cb3360653652 3097:e6ba32b060df
47 if m1.When.After(when) { 47 if m1.When.After(when) {
48 lo = mid + 1 48 lo = mid + 1
49 continue 49 continue
50 } 50 }
51 if m1.When.Equal(when) { 51 if m1.When.Equal(when) {
52 //log.Printf("matches first: %f\n", m1.Value)
52 return m1.Value, true 53 return m1.Value, true
53 } 54 }
54 if m2.When.Equal(when) { 55 if m2.When.Equal(when) {
56 //log.Printf("matches second: %f\n", m1.Value)
55 return m2.Value, true 57 return m2.Value, true
56 } 58 }
57 59
58 // f(m1.When) = m1.Value 60 // f(m1.When) = m1.Value
59 // f(m2.When) = m2.Value 61 // f(m2.When) = m2.Value
67 } 69 }
68 70
69 a := (m1.Value - m2.Value) / m1.When.Sub(m2.When).Seconds() 71 a := (m1.Value - m2.Value) / m1.When.Sub(m2.When).Seconds()
70 b := m1.Value - m1.When.Sub(utc0).Seconds()*a 72 b := m1.Value - m1.When.Sub(utc0).Seconds()*a
71 m := when.Sub(utc0).Seconds()*a + b 73 m := when.Sub(utc0).Seconds()*a + b
74
75 //log.Printf("%f %f %f\n", m1.Value, m, m2.Value)
72 return m, true 76 return m, true
73 } 77 }
74 78
75 if len(mvs) == 1 && when.Equal(mvs[0].When) { 79 if l := len(mvs); l > 0 {
76 return mvs[0].Value, true 80 if when.Equal(mvs[0].When) {
81 //log.Printf("at start\n")
82 return mvs[0].Value, true
83 }
84 if !when.Before(mvs[l-1].When) {
85 //log.Printf("after end\n")
86 }
87 return mvs[l-1].Value, true
77 } 88 }
89
90 //if len(mvs) > 0 {
91 // log.Printf("does not match %v %v %v\n",
92 // mvs[0].When, mvs[len(mvs)-1].When.Sub(mvs[0].When), when)
93 //}
78 94
79 return 0, false 95 return 0, false
80 } 96 }
81 97
82 func NashSutcliffe(predicted, observed []float64) float64 { 98 func NashSutcliffe(predicted, observed []float64) float64 {