de.jstacs.algorithms.graphs.tensor

## Class Tensor

• ### Field Summary

Fields
Modifier and Type Field and Description
`protected int` `L`
The number of nodes minus 1.
`protected byte` `order`
The order of the tensor.
`protected int[]` `powers`
An array containing the powers for the number of nodes.
• ### Constructor Summary

Constructors
Constructor and Description
```Tensor(int n, byte k)```
Creates a new `Tensor` for `n` nodes and order `k`.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`protected int` ```getAsymIndex(int child, int[] parents, byte k)```
Returns the index for an asymmetric tensor.
`abstract int[]` ```getMaximalEdgeFor(byte k, int child, int... parents)```
Returns the edge `permute(parents[0],...,parents[k-1]) -> child` that maximizes the score.
`int` `getNumberOfNodes()`
Returns the number of nodes.
`byte` `getOrder()`
Returns the order.
`abstract double` `getRootValue(int child)`
Returns the value for `child` as root.
`abstract double` ```getValue(byte k, int child, int... parents)```
Returns the value for the edge `parents[0],...,parents[k-1] -> child`.
`static Tensor` ```readTensorFromFile(String fname, boolean asym)```
`abstract void` ```resetValue(byte k, int child, int... parents)```
Sets the value for the edge `parents[0],...,parents[k-1] -> child` to `Double.NEGATIVE_INFINITY`.
`abstract void` ```setRootValue(int child, double val)```
Sets the value `val` for the root node `child`.
`abstract void` ```setValue(byte k, double val, int child, int... parents)```
Sets the value for the edge `parents[0],...,parents[k-1] -> child`.
`double[][][]` `toDouble3DArray()`
Creates a three-dimensional `double` array representation of the `Tensor`.
`void` ```writeTensorToFile(String fname, OutputStream desc)```
This method writes a `Tensor` in the exchange format in a specified file.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### powers

`protected int[] powers`
An array containing the powers for the number of nodes. This might be used in the computation of some indices.
• #### L

`protected int L`
The number of nodes minus 1.
• #### order

`protected byte order`
The order of the tensor.
• ### Constructor Detail

• #### Tensor

```public Tensor(int n,
byte k)
throws IllegalArgumentException```
Creates a new `Tensor` for `n` nodes and order `k`.
Parameters:
`n` - the number of nodes
`k` - the order
Throws:
`IllegalArgumentException` - if n < 0 or k < 1
• ### Method Detail

• #### getMaximalEdgeFor

```public abstract int[] getMaximalEdgeFor(byte k,
int child,
int... parents)```
Returns the edge `permute(parents[0],...,parents[k-1]) -> child` that maximizes the score.
Parameters:
`k` - the number of parents to be used
`child` - the child node
`parents` - the parent nodes (only the first `k` will be used)
Returns:
the edge `permute(parents[0],...,parents[k-1]) -> child` that maximizes the score
• #### getNumberOfNodes

`public int getNumberOfNodes()`
Returns the number of nodes.
Returns:
the number of nodes
• #### getOrder

`public byte getOrder()`
Returns the order.
Returns:
the order.
• #### getRootValue

`public abstract double getRootValue(int child)`
Returns the value for `child` as root.
Parameters:
`child` - the name of the node
Returns:
the value for the node
• #### getValue

```public abstract double getValue(byte k,
int child,
int... parents)```
Returns the value for the edge `parents[0],...,parents[k-1] -> child`.
Parameters:
`k` - the number of parents to be used
`child` - the child node
`parents` - the parent nodes (only the first `k` will be used)
Returns:
the value for the edge `parents[0],...,parents[k-1] -> child`
• #### setRootValue

```public abstract void setRootValue(int child,
double val)```
Sets the value `val` for the root node `child`.
Parameters:
`child` - the name of the node
`val` - the value for the node
• #### setValue

```public abstract void setValue(byte k,
double val,
int child,
int... parents)```
Sets the value for the edge `parents[0],...,parents[k-1] -> child`.
Parameters:
`k` - the number of parents to be used
`val` - the new value
`child` - the child node
`parents` - the parent nodes (only the first `k` will be used)
• #### resetValue

```public abstract void resetValue(byte k,
int child,
int... parents)```
Sets the value for the edge `parents[0],...,parents[k-1] -> child` to `Double.NEGATIVE_INFINITY`.
Parameters:
`k` - the number of parents to be used
`child` - the child node
`parents` - the parent nodes (only the first `k` will be used)
• #### writeTensorToFile

```public void writeTensorToFile(String fname,
OutputStream desc)
throws IOException```
This method writes a `Tensor` in the exchange format in a specified file.
Parameters:
`fname` - the file name
`desc` - gives you the possibility to write the description of the tensor file
Throws:
`IOException` - if something went wrong with the file
`readTensorFromFile(String, boolean)`
• #### toDouble3DArray

`public double[][][] toDouble3DArray()`
Creates a three-dimensional `double` array representation of the `Tensor`.
Returns:
a three-dimensional `double` array representation of the `Tensor`
• #### getAsymIndex

```protected int getAsymIndex(int child,
int[] parents,
byte k)```
Returns the index for an asymmetric tensor.
Parameters:
`child` - the child node
`parents` - the parent notes
`k` - the order
Returns:
the index for an asymmetric tensor
`powers`