public abstract class BaseNeuralNetwork extends Object implements NeuralNetwork, Persistable
DBN
Modifier and Type | Class and Description |
---|---|
static class |
BaseNeuralNetwork.Builder<E extends BaseNeuralNetwork> |
NeuralNetwork.LossFunction, NeuralNetwork.OptimizationAlgorithm
Modifier and Type | Field and Description |
---|---|
protected boolean |
applySparsity |
protected org.apache.commons.math3.distribution.RealDistribution |
dist |
protected org.jblas.DoubleMatrix |
doMask |
protected double |
dropOut |
protected double |
fanIn |
protected boolean |
firstTimeThrough |
protected List<NeuralNetworkGradientListener> |
gradientListeners |
protected org.jblas.DoubleMatrix |
hBias |
protected AdaGrad |
hBiasAdaGrad |
protected org.jblas.DoubleMatrix |
input |
protected double |
l2 |
protected NeuralNetwork.LossFunction |
lossFunction |
protected double |
momentum |
protected int |
nHidden
Number of hidden units
One tip with this is usually having
more hidden units than inputs (read: input rows here)
will typically cause terrible overfitting.
|
protected boolean |
normalizeByInputRows |
int |
nVisible |
protected NeuralNetwork.OptimizationAlgorithm |
optimizationAlgo |
protected NeuralNetworkOptimizer |
optimizer |
protected int |
renderWeightsEveryNumEpochs |
protected org.apache.commons.math3.random.RandomGenerator |
rng |
protected double |
sparsity |
protected boolean |
useAdaGrad |
protected boolean |
useRegularization |
protected org.jblas.DoubleMatrix |
vBias |
protected AdaGrad |
vBiasAdaGrad |
protected org.jblas.DoubleMatrix |
W |
protected AdaGrad |
wAdaGrad |
Modifier | Constructor and Description |
---|---|
protected |
BaseNeuralNetwork() |
|
BaseNeuralNetwork(org.jblas.DoubleMatrix input,
int nVisible,
int nHidden,
org.jblas.DoubleMatrix W,
org.jblas.DoubleMatrix hbias,
org.jblas.DoubleMatrix vbias,
org.apache.commons.math3.random.RandomGenerator rng,
double fanIn,
org.apache.commons.math3.distribution.RealDistribution dist) |
|
BaseNeuralNetwork(int nVisible,
int nHidden,
org.jblas.DoubleMatrix W,
org.jblas.DoubleMatrix hbias,
org.jblas.DoubleMatrix vbias,
org.apache.commons.math3.random.RandomGenerator rng,
double fanIn,
org.apache.commons.math3.distribution.RealDistribution dist) |
Modifier and Type | Method and Description |
---|---|
protected void |
applyDropOutIfNecessary(org.jblas.DoubleMatrix input) |
protected void |
applySparsity(org.jblas.DoubleMatrix hBiasGradient,
double learningRate)
Applies sparsity to the passed in hbias gradient
|
NeuralNetwork |
clone() |
double |
dropOut() |
void |
epochDone(int epoch)
Event listener for each iteration
|
double |
fanIn() |
AdaGrad |
getAdaGrad() |
org.apache.commons.math3.distribution.RealDistribution |
getDist() |
List<NeuralNetworkGradientListener> |
getGradientListeners() |
org.jblas.DoubleMatrix |
gethBias() |
AdaGrad |
gethBiasAdaGrad() |
org.jblas.DoubleMatrix |
getInput() |
double |
getL2() |
NeuralNetwork.LossFunction |
getLossFunction() |
double |
getMomentum() |
int |
getnHidden() |
int |
getnVisible() |
NeuralNetwork.OptimizationAlgorithm |
getOptimizationAlgorithm() |
double |
getReConstructionCrossEntropy()
Reconstruction entropy.
|
int |
getRenderEpochs() |
org.apache.commons.math3.random.RandomGenerator |
getRng() |
double |
getSparsity() |
org.jblas.DoubleMatrix |
getvBias() |
AdaGrad |
getVBiasAdaGrad() |
org.jblas.DoubleMatrix |
getW() |
org.jblas.DoubleMatrix |
hBiasMean() |
protected void |
initWeights()
Initialize weights.
|
void |
jostleWeighMatrix() |
double |
l2RegularizedCoefficient() |
void |
load(InputStream is)
Load (using
ObjectInputStream |
double |
lossFunction() |
abstract double |
lossFunction(Object[] params)
The loss function (cross entropy, reconstruction error,...)
|
void |
merge(NeuralNetwork network,
int batchSize)
Performs a network merge in the form of
a += b - a / n
where a is a matrix here
b is a matrix on the incoming network
and n is the batch size
|
double |
negativeLogLikelihood()
Negative log likelihood of the current input given
the corruption level
|
double |
negativeLoglikelihood(org.jblas.DoubleMatrix input)
Negative log likelihood of the current input given
the corruption level
|
boolean |
normalizeByInputRows() |
abstract org.jblas.DoubleMatrix |
reconstruct(org.jblas.DoubleMatrix x)
All neural networks are based on this idea of
minimizing reconstruction error.
|
void |
resetAdaGrad(double lr) |
void |
setAdaGrad(AdaGrad adaGrad) |
void |
setDist(org.apache.commons.math3.distribution.RealDistribution dist) |
void |
setDropOut(double dropOut) |
void |
setFanIn(double fanIn) |
void |
setGradientListeners(List<NeuralNetworkGradientListener> gradientListeners) |
void |
sethBias(org.jblas.DoubleMatrix hBias) |
void |
setHbiasAdaGrad(AdaGrad adaGrad) |
void |
setInput(org.jblas.DoubleMatrix input) |
void |
setL2(double l2) |
void |
setLossFunction(NeuralNetwork.LossFunction lossFunction) |
void |
setMomentum(double momentum) |
void |
setnHidden(int nHidden) |
void |
setnVisible(int nVisible) |
void |
setOptimizationAlgorithm(NeuralNetwork.OptimizationAlgorithm optimizationAlgorithm) |
void |
setRenderEpochs(int renderEpochs) |
void |
setRng(org.apache.commons.math3.random.RandomGenerator rng) |
void |
setSparsity(double sparsity) |
void |
setvBias(org.jblas.DoubleMatrix vBias) |
void |
setVBiasAdaGrad(AdaGrad adaGrad) |
void |
setW(org.jblas.DoubleMatrix w) |
double |
squaredLoss() |
abstract void |
train(org.jblas.DoubleMatrix input,
double lr,
Object[] params)
Train one iteration of the network
|
NeuralNetwork |
transpose() |
protected void |
triggerGradientEvents(NeuralNetworkGradient gradient)
Triggers network gradient listeners.
|
void |
update(BaseNeuralNetwork n)
Copies params from the passed in network
to this one
|
protected void |
updateGradientAccordingToParams(NeuralNetworkGradient gradient,
double learningRate)
Update the gradient according to the configuration such as adagrad, momentum, and sparsity
|
void |
write(OutputStream os)
Write this to an object output stream
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getGradient, sampleHiddenGivenVisible, sampleVisibleGivenHidden, trainTillConvergence
public int nVisible
protected int nHidden
protected org.jblas.DoubleMatrix W
protected org.jblas.DoubleMatrix hBias
protected org.jblas.DoubleMatrix vBias
protected org.apache.commons.math3.random.RandomGenerator rng
protected org.jblas.DoubleMatrix input
protected double sparsity
protected double momentum
protected transient org.apache.commons.math3.distribution.RealDistribution dist
protected double l2
protected transient NeuralNetworkOptimizer optimizer
protected int renderWeightsEveryNumEpochs
protected double fanIn
protected boolean useRegularization
protected boolean useAdaGrad
protected boolean firstTimeThrough
protected boolean normalizeByInputRows
protected boolean applySparsity
protected List<NeuralNetworkGradientListener> gradientListeners
protected double dropOut
protected org.jblas.DoubleMatrix doMask
protected NeuralNetwork.OptimizationAlgorithm optimizationAlgo
protected NeuralNetwork.LossFunction lossFunction
protected AdaGrad wAdaGrad
protected AdaGrad hBiasAdaGrad
protected AdaGrad vBiasAdaGrad
protected BaseNeuralNetwork()
public BaseNeuralNetwork(int nVisible, int nHidden, org.jblas.DoubleMatrix W, org.jblas.DoubleMatrix hbias, org.jblas.DoubleMatrix vbias, org.apache.commons.math3.random.RandomGenerator rng, double fanIn, org.apache.commons.math3.distribution.RealDistribution dist)
nVisible
- the number of outbound nodesnHidden
- the number of nodes in the hidden layerW
- the weights for this vector, maybe null, if so this will
create a matrix with nHidden x nVisible dimensions.hBias
- the hidden biasvBias
- the visible bias (usually b for the output layer)rng
- the rng, if not a seed of 1234 is used.public BaseNeuralNetwork(org.jblas.DoubleMatrix input, int nVisible, int nHidden, org.jblas.DoubleMatrix W, org.jblas.DoubleMatrix hbias, org.jblas.DoubleMatrix vbias, org.apache.commons.math3.random.RandomGenerator rng, double fanIn, org.apache.commons.math3.distribution.RealDistribution dist)
input
- the input examplesnVisible
- the number of outbound nodesnHidden
- the number of nodes in the hidden layerW
- the weights for this vector, maybe null, if so this will
create a matrix with nHidden x nVisible dimensions.hBias
- the hidden biasvBias
- the visible bias (usually b for the output layer)rng
- the rng, if not a seed of 1234 is used.public double l2RegularizedCoefficient()
l2RegularizedCoefficient
in interface NeuralNetwork
protected void initWeights()
public void resetAdaGrad(double lr)
resetAdaGrad
in interface NeuralNetwork
public List<NeuralNetworkGradientListener> getGradientListeners()
getGradientListeners
in interface NeuralNetwork
public void setGradientListeners(List<NeuralNetworkGradientListener> gradientListeners)
setGradientListeners
in interface NeuralNetwork
public void setRenderEpochs(int renderEpochs)
setRenderEpochs
in interface NeuralNetwork
public int getRenderEpochs()
getRenderEpochs
in interface NeuralNetwork
public double fanIn()
fanIn
in interface NeuralNetwork
public void setFanIn(double fanIn)
setFanIn
in interface NeuralNetwork
public void jostleWeighMatrix()
protected void applySparsity(org.jblas.DoubleMatrix hBiasGradient, double learningRate)
hBiasGradient
- the hbias gradient to apply tolearningRate
- the learning rate usedprotected void updateGradientAccordingToParams(NeuralNetworkGradient gradient, double learningRate)
gradient
- the gradient to modifylearningRate
- the learning rate for the current iteratiaonprotected void triggerGradientEvents(NeuralNetworkGradient gradient)
gradient
- the gradient that triggered the eventpublic void setDropOut(double dropOut)
setDropOut
in interface NeuralNetwork
public double dropOut()
dropOut
in interface NeuralNetwork
public AdaGrad getAdaGrad()
getAdaGrad
in interface NeuralNetwork
public void setAdaGrad(AdaGrad adaGrad)
setAdaGrad
in interface NeuralNetwork
public NeuralNetwork transpose()
transpose
in interface NeuralNetwork
public NeuralNetwork clone()
clone
in interface NeuralNetwork
clone
in class Object
public NeuralNetwork.LossFunction getLossFunction()
getLossFunction
in interface NeuralNetwork
public void setLossFunction(NeuralNetwork.LossFunction lossFunction)
setLossFunction
in interface NeuralNetwork
public NeuralNetwork.OptimizationAlgorithm getOptimizationAlgorithm()
getOptimizationAlgorithm
in interface NeuralNetwork
public void setOptimizationAlgorithm(NeuralNetwork.OptimizationAlgorithm optimizationAlgorithm)
setOptimizationAlgorithm
in interface NeuralNetwork
public org.apache.commons.math3.distribution.RealDistribution getDist()
getDist
in interface NeuralNetwork
public void setDist(org.apache.commons.math3.distribution.RealDistribution dist)
setDist
in interface NeuralNetwork
public void merge(NeuralNetwork network, int batchSize)
NeuralNetwork
merge
in interface NeuralNetwork
network
- the network to merge withbatchSize
- the batch size (number of training examples)
to average bypublic void update(BaseNeuralNetwork n)
n
- the network to copypublic void load(InputStream is)
ObjectInputStream
load
in interface Persistable
is
- the input stream to load from (usually a file)public double negativeLogLikelihood()
negativeLogLikelihood
in interface NeuralNetwork
corruptionLevel
- the corruption level to usepublic double negativeLoglikelihood(org.jblas.DoubleMatrix input)
public double getReConstructionCrossEntropy()
getReConstructionCrossEntropy
in interface NeuralNetwork
public boolean normalizeByInputRows()
normalizeByInputRows
in interface NeuralNetwork
public int getnVisible()
getnVisible
in interface NeuralNetwork
public void setnVisible(int nVisible)
setnVisible
in interface NeuralNetwork
public int getnHidden()
getnHidden
in interface NeuralNetwork
public void setnHidden(int nHidden)
setnHidden
in interface NeuralNetwork
public org.jblas.DoubleMatrix getW()
getW
in interface NeuralNetwork
public void setW(org.jblas.DoubleMatrix w)
setW
in interface NeuralNetwork
public org.jblas.DoubleMatrix gethBias()
gethBias
in interface NeuralNetwork
public void sethBias(org.jblas.DoubleMatrix hBias)
sethBias
in interface NeuralNetwork
public org.jblas.DoubleMatrix getvBias()
getvBias
in interface NeuralNetwork
public void setvBias(org.jblas.DoubleMatrix vBias)
setvBias
in interface NeuralNetwork
public org.apache.commons.math3.random.RandomGenerator getRng()
getRng
in interface NeuralNetwork
public void setRng(org.apache.commons.math3.random.RandomGenerator rng)
setRng
in interface NeuralNetwork
public org.jblas.DoubleMatrix getInput()
getInput
in interface NeuralNetwork
public void setInput(org.jblas.DoubleMatrix input)
setInput
in interface NeuralNetwork
public double getSparsity()
getSparsity
in interface NeuralNetwork
public void setSparsity(double sparsity)
setSparsity
in interface NeuralNetwork
public double getMomentum()
getMomentum
in interface NeuralNetwork
public void setMomentum(double momentum)
setMomentum
in interface NeuralNetwork
public double getL2()
getL2
in interface NeuralNetwork
public void setL2(double l2)
setL2
in interface NeuralNetwork
public AdaGrad gethBiasAdaGrad()
gethBiasAdaGrad
in interface NeuralNetwork
public void setHbiasAdaGrad(AdaGrad adaGrad)
setHbiasAdaGrad
in interface NeuralNetwork
public AdaGrad getVBiasAdaGrad()
getVBiasAdaGrad
in interface NeuralNetwork
public void setVBiasAdaGrad(AdaGrad adaGrad)
setVBiasAdaGrad
in interface NeuralNetwork
public void write(OutputStream os)
write
in interface Persistable
os
- the output stream to write topublic abstract org.jblas.DoubleMatrix reconstruct(org.jblas.DoubleMatrix x)
x
- the input to reconstructpublic abstract double lossFunction(Object[] params)
public double lossFunction()
protected void applyDropOutIfNecessary(org.jblas.DoubleMatrix input)
public abstract void train(org.jblas.DoubleMatrix input, double lr, Object[] params)
train
in interface NeuralNetwork
input
- the input to train onlr
- the learning rate to train atparams
- the extra params (k, corruption level,...)public double squaredLoss()
squaredLoss
in interface NeuralNetwork
public org.jblas.DoubleMatrix hBiasMean()
hBiasMean
in interface NeuralNetwork
public void epochDone(int epoch)
NeuralNetEpochListener
epochDone
in interface NeuralNetwork
epochDone
in interface NeuralNetEpochListener
Copyright © 2014. All Rights Reserved.