Coder Social home page Coder Social logo

evidentialflux.jl's Introduction

EvidentialFlux

Documentation SciML Code Style format-check DOI

This is a Julia implementation in Flux of the Evidential Deep Learning framework. It strives to estimate heteroskedastic aleatoric uncertainty as well as epistemic uncertainty along with every prediction made. All of it calculated in one glorious forward pass. Boom!

Installing

If you want bleeding edge you can install it directly from my repo like this:

using Pkg; Pkg.add(url="https://github.com/DoktorMike/EvidentialFlux.jl")

Otherwise just do

using Pkg; Pkg.add("EvidentialFlux.jl")

For the impatient

Below is an example of how to train Deep Evidential Regression model, extract the predictions as well as the epistemic and aleatoric uncertainty. For a more elaborate example have a look in the examples folder.

using Flux
using EvidentialFlux

x = Float32.(-4:0.1:4)
y = x .^3 .+ randn(Float32, length(x)) .* 3

lr = 0.0005
m = Chain(Dense(1 => 100, relu), Dense(100 => 100, relu), Dense(100 => 100, relu), NIG(100 => 1))
opt = AdamW(lr, (0.89, 0.995), 0.001)
pars = Flux.params(m)
for epoch in 1:500
    grads = Flux.gradient(pars) do= m(x') 
        γ, ν, α, β = ŷ[1, :], ŷ[2, :], ŷ[3, :], ŷ[4, :]
        trnloss = Statistics.mean(nigloss2(y, γ, ν, α, β, 0.01, 2))
        trnloss
    end
    Flux.Optimise.update!(opt, pars, grads)
end

γ, ν, α, β = predict(m, x)
eu = epistemic(ν)
au = aleatoric(ν, α, β)

Classification

Deep evidential modeling works for classification as well as for regression. In the plot below you can see the epistemic uncertainty as a consequence of position in the plot. The task is to separate three Gaussians in 2D. The code for this example can be found in classification.jl.

uncertainty

Regression

In the case of a regression problem we utilize the NormalInverseGamma distribution to model a type II likelihood function that then explicitely models the aleatoric and epistemic uncertainty. The code for the example producing the plot below can be found in regression.jl.

uncertainty

Summary

Uncertainty is crucial for the deployment and utilization of robust machine learning in production. No model is perfect and each one of them have their own strengths and weaknesses, but as a minimum requirement we should all at least demand that our models report uncertainty in every prediction.

evidentialflux.jl's People

Contributors

doktormike avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.