public class BarnesHutTsne extends java.lang.Object implements Model
Modifier and Type | Class and Description |
---|---|
static class |
BarnesHutTsne.Builder |
Modifier and Type | Field and Description |
---|---|
protected org.nd4j.linalg.learning.AdaGrad |
adaGrad |
protected double |
finalMomentum |
protected double |
initialMomentum |
protected IterationListener |
iterationListener |
protected double |
learningRate |
protected int |
maxIter |
protected double |
minGain |
protected double |
momentum |
protected boolean |
normalize |
protected double |
perplexity |
protected double |
realMin |
protected int |
stopLyingIteration |
protected int |
switchMomentumIteration |
protected double |
tolerance |
protected boolean |
useAdaGrad |
protected boolean |
usePca |
protected org.nd4j.linalg.api.ndarray.INDArray |
Y |
static java.lang.String |
Y_GRAD |
Constructor and Description |
---|
BarnesHutTsne(int numDimensions,
java.lang.String simiarlityFunction,
double theta,
boolean invert,
int maxIter,
double realMin,
double initialMomentum,
double finalMomentum,
double momentum,
int switchMomentumIteration,
boolean normalize,
int stopLyingIteration,
double tolerance,
double learningRate,
boolean useAdaGrad,
double perplexity,
IterationListener iterationListener,
double minGain) |
Modifier and Type | Method and Description |
---|---|
void |
accumulateScore(double accum)
Sets a rolling tally for the score.
|
void |
applyLearningRateScoreDecay()
Update learningRate using for this model.
|
int |
batchSize()
The current inputs batch size
|
void |
clear()
Clear input
|
Pair<org.nd4j.linalg.api.ndarray.INDArray,java.lang.Double> |
computeGaussianKernel(org.nd4j.linalg.api.ndarray.INDArray distances,
double beta,
int k)
Computes a gaussian kernel
given a vector of squared distance distances
|
org.nd4j.linalg.api.ndarray.INDArray |
computeGaussianPerplexity(org.nd4j.linalg.api.ndarray.INDArray d,
double u)
Convert data to probability
co-occurrences (aka calculating the kernel)
|
void |
computeGradientAndScore()
Update the score
|
NeuralNetConfiguration |
conf()
The configuration for the neural network
|
void |
fit()
All models have a fit method
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray data)
Fit the model to the given data
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray data,
int nDims)
Deprecated.
Use
fit(INDArray) |
org.nd4j.linalg.api.ndarray.INDArray |
getData()
Return the matrix reduce to the NDim.
|
int |
getNumDimensions() |
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
org.nd4j.linalg.api.ndarray.INDArray |
getParam(java.lang.String param)
Get the parameter
|
double |
getPerplexity() |
java.lang.String |
getSimiarlityFunction() |
double |
getTheta() |
Gradient |
gradient()
Calculate a gradient
|
protected Pair<java.lang.Double,org.nd4j.linalg.api.ndarray.INDArray> |
gradient(org.nd4j.linalg.api.ndarray.INDArray p) |
Pair<Gradient,java.lang.Double> |
gradientAndScore()
Get the gradient and score
|
void |
init()
Init the model
|
void |
initParams()
Initialize the parameters
|
org.nd4j.linalg.api.ndarray.INDArray |
input()
The input/feature matrix for the model
|
boolean |
isInvert() |
void |
iterate(org.nd4j.linalg.api.ndarray.INDArray input)
Run one iteration
|
int |
numParams()
the number of parameters for the model
|
int |
numParams(boolean backwards)
the number of parameters for the model
|
org.nd4j.linalg.api.ndarray.INDArray |
params()
Parameters of the model (if any)
|
java.util.Map<java.lang.String,org.nd4j.linalg.api.ndarray.INDArray> |
paramTable()
The param table
|
java.util.Map<java.lang.String,org.nd4j.linalg.api.ndarray.INDArray> |
paramTable(boolean backprapParamsOnly)
Table of parameters by key, for backprop
For many models (dense layers, etc) - all parameters are backprop parameters
|
void |
plot(org.nd4j.linalg.api.ndarray.INDArray matrix,
int nDims,
java.util.List<java.lang.String> labels,
java.lang.String path)
Deprecated.
use
fit(INDArray) and saveAsFile(List, String) instead. |
void |
saveAsFile(java.util.List<java.lang.String> labels,
java.lang.String path)
Save the model as a file with a csv format, adding the label as the last column.
|
double |
score()
The score for the model
|
void |
setBackpropGradientsViewArray(org.nd4j.linalg.api.ndarray.INDArray gradients)
Set the gradients array as a view of the full (backprop) network parameters
NOTE: this is intended to be used internally in MultiLayerNetwork and ComputationGraph, not by users.
|
void |
setConf(NeuralNetConfiguration conf)
Setter for the configuration
|
void |
setData(org.nd4j.linalg.api.ndarray.INDArray data) |
void |
setInvert(boolean invert) |
void |
setListeners(java.util.Collection<IterationListener> listeners)
Set the IterationListeners for the ComputationGraph (and all layers in the network)
|
void |
setListeners(IterationListener... listeners)
Set the IterationListeners for the ComputationGraph (and all layers in the network)
|
void |
setNumDimensions(int numDimensions) |
void |
setParam(java.lang.String key,
org.nd4j.linalg.api.ndarray.INDArray val)
Set the parameter with a new ndarray
|
void |
setParams(org.nd4j.linalg.api.ndarray.INDArray params)
Set the parameters for this model.
|
void |
setParamsViewArray(org.nd4j.linalg.api.ndarray.INDArray params)
Set the initial parameters array as a view of the full (backprop) network parameters
NOTE: this is intended to be used internally in MultiLayerNetwork and ComputationGraph, not by users.
|
void |
setParamTable(java.util.Map<java.lang.String,org.nd4j.linalg.api.ndarray.INDArray> paramTable)
Setter for the param table
|
void |
setSimiarlityFunction(java.lang.String simiarlityFunction) |
void |
step(org.nd4j.linalg.api.ndarray.INDArray p,
int i)
An individual iteration
|
org.nd4j.linalg.api.ndarray.INDArray |
symmetrized(org.nd4j.linalg.api.ndarray.INDArray rowP,
org.nd4j.linalg.api.ndarray.INDArray colP,
org.nd4j.linalg.api.ndarray.INDArray valP)
Symmetrize the value matrix
|
void |
update(Gradient gradient)
Update layer weights and biases with gradient change
|
void |
update(org.nd4j.linalg.api.ndarray.INDArray gradient,
java.lang.String paramType)
Perform one update applying the gradient
|
void |
validateInput()
Validate the input
|
protected int maxIter
protected double realMin
protected double initialMomentum
protected double finalMomentum
protected double minGain
protected double momentum
protected int switchMomentumIteration
protected boolean normalize
protected boolean usePca
protected int stopLyingIteration
protected double tolerance
protected double learningRate
protected org.nd4j.linalg.learning.AdaGrad adaGrad
protected boolean useAdaGrad
protected double perplexity
protected org.nd4j.linalg.api.ndarray.INDArray Y
public static final java.lang.String Y_GRAD
protected transient IterationListener iterationListener
public BarnesHutTsne(int numDimensions, java.lang.String simiarlityFunction, double theta, boolean invert, int maxIter, double realMin, double initialMomentum, double finalMomentum, double momentum, int switchMomentumIteration, boolean normalize, int stopLyingIteration, double tolerance, double learningRate, boolean useAdaGrad, double perplexity, IterationListener iterationListener, double minGain)
public java.lang.String getSimiarlityFunction()
public void setSimiarlityFunction(java.lang.String simiarlityFunction)
public boolean isInvert()
public void setInvert(boolean invert)
public double getTheta()
public double getPerplexity()
public int getNumDimensions()
public void setNumDimensions(int numDimensions)
public org.nd4j.linalg.api.ndarray.INDArray computeGaussianPerplexity(org.nd4j.linalg.api.ndarray.INDArray d, double u)
d
- the data to convertu
- the perplexity of the modelpublic org.nd4j.linalg.api.ndarray.INDArray input()
Model
public void validateInput()
Model
validateInput
in interface Model
public ConvexOptimizer getOptimizer()
Model
getOptimizer
in interface Model
public org.nd4j.linalg.api.ndarray.INDArray getParam(java.lang.String param)
Model
public void initParams()
Model
initParams
in interface Model
public java.util.Map<java.lang.String,org.nd4j.linalg.api.ndarray.INDArray> paramTable()
Model
paramTable
in interface Model
public java.util.Map<java.lang.String,org.nd4j.linalg.api.ndarray.INDArray> paramTable(boolean backprapParamsOnly)
Model
paramTable
in interface Model
backprapParamsOnly
- If true, return backprop params only. If false: return all params (equivalent to
paramsTable())public void setParamTable(java.util.Map<java.lang.String,org.nd4j.linalg.api.ndarray.INDArray> paramTable)
Model
setParamTable
in interface Model
public void setParam(java.lang.String key, org.nd4j.linalg.api.ndarray.INDArray val)
Model
public void clear()
Model
protected Pair<java.lang.Double,org.nd4j.linalg.api.ndarray.INDArray> gradient(org.nd4j.linalg.api.ndarray.INDArray p)
public org.nd4j.linalg.api.ndarray.INDArray symmetrized(org.nd4j.linalg.api.ndarray.INDArray rowP, org.nd4j.linalg.api.ndarray.INDArray colP, org.nd4j.linalg.api.ndarray.INDArray valP)
rowP
- colP
- valP
- public Pair<org.nd4j.linalg.api.ndarray.INDArray,java.lang.Double> computeGaussianKernel(org.nd4j.linalg.api.ndarray.INDArray distances, double beta, int k)
distances
- beta
- public void setListeners(java.util.Collection<IterationListener> listeners)
setListeners
in interface Model
listeners
- public void setListeners(IterationListener... listeners)
setListeners
in interface Model
listeners
- public void fit()
Model
public void update(Gradient gradient)
Model
public void step(org.nd4j.linalg.api.ndarray.INDArray p, int i)
p
- the probabilities that certain points
are near each otheri
- the iteration (primarily for debugging purposes)public void update(org.nd4j.linalg.api.ndarray.INDArray gradient, java.lang.String paramType)
Model
public void saveAsFile(java.util.List<java.lang.String> labels, java.lang.String path) throws java.io.IOException
labels
- path
- the path to writejava.io.IOException
@Deprecated public void plot(org.nd4j.linalg.api.ndarray.INDArray matrix, int nDims, java.util.List<java.lang.String> labels, java.lang.String path) throws java.io.IOException
fit(INDArray)
and saveAsFile(List, String)
instead.matrix
- the matrix to plotnDims
- the numberlabels
- path
- the path to writejava.io.IOException
public double score()
Model
public void computeGradientAndScore()
Model
computeGradientAndScore
in interface Model
public void accumulateScore(double accum)
Model
accumulateScore
in interface Model
accum
- the amount to accumpublic org.nd4j.linalg.api.ndarray.INDArray params()
Model
public int numParams()
Model
public int numParams(boolean backwards)
Model
public void setParams(org.nd4j.linalg.api.ndarray.INDArray params)
Model
public void setParamsViewArray(org.nd4j.linalg.api.ndarray.INDArray params)
Model
setParamsViewArray
in interface Model
params
- a 1 x nParams row vector that is a view of the larger (MLN/CG) parameters arraypublic void setBackpropGradientsViewArray(org.nd4j.linalg.api.ndarray.INDArray gradients)
Model
setBackpropGradientsViewArray
in interface Model
gradients
- a 1 x nParams row vector that is a view of the larger (MLN/CG) gradients arraypublic void applyLearningRateScoreDecay()
Model
applyLearningRateScoreDecay
in interface Model
public void fit(org.nd4j.linalg.api.ndarray.INDArray data)
Model
@Deprecated public void fit(org.nd4j.linalg.api.ndarray.INDArray data, int nDims)
fit(INDArray)
public void iterate(org.nd4j.linalg.api.ndarray.INDArray input)
Model
public Pair<Gradient,java.lang.Double> gradientAndScore()
Model
gradientAndScore
in interface Model
public int batchSize()
Model
public NeuralNetConfiguration conf()
Model
public void setConf(NeuralNetConfiguration conf)
Model
public org.nd4j.linalg.api.ndarray.INDArray getData()
public void setData(org.nd4j.linalg.api.ndarray.INDArray data)