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 DataType
dataType
protected SameDiff
sameDiff
protected long[]
shape
protected VariableType
variableType
protected String
varName
-
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 SDVariable
add(double scalar)
SDVariable
add(String varName, double scalar)
Scalar addition:out = this + scalar
Output variable has the same shape as the input variableSDVariable
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.SDVariable
add(SDVariable other)
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.SDVariable
argmax(int... dimensions)
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.SDVariable
argmax(String name, int... dimensions)
SDVariable
argmin(int... dimensions)
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.SDVariable
argmin(String name, int... dimensions)
SDVariable
assign(Number value)
Return a variable with equal shape to the input, but all elements set to the specified valueSDVariable
castTo(@NonNull DataType dataType)
SDVariable
castTo(String name, @NonNull DataType dataType)
SDVariable
clone(String name, SameDiff sd)
SDVariable
clone(SameDiff sd)
SDVariable
convertToConstant()
Convert this variable to a constant.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).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.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.DataType
dataType()
SDVariable
div(double scalar)
SDVariable
div(String varName, double scalar)
Scalar division:out = this / scalar
Output variable has the same shape as the input variableSDVariable
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.SDVariable
div(SDVariable x)
SDVariable
dot(String name, SDVariable other, int... dimensions)
Matrix dot product: out = dot(this,other, dimensions)SDVariable
dot(SDVariable other, int... dimensions)
SDVariable
dup()
Create a new SDVariable, the contents of which is copied from this current variableSDVariable
eq(double value)
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 otherwiseSDVariable
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.SDVariable
eq(SDVariable other)
boolean
equals(Object o)
INDArray
eval()
Evaluate the result of this variableINDArray
eval(Map<String,INDArray> placeholders)
Evaluate the result of this variableSDVariable
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.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.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.INDArray
getArr()
A getter for the allocated ndarray with thisSDVariable
.INDArray
getArr(boolean enforceExistence)
A getter for the allocated ndarray with thisSDVariable
.SDVariable
getGradient()
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 variableLongShapeDescriptor
getShapeDescriptor()
String
getVarName()
Deprecated.Usename()
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.SDVariable
gradient()
Alias for the gradient variable - same asgetGradient()
.SDVariable
gt(double value)
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 otherwiseSDVariable
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.SDVariable
gt(SDVariable other)
SDVariable
gte(double value)
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 otherwiseSDVariable
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.SDVariable
gte(SDVariable other)
boolean
hasGradient()
Determine if this variable has a gradient with respect to the current loss.int
hashCode()
boolean
isConstant()
boolean
isPlaceHolder()
Returns true if this variable is a placeholderSDVariable
length()
Return the total number of elements in this arraySDVariable
lt(double value)
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 otherwiseSDVariable
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.SDVariable
lt(SDVariable other)
SDVariable
lte(double value)
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 otherwiseSDVariable
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.SDVariable
lte(SDVariable other)
void
markAsLoss()
Mark this variable as a loss function variable.SDVariable
max(boolean keepDims, int... dimensions)
SDVariable
max(int... dimensions)
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.SDVariable
max(String name, int... dimensions)
SDVariable
mean(boolean keepDims, int... dimensions)
SDVariable
mean(int... dimensions)
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.SDVariable
mean(String name, int... dimensions)
SDVariable
min(boolean keepDims, int... dimensions)
SDVariable
min(int... dimensions)
SDVariable
min(String name, boolean keepDims, int... dimensions)
Minimum array reduction operation, optionally along specified dimensions.SDVariable
min(String name, int... dimensions)
SDVariable
minus(double other)
For Kotlin operator interopSDVariable
minus(SDVariable other)
For Kotlin operator interopSDVariable
mmul(String name, SDVariable other)
Matrix multiplication: out = mmul(this,other)SDVariable
mmul(String name, SDVariable other, @NonNull MMulTranspose mMulTranspose)
Matrix multiplication: out = mmul(this,other)SDVariable
mmul(SDVariable other)
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.SDVariable
mul(double scalar)
SDVariable
mul(String varName, double scalar)
Scalar multiplication:out = this * scalar
Output variable has the same shape as the input variableSDVariable
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.SDVariable
mul(SDVariable x)
String
name()
Get the name of the SDVariableSDVariable
neg()
Negate op - returns a new variable with the values of the current variable negatedSDVariable
neg(String name)
Negate op - returns a new variable with the values of the current variable negatedSDVariable
neq(double value)
Seeneq(SDVariable)
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 otherwiseSDVariable
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.SDVariable
neq(SDVariable other)
SDVariable
norm1(boolean keepDims, int... dimensions)
SDVariable
norm1(int... dimensions)
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.SDVariable
norm1(String name, int... dimensions)
SDVariable
norm2(boolean keepDims, int... dimensions)
SDVariable
norm2(int... dimensions)
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.SDVariable
norm2(String name, int... dimensions)
SDVariable
normmax(boolean keepDims, int... dimensions)
SDVariable
normmax(int... dimensions)
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.SDVariable
normmax(String name, int... dimensions)
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]SDVariable
permute(SDVariable dimensions)
long[]
placeholderShape()
SDVariable
plus(double other)
For Kotlin operator interopSDVariable
plus(SDVariable other)
For Kotlin operator interopSDVariable
pow(double scalar)
SDVariable
pow(String varName, double scalar)
Scalar power operation:out = this ^ scalar
Output variable has the same shape as the input variableSDVariable
prod(boolean keepDims, int... dimensions)
SDVariable
prod(int... dimensions)
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.SDVariable
prod(String name, int... dimensions)
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.SDVariable
rank()
Get the rank of this variable as a dynamic SDVariableSDVariable
rdiv(double scalar)
SDVariable
rdiv(String varName, double scalar)
Scalar reverse division:out = scalar / this
Output variable has the same shape as the input variableSDVariable
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.SDVariable
rdiv(SDVariable sameDiffVariable)
SDVariable
rename(String newName)
Rename this variable to a new name.SDVariable
reshape(int... newShape)
Reshape the current variable to the specified shape.SDVariable
reshape(long... newShape)
Reshape the current variable to the specified shape.SDVariable
reshape(String name, SDVariable newShape)
Reshape the current variable to the specified (dynamic) shape.SDVariable
reshape(SDVariable newShape)
Reshape the current variable to the specified (dynamic) shape.SDVariable
rsub(double scalar)
SDVariable
rsub(String varName, double scalar)
Scalar reverse subtraction:out = scalar - this
Output variable has the same shape as the input variableSDVariable
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.SDVariable
rsub(SDVariable x)
SDVariable
setArray(INDArray array)
Associate the specified array with this variablevoid
setShape(long... shape)
void
setVarName(String varName)
SDVariable
shape()
Get the shape of the array as a dynamic SDVariablestatic SDVariable
sliceEnd(SDVariable input, SDVariable sliceIndexInput)
SDVariable
squaredDifference(String name, SDVariable x)
Squared difference operation:(this - x)^2
SDVariable
squaredDifference(SDVariable x)
SDVariable
std(boolean biasCorrected, int... dimensions)
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.SDVariable
std(String name, boolean biasCorrected, int... dimensions)
SDVariable
sub(double scalar)
SDVariable
sub(String varName, double scalar)
Scalar subtraction:out = this - scalar
Output variable has the same shape as the input variableSDVariable
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.SDVariable
sub(SDVariable x)
SDVariable
sum(boolean keepDims, int... dimensions)
SDVariable
sum(int... dimensions)
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.SDVariable
sum(String name, int... dimensions)
SDVariable
times(double other)
For Kotlin operator interopSDVariable
times(SDVariable other)
For Kotlin operator interopString
toString()
-
-
-
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
INDArray
associated 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
INDArray
associated 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. OtherwiseStridedSlice
will be more performant for creating views. Many timesStridedSlice
avoids 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. OtherwiseStridedSlice
will be more performant for creating views. Many timesStridedSlice
avoids 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)
-
-