stat/distuv/Laplace Fit not properly estimating scaling factor
Created by: mestorlx
What are you trying to do?
Want to fit a Laplace distribution to a set of sample data According to the documentation
// Fit sets the parameters of the probability distribution from the
// data samples x with relative weights w.
func (l *Laplace) Fit(samples, weights []float64) {
What did you do?
package main
import (
"gonum.org/v1/gonum/stat/distuv"
)
func main() {
d.Fit(data, weights)
}
What did you expect to happen?
According to the wiki the scaling factor should be b=(1/n)sum|xi-m|
What actually happened?
the method is implemented with
// The scale parameter is the average absolute distance
// between the sample and the mean
absError := stat.MomentAbout(1, samples, l.Mu, weights)
However the moment is computed with
m += weights[i] * math.Pow(v-mean, moment)
Because we are at moment 1 so Pow
is just v-mean
hence m converge to zero.
What version of Go and Gonum are you using?
go version go1.11.1 darwin/amd64 513db5a0
Does this issue reproduce with the current master?
Yes
I understand that the moment is correctly computed. The Fit function should be updated. If its of interest I can submit a patch.