• Stars
    star
    67
  • Rank 447,261 (Top 10 %)
  • Language
    Julia
  • License
    Other
  • Created over 9 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Restricted Boltzmann Machines in Julia

Boltzmann.jl

Build Status codecov.io

Restricted Boltzmann machines and deep belief networks in Julia

Installation

Pkg.add("Boltzmann")

installing latest development version:

Pkg.clone("https://github.com/dfdx/Boltzmann.jl")

RBM Basic Usage

Train RBM:

using Boltzmann

X = randn(100, 2000)    # 2000 observations (examples) 
                        #  with 100 variables (features) each
X = (X + abs(minimum(X))) / (maximum(X) - minimum(X)) # scale X to [0..1]
rbm = GRBM(100, 50)     # define Gaussian RBM with 100 visible (input) 
                        #  and 50 hidden (output) variables
fit(rbm, X)             # fit model to data 

(for more meaningful dataset see MNIST Example)

After model is fitted, you can extract learned coefficients (a.k.a. weights):

W = coef(rbm)

transform data vectors into new higher-level representation (e.g. for further classification):

Xt = transform(rbm, X)  # vectors of X have length 100, vectors of Xt - length 50

or generate vectors similar to given ones (e.g. for recommendation, see example here)

x = ... 
x_new = generate(rbm, x)

RBMs can handle both - dense and sparse arrays. It cannot, however, handle DataArrays because it's up to application how to treat missing values.

RBM Kinds

This package provides implementation of the 2 most popular kinds of restricted Boltzmann machines:

  • BernoulliRBM: RBM with binary visible and hidden units
  • GRBM: RBM with Gaussian visible and binary hidden units

Bernoulli RBM is classic one and works great for modeling binary (e.g. like/dislike) and nearly binary (e.g. logistic-based) data. Gaussian RBM works better when visible variables approximately follow normal distribution, which is often the case e.g. for image data.

Deep Belief Networks

DBNs are created as a stack of named RBMs. Below is an example of training DBN for MNIST dataset:

using Boltzmann
using MNIST

X, y = traindata()
X = X[:, 1:1000]                     # take only 1000 observations for speed
X = X / (maximum(X) - (minimum(X)))  # normalize to [0..1]

layers = [("vis", GRBM(784, 256)),
          ("hid1", BernoulliRBM(256, 100)),
          ("hid2", BernoulliRBM(100, 100))]
dbn = DBN(layers)
fit(dbn, X)
transform(dbn, X)

Deep Autoencoders

Once built, DBN can be converted into a deep autoencoder. Continuing previous example:

dae = unroll(dbn)

DAEs cannot be trained directly, but can be used to transform input data:

transform(dae, X)

In this case output will have the same dimensionality as input, but with a noise removed.

Integration with Mocha

Mocha.jl is an excellent deep learning framework implementing auto-encoders and a number of fine-tuning algorithms. Boltzmann.jl allows to save pretrained model in a Mocha-compatible file format to be used later on for supervised learning. Below is a snippet of the essential API, while complete code is available in Mocha Export Example:

# pretraining and exporting in Boltzmann.jl
dbn_layers = [("vis", GRBM(100, 50)),
              ("hid1", BernoulliRBM(50, 25)),
              ("hid2", BernoulliRBM(25, 20))]
dbn = DBN(dbn_layers)
fit(dbn, X)
save_params(DBN_PATH, dbn)

# loading in Mocha.jl
backend = CPUBackend()
data = MemoryDataLayer(tops=[:data, :label], batch_size=500, data=Array[X, y])
vis = InnerProductLayer(name="vis", output_dim=50, tops=[:vis], bottoms=[:data])
hid1 = InnerProductLayer(name="hid1", output_dim=25, tops=[:hid1], bottoms=[:vis])
hid2 = InnerProductLayer(name="hid2", output_dim=20, tops=[:hid2], bottoms=[:hid1])
loss = SoftmaxLossLayer(name="loss",bottoms=[:hid2, :label])
net = Net("TEST", backend, [data, vis, hid1, hid2])

