public abstract class BaseMultiLayerNetwork extends Object implements Serializable, Persistable
Modifier and Type | Class and Description |
---|---|
static class |
BaseMultiLayerNetwork.Builder<E extends BaseMultiLayerNetwork> |
Modifier and Type | Field and Description |
---|---|
protected double |
dropOut |
double |
errorTolerance |
protected Map<Integer,List<NeuralNetworkGradientListener>> |
gradientListeners |
double |
learningRateUpdate |
protected NeuralNetwork.LossFunction |
lossFunction
Which loss function to use:
Squared loss, Reconstruction entropy, negative log likelihood
|
protected List<MultiLayerGradientListener> |
multiLayerGradientListeners |
protected boolean |
normalizeByInputRows |
protected NeuralNetwork.OptimizationAlgorithm |
optimizationAlgorithm
Which optimization algorithm to use: SGD or CG
|
Modifier | Constructor and Description |
---|---|
protected |
BaseMultiLayerNetwork() |
protected |
BaseMultiLayerNetwork(int nIns,
int[] hiddenLayerSizes,
int nOuts,
int nLayers,
org.apache.commons.math3.random.RandomGenerator rng) |
protected |
BaseMultiLayerNetwork(int nIn,
int[] hiddenLayerSizes,
int nOuts,
int nLayers,
org.apache.commons.math3.random.RandomGenerator rng,
org.jblas.DoubleMatrix input,
org.jblas.DoubleMatrix labels) |
Modifier and Type | Method and Description |
---|---|
protected void |
applyTransforms() |
void |
asDecoder(BaseMultiLayerNetwork network)
Set as decoder for another neural net
designed for encoding (primary output is
encoding input)
|
void |
backProp(double lr,
int epochs)
Backpropagation of errors for weights
|
protected void |
backPropStep(BaseMultiLayerNetwork revert,
double lr,
int epoch)
Do a back prop iteration.
|
BaseMultiLayerNetwork |
clone() |
HiddenLayer |
createHiddenLayer(int index,
int nIn,
int nOut,
ActivationFunction activation,
org.apache.commons.math3.random.RandomGenerator rng,
org.jblas.DoubleMatrix layerInput,
org.apache.commons.math3.distribution.RealDistribution dist)
Creates a hidden layer with the given parameters.
|
abstract NeuralNetwork |
createLayer(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,
int index)
Creates a layer depending on the index.
|
abstract NeuralNetwork[] |
createNetworkLayers(int numLayers) |
void |
encode(BaseMultiLayerNetwork network)
Transposes this network to turn it in to
ad encoder for the given auto encoder networkk
|
double |
fanIn()
Returns the -fanIn to fanIn
coefficient used for initializing the
weights.
|
List<org.jblas.DoubleMatrix> |
feedForward()
Compute activations from input to output of the output layer
|
List<org.jblas.DoubleMatrix> |
feedForward(org.jblas.DoubleMatrix input)
Compute activations from input to output of the output layer
|
void |
finetune(double lr,
int epochs)
Finetunes with the current cached labels
|
void |
finetune(org.jblas.DoubleMatrix labels,
double lr,
int epochs)
Run SGD based on the given labels
|
ActivationFunction |
getActivation() |
org.jblas.DoubleMatrix |
getColumnMeans() |
org.jblas.DoubleMatrix |
getColumnStds() |
org.jblas.DoubleMatrix |
getColumnSums() |
org.apache.commons.math3.distribution.RealDistribution |
getDist() |
double |
getDropOut() |
double |
getErrorTolerance() |
double |
getFanIn() |
MultiLayerGradient |
getGradient(Object[] params)
Gets the multi layer gradient for this network.
|
Map<Integer,MatrixTransform> |
getHiddenBiasTransforms() |
int[] |
getHiddenLayerSizes() |
org.jblas.DoubleMatrix |
getInput() |
double |
getL2() |
org.jblas.DoubleMatrix |
getLabels() |
NeuralNetwork[] |
getLayers() |
double |
getLearningRateUpdate() |
LogisticRegression |
getLogLayer() |
NeuralNetwork.LossFunction |
getLossFunction() |
double |
getMomentum() |
int |
getnIns() |
int |
getnLayers() |
int |
getnOuts() |
NeuralNetwork.OptimizationAlgorithm |
getOptimizationAlgorithm() |
MultiLayerNetworkOptimizer |
getOptimizer() |
double |
getReconstructionCrossEntropy()
Returns the sum of the reconstruction entropies
divided by the number of layers
|
int |
getRenderWeightsEveryNEpochs() |
org.apache.commons.math3.random.RandomGenerator |
getRng() |
HiddenLayer[] |
getSigmoidLayers() |
double |
getSparsity() |
Map<Integer,MatrixTransform> |
getVisibleBiasTransforms() |
Map<Integer,MatrixTransform> |
getWeightTransforms() |
void |
init() |
void |
initialize(DataSet data)
Sets the input and labels from this dataset
|
void |
initializeLayers(org.jblas.DoubleMatrix input)
Base class for initializing the layers based on the input.
|
protected void |
initializeNetwork(NeuralNetwork network) |
boolean |
isForceNumEpochs() |
boolean |
isNormalizeByInputRows() |
boolean |
isShouldBackProp() |
boolean |
isShouldInit() |
boolean |
isToDecode() |
boolean |
isUseAdaGrad() |
boolean |
isUseHiddenActivationsForwardProp() |
boolean |
isUseRegularization() |
void |
load(InputStream is)
Load (using
ObjectInputStream |
static BaseMultiLayerNetwork |
loadFromFile(InputStream is)
Load (using
ObjectInputStream |
void |
merge(BaseMultiLayerNetwork network,
int batchSize)
Merges this network with the other one.
|
double |
negativeLogLikelihood()
Negative log likelihood of the model
|
org.jblas.DoubleMatrix |
predict(org.jblas.DoubleMatrix x)
Label the probabilities of the input
|
abstract void |
pretrain(org.jblas.DoubleMatrix input,
Object[] otherParams)
Pretrain the network with the given parameters
|
org.jblas.DoubleMatrix |
reconstruct(org.jblas.DoubleMatrix x)
Reconstruct from the final layer
|
org.jblas.DoubleMatrix |
reconstruct(org.jblas.DoubleMatrix x,
int layerNum)
Reconstructs the input.
|
void |
resetAdaGrad(double lr)
Resets adagrad with the given learning rate.
|
void |
setActivation(ActivationFunction activation) |
void |
setColumnMeans(org.jblas.DoubleMatrix columnMeans) |
void |
setColumnStds(org.jblas.DoubleMatrix columnStds) |
void |
setColumnSums(org.jblas.DoubleMatrix columnSums) |
void |
setDist(org.apache.commons.math3.distribution.RealDistribution dist) |
void |
setDropOut(double dropOut) |
void |
setErrorTolerance(double errorTolerance) |
void |
setFanIn(double fanIn) |
void |
setForceNumEpochs(boolean forceNumEpochs) |
void |
setHiddenLayerSizes(int[] hiddenLayerSizes) |
void |
setInput(org.jblas.DoubleMatrix input)
Note that if input isn't null
and the layers are null, this is a way
of initializing the neural network
|
void |
setL2(double l2) |
void |
setLabels(org.jblas.DoubleMatrix labels) |
void |
setLayers(NeuralNetwork[] layers) |
void |
setLearningRateUpdate(double learningRateUpdate) |
void |
setLogLayer(LogisticRegression logLayer) |
void |
setLossFunction(NeuralNetwork.LossFunction lossFunction) |
void |
setMomentum(double momentum) |
void |
setnIns(int nIns) |
void |
setnLayers(int nLayers) |
void |
setNormalizeByInputRows(boolean normalizeByInputRows) |
void |
setnOuts(int nOuts) |
void |
setOptimizationAlgorithm(NeuralNetwork.OptimizationAlgorithm optimizationAlgorithm) |
void |
setOptimizer(MultiLayerNetworkOptimizer optimizer) |
void |
setRenderWeightsEveryNEpochs(int renderWeightsEveryNEpochs) |
void |
setRng(org.apache.commons.math3.random.RandomGenerator rng) |
void |
setShouldBackProp(boolean shouldBackProp) |
void |
setShouldInit(boolean shouldInit) |
void |
setSigmoidLayers(HiddenLayer[] sigmoidLayers) |
void |
setSparsity(double sparsity) |
void |
setToDecode(boolean toDecode) |
void |
setUseAdaGrad(boolean useAdaGrad) |
void |
setUseHiddenActivationsForwardProp(boolean useHiddenActivationsForwardProp) |
void |
setUseRegularization(boolean useRegularization) |
void |
setWeightTransforms(Map<Integer,MatrixTransform> weightTransforms) |
void |
synchonrizeRng()
Synchronizes the rng, this is mean for use with scale out methods
|
abstract void |
trainNetwork(org.jblas.DoubleMatrix input,
org.jblas.DoubleMatrix labels,
Object[] otherParams)
Train the network running some unsupervised
pretraining followed by SGD/finetune
|
protected void |
update(BaseMultiLayerNetwork network)
Assigns the parameters of this model to the ones specified by this
network.
|
void |
write(OutputStream os) |
public double learningRateUpdate
public double errorTolerance
protected Map<Integer,List<NeuralNetworkGradientListener>> gradientListeners
protected List<MultiLayerGradientListener> multiLayerGradientListeners
protected double dropOut
protected boolean normalizeByInputRows
protected NeuralNetwork.OptimizationAlgorithm optimizationAlgorithm
protected NeuralNetwork.LossFunction lossFunction
protected BaseMultiLayerNetwork()
protected BaseMultiLayerNetwork(int nIns, int[] hiddenLayerSizes, int nOuts, int nLayers, org.apache.commons.math3.random.RandomGenerator rng)
protected BaseMultiLayerNetwork(int nIn, int[] hiddenLayerSizes, int nOuts, int nLayers, org.apache.commons.math3.random.RandomGenerator rng, org.jblas.DoubleMatrix input, org.jblas.DoubleMatrix labels)
public double fanIn()
public void synchonrizeRng()
public void resetAdaGrad(double lr)
lr
- the new master learning rate to usepublic double getReconstructionCrossEntropy()
public void asDecoder(BaseMultiLayerNetwork network)
network
- the network to decodepublic void initializeLayers(org.jblas.DoubleMatrix input)
input
- the input matrix for trainingpublic void init()
protected void initializeNetwork(NeuralNetwork network)
public void finetune(double lr, int epochs)
lr
- the learning rate to useepochs
- the max number of epochs to finetune withpublic void initialize(DataSet data)
data
- the dataset to initialize withpublic MultiLayerGradient getGradient(Object[] params)
params
- the params to pass (k, corruption level,...)lr
- the learning rate to use for logistic regressionpublic List<org.jblas.DoubleMatrix> feedForward()
public List<org.jblas.DoubleMatrix> feedForward(org.jblas.DoubleMatrix input)
public BaseMultiLayerNetwork clone()
public void backProp(double lr, int epochs)
lr
- the learning rate to useepochs
- the number of epochs to iterate (this is already called in finetune)protected void backPropStep(BaseMultiLayerNetwork revert, double lr, int epoch)
lastEntropy
- the last error to be had on the previous epochrevert
- the best network so farlr
- the learning rate to use for trainingepoch
- the epoch to usepublic void finetune(org.jblas.DoubleMatrix labels, double lr, int epochs)
labels
- the labels to uselr
- the learning rate during trainingepochs
- the number of times to iteratepublic org.jblas.DoubleMatrix predict(org.jblas.DoubleMatrix x)
x
- the input to labelpublic org.jblas.DoubleMatrix reconstruct(org.jblas.DoubleMatrix x, int layerNum)
x
- the input to reconstructlayerNum
- the layer to output for encodingpublic org.jblas.DoubleMatrix reconstruct(org.jblas.DoubleMatrix x)
x
- the input to reconstructpublic void write(OutputStream os)
write
in interface Persistable
public void load(InputStream is)
ObjectInputStream
load
in interface Persistable
is
- the input stream to load from (usually a file)public static BaseMultiLayerNetwork loadFromFile(InputStream is)
ObjectInputStream
is
- the input stream to load from (usually a file)protected void update(BaseMultiLayerNetwork network)
network
- the network to get parameters frompublic double negativeLogLikelihood()
public abstract void trainNetwork(org.jblas.DoubleMatrix input, org.jblas.DoubleMatrix labels, Object[] otherParams)
input
- the input to train onlabels
- the labels for the training examples(a matrix of the following format:
[0,1,0] where 0 represents the labels its not and 1 represents labels for the positive outcomesotherParams
- the other parameters for child classes (algorithm specific parameters such as corruption level for SDA)public abstract void pretrain(org.jblas.DoubleMatrix input, Object[] otherParams)
input
- the input to train onsotherParams
- the other parameters for child classes (algorithm specific parameters such as corruption level for SDA)protected void applyTransforms()
public abstract NeuralNetwork createLayer(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, int index)
CDBN
where the first layer needs to be an CRBM
for continuous inputs.
Please be sure to call super.initializeNetwork
to handle the passing of baseline parameters such as fanin
and rendering.input
- the input to the layernVisible
- the number of visible inputsnHidden
- the number of hidden unitsW
- the weight vectorhbias
- the hidden biasvBias
- the visible biasrng
- the rng to use (THiS IS IMPORTANT; YOU DO NOT WANT TO HAVE A MIS REFERENCED RNG OTHERWISE NUMBERS WILL BE MEANINGLESS)index
- the index of the layerRBM
public abstract NeuralNetwork[] createNetworkLayers(int numLayers)
public HiddenLayer createHiddenLayer(int index, int nIn, int nOut, ActivationFunction activation, org.apache.commons.math3.random.RandomGenerator rng, org.jblas.DoubleMatrix layerInput, org.apache.commons.math3.distribution.RealDistribution dist)
nIn
- the number of inputsnOut
- the number of outputsactivation
- the activation function for the layerrng
- the rng to use for samplinglayerInput
- the layer starting inputdist
- the probability distribution to use
for generating weightspublic void merge(BaseMultiLayerNetwork network, int batchSize)
network
- the network to merge withbatchSize
- the batch size (number of training examples)
to average bypublic void encode(BaseMultiLayerNetwork network)
network
- the network to decodepublic org.jblas.DoubleMatrix getLabels()
public LogisticRegression getLogLayer()
public void setInput(org.jblas.DoubleMatrix input)
input
- public boolean isShouldBackProp()
public NeuralNetwork.OptimizationAlgorithm getOptimizationAlgorithm()
public void setOptimizationAlgorithm(NeuralNetwork.OptimizationAlgorithm optimizationAlgorithm)
public NeuralNetwork.LossFunction getLossFunction()
public void setLossFunction(NeuralNetwork.LossFunction lossFunction)
public org.jblas.DoubleMatrix getInput()
public HiddenLayer[] getSigmoidLayers()
public NeuralNetwork[] getLayers()
public boolean isForceNumEpochs()
public org.jblas.DoubleMatrix getColumnSums()
public void setColumnSums(org.jblas.DoubleMatrix columnSums)
public int[] getHiddenLayerSizes()
public void setHiddenLayerSizes(int[] hiddenLayerSizes)
public org.apache.commons.math3.random.RandomGenerator getRng()
public void setRng(org.apache.commons.math3.random.RandomGenerator rng)
public org.apache.commons.math3.distribution.RealDistribution getDist()
public void setDist(org.apache.commons.math3.distribution.RealDistribution dist)
public MultiLayerNetworkOptimizer getOptimizer()
public void setOptimizer(MultiLayerNetworkOptimizer optimizer)
public ActivationFunction getActivation()
public void setActivation(ActivationFunction activation)
public boolean isToDecode()
public void setToDecode(boolean toDecode)
public boolean isShouldInit()
public void setShouldInit(boolean shouldInit)
public double getFanIn()
public void setFanIn(double fanIn)
public int getRenderWeightsEveryNEpochs()
public void setRenderWeightsEveryNEpochs(int renderWeightsEveryNEpochs)
public Map<Integer,MatrixTransform> getWeightTransforms()
public void setWeightTransforms(Map<Integer,MatrixTransform> weightTransforms)
public double getSparsity()
public void setSparsity(double sparsity)
public double getLearningRateUpdate()
public void setLearningRateUpdate(double learningRateUpdate)
public double getErrorTolerance()
public void setErrorTolerance(double errorTolerance)
public void setLabels(org.jblas.DoubleMatrix labels)
public void setForceNumEpochs(boolean forceNumEpochs)
public org.jblas.DoubleMatrix getColumnMeans()
public void setColumnMeans(org.jblas.DoubleMatrix columnMeans)
public org.jblas.DoubleMatrix getColumnStds()
public void setColumnStds(org.jblas.DoubleMatrix columnStds)
public boolean isUseAdaGrad()
public void setUseAdaGrad(boolean useAdaGrad)
public boolean isNormalizeByInputRows()
public void setNormalizeByInputRows(boolean normalizeByInputRows)
public boolean isUseHiddenActivationsForwardProp()
public void setUseHiddenActivationsForwardProp(boolean useHiddenActivationsForwardProp)
public double getDropOut()
public void setDropOut(double dropOut)
public Map<Integer,MatrixTransform> getHiddenBiasTransforms()
public Map<Integer,MatrixTransform> getVisibleBiasTransforms()
public int getnIns()
public void setnIns(int nIns)
public int getnOuts()
public void setnOuts(int nOuts)
public int getnLayers()
public void setnLayers(int nLayers)
public double getMomentum()
public void setMomentum(double momentum)
public double getL2()
public void setL2(double l2)
public boolean isUseRegularization()
public void setUseRegularization(boolean useRegularization)
public void setSigmoidLayers(HiddenLayer[] sigmoidLayers)
public void setLogLayer(LogisticRegression logLayer)
public void setShouldBackProp(boolean shouldBackProp)
public void setLayers(NeuralNetwork[] layers)
Copyright © 2014. All Rights Reserved.