Open mmikhasenko opened 1 year ago
gauss
on randn()
using AlgebraPDF
#
gauss = FGauss((μ=2.4, σ=1.3)) |> Normalized((-10.0, 10.0))
data = randn(10_000)
nll = NegativeLogLikelihood(gauss, data)
Now, calling the function with four different signatures
@btime nll(1.1)
@btime nll(1.1, [2.4, 1.3])
@btime nll(1.1; p=(μ=2.4, σ=1.3))
@btime nll(1.1; p=(σ=1.3, μ=2.4))
gives the same result and takes about 200us
195.200 μs (135 allocations: 159.16 KiB)
197.300 μs (144 allocations: 159.47 KiB)
196.900 μs (135 allocations: 159.16 KiB)
197.700 μs (135 allocations: 159.16 KiB)
Roughly same time when using FlaggedNamedTuple
for parameters
gauss = FGauss(Ext(μ=2.4, σ=1.3)) |> Normalized((-10.0, 10.0))
213.200 μs (165 allocations: 160.39 KiB)
206.500 μs (175 allocations: 160.77 KiB)
201.800 μs (156 allocations: 159.98 KiB)
202.100 μs (156 allocations: 159.98 KiB)
interestingly, code_warntype
indicated some problems of input arguments
MethodInstance for (::NegativeLogLikelihood{Normalized{FGauss{FlaggedNamedTuple{(:μ, :σ)}}, Tuple{Float64, Float64}}, Vector{Float64}})(::Float64)
from (d::AbstractFunctionWithParameters)(x; p) in AlgebraPDF at Documents\AlgebraPDF.jl\src\functionwithparameters.jl:15
Arguments
d::NegativeLogLikelihood{Normalized{FGauss{FlaggedNamedTuple{(:μ, :σ)}}, Tuple{Float64, Float64}}, Vector{Float64}}
x::Float64
Body::Any
1 ─ %1 = AlgebraPDF.freepars(d)::Any
│ %2 = AlgebraPDF.:(var"#_#4")(%1, d, x)::Any
└── return %2
The repository misses check of performance. Some tests should be added.