stat/distuv: Logistic.LogProb disagrees with log(Logistic.Prob) unless Mu = 0 and S = 1
This bug was found by an automated program we have running that writes tests with hegel (but I have personally reviewed it). More details at the bottom, but the short version is that I am not personally affected by this bug, and if that's not welcome then please feel free to disregard it.
What are you trying to do?
Evaluate the log density of a logistic distribution with a location or scale other than the standard one.
What did you do?
Logistic.LogProb returns the same value whatever Mu and S are, and agrees with math.Log(Prob(x)) only for the standard distribution Mu: 0, S: 1:
package main
import (
"fmt"
"math"
"gonum.org/v1/gonum/stat/distuv"
)
func main() {
for _, d := range []distuv.Logistic{
{Mu: 0, S: 1},
{Mu: 2, S: 1},
{Mu: 0, S: 3},
{Mu: 3, S: 630},
} {
fmt.Printf("Logistic{Mu: %v, S: %v}: LogProb(0) = %v log(Prob(0)) = %v\n",
d.Mu, d.S, d.LogProb(0), math.Log(d.Prob(0)))
}
}What did you expect to happen?
LogProb(x) to equal math.Log(d.Prob(x)) for every Mu and S, as its documentation says it is the natural logarithm of the density: -2.253856022085945, -2.4849066497880004 and -7.832019849434353 on the last three lines.
What actually happened?
Output:
Logistic{Mu: 0, S: 1}: LogProb(0) = -1.3862943611198906 log(Prob(0)) = -1.3862943611198906
Logistic{Mu: 2, S: 1}: LogProb(0) = -1.3862943611198906 log(Prob(0)) = -2.253856022085945
Logistic{Mu: 0, S: 3}: LogProb(0) = -1.3862943611198906 log(Prob(0)) = -2.4849066497880004
Logistic{Mu: 3, S: 630}: LogProb(0) = -1.3862943611198906 log(Prob(0)) = -7.832019849434353LogProb(0) is log(1/4) for all four distributions; Prob, CDF and the other methods of the same distribution do respond to Mu and S.
What version of Go and Gonum are you using?
go version go1.27.1 darwin/arm64
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=Does this issue reproduce with the current master?
Yes, the output above is identical on master at 2b52c28 (gonum.org/v1/gonum v0.17.1-0.20260830200947-2b52c28fc756).
As mentioned at the top, this was found by an automated program that writes property-based tests for various open source projects using hegel, and the report was reviewed by hand before filing. We've also potentially found (but not yet hand validated) 38 other bugs in gonum. You can see the tests at https://github.com/hegeldev/hegel-zoo/tree/main/targets/go/gonum. Let us know if you would like us to file the other bugs found and/or contribute the tests. NB the tests are currently LLM generated and probably not yet suitable for inclusion as is, but we're happy to help get them into a better state if you want them.
Source: gonum/gonum