Package org.nd4j.autodiff.samediff
Class SDVariable
- java.lang.Object
-
- org.nd4j.autodiff.samediff.SDVariable
-
- All Implemented Interfaces:
Serializable
public class SDVariable extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DataTypedataTypeprotected SameDiffsameDiffprotected long[]shapeprotected VariableTypevariableTypeprotected StringvarName
-
Constructor Summary
Constructors Constructor Description SDVariable(@NonNull String varName, @NonNull VariableType varType, @NonNull SameDiff sameDiff, long[] shape, DataType dataType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description SDVariableadd(double scalar)SDVariableadd(String varName, double scalar)Scalar addition:out = this + scalar
Output variable has the same shape as the input variableSDVariableadd(String name, SDVariable x)Addition operation: elementwisethis + x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.SDVariableadd(SDVariable other)voidaddControlDependency(SDVariable controlDependency)Add a control dependency for this variable on the specified variable.
Control dependencies can be used to enforce the execution order.SDVariableargmax(int... dimensions)SDVariableargmax(String name, boolean keepDims, int... dimensions)Argmax array reduction operation, optionally along specified dimensions.
Output values are the index of the maximum value of each slice along the specified dimension.
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariableargmax(String name, int... dimensions)SDVariableargmin(int... dimensions)SDVariableargmin(String name, boolean keepDims, int... dimensions)Argmin array reduction operation, optionally along specified dimensions.
Output values are the index of the minimum value of each slice along the specified dimension.
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariableargmin(String name, int... dimensions)SDVariableassign(Number value)Return a variable with equal shape to the input, but all elements set to the specified valueSDVariablecastTo(@NonNull DataType dataType)SDVariablecastTo(String name, @NonNull DataType dataType)SDVariableclone(String name, SameDiff sd)SDVariableclone(SameDiff sd)SDVariableconvertToConstant()Convert this variable to a constant.SDVariableconvertToVariable()Convert this variable to a VARIABLE type SDVariable.
This can only be done for constants and placeholders, not ARRAY type variables (which are usually network activations).static SameDiffcreateLoopConcat(SDVariable relative, SDVariable indices)Create a graph that takes in the indices as a placeholder, loops over each element in the index vector and appends the slice to the end result.static SameDiffcreateLoopPut(SDVariable relative, SDVariable indices)Create a graph that takes in the indices as a placeholder, loops over each element in the index vector and appends the slice to the end result.DataTypedataType()SDVariablediv(double scalar)SDVariablediv(String varName, double scalar)Scalar division:out = this / scalar
Output variable has the same shape as the input variableSDVariablediv(String name, SDVariable x)Division operation: elementwisethis / x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.SDVariablediv(SDVariable x)SDVariabledot(String name, SDVariable other, int... dimensions)Matrix dot product: out = dot(this,other, dimensions)SDVariabledot(SDVariable other, int... dimensions)SDVariabledup()Create a new SDVariable, the contents of which is copied from this current variableSDVariableeq(double value)SDVariableeq(String name, double value)Equals operation: elementwisethis == value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwiseSDVariableeq(String name, SDVariable other)Equal to operation: elementwisethis == y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.SDVariableeq(SDVariable other)booleanequals(Object o)INDArrayeval()Evaluate the result of this variableINDArrayeval(Map<String,INDArray> placeholders)Evaluate the result of this variableSDVariablefdiv(String name, SDVariable x)Floor division operation: elementwisethis // x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.SDVariableget(SDIndex... indices)Get a variable with content equal to a specified sub-array of this variable.
Can be used (for example) to get rows, columns, sub-matrices, etc.SDVariableget(SDVariable indices)Get a variable with content equal to a specified sub-array of this variable.
Can be used (for example) to get rows, columns, sub-matrices, etc.INDArraygetArr()A getter for the allocated ndarray with thisSDVariable.INDArraygetArr(boolean enforceExistence)A getter for the allocated ndarray with thisSDVariable.SDVariablegetGradient()The gradient variable is the variable that represents the derivative of the loss function with respect to the output of this variable.long[]getShape()Returns the shape of this variableLongShapeDescriptorgetShapeDescriptor()StringgetVarName()Deprecated.Usename()SDVariablegetView(SDIndex... indices)Get a variable with content equal to a specified sub-array of this variable.
Can be used (for example) to get rows, columns, sub-matrices, etc.SDVariablegradient()Alias for the gradient variable - same asgetGradient().SDVariablegt(double value)SDVariablegt(String name, double value)Greater than operation: elementwisethis > value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwiseSDVariablegt(String name, SDVariable other)Greater than operation: elementwisethis > y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.SDVariablegt(SDVariable other)SDVariablegte(double value)SDVariablegte(String name, double value)Greater than or equals operation: elementwisethis >= value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwiseSDVariablegte(String name, SDVariable other)Greater than or equal to operation: elementwisethis >= y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.SDVariablegte(SDVariable other)booleanhasGradient()Determine if this variable has a gradient with respect to the current loss.inthashCode()booleanisConstant()booleanisPlaceHolder()Returns true if this variable is a placeholderSDVariablelength()Return the total number of elements in this arraySDVariablelt(double value)SDVariablelt(String name, double value)Less than operation: elementwisethis < value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwiseSDVariablelt(String name, SDVariable other)Less than operation: elementwisethis < y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.SDVariablelt(SDVariable other)SDVariablelte(double value)SDVariablelte(String name, double value)Less than or equals operation: elementwisethis <= value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwiseSDVariablelte(String name, SDVariable other)Less than or equal to operation: elementwisethis <= y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.SDVariablelte(SDVariable other)voidmarkAsLoss()Mark this variable as a loss function variable.SDVariablemax(boolean keepDims, int... dimensions)SDVariablemax(int... dimensions)SDVariablemax(String name, boolean keepDims, int... dimensions)Maximum array reduction operation, optionally along specified dimensions
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariablemax(String name, int... dimensions)SDVariablemean(boolean keepDims, int... dimensions)SDVariablemean(int... dimensions)SDVariablemean(String name, boolean keepDims, int... dimensions)Mean (average) array reduction operation, optionally along specified dimensions
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariablemean(String name, int... dimensions)SDVariablemin(boolean keepDims, int... dimensions)SDVariablemin(int... dimensions)SDVariablemin(String name, boolean keepDims, int... dimensions)Minimum array reduction operation, optionally along specified dimensions.SDVariablemin(String name, int... dimensions)SDVariableminus(double other)For Kotlin operator interopSDVariableminus(SDVariable other)For Kotlin operator interopSDVariablemmul(String name, SDVariable other)Matrix multiplication: out = mmul(this,other)SDVariablemmul(String name, SDVariable other, @NonNull MMulTranspose mMulTranspose)Matrix multiplication: out = mmul(this,other)SDVariablemmul(SDVariable other)SDVariablemod(String name, SDVariable x)Modulo operation: elementwisethis / x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.SDVariablemul(double scalar)SDVariablemul(String varName, double scalar)Scalar multiplication:out = this * scalar
Output variable has the same shape as the input variableSDVariablemul(String name, SDVariable x)Multiplication operation: elementwisethis * x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.SDVariablemul(SDVariable x)Stringname()Get the name of the SDVariableSDVariableneg()Negate op - returns a new variable with the values of the current variable negatedSDVariableneg(String name)Negate op - returns a new variable with the values of the current variable negatedSDVariableneq(double value)Seeneq(SDVariable)SDVariableneq(String name, double value)Not equals operation: elementwisethis != value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwiseSDVariableneq(String name, SDVariable other)Not equal to operation: elementwisethis != y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.SDVariableneq(SDVariable other)SDVariablenorm1(boolean keepDims, int... dimensions)SDVariablenorm1(int... dimensions)SDVariablenorm1(String name, boolean keepDims, int... dimensions)Norm1 (L1 norm) reduction operation: The output contains the L1 norm for each tensor/subset along the specified dimensions:
out = sum_i abs(x[i])
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariablenorm1(String name, int... dimensions)SDVariablenorm2(boolean keepDims, int... dimensions)SDVariablenorm2(int... dimensions)SDVariablenorm2(String name, boolean keepDims, int... dimensions)Norm2 (L2 norm) reduction operation: The output contains the L2 norm for each tensor/subset along the specified dimensions:
out = sqrt(sum_i x[i]^2)
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariablenorm2(String name, int... dimensions)SDVariablenormmax(boolean keepDims, int... dimensions)SDVariablenormmax(int... dimensions)SDVariablenormmax(String name, boolean keepDims, int... dimensions)Max norm (infinity norm) reduction operation: The output contains the max norm for each tensor/subset along the specified dimensions:
out = max(abs(x[i]))
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariablenormmax(String name, int... dimensions)SDVariablepermute(int... dimensions)Permute the dimensions of the current variable according to the specified permutation indices.
Example: if the current variable has shape [a,b,c] and dimensions = [2,0,1] the output has shape [c,a,b]SDVariablepermute(SDVariable dimensions)long[]placeholderShape()SDVariableplus(double other)For Kotlin operator interopSDVariableplus(SDVariable other)For Kotlin operator interopSDVariablepow(double scalar)SDVariablepow(String varName, double scalar)Scalar power operation:out = this ^ scalar
Output variable has the same shape as the input variableSDVariableprod(boolean keepDims, int... dimensions)SDVariableprod(int... dimensions)SDVariableprod(String name, boolean keepDims, int... dimensions)Product array reduction operation, optionally along specified dimensions
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariableprod(String name, int... dimensions)SDVariableput(SDVariable indices, SDVariable toPut, SDVariable putIndices)Get a variable with content equal to a specified sub-array of this variable.
Can be used (for example) to get rows, columns, sub-matrices, etc.SDVariablerank()Get the rank of this variable as a dynamic SDVariableSDVariablerdiv(double scalar)SDVariablerdiv(String varName, double scalar)Scalar reverse division:out = scalar / this
Output variable has the same shape as the input variableSDVariablerdiv(String name, SDVariable x)Reverse division operation: elementwisex / this
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.SDVariablerdiv(SDVariable sameDiffVariable)SDVariablerename(String newName)Rename this variable to a new name.SDVariablereshape(int... newShape)Reshape the current variable to the specified shape.SDVariablereshape(long... newShape)Reshape the current variable to the specified shape.SDVariablereshape(String name, SDVariable newShape)Reshape the current variable to the specified (dynamic) shape.SDVariablereshape(SDVariable newShape)Reshape the current variable to the specified (dynamic) shape.SDVariablersub(double scalar)SDVariablersub(String varName, double scalar)Scalar reverse subtraction:out = scalar - this
Output variable has the same shape as the input variableSDVariablersub(String name, SDVariable x)Reverse subtraction operation: elementwisex - this
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.SDVariablersub(SDVariable x)SDVariablesetArray(INDArray array)Associate the specified array with this variablevoidsetShape(long... shape)voidsetVarName(String varName)SDVariableshape()Get the shape of the array as a dynamic SDVariablestatic SDVariablesliceEnd(SDVariable input, SDVariable sliceIndexInput)SDVariablesquaredDifference(String name, SDVariable x)Squared difference operation:(this - x)^2SDVariablesquaredDifference(SDVariable x)SDVariablestd(boolean biasCorrected, int... dimensions)SDVariablestd(String name, boolean biasCorrected, boolean keepDims, int... dimensions)Stardard deviation array reduction operation, optionally along specified dimensions
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariablestd(String name, boolean biasCorrected, int... dimensions)SDVariablesub(double scalar)SDVariablesub(String varName, double scalar)Scalar subtraction:out = this - scalar
Output variable has the same shape as the input variableSDVariablesub(String name, SDVariable x)Subtraction operation: elementwisethis - x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.SDVariablesub(SDVariable x)SDVariablesum(boolean keepDims, int... dimensions)SDVariablesum(int... dimensions)SDVariablesum(String name, boolean keepDims, int... dimensions)Sum array reduction operation, optionally along specified dimensions.
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1.SDVariablesum(String name, int... dimensions)SDVariabletimes(double other)For Kotlin operator interopSDVariabletimes(SDVariable other)For Kotlin operator interopStringtoString()
-
-
-
Field Detail
-
sameDiff
protected SameDiff sameDiff
-
varName
protected String varName
-
variableType
protected VariableType variableType
-
shape
protected long[] shape
-
dataType
protected DataType dataType
-
-
Constructor Detail
-
SDVariable
public SDVariable(@NonNull @NonNull String varName, @NonNull @NonNull VariableType varType, @NonNull @NonNull SameDiff sameDiff, long[] shape, DataType dataType)
-
-
Method Detail
-
name
public String name()
Get the name of the SDVariable- Returns:
- Name of the variable
-
setVarName
public void setVarName(String varName)
-
getVarName
@Deprecated public String getVarName()
Deprecated.Usename()
-
isPlaceHolder
public boolean isPlaceHolder()
Returns true if this variable is a placeholder- Returns:
-
isConstant
public boolean isConstant()
-
getArr
public INDArray getArr()
A getter for the allocated ndarray with thisSDVariable. This getter will lazy initialize an array if one is not found based on the associated shape andWeightInitScheme- if this is possible. If this is not possible (due to shapes being unknown, etc) null is returned- Returns:
- the
INDArrayassociated with this variable.
-
getArr
public INDArray getArr(boolean enforceExistence)
A getter for the allocated ndarray with thisSDVariable. This getter will lazy initialize an array if one is not found based on the associated shape andWeightInitScheme- if this is possible.
If this is not possible (due to shapes being unknown, etc) either:
(a) null is returned - if enforceExistence == false, or
(b) an IllegalStateException is thrown, if enforceExistence == true- Returns:
- the
INDArrayassociated with this variable.
-
gradient
public SDVariable gradient()
Alias for the gradient variable - same asgetGradient(). The gradient variable is the variable that represents the derivative of the loss function with respect to the output of this variable. I.e., if this variable is X and loss function is L, then gradient() returns the variable representing dL/dX.
Note that only floating point variables can have gradients.
-
getGradient
public SDVariable getGradient()
The gradient variable is the variable that represents the derivative of the loss function with respect to the output of this variable. I.e., if this variable is X and loss function is L, then gradient() returns the variable representing dL/dX
Note that only floating point variables can have gradients.
Note also that a gradient may not yet be defined, and/or if no loss function variables have been set.
You can set the loss function variables usingSameDiff.setLossVariables(String...)and then create the gradient functions usingSameDiff.createGradFunction(). Alternatively, the gradient function will be created automatically when training is performed.
-
getShape
public long[] getShape()
Returns the shape of this variable- Returns:
- Shape of the variable
-
setShape
public void setShape(long... shape)
-
placeholderShape
public long[] placeholderShape()
-
dataType
public DataType dataType()
-
getShapeDescriptor
public LongShapeDescriptor getShapeDescriptor()
-
castTo
public SDVariable castTo(@NonNull @NonNull DataType dataType)
-
castTo
public SDVariable castTo(String name, @NonNull @NonNull DataType dataType)
-
dup
public SDVariable dup()
Create a new SDVariable, the contents of which is copied from this current variable- Returns:
- The new variable
-
assign
public SDVariable assign(Number value)
Return a variable with equal shape to the input, but all elements set to the specified value- Parameters:
value- Value for returned variable- Returns:
- new variable
-
neg
public SDVariable neg()
Negate op - returns a new variable with the values of the current variable negated- Returns:
- Negated variable
-
neg
public SDVariable neg(String name)
Negate op - returns a new variable with the values of the current variable negated- Parameters:
name- Name of the new variable- Returns:
- Negated variable
-
lt
public SDVariable lt(double value)
-
lt
public SDVariable lt(String name, double value)
Less than operation: elementwisethis < value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise- Parameters:
name- Name of the output variablevalue- value argument to use in operation- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
lte
public SDVariable lte(double value)
-
lte
public SDVariable lte(String name, double value)
Less than or equals operation: elementwisethis <= value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise- Parameters:
name- Name of the output variablevalue- value argument to use in operation- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
gt
public SDVariable gt(double value)
-
gt
public SDVariable gt(String name, double value)
Greater than operation: elementwisethis > value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise- Parameters:
name- Name of the output variablevalue- value argument to use in operation- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
gte
public SDVariable gte(double value)
-
gte
public SDVariable gte(String name, double value)
Greater than or equals operation: elementwisethis >= value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise- Parameters:
name- Name of the output variablevalue- value argument to use in operation- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
eq
public SDVariable eq(double value)
-
eq
public SDVariable eq(String name, double value)
Equals operation: elementwisethis == value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise- Parameters:
name- Name of the output variablevalue- value argument to use in operation- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
neq
public SDVariable neq(double value)
Seeneq(SDVariable)
-
neq
public SDVariable neq(String name, double value)
Not equals operation: elementwisethis != value
Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise- Parameters:
name- Name of the output variablevalue- value argument to use in operation- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
lt
public SDVariable lt(SDVariable other)
-
lt
public SDVariable lt(String name, SDVariable other)
Less than operation: elementwisethis < y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.- Parameters:
name- Name of the output variableother- Variable to compare values against- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
lte
public SDVariable lte(SDVariable other)
-
lte
public SDVariable lte(String name, SDVariable other)
Less than or equal to operation: elementwisethis <= y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.- Parameters:
name- Name of the output variableother- Variable to compare values against- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
gt
public SDVariable gt(SDVariable other)
-
gt
public SDVariable gt(String name, SDVariable other)
Greater than operation: elementwisethis > y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.- Parameters:
name- Name of the output variableother- Variable to compare values against- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
gte
public SDVariable gte(SDVariable other)
-
gte
public SDVariable gte(String name, SDVariable other)
Greater than or equal to operation: elementwisethis >= y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.- Parameters:
name- Name of the output variableother- Variable to compare values against- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
eq
public SDVariable eq(SDVariable other)
-
eq
public SDVariable eq(String name, SDVariable other)
Equal to operation: elementwisethis == y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.- Parameters:
name- Name of the output variableother- Variable to compare values against- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
neq
public SDVariable neq(SDVariable other)
-
neq
public SDVariable neq(String name, SDVariable other)
Not equal to operation: elementwisethis != y
If x and y arrays have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
Returns an array with values 1 where condition is satisfied, or value 0 otherwise.- Parameters:
name- Name of the output variableother- Variable to compare values against- Returns:
- Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
-
mmul
public SDVariable mmul(SDVariable other)
-
mmul
public SDVariable mmul(String name, SDVariable other)
Matrix multiplication: out = mmul(this,other)- Parameters:
name- Name of the output variableother- Other variable to perform matrix multiplication with- Returns:
- Output variable (result of mmul)
-
mmul
public SDVariable mmul(String name, SDVariable other, @NonNull @NonNull MMulTranspose mMulTranspose)
Matrix multiplication: out = mmul(this,other)- Parameters:
name- Name of the output variableother- Other variable to perform matrix multiplication withmMulTranspose- Matrix transpose configuration- Returns:
- Output variable (result of mmul)
-
dot
public SDVariable dot(SDVariable other, int... dimensions)
-
dot
public SDVariable dot(String name, SDVariable other, int... dimensions)
Matrix dot product: out = dot(this,other, dimensions)- Parameters:
name- Name of the output variableother- Other variable to perform matrix multiplication with- Returns:
- Output variable (result of mmul)
-
add
public SDVariable add(double scalar)
-
add
public SDVariable add(String varName, double scalar)
Scalar addition:out = this + scalar
Output variable has the same shape as the input variable- Parameters:
varName- Output variable namescalar- Scalar for operation- Returns:
- Output variable
-
add
public SDVariable add(SDVariable other)
-
add
public SDVariable add(String name, SDVariable x)
Addition operation: elementwisethis + x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.- Parameters:
name- Name of the output variablex- Variable to perform operation with- Returns:
- Output (result) SDVariable
-
plus
public SDVariable plus(SDVariable other)
For Kotlin operator interop- See Also:
add(String, SDVariable)
-
plus
public SDVariable plus(double other)
For Kotlin operator interop- See Also:
add(String, double)
-
sub
public SDVariable sub(double scalar)
-
sub
public SDVariable sub(String varName, double scalar)
Scalar subtraction:out = this - scalar
Output variable has the same shape as the input variable- Parameters:
varName- Output variable namescalar- Scalar for operation- Returns:
- Output variable
-
sub
public SDVariable sub(SDVariable x)
-
sub
public SDVariable sub(String name, SDVariable x)
Subtraction operation: elementwisethis - x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.- Parameters:
name- Name of the output variablex- Variable to perform operation with- Returns:
- Output (result) SDVariable
-
minus
public SDVariable minus(SDVariable other)
For Kotlin operator interop- See Also:
sub(String, SDVariable)
-
minus
public SDVariable minus(double other)
For Kotlin operator interop- See Also:
sub(String, double)
-
div
public SDVariable div(double scalar)
-
div
public SDVariable div(String varName, double scalar)
Scalar division:out = this / scalar
Output variable has the same shape as the input variable- Parameters:
varName- Output variable namescalar- Scalar for operation- Returns:
- Output variable
-
div
public SDVariable div(SDVariable x)
-
div
public SDVariable div(String name, SDVariable x)
Division operation: elementwisethis / x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.- Parameters:
name- Name of the output variablex- Variable to perform operation with- Returns:
- Output (result) SDVariable
-
fdiv
public SDVariable fdiv(String name, SDVariable x)
Floor division operation: elementwisethis // x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.- Parameters:
name- Name of the output variablex- Variable to perform operation with- Returns:
- Output (result) SDVariable
-
mod
public SDVariable mod(String name, SDVariable x)
Modulo operation: elementwisethis / x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.- Parameters:
name- Name of the output variablex- Variable to perform operation with- Returns:
- Output (result) SDVariable
-
mul
public SDVariable mul(double scalar)
-
mul
public SDVariable mul(String varName, double scalar)
Scalar multiplication:out = this * scalar
Output variable has the same shape as the input variable- Parameters:
varName- Output variable namescalar- Scalar for operation- Returns:
- Output variable
-
mul
public SDVariable mul(SDVariable x)
-
mul
public SDVariable mul(String name, SDVariable x)
Multiplication operation: elementwisethis * x
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.- Parameters:
name- Name of the output variablex- Variable to perform operation with- Returns:
- Output (result) SDVariable
-
times
public SDVariable times(SDVariable other)
For Kotlin operator interop- See Also:
mul(String, SDVariable)
-
times
public SDVariable times(double other)
For Kotlin operator interop- See Also:
mul(String, double)
-
pow
public SDVariable pow(double scalar)
-
pow
public SDVariable pow(String varName, double scalar)
Scalar power operation:out = this ^ scalar
Output variable has the same shape as the input variable- Parameters:
varName- Output variable namescalar- Scalar for operation- Returns:
- Output variable
-
rsub
public SDVariable rsub(double scalar)
-
rsub
public SDVariable rsub(String varName, double scalar)
Scalar reverse subtraction:out = scalar - this
Output variable has the same shape as the input variable- Parameters:
varName- Output variable namescalar- Scalar for operation- Returns:
- Output variable
-
rsub
public SDVariable rsub(SDVariable x)
-
rsub
public SDVariable rsub(String name, SDVariable x)
Reverse subtraction operation: elementwisex - this
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.- Parameters:
name- Name of the output variablex- Variable to perform operation with- Returns:
- Output (result) SDVariable
-
rdiv
public SDVariable rdiv(double scalar)
-
rdiv
public SDVariable rdiv(String varName, double scalar)
Scalar reverse division:out = scalar / this
Output variable has the same shape as the input variable- Parameters:
varName- Output variable namescalar- Scalar for operation- Returns:
- Output variable
-
rdiv
public SDVariable rdiv(SDVariable sameDiffVariable)
-
rdiv
public SDVariable rdiv(String name, SDVariable x)
Reverse division operation: elementwisex / this
If this and x variables have equal shape, the output shape is the same as the inputs.
Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.- Parameters:
name- Name of the output variablex- Variable to perform operation with- Returns:
- Output (result) SDVariable
-
squaredDifference
public SDVariable squaredDifference(SDVariable x)
-
squaredDifference
public SDVariable squaredDifference(String name, SDVariable x)
Squared difference operation:(this - x)^2- Parameters:
x- Other input variable- Returns:
- squared difference between variables
-
sum
public SDVariable sum(int... dimensions)
-
sum
public SDVariable sum(boolean keepDims, int... dimensions)
-
sum
public SDVariable sum(String name, int... dimensions)
-
sum
public SDVariable sum(String name, boolean keepDims, int... dimensions)
Sum array reduction operation, optionally along specified dimensions.
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Output variable namekeepDims- If true: keep the dimensions that are reduced on (as length 1). False: remove the reduction dimensionsdimensions- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed- Returns:
- Output variable: reduced array of rank (input rank - num dimensions) if keepDims = false, or of rank (input rank) if keepdims = true
-
mean
public SDVariable mean(boolean keepDims, int... dimensions)
-
mean
public SDVariable mean(String name, int... dimensions)
-
mean
public SDVariable mean(int... dimensions)
-
mean
public SDVariable mean(String name, boolean keepDims, int... dimensions)
Mean (average) array reduction operation, optionally along specified dimensions
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Output variable namekeepDims- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensionsdimensions- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed- Returns:
- Reduced array of rank (input rank - num dimensions)
-
std
public SDVariable std(boolean biasCorrected, int... dimensions)
-
std
public SDVariable std(String name, boolean biasCorrected, int... dimensions)
-
std
public SDVariable std(String name, boolean biasCorrected, boolean keepDims, int... dimensions)
Stardard deviation array reduction operation, optionally along specified dimensions
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
biasCorrected- If true: divide by (N-1) (i.e., sample stdev). If false: divide by N (population stdev)keepDims- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensionsdimensions- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed- Returns:
- Output variable: reduced array of rank (input rank - num dimensions)
-
prod
public SDVariable prod(int... dimensions)
-
prod
public SDVariable prod(boolean keepDims, int... dimensions)
-
prod
public SDVariable prod(String name, int... dimensions)
-
prod
public SDVariable prod(String name, boolean keepDims, int... dimensions)
Product array reduction operation, optionally along specified dimensions
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Output variable namekeepDims- If true: keep the dimensions that are reduced on (as length 1). False: remove the reduction dimensionsdimensions- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed- Returns:
- Output variable: reduced array of rank (input rank - num dimensions)
-
min
public SDVariable min(int... dimensions)
-
min
public SDVariable min(boolean keepDims, int... dimensions)
-
min
public SDVariable min(String name, int... dimensions)
-
min
public SDVariable min(String name, boolean keepDims, int... dimensions)
Minimum array reduction operation, optionally along specified dimensions. out = min(in)
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Output variable namekeepDims- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensionsdimensions- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed- Returns:
- Reduced array of rank (input rank - num dimensions)
-
max
public SDVariable max(int... dimensions)
-
max
public SDVariable max(String name, int... dimensions)
-
max
public SDVariable max(boolean keepDims, int... dimensions)
-
max
public SDVariable max(String name, boolean keepDims, int... dimensions)
Maximum array reduction operation, optionally along specified dimensions
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Output variable namekeepDims- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensionsdimensions- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed- Returns:
- Reduced array of rank (input rank - num dimensions)
-
norm1
public SDVariable norm1(int... dimensions)
-
norm1
public SDVariable norm1(boolean keepDims, int... dimensions)
-
norm1
public SDVariable norm1(String name, int... dimensions)
-
norm1
public SDVariable norm1(String name, boolean keepDims, int... dimensions)
Norm1 (L1 norm) reduction operation: The output contains the L1 norm for each tensor/subset along the specified dimensions:
out = sum_i abs(x[i])
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Output variable namekeepDims- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensionsdimensions- dimensions to reduce over- Returns:
- Output variable
-
norm2
public SDVariable norm2(int... dimensions)
-
norm2
public SDVariable norm2(boolean keepDims, int... dimensions)
-
norm2
public SDVariable norm2(String name, int... dimensions)
-
norm2
public SDVariable norm2(String name, boolean keepDims, int... dimensions)
Norm2 (L2 norm) reduction operation: The output contains the L2 norm for each tensor/subset along the specified dimensions:
out = sqrt(sum_i x[i]^2)
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Output variable namekeepDims- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensionsdimensions- dimensions to reduce over- Returns:
- Output variable
-
normmax
public SDVariable normmax(int... dimensions)
-
normmax
public SDVariable normmax(boolean keepDims, int... dimensions)
-
normmax
public SDVariable normmax(String name, int... dimensions)
-
normmax
public SDVariable normmax(String name, boolean keepDims, int... dimensions)
Max norm (infinity norm) reduction operation: The output contains the max norm for each tensor/subset along the specified dimensions:
out = max(abs(x[i]))
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Output variable namekeepDims- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensionsdimensions- dimensions to reduce over- Returns:
- Output variable
-
argmax
public SDVariable argmax(int... dimensions)
-
argmax
public SDVariable argmax(String name, int... dimensions)
-
argmax
public SDVariable argmax(String name, boolean keepDims, int... dimensions)
Argmax array reduction operation, optionally along specified dimensions.
Output values are the index of the maximum value of each slice along the specified dimension.
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Name of the output variablekeepDims- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensionsdimensions- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed- Returns:
- Output variable: reduced array of rank (input rank - num dimensions) if keepDims = false, or of rank (input rank) if keepdims = true
-
argmin
public SDVariable argmin(int... dimensions)
-
argmin
public SDVariable argmin(String name, int... dimensions)
-
argmin
public SDVariable argmin(String name, boolean keepDims, int... dimensions)
Argmin array reduction operation, optionally along specified dimensions.
Output values are the index of the minimum value of each slice along the specified dimension.
Note that if keepDims = true, the output variable has the same rank as the input variable, with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting the mean along a dimension).
Example: if input has shape [a,b,c] and dimensions=[1] then output has shape: keepDims = true: [a,1,c]
keepDims = false: [a,c]- Parameters:
name- Name of the output variablekeepDims- If true: keep the dimensions that are reduced on (as length 1). False: remove the reduction dimensionsdimensions- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed- Returns:
- Output variable: reduced array of rank (input rank - num dimensions) if keepDims = false, or of rank (input rank) if keepdims = true
-
length
public SDVariable length()
Return the total number of elements in this array- Returns:
-
shape
public SDVariable shape()
Get the shape of the array as a dynamic SDVariable- Returns:
- Shape SDVariable
-
rank
public SDVariable rank()
Get the rank of this variable as a dynamic SDVariable- Returns:
- Rank SDVariable
-
reshape
public SDVariable reshape(SDVariable newShape)
Reshape the current variable to the specified (dynamic) shape. The output variable will have the same values as the input, but with the specified shape.
Note that prod(shape) must match length(input) == prod(input.shape)- Parameters:
newShape- New shape for variable- Returns:
- Output variable
-
reshape
public SDVariable reshape(String name, SDVariable newShape)
Reshape the current variable to the specified (dynamic) shape. The output variable will have the same values as the input, but with the specified shape.
Note that prod(shape) must match length(input) == prod(input.shape)- Parameters:
newShape- New shape for variable- Returns:
- Output variable
-
reshape
public SDVariable reshape(int... newShape)
Reshape the current variable to the specified shape. The output variable will have the same values as the input, but with the specified shape.
Note that prod(shape) must match length(input) == prod(input.shape)- Parameters:
newShape- New shape for variable- Returns:
- Output variable
-
reshape
public SDVariable reshape(long... newShape)
Reshape the current variable to the specified shape. The output variable will have the same values as the input, but with the specified shape.
Note that prod(shape) must match length(input) == prod(input.shape)- Parameters:
newShape- New shape for variable- Returns:
- Output variable
-
permute
public SDVariable permute(int... dimensions)
Permute the dimensions of the current variable according to the specified permutation indices.
Example: if the current variable has shape [a,b,c] and dimensions = [2,0,1] the output has shape [c,a,b]- Parameters:
dimensions- The new dimension order- Returns:
- Output variable (permuted input)
-
permute
public SDVariable permute(SDVariable dimensions)
-
setArray
public SDVariable setArray(INDArray array)
Associate the specified array with this variable- Parameters:
array- Array to associate with this variable- Returns:
- This variable
-
eval
public INDArray eval()
Evaluate the result of this variable- Returns:
-
eval
public INDArray eval(Map<String,INDArray> placeholders)
Evaluate the result of this variable- Returns:
-
addControlDependency
public void addControlDependency(SDVariable controlDependency)
Add a control dependency for this variable on the specified variable.
Control dependencies can be used to enforce the execution order. For example, if a control dependency X->Y exists, then Y will only be executed after X is executed - even if Y wouldn't normally depend on the result/values of X.- Parameters:
controlDependency- Control dependency to add for this variable
-
getView
public SDVariable getView(SDIndex... indices)
Get a variable with content equal to a specified sub-array of this variable.
Can be used (for example) to get rows, columns, sub-matrices, etc.- Parameters:
indices- Indices to get- Returns:
- Sub-array variable
-
get
public SDVariable get(SDIndex... indices)
Get a variable with content equal to a specified sub-array of this variable.
Can be used (for example) to get rows, columns, sub-matrices, etc.- Parameters:
indices- Indices to get- Returns:
- Sub-array variable
-
sliceEnd
public static SDVariable sliceEnd(SDVariable input, SDVariable sliceIndexInput)
-
get
public SDVariable get(SDVariable indices)
Get a variable with content equal to a specified sub-array of this variable.
Can be used (for example) to get rows, columns, sub-matrices, etc. This will loop over the indices (think of it as a list) and concatenate each slice of the input array to the final result. Expected input for indices would be a vector with indices such as 0,1,2,3,4. For each element in the index we then concatenate the result to the previous iteration. Note that this is slow and should only be used in very specific circumstances. OtherwiseStridedSlicewill be more performant for creating views. Many timesStridedSliceavoids this slower approach by directly calculating the strides of a view.- Parameters:
indices- Indices to get- Returns:
- Sub-array variable
-
put
public SDVariable put(SDVariable indices, SDVariable toPut, SDVariable putIndices)
Get a variable with content equal to a specified sub-array of this variable.
Can be used (for example) to get rows, columns, sub-matrices, etc. This will loop over the indices (think of it as a list) and add each slice specified by the indices from the source to the new array. The end result will be this variable but with the new updated results. Note that this is slow and should only be used in very specific circumstances. OtherwiseStridedSlicewill be more performant for creating views. Many timesStridedSliceavoids this slower approach by directly calculating the strides of a view.- Parameters:
indices- Indices to gettoPut- the source array to pull results from to put in to this arrayputIndices- the equivalent indices for the other array- Returns:
- the updated array with the elements from the toPut array put in to this new array
-
createLoopPut
public static SameDiff createLoopPut(SDVariable relative, SDVariable indices)
Create a graph that takes in the indices as a placeholder, loops over each element in the index vector and appends the slice to the end result. This graph is equivalent to something like: INDArray input = ....; INDArray indices = ...; INDArray result = input.get(NDArrayIndex.point(indices.getInt(0)); for(int i = i; i < maxIndex && customInputResult; i++) { result = Nd4j.concat(0,input.get(NDArrayIndex.point(i))); } return resultNote this is similar to
INDArray.get(INDArray)- Parameters:
relative- the expected target input variable. We use this to pull expected return data type for the resultindices- the indices to get- Returns:
- the graph for dynamically creating a result graph
-
createLoopConcat
public static SameDiff createLoopConcat(SDVariable relative, SDVariable indices)
Create a graph that takes in the indices as a placeholder, loops over each element in the index vector and appends the slice to the end result. This graph is equivalent to something like: INDArray input = ....; INDArray indices = ...; INDArray result = input.get(NDArrayIndex.point(indices.getInt(0)); for(int i = i; i < maxIndex && customInputResult; i++) { result = Nd4j.concat(0,input.get(NDArrayIndex.point(i))); } return result Note this is similar toINDArray.get(INDArray)- Parameters:
relative- the expected target input variable. We use this to pull expected return data type for the resultindices- the indices to get- Returns:
- the graph for dynamically creating a result graph
-
convertToConstant
public SDVariable convertToConstant()
Convert this variable to a constant. This is equivalent to "freezing" a variable so that it's value won't be changed by further training.
This can only be done for variables and placeholders, not ARRAY type variables (which are usually network activations). As a constant, this variable will no longer be modified by any subsequent training.- Returns:
- This variable (now a constant)
-
convertToVariable
public SDVariable convertToVariable()
Convert this variable to a VARIABLE type SDVariable.
This can only be done for constants and placeholders, not ARRAY type variables (which are usually network activations). As a variable, this variable will modified during any subsequent training.- Returns:
- This variable (now a variable type SDVariable)
-
rename
public SDVariable rename(String newName)
Rename this variable to a new name. Equivalent toSameDiff.renameVariable(String, String)- Parameters:
newName- The new name for the variable - no variable with this name must already exist- Returns:
- The current variable (same object)
-
markAsLoss
public void markAsLoss()
Mark this variable as a loss function variable. This means that this variable will be minimized via backprop during training.
This will add the variable as a loss to any others - i.e., if multiple variables are marked as losses, their values will be summed to give the total network loss.
Note that only floating point (Float16/32/64) variables may be marked as a loss.
Note also that only ARRAY type SDVariables can be marked as losses to be minimized. That is, we cannot mark the value of a constant, variable or placeholder to be minimized as doing so would not make sense.
This is equivalent toSameDiff.addLossVariable(String)
-
hasGradient
public boolean hasGradient()
Determine if this variable has a gradient with respect to the current loss. Note that: (a) Non-floating-point variables (integer, string, etc) will never have gradients
(b) This method will return false if no gradient function has been created yet. SeeSameDiff.createGradFunction()andSameDiff.setLossVariables(String...)
(c) Floating point variables may not have any gradient if the current loss does not depend on the variable at all- Returns:
- True if a gradient variable exists for the specified variable, for the current loss
-
clone
public SDVariable clone(String name, SameDiff sd)
-
clone
public SDVariable clone(SameDiff sd)
-
-