Coder Social home page Coder Social logo

k9's Introduction

k9

A small library using core.matrix to construct Neural Networks

Usage

Construct simple 3 layer networks with

(construct-network n-inputs n-hiddens n-ouputs)

Example

(construct-network 2 3 2)
;=> [ [0 0] [input-to-hidden-strengths] [0 0 0] [hidden-to-output-strengths] [0 0]]

Feed foward input and get back output neuron values with

(ff input network)

Example

(ff [1 0] (construct-network 2 3 2));=>[0.023969361623158485 0.014886788800864243]

Train the network on data in the form of [[input target] [input target] ... ] => returns a new network

(train-data network data learning-rate)

Example

(def nn (construct-network 2 3 2))
#'user/nn
;; without training
(ff [1 0] nn) ;=> [0.03061049829949632 0.043037351551821625]
(def n1 (train-data nn  [
                         [[1 0] [0 1]]
                         [[0.5 0] [0 0.5]]
                         [[0.25 0] [0 0.25]]]
                     0.2))
(ff [1 0] n1) 
;=> [0.0383350329723964 0.06845383345543034]

Another example

(defn inverse-data []
  (let [n (rand 1)]
    [[n 0] [0 n]]))

(def n3 (train-data nn (repeatedly 400 inverse-data) 0.5))

(ff [1 0] n3) ;=> [-3.0872502374300364E-4 0.8334331107408276]

Can also train the network repeatedly on a set of data for "epochs"

(train-epochs n network training-data learning-rate)

Example

(def n4 (train-epochs 5 nn (repeatedly 200 inverse-data) 0.2))
(ff [1 0] n4) ;=> [-3.794899940782748E-4 0.8105184486966243

Example with Colors

There is another example in the examples directory where the network learns to name colors based on their rgb value.

Blog Post

I made a blog post about making a simple neural network with an example here: Blog

License

Copyright © 2013 Carin Meier

Distributed under the Eclipse Public License, the same as Clojure

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.