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 |
---|---|
double |
errorTolerance |
NeuralNetwork[] |
layers |
double |
learningRateUpdate |
Constructor and Description |
---|
BaseMultiLayerNetwork() |
BaseMultiLayerNetwork(int n_ins,
int[] hidden_layer_sizes,
int n_outs,
int n_layers,
org.apache.commons.math3.random.RandomGenerator rng) |
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 boolean |
backPropStep(Double lastEntropy,
BaseMultiLayerNetwork revert,
double lr,
int epoch)
Do a back prop iteration.
|
protected BaseMultiLayerNetwork |
clone() |
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(org.jblas.DoubleMatrix input)
Compute activations from input to output of the output layer
|
void |
finetune(double lr,
int epochs) |
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 |
getErrorTolerance() |
double |
getFanIn() |
int[] |
getHiddenLayerSizes() |
org.jblas.DoubleMatrix |
getInput() |
double |
getL2() |
org.jblas.DoubleMatrix |
getLabels() |
NeuralNetwork[] |
getLayers() |
double |
getLearningRateUpdate() |
LogisticRegression |
getLogLayer() |
double |
getMomentum() |
int |
getnIns() |
int |
getnLayers() |
int |
getnOuts() |
MultiLayerNetworkOptimizer |
getOptimizer() |
int |
getRenderWeightsEveryNEpochs() |
org.apache.commons.math3.random.RandomGenerator |
getRng() |
HiddenLayer[] |
getSigmoidLayers() |
double |
getSparsity() |
Map<Integer,MatrixTransform> |
getWeightTransforms() |
void |
initializeLayers(org.jblas.DoubleMatrix input)
Base class for initializing the layers based on the input.
|
protected void |
initializeNetwork(NeuralNetwork network) |
boolean |
isForceNumEpochs() |
boolean |
isShouldBackProp() |
boolean |
isShouldInit() |
boolean |
isToDecode() |
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
|
org.jblas.DoubleMatrix |
reconstruct(org.jblas.DoubleMatrix x) |
org.jblas.DoubleMatrix |
reconstruct(org.jblas.DoubleMatrix x,
int layerNum)
Reconstructs the input.
|
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 |
setErrorTolerance(double errorTolerance) |
void |
setFanIn(double fanIn) |
void |
setForceNumEpochs(boolean forceNumEpochs) |
void |
setHiddenLayerSizes(int[] hiddenLayerSizes) |
void |
setInput(org.jblas.DoubleMatrix input) |
void |
setL2(double l2) |
void |
setLabels(org.jblas.DoubleMatrix labels) |
void |
setLayers(NeuralNetwork[] layers) |
void |
setLearningRateUpdate(double learningRateUpdate) |
void |
setLogLayer(LogisticRegression logLayer) |
void |
setMomentum(double momentum) |
void |
setnIns(int nIns) |
void |
setnLayers(int nLayers) |
void |
setnOuts(int nOuts) |
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 |
setUseRegularization(boolean useRegularization) |
void |
setWeightTransforms(Map<Integer,MatrixTransform> weightTransforms) |
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)
Serializes this to the output stream.
|
public double learningRateUpdate
public NeuralNetwork[] layers
public double errorTolerance
public BaseMultiLayerNetwork()
public BaseMultiLayerNetwork(int n_ins, int[] hidden_layer_sizes, int n_outs, int n_layers, org.apache.commons.math3.random.RandomGenerator rng)
public 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 asDecoder(BaseMultiLayerNetwork network)
network
- the network to decodepublic void initializeLayers(org.jblas.DoubleMatrix input)
input
- the input matrix for trainingpublic 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)
protected void initializeNetwork(NeuralNetwork network)
public void finetune(double lr, int epochs)
public org.jblas.DoubleMatrix getLabels()
public LogisticRegression getLogLayer()
public void setInput(org.jblas.DoubleMatrix input)
public org.jblas.DoubleMatrix getInput()
public HiddenLayer[] getSigmoidLayers()
public NeuralNetwork[] getLayers()
public List<org.jblas.DoubleMatrix> feedForward(org.jblas.DoubleMatrix input)
protected 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 boolean backPropStep(Double lastEntropy, 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)
public void write(OutputStream os)
write
in interface Persistable
os
- the output stream to write topublic 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)protected void applyTransforms()
public boolean isShouldBackProp()
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 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 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)
Copyright © 2014. All Rights Reserved.