mirror of
https://github.com/gonum/gonum.git
synced 2025-10-20 13:55:20 +08:00
stat/distuv: improve Pareto.Rand performance, also adding Pareto.Rand benchmark
This commit is contained in:

committed by
Dan Kortschak

parent
2394b570ca
commit
ce6167c3f2
@@ -104,7 +104,7 @@ func (p Pareto) Rand() float64 {
|
|||||||
} else {
|
} else {
|
||||||
rnd = rand.New(p.Src).ExpFloat64()
|
rnd = rand.New(p.Src).ExpFloat64()
|
||||||
}
|
}
|
||||||
return math.Exp(math.Log(p.Xm) + 1/p.Alpha*rnd)
|
return p.Xm * math.Exp(rnd/p.Alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StdDev returns the standard deviation of the probability distribution.
|
// StdDev returns the standard deviation of the probability distribution.
|
||||||
|
@@ -204,3 +204,11 @@ func TestParetoNotExists(t *testing.T) {
|
|||||||
t.Errorf("Expected standard deviation == +Inf for Alpha == 1, got %v", stdDev)
|
t.Errorf("Expected standard deviation == +Inf for Alpha == 1, got %v", stdDev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkParetoRand(b *testing.B) {
|
||||||
|
src := rand.New(rand.NewSource(1))
|
||||||
|
p := Pareto{1, 1, src}
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
p.Rand()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user