public interface Tensor
A tensor consists of a set of dimension names and a set of cells containing scalar values. Each cell is is identified by its address, which consists of a set of dimension-label pairs which defines the location of that cell. Both dimensions and labels are string on the form of an identifier or integer.
The size of the set of dimensions of a tensor is called its order.
In contrast to regular mathematical formulations of tensors, this definition of a tensor allows sparseness as there is no built-in notion of a contiguous space, and even in cases where a space is implied (such as when address labels are integers), there is no requirement that every implied cell has a defined value. Undefined values have no define representation as they are never observed.
Tensors can be read and serialized to and from a string form documented in the toString()
method.
Modifier and Type | Interface and Description |
---|---|
static interface |
Tensor.Builder |
static class |
Tensor.Cell |
Modifier and Type | Method and Description |
---|---|
default Tensor |
add(Tensor argument) |
default Tensor |
approxEqual(Tensor argument) |
static boolean |
approxEquals(double x,
double y) |
static boolean |
approxEquals(double x,
double y,
double tolerance) |
default Tensor |
argmax(String dimension) |
default Tensor |
argmin(String dimension) |
default double |
asDouble()
Returns the value of this as a double if it has no dimensions and one value
|
default Tensor |
atan2(Tensor argument) |
default Tensor |
avg() |
default Tensor |
avg(List<String> dimensions) |
default Tensor |
avg(String dimension) |
Iterator<Tensor.Cell> |
cellIterator()
Returns the cell of this in some undefined order
|
Map<TensorAddress,Double> |
cells()
Returns an immutable map of the cells of this in no particular order.
|
default Tensor |
concat(double argument,
String dimension) |
default Tensor |
concat(Tensor argument,
String dimension) |
static String |
contentToString(Tensor tensor) |
default Tensor |
count() |
default Tensor |
count(List<String> dimensions) |
default Tensor |
count(String dimension) |
static Tensor |
diag(TensorType type) |
default Tensor |
divide(Tensor argument) |
default Tensor |
equal(Tensor argument) |
boolean |
equals(Object o)
Returns whether this tensor and the given tensor is mathematically equal:
That they have the same dimension *names* and the same content.
|
static boolean |
equals(Tensor a,
Tensor b)
Implement here to make this work across implementations.
|
default Tensor |
fmod(Tensor argument) |
static Tensor |
from(String tensorString)
Returns a tensor instance containing the given data on the standard string format returned by toString.
|
static Tensor |
from(String tensorType,
String tensorString)
Returns a tensor instance containing the given data on the standard string format returned by toString
|
static Tensor |
from(TensorType type,
String tensorString)
Returns a tensor instance containing the given data on the standard string format returned by toString
|
static Tensor |
generate(TensorType type,
Function<List<Long>,Double> valueSupplier) |
double |
get(TensorAddress address)
Returns the value of a cell, or NaN if this cell does not exist/have no value
|
default boolean |
isEmpty()
Returns whether this have any cells
|
default Tensor |
join(Tensor argument,
DoubleBinaryOperator combinator) |
default Tensor |
l1Normalize(String dimension) |
default Tensor |
l2Normalize(String dimension) |
default Tensor |
larger(Tensor argument) |
default Tensor |
largerOrEqual(Tensor argument) |
default Tensor |
ldexp(Tensor argument) |
default Tensor |
map(DoubleUnaryOperator mapper) |
default Tensor |
matmul(Tensor argument,
String dimension) |
default Tensor |
max() |
default Tensor |
max(List<String> dimensions) |
default Tensor |
max(String dimension) |
default Tensor |
max(Tensor argument) |
default Tensor |
min() |
default Tensor |
min(List<String> dimensions) |
default Tensor |
min(String dimension) |
default Tensor |
min(Tensor argument) |
default Tensor |
multiply(Tensor argument) |
default Tensor |
notEqual(Tensor argument) |
default Tensor |
pow(Tensor argument) |
default Tensor |
prod() |
default Tensor |
prod(List<String> dimensions) |
default Tensor |
prod(String dimension) |
static Tensor |
random(TensorType type) |
static Tensor |
range(TensorType type) |
default Tensor |
reduce(Reduce.Aggregator aggregator,
List<String> dimensions)
Aggregates cells over a set of dimensions, or over all dimensions if no dimensions are specified
|
default Tensor |
reduce(Reduce.Aggregator aggregator,
String... dimensions)
Aggregates cells over a set of dimensions, or over all dimensions if no dimensions are specified
|
default Tensor |
rename(List<String> fromDimensions,
List<String> toDimensions) |
default Tensor |
rename(String fromDimension,
String toDimension) |
long |
size()
Returns the number of cells in this
|
default Tensor |
smaller(Tensor argument) |
default Tensor |
smallerOrEqual(Tensor argument) |
default Tensor |
softmax(String dimension) |
default Tensor |
subtract(Tensor argument) |
default Tensor |
sum() |
default Tensor |
sum(List<String> dimensions) |
default Tensor |
sum(String dimension) |
static String |
toStandardString(Tensor tensor)
Call this from toString in implementations to return the standard string format.
|
String |
toString()
Returns this tensor on the form
{address1:value1,address2:value2,...}
where each address is on the form {dimension1:label1,dimension2:label2,...} ,
and values are numbers. |
TensorType |
type() |
Iterator<Double> |
valueIterator()
Returns the values of this in some undefined order
|
default Tensor |
xwPlusB(Tensor w,
Tensor b,
String dimension) |
TensorType type()
default boolean isEmpty()
long size()
double get(TensorAddress address)
Iterator<Tensor.Cell> cellIterator()
Map<TensorAddress,Double> cells()
default double asDouble()
IllegalStateException
- if this does not have zero dimensions and one valuedefault Tensor map(DoubleUnaryOperator mapper)
default Tensor reduce(Reduce.Aggregator aggregator, String... dimensions)
default Tensor reduce(Reduce.Aggregator aggregator, List<String> dimensions)
default Tensor join(Tensor argument, DoubleBinaryOperator combinator)
static Tensor diag(TensorType type)
static Tensor random(TensorType type)
static Tensor range(TensorType type)
default Tensor avg()
default Tensor count()
default Tensor max()
default Tensor min()
default Tensor prod()
default Tensor sum()
String toString()
{address1:value1,address2:value2,...}
where each address is on the form {dimension1:label1,dimension2:label2,...}
,
and values are numbers.
Cells are listed in the natural order of tensor addresses: Increasing size primarily and by element lexical order secondarily.
Note that while this is suggestive of JSON, it is not JSON.
static String toStandardString(Tensor tensor)
tensor
- the tensor to return the standard string format ofboolean equals(Object o)
static boolean equals(Tensor a, Tensor b)
static boolean approxEquals(double x, double y, double tolerance)
static boolean approxEquals(double x, double y)
static Tensor from(TensorType type, String tensorString)
type
- the type of the tensor to returntensorString
- the tensor on the standard tensor string formatstatic Tensor from(String tensorType, String tensorString)
tensorType
- the type of the tensor to return, as a string on the tensor type format, given in
TensorType.fromSpec(java.lang.String)
tensorString
- the tensor on the standard tensor string formatCopyright © 2018. All rights reserved.