JuliaGaussianProcesses / KernelFunctions.jl

Julia package for kernel functions for machine learning
https://juliagaussianprocesses.github.io/KernelFunctions.jl/stable/
MIT License
267 stars 32 forks source link

Independent mokernel failing numerical equality test randomly #494

Open mjp98 opened 1 year ago

mjp98 commented 1 year ago

Testing locally on 1.8.5, I find that https://github.com/JuliaGaussianProcesses/KernelFunctions.jl/blob/master/test/mokernels/independent.jl#L17 occasionally fails,

independent: Test Failed at .../KernelFunctions.jl/test/mokernels/independent.jl:17
  Expression: kernelmatrix(k, x, y) == kernelmatrix(k, collect(x), collect(y))
      Evaluated: [0.6308251776147069 0.7710805544766418 … 0.0 0.0; 0.7662058489033383 0.6549773138194038 … 0.0 0.0; … ; 0.0 0.0 … 0.5723057547891549 0.4955933062398087; 0.0 0.0 … 0.7238376039335678 0.45712391842322964] == [0.6308251776147069 0.7710805544766418 … 0.0 0.0; 0.7662058489033383 0.6549773138194038 … 0.0 0.0; … ; 0.0 0.0 … 0.5723057547891549 0.4955933062398087; 0.0 0.0 … 0.7238376039335678 0.45712391842322964]

presumably due to some floating point error. The input matrices are set randomly:

    x = KernelFunctions.MOInputIsotopicByOutputs([rand(5) for _ in 1:4], outdim)
    y = KernelFunctions.MOInputIsotopicByOutputs([rand(5) for _ in 1:4], outdim)
    z = KernelFunctions.MOInputIsotopicByOutputs([rand(5) for _ in 1:2], outdim)

It may be worth adding a seed (maybe with StableRNGs.jl?) so this is consistent across runs, and only testing equality up to a sensible numerical tolerance

willtebbutt commented 1 year ago

Definitely. This looks like a test we shouldn't have written. I'll make a PR with the changes now.

willtebbutt commented 1 year ago

495 should resolve