Giter VIP home page Giter VIP logo

enclog's Introduction

enclog

Clojure wrapper for the encog (v3) machine-learning framework .

-from the official encog website:

"Encog is an open source Machine Learning framework for both Java and DotNet. Encog is primarily focused on neural networks and bot programming. It allows you to create many common neural network forms, such as feedforward perceptrons, self organizing maps, Adaline, bidirectional associative memory, Elman, Jordan and Hopfield networks and offers a variety of training schemes."

-from me:

Encog has been around for almost 5 years, and so can be considered fairly mature and optimised. Apart from neural-nets, version 3 introduced SVM and Bayesian classification. With this library, which is a thin wrapper around encog, you can construct and train many types of neural nets in less than 10 lines of pure Clojure code. The whole idea, from the start, was to expose the user as little as possible to the Java side of things, thus eliminating any potential sharp edges of a rather big librabry like encog. Hopefully I've done a good job...feel free to try it out, and more importantly, feel free to drop any comments/opinions/advice/critique etc etc...

P.S.: This is still work in progress. Nonetheless the neural nets, training methods,randomization and normalisation are pretty much complete - what's left at this point is the bayesian stuff if I'm not mistaken...aaaa also I'm pretty sure we need tests :) ...

Usage

The jar(s)?

Clojars Project

Quick demo:

-quick & dirty: (need lein2)

