Giter VIP home page Giter VIP logo

fluxmlstuff's Introduction

FluxMLStuff

Basic ML projects in Julia using the Flux ML library.

Introduction

Julia is a high-level, high-performance open source programming language for technical computing.

  • It is fast, it has a JIT compiler that compiles julia code to native code via LLVM at runtime
  • It is dynamically typed, feels like a scripting language and can be used interactively.
  • It is a general purpose language well suited for Data Science, Machine Learning, Parellel Computing and Scientific Domains.

Flux is a julia library for machine learning. It features:

  • Compiled eager code
  • Intuitive way to define models just like in mathematics
  • Automatic Differentiation (Differentiable Programming)
    • This means that for using gradient descent, Flux will compute the gradients by itself at runtime. We do not have to specify the details of the backpropagation step. This also means we are not limited to the standard layers. We can create our own layers with complex code (loops, if/else, even Diffrential Equation solvers!)
  • Can be used with GPUs/TPUs
  • Can be exported easily to web technologies

1. Curve Fitting using Linear/Polynomial Regression

In this one we have taken a nonlinear function, and tried to approximate it using a simple polynomial model. We can think of it either as simply curve futting using a polynomial, or Linear Regression with features x, x^2, ... etc.

The function to be aproximated:

y(x) = 5x + 2sin(5x) + 3 + 0.1 * randn()

The model:

p = param(rand(5))
model(x) = p' * (x .^ Array(0:4))
# model(x) = p1 + p2 x + p3 x^2 + p4 x^3 + p5 x^4

Training code:

for i in 1:1000
    ps = params(p)
    Flux.train!(loss, ps, zip(xs, ys), Momentum())
    # plot the model from 0 to 1
    scatter(xs, ys)
    display(plot!((x) -> (model(x).data), 0, 1))
    println("Total Loss: $(totalLoss()), p: $p")
end

Animation:

Animation

2. Multi Layer Perceptron

Again, we are fitting a curve. But this time we will fit it using a Multi Layer Perceptron with two hidden layers having 3 neurons each.

The model:

model = Chain(
    Dense(1, 3, σ),
    Dense(3, 3, σ),
    Dense(3, 1),
)

Animation: (wait for it :P ...)

Animation

fluxmlstuff's People

Contributors

krkartikay avatar

Watchers

James Cloos avatar  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.