public abstract class Tensor extends Object
AsymmetricTensor,
SymmetricTensor| 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 and Description |
|---|
Tensor(int n,
byte k)
|
| 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)
The opposite of the method
writeTensorToFile(String, OutputStream). |
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. |
protected int[] powers
protected int L
protected byte order
public Tensor(int n,
byte k)
throws IllegalArgumentException
n - the number of nodesk - the orderIllegalArgumentException - if n < 0 or k < 1public abstract int[] getMaximalEdgeFor(byte k,
int child,
int... parents)
permute(parents[0],...,parents[k-1]) -> child that maximizes
the score.k - the number of parents to be usedchild - the child nodeparents - the parent nodes (only the first k will be used)permute(parents[0],...,parents[k-1]) -> child that
maximizes the scorepublic int getNumberOfNodes()
public byte getOrder()
public abstract double getRootValue(int child)
child as root.child - the name of the nodepublic abstract double getValue(byte k,
int child,
int... parents)
parents[0],...,parents[k-1] -> child.k - the number of parents to be usedchild - the child nodeparents - the parent nodes (only the first k will be used)parents[0],...,parents[k-1] -> childpublic abstract void setRootValue(int child,
double val)
val for the root node child.child - the name of the nodeval - the value for the nodepublic abstract void setValue(byte k,
double val,
int child,
int... parents)
parents[0],...,parents[k-1] -> child.k - the number of parents to be usedval - the new valuechild - the child nodeparents - the parent nodes (only the first k will be used)public abstract void resetValue(byte k,
int child,
int... parents)
parents[0],...,parents[k-1] -> child to
Double.NEGATIVE_INFINITY.k - the number of parents to be usedchild - the child nodeparents - the parent nodes (only the first k will be used)public void writeTensorToFile(String fname, OutputStream desc) throws IOException
Tensor in the exchange format in a specified
file.fname - the file namedesc - gives you the possibility to write the description of the
tensor fileIOException - if something went wrong with the filereadTensorFromFile(String, boolean)public static Tensor readTensorFromFile(String fname, boolean asym) throws NumberFormatException, IOException
writeTensorToFile(String, OutputStream).fname - the file nameasym - true generates an AsymmetricTensor,
otherwise a SymmetricTensorIOException - if something went wrong with the fileNumberFormatException - if the file could not be parsed correctlywriteTensorToFile(String, OutputStream)public double[][][] toDouble3DArray()
double array representation of
the Tensor.double array representation of
the Tensorprotected int getAsymIndex(int child,
int[] parents,
byte k)
child - the child nodeparents - the parent notesk - the orderpowers