haifengl / smile

Statistical Machine Intelligence & Learning Engine
https://haifengl.github.io
Other
6.02k stars 1.13k forks source link

java.lang.StackOverflowError #747

Closed phrmoy closed 1 year ago

phrmoy commented 1 year ago

Describe the bug StackOverflowError is thrown for a specific mixture model fitted on a Gaussian dataset. Please note, sometimes, it may not throw for the given example, but it throws most of the time.

Expected behavior Expected mixture model's fit not to throw StackOverflowError on a Gaussian dataset generated by smile.

Actual behavior MixtureModelsTest ABORTED java.lang.StackOverflowError: at smile.math.special.Gamma.gamma(Gamma.java:84) at smile.math.special.Gamma.gamma(Gamma.java:84) at smile.math.special.Gamma.gamma(Gamma.java:84) at smile.math.special.Gamma.gamma(Gamma.java:84) at smile.math.special.Gamma.gamma(Gamma.java:84)

Code snippet

    val xs = (for _ <- 1 to 1000 yield GaussianDistribution(10.0, 5.0).rand()).filter(_ > 0).toArray
    val distributions = List(Gamma Distribution(0.0005, 1.0185))
    val priori = 1.0 / distributions.length
    val components =
      distributions.map { dist =>
        new Mixture.Component(priori, dist)
      }
    val kernel =
      ExponentialFamilyMixture.fit(
        xs,
        components: _*
      )

Input data val xs = (for <- 1 to 1000 yield GaussianDistribution(10.0, 5.0).rand()).filter( > 0).toArray

Additional context

haifengl commented 1 year ago

There is only one component in the mixture, which doesn't make sense for mixture models.