(use '[cemerick.pomegranate :only (add-dependencies)])
(add-dependencies :coordinates '[[enclog "0.6.3"]] 
                  :repositories (merge cemerick.pomegranate.aether/maven-central {"clojars" "http://clojars.org/repo"}))
(use '[enclog nnets training])

Ok, most the networks are already functional so let's go ahead and make one. Let's assume that for some reason we need a feed-forward net with 2 input neurons, 1 output neuron (classification), and 1 hidden layer with 2 neurons for the XOR problem.

(def net  
    (network  (neural-pattern :feed-forward) 
               :activation :sigmoid 
               :input   2
               :output  1
               :hidden [2])) ;;a single hidden layer 
                                    

...and voila! we get back the complete network initialised with random weights.

Most of the constructor-functions (make-something) accept keyword based arguments. For the full list of options refer to documentation or source code. Don't worry if you accidentaly pass in wrong parameters to a network e.g wrong activation function for a specific net-type. Each concrete implementation of the 'network' multi-method ignores arguments that are not settable by a particular neural pattern!

Of course, now that we have the network we need to train it...well, that's easy too! first we are going to need some dummy data...

(let [xor-input [[0.0 0.0] [1.0 0.0] [0.0 0.1] [1.0 1.0]]
      xor-ideal [[0.0] [1.0] [1.0] [0.0]] 
      dataset   (data :basic-dataset xor-input xor-ideal)
      trainer   (trainer :back-prop :network net :training-set dataset)]
 (train trainer 0.01 500 []))
  
;;train expects a training-method , error tolerance, iteration limit & strategies (possibly none)
;;in this case we're using simple back-propagation as our training scheme of preference.
;;feed-forward networks can be used with a variety of activations/trainers.

and that's it really! after training finishes you can start using the network as normal. For more in depth instructions consider looking at the 2 examples found in the examples.clj ns. These include the classic xor example (trained with resilient-propagation) and the lunar lander example (trained with genetic algorithm) from the from encog wiki/books.

In general you should always remember:

  • Most (if not all) of the constructor-functions (e.g. network, data, trainer etc.) accept keywords for arguments. The documentation tells you exactly what your options are. Some constructor-functions return other functions (closures) which then need to be called again with potentially extra arguments, in order to get the full object.

  • 'network' is a big multi-method that is responsible for looking at what type of neural pattern has been passed in and dispatching the appropriate method. This is the 'spine' of creating networks with enclog.

  • NeuroEvolution of Augmenting Topologies (NEAT) don't need to be initialised as seperate networks like all other networks do. Instead, we usually initialise a NEATPopulation which we then pass to NEATTraining via

(trainer :neat :fitness-fn #(...) :population-object (NEATPopulation. 2 1 1000)) ;;settable population object
(trainer :neat :fitness-fn #(...) :input 2 :output 1 :population-size 1000)  ;;a brand new population with default parameters
  • Simple convenience functions do exist for evaluating quickly a trained network and also for implementing the CalculateScore class which is needed for doing GA or simulated-annealing training.

  • Ideally, check the source when any 'strange' error occurs. You don't even have to go online - it's in the jar!

Notes

This project is no longer under active development.

License

Copyright © 2012 Dimitrios Piliouras

Distributed under the Eclipse Public License, the same as Clojure.

enclog's People

Contributors

jimpil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

enclog's Issues

there is a bug in v0.6.5

(ns resilient.core
  ;;(:use incanter.core)
  (:use [enclog nnets training])
  (:gen-class))

(defn round-output
  "Round outputs to nearest integer."
  [output]
  (mapv #(Math/round ^Double %) output))

(def dataset
  (let [xor-input [[0.0 0.0] [1.0 0.0] [0.0 1.0] [1.0 1.0]]
        xor-ideal [[0.0]     [1.0]     [1.0]     [0.0]]]
        (data :basic-dataset xor-input xor-ideal)))

(defn train-network [network data trainer-algo]
  (let [trainer (trainer trainer-algo
                         :network network
                         :training-set data)]
    (train trainer 0.01 10000 [])))

(def elman-network (network (neural-pattern :elman)
                             :activation :sigmoid
                             :input      2
                             :output     1
                             :hidden     [3]))

(defn run-network [network input]
  (let [input-data (data :basic input)
        output     (.compute network input-data)
        output-vec (.getData output)]
    (round-output output-vec)))

(def EN (train-network elman-network dataset :resilient-prop))

as i configure dependencies in project.clj

:dependencies [[org.clojure/clojure "1.6.0"]
                 [cc.artifice/clj-ml "0.4.0"]
                 [org.encog/encog-core "3.2.0"]
                 [enclog "0.6.5"]
                 [org.clojure/tools.namespace "0.2.5"]
                 [incanter "1.5.5"]
                 [clatrix "0.3.0"]
                 [net.mikera/core.matrix "0.27.0"]]

and the log generate from train-network function is that

Iteration # 9,978 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,979 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,980 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,981 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,982 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,983 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,984 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,985 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,986 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,987 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,988 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,989 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,990 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,991 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,992 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,993 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,994 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,995 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,996 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,997 Error: 10.879860% Target-Error: 1.000000%
Iteration # 9,998 Error: 20.051045% Target-Error: 1.000000%
Iteration # 9,999 Error: 10.879860% Target-Error: 1.000000%
Iteration # 10,000 Error: 20.051045% Target-Error: 1.000000%

as you can see after iterate to 10000 times it still get a large error...

but when i change encog-core to 3.1.0 and enclog to 0.6.3 the log when i train the elman network shows that

Iteration # 146 Error: 6.437994% Target-Error: 1.000000%
Iteration # 147 Error: 6.162065% Target-Error: 1.000000%
Iteration # 148 Error: 5.905370% Target-Error: 1.000000%
Iteration # 149 Error: 5.685170% Target-Error: 1.000000%
Iteration # 150 Error: 8.820329% Target-Error: 1.000000%
Iteration # 151 Error: 6.344310% Target-Error: 1.000000%
Iteration # 152 Error: 6.236660% Target-Error: 1.000000%
Iteration # 153 Error: 6.115702% Target-Error: 1.000000%
Iteration # 154 Error: 5.980763% Target-Error: 1.000000%
Iteration # 155 Error: 5.831186% Target-Error: 1.000000%
Iteration # 156 Error: 5.666209% Target-Error: 1.000000%
Iteration # 157 Error: 5.484842% Target-Error: 1.000000%
Iteration # 158 Error: 5.285799% Target-Error: 1.000000%
Iteration # 159 Error: 5.067628% Target-Error: 1.000000%
Iteration # 160 Error: 4.829173% Target-Error: 1.000000%
Iteration # 161 Error: 4.570456% Target-Error: 1.000000%
Iteration # 162 Error: 4.294153% Target-Error: 1.000000%
Iteration # 163 Error: 4.008254% Target-Error: 1.000000%
Iteration # 164 Error: 3.732056% Target-Error: 1.000000%
Iteration # 165 Error: 3.511699% Target-Error: 1.000000%
Iteration # 166 Error: 3.360398% Target-Error: 1.000000%
Iteration # 167 Error: 3.504944% Target-Error: 1.000000%
Iteration # 168 Error: 4.968425% Target-Error: 1.000000%
Iteration # 169 Error: 0.958797% Target-Error: 1.000000%

when iterate to 169 times and the algorithm converged

so anyone can show me how to fix the issue in enclog 0.6.5 ?

what's more i think resilient propgate algorithm did not perform as well as backpropgate algorithm :(

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.