h5open(DBN_PATH) do h5
    load_network(h5, net)
end

More Repositories

1

Spark.jl

Julia binding for Apache Spark
Julia
200
star
2

Yota.jl

Reverse-mode automatic differentiation in Julia
Julia
157
star
3

Avalon.jl

Starter kit for legendary models
Julia
106
star
4

Espresso.jl

Expression transformation package
Julia
55
star
5

Ghost.jl

The Code Tracer
Julia
47
star
6

Lilith.jl

Renamed to Avalon.jl
Jupyter Notebook
44
star
7

HQDL.jl

Curated list of high-quality operators for deep learning in Julia
Julia
38
star
8

RDKafka.jl

Wrapper for librdkafka
Julia
36
star
9

Umlaut.jl

The Code Tracer
Julia
30
star
10

XDiff.jl

eXpression differentiation in Julia
Julia
28
star
11

flatparser

Flat feature extractor for some major real estate web sites in Moscow, St Petersburg and Minsk
Clojure
28
star
12

NaiveBayes.jl

Naive Bayes classifier
Julia
25
star
13

Kafka.jl

Client for Apache Kafka in Julia
Julia
16
star
14

PiecewiseAffineTransforms.jl

Smooth image transformations for complex shapes
Julia
11
star
15

ActiveAppearanceModels.jl

Active Appearance Models
Julia
8
star
16

cdbn

Convolutional DBN
Python
7
star
17

VariationalAE.jl

Variational Autoencoder in Julia
Julia
6
star
18

FaceDatasets.jl

Simple(r) access to face-related datasets
Julia
3
star
19

XGrad.jl

eXpression gradients in Julia
Julia
3
star
20

masque

Experiments on Deep Learning and Emotion Classification
Python
3
star
21

Faceless.jl

Facial emotion recognition from an image
Julia
2
star
22

lastfm-rbm

Example of using RBM for analysis of Last.fm data
Julia
2
star
23

Milk.jl

Machine Learning Toolkit
Julia
2
star
24

RealNVP.jl

Implementation of RealNVP in Julia
Julia
2
star
25

Zen.jl

Tracing-based AutoDiff for Julia
Julia
2
star
26

Leto.jl

2
star
27

nginx-julia-module

C
2
star
28

clinch

Clojure library for semantic classification
Clojure
2
star
29

Remix.jl

Deep learning primitives, restricted and robust
Julia
2
star
30

Discourse.jl

Discourse API Client
Julia
2
star
31

IncDataStats.jl

Data structures for aggregating statistics over very large data sets
Julia
1
star
32

flavorite

Simple item-based recommender engine
Python
1
star
33

CCV.jl

Wrapper for libccv
Julia
1
star
34

profile-matcher

Profile Matcher
HTML
1
star
35

vtk.by

vingtsunkuen.by
JavaScript
1
star
36

Stuff.jl

Code snippets, no special goal, not maintained and not taken seriously
Julia
1
star
37

PackageTracker.jl

Julia
1
star
38

SESync.jl

Julia
1
star
39

emacs-config

My init.el and related files
Emacs Lisp
1
star
40

Dlib.jl

Julia wrapper for dlib, a modern C++ toolkit for machine learning
Julia
1
star
41

Graphite.jl

Graphite client for Julia
Julia
1
star
42

RDKafka.jl.deps

Julia
1
star
43

YotaTracked.jl

Version of Yota.jl based on tracked data types
Julia
1
star
44

PokeDB.jl

Database suitable for nothing but exports
Julia
1
star
45

Woody.jl

Simple load testing in Julia
Julia
1
star
46

JavaCoreNLP.jl

Julia
1
star
47

dfdx.github.io

df/dx
JavaScript
1
star
48

foodie

Python
1
star