Variabl

scalation.modeling.autograd.Variabl
case class Variabl(var data: TensorD, gradFn: Option[Function] = ..., name: Option[String] = ...)(using ops: AutogradOps)

The Variabl case class represents a tensor with automatic differentiation capability. It tracks operations applied to it for backward gradient propagation. Variabls can be combined using arithmetic operations, activation functions, and loss functions. Backpropagation is triggered via the backward method.

Value parameters

data

the tensor data for this variable.

gradFn

an optional function for backpropagation.

name

an optional name for this variable.

ops

the implicit autograd operations for tensor computations.

Attributes

Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

inline def *(other: Variabl): Variabl

Multiplies this variable with another variable element-wise.

Multiplies this variable with another variable element-wise.

Value parameters

other

the variable to multiply.

Attributes

Returns

a new Variabl representing the multiplication.

inline def *(s: Double): Variabl

Multiplies this variable by a constant.

Multiplies this variable by a constant.

Value parameters

s

the constant multiplier.

Attributes

Returns

a new Variabl representing the scaled variable.

inline def +(other: Variabl): Variabl

Adds this variable with another variable.

Adds this variable with another variable.

Value parameters

other

the variable to add.

Attributes

Returns

a new Variabl representing the element-wise addition.

inline def +(s: Double): Variabl

Adds a constant to this variable.

Adds a constant to this variable.

Value parameters

s

the constant to add.

Attributes

Returns

a new Variabl representing the result.

inline def -(other: Variabl): Variabl

Subtracts another variable from this variable.

Subtracts another variable from this variable.

Value parameters

other

the variable to subtract.

Attributes

Returns

a new Variabl representing the element-wise subtraction.

inline def -(s: Double): Variabl

Subtracts a constant from this variable.

Subtracts a constant from this variable.

Value parameters

s

the constant to subtract.

Attributes

Returns

a new Variabl representing the result.

inline def /(other: Variabl): Variabl

Divides this variable by another variable element-wise.

Divides this variable by another variable element-wise.

Value parameters

other

the variable divisor.

Attributes

Returns

a new Variabl representing the division.

inline def /(s: Double): Variabl

Divides this variable by a constant.

Divides this variable by a constant.

Value parameters

s

the constant divisor.

Attributes

Returns

a new Variabl representing the scaled division.

inline def abs: Variabl
def apply(a: SliceArg, b: SliceArg, c: SliceArg): Variabl

Slice this tensor variable along its three dimensions. Allows slicing using either Range objects or the special character '?' to denote selecting the entire dimension (as in x(?, 2, 5 until 10)).

Slice this tensor variable along its three dimensions. Allows slicing using either Range objects or the special character '?' to denote selecting the entire dimension (as in x(?, 2, 5 until 10)).

Value parameters

a

the slice for dimension 0 (a Range or '?')

b

the slice for dimension 1 (a Range or '?')

c

the slice for dimension 2 (a Range or '?')

Attributes

Returns

a new Variabl representing the sliced view

Throws
IllegalArgumentException

if any slice argument is not a Range or '?'

inline def backward(): Unit

Performs backpropagation with a default gradient of ones.

Performs backpropagation with a default gradient of ones.

Attributes

inline def backward(gradOutput: TensorD): Unit

Performs backpropagation using the specified output gradient.

Performs backpropagation using the specified output gradient.

Value parameters

gradOutput

the gradient tensor to propagate.

Attributes

inline def bmm(other: Variabl): Variabl

Performs batched matrix multiplication of this variable with another variable.

Performs batched matrix multiplication of this variable with another variable.

Value parameters

other

the variable to multiply in batches.

Attributes

Returns

a Variabl representing the batch matrix multiplication.

inline def ceil: Variabl
inline def clip(min: Double, max: Double): Variabl
def detach(name: Option[String] = ...): Variabl

Detaches the variable from the computation graph, returning a new variable with the same data.

Detaches the variable from the computation graph, returning a new variable with the same data.

Value parameters

name

an optional new name for the detached variable.

Attributes

Returns

a new variable with identical data but no gradient function.

inline def dot(other: Variabl): Variabl

Computes the dot product of this variable with another variable.

Computes the dot product of this variable with another variable.

Value parameters

other

the variable to perform the dot product with.

Attributes

Returns

a Variabl representing the dot product.

inline def elu(alpha: Double = ...): Variabl

Applies the ELU activation function to this variable.

Applies the ELU activation function to this variable.

Value parameters

alpha

the ELU scaling parameter (default is 1.0).

Attributes

Returns

a Variabl after applying ELU.

inline def exp: Variabl
inline def floor: Variabl
inline def fullLike(value: Double): Variabl

Returns a new variable with data filled with the specified value and the same shape as this variable.

Returns a new variable with data filled with the specified value and the same shape as this variable.

Value parameters

value

the value to fill the new variable with.

Attributes

Returns

a Variabl with the specified value.

inline def gelu: Variabl

Applies the GeLU activation function to this variable.

Applies the GeLU activation function to this variable.

Attributes

Returns

a Variabl after applying GeLU.

inline def id: Variabl
inline def leakyReLU(alpha: Double = ...): Variabl

Applies the LeakyReLU activation function to this variable.

Applies the LeakyReLU activation function to this variable.

Value parameters

alpha

the slope for negative inputs (default is 0.2).

Attributes

Returns

a Variabl after applying LeakyReLU.

inline def log: Variabl
inline def logBase(base: Double): Variabl
inline def matmul(other: Variabl): Variabl

Performs matrix multiplication of this variable with another variable.

Performs matrix multiplication of this variable with another variable.

Value parameters

other

the variable to multiply matrices with.

Attributes

Returns

a Variabl representing the matrix multiplication result.

inline def max(other: Variabl): Variabl
inline def max(s: Double): Variabl
inline def maxValue: Variabl
inline def mean: Variabl
inline def meanAxis(axis: Int): Variabl
inline def min(other: Variabl): Variabl
inline def min(s: Double): Variabl
inline def minValue: Variabl
inline def onesLike(): Variabl

Returns a new variable with data filled with ones and the same shape as this variable.

Returns a new variable with data filled with ones and the same shape as this variable.

Attributes

Returns

a Variabl with ones.

inline def permute(axes: Seq[Int]): Variabl
inline def reciprocal: Variabl
inline def relu: Variabl

Applies the ReLU activation function to this variable.

Applies the ReLU activation function to this variable.

Attributes

Returns

a Variabl after applying ReLU.

inline def reshape(newShape: Seq[Int]): Variabl
inline def round: Variabl
inline def shape: List[Int]

Returns the shape of the tensor data as a list of dimensions.

Returns the shape of the tensor data as a list of dimensions.

Attributes

Returns

a List [Int] representing the dimensions of the data.

inline def sigmoid: Variabl

Applies the sigmoid activation function to this variable.

Applies the sigmoid activation function to this variable.

Attributes

Returns

a Variabl after applying sigmoid.

inline def sign: Variabl
inline def softmax: Variabl

Applies the softmax activation function to this variable.

Applies the softmax activation function to this variable.

Attributes

Returns

a Variabl after applying softmax.

inline def sqrt: Variabl
inline def std: Variabl
inline def stdAxis(axis: Int): Variabl
inline def sum: Variabl
inline def sumAlongAxis(axis: Int): Variabl

Computes the sum of elements along the specified axis and returns the result as a new variable.

Computes the sum of elements along the specified axis and returns the result as a new variable.

Value parameters

axis

the axis along which to compute the sum.

Attributes

Returns

a Variabl representing the sum along the axis.

inline def tanh: Variabl

Applies the tanh activation function to this variable.

Applies the tanh activation function to this variable.

Attributes

Returns

a Variabl after applying tanh.

override def toString: String

Returns a string representation of the variable. If a name is defined, it is included in the output.

Returns a string representation of the variable. If a name is defined, it is included in the output.

Attributes

Returns

a string containing the name (if available) and data.

Definition Classes
Any
inline def transpose(i: Int, j: Int): Variabl
inline def unary_-: Variabl
inline def varAxis(axis: Int): Variabl
inline def variance: Variabl
inline def zerosLike(): Variabl

Returns a new variable with data filled with zeros and the same shape as this variable.

Returns a new variable with data filled with zeros and the same shape as this variable.

Attributes

Returns

a Variabl with zeros.

inline def ~>(f: Variabl => Variabl): Variabl

Chains the provided function with this variable.

Chains the provided function with this variable.

Value parameters

f

a function that takes a Variabl and returns a Variabl.

Attributes

Returns

the result of applying the function to this variable.

inline def ~^(s: Int): Variabl

Raises this variable to the power of the given exponent.

Raises this variable to the power of the given exponent.

Value parameters

s

the exponent to raise this variable to.

Attributes

Returns

a new Variabl representing the power operation.

Inherited methods

def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product

Concrete fields

var grad: TensorD

The gradient tensor associated with this variable. Initially set to a tensor of zeros with the same shape as data.

The gradient tensor associated with this variable. Initially set to a tensor of zeros with the same shape as data.

Attributes