Code Monkey home page Code Monkey logo

gradnite's Introduction

Gradnite Gradnite

A simple Autograd engine written in Crystal.

Usage

Add Gradnite to your shard.yml and run shards install:

dependencies:
  gradnite:
    github: lucianbuzzo/gradnite
    version: 0.1.0

You can now require the module and use it's classes:

# require the gradnite module
require "gradnite"

# create a new Node
node = Gradnite::Node.new(1.0)

# add two nodes together
node = Gradnite::Node.new(1.0) + Gradnite::Node.new(2.0)

# multiply two nodes together
node = Gradnite::Node.new(1.0) * Gradnite::Node.new(2.0)

# divide two nodes together
node = Gradnite::Node.new(1.0) / Gradnite::Node.new(2.0)

# create a Neuron with 4 inputes
neuron = Gradnite::Neuron.new(4)

# create an MLP with 2 inputs, 2 hidden layers of 3 neurons each and 1 output
mlp = Gradnite::MLP.new(2, [3, 3, 1])

# run a forward pass on the mlp
mlp.forward([1.0, 2.0])

# run back propagation on the mlp
mlp.backward

# update the weights of the mlp
mlp.parameters.each { |p|
    p.value += -0.1 * p.grad
}

Gradnite also includes a utility for visualizing the computation graph of a neural network using graphviz. To use it, make sure you have graphviz installed locally and call the draw_dot function with a node:

a = Gradnite::Node.new value: 1.0, label: "a"
b = Gradnite::Node.new value: 2.0, label: "b"
c = a * b
c.label = "c"

Gradnite::draw_dot(c, "examples/multiply.dot")

You can now generate a png image of the computation graph using the dot command:

dot -Tpng examples/multiply.dot -o examples/multiply.png

For more examples of usage see the examples directory.

Development

Install prerequisites:

brew install crystal watchexec graphviz

Run in watch mode:

./watch.sh examples/binary_classifier.cr

gradnite's People

Contributors

lucianbuzzo avatar

Watchers

 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.