public class SymmetricTensor extends Tensor
Tensors with a special symmetry property.
This property states that for a given target node and for all permutations of
parent nodes the edge weight is constant. This is very helpful to save
storage and time in some algorithms. Since it is very useful it also enables
you to use this class if your tensor does not fulfill this property. For that
case the tensor saves only the maximum edge weight and the permutation of the
parent nodes.Tensor,
AsymmetricTensor| Constructor and Description |
|---|
SymmetricTensor(AsymmetricTensor asym_tensor)
This constructor creates and checks a filled asymmetric tensor from an
AsymmetricTensor instance. |
SymmetricTensor(double[][][] asym_tensor,
int N,
byte k)
This constructor creates and checks a filled asymmetric tensor with given
dimension.
|
SymmetricTensor(int n,
byte k)
This constructor creates an empty symmetric tensor with given dimension.
|
SymmetricTensor(SymmetricTensor[] parts,
double[] weights)
The constructor can be used creating a new
SymmetricTensor as
weighted sum of SymmetricTensors. |
| Modifier and Type | Method and Description |
|---|---|
double |
getBest(int child,
int[] par,
byte k)
Returns the maximal weight which can be reached for an edge from
k nodes from the (encoded) set par to the node
child. |
int[] |
getEdgeFromIndex(int idx,
int k)
This method decodes an index in an edge.
|
int[] |
getMaximalEdgeFor(byte k,
int child,
int... parents)
Returns the edge
permute(parents[0],...,parents[k-1]) -> child that maximizes
the score. |
double |
getRootValue(int child)
Returns the value for
child as root. |
int |
getTrueIndexForLastGetBest()
Returns the edge from
getBest(int, int[], byte) in an encoded
index. |
double |
getValue(byte k,
int child,
int... parents)
Returns the value for the edge
parents[0],...,parents[k-1] -> child. |
void |
resetValue(byte k,
int child,
int... parents)
Sets the value for the edge
parents -> child to
Double.NEGATIVE_INFTINITY. |
void |
setRootValue(int child,
double val)
Sets the value
val for the root node child. |
void |
setValue(byte k,
double val,
int child,
int... parents)
Sets the value if it is bigger than the current value and keeps the
parents information.
|
getAsymIndex, getNumberOfNodes, getOrder, readTensorFromFile, toDouble3DArray, writeTensorToFilepublic SymmetricTensor(int n,
byte k)
n - the number of nodesk - the orderTensor.Tensor(int, byte)public SymmetricTensor(SymmetricTensor[] parts, double[] weights) throws IllegalArgumentException
SymmetricTensor as
weighted sum of SymmetricTensors.parts - the SymmetricTensorsweights - the weight for each SymmetricTensorIllegalArgumentException - if something went wrongSymmetricTensor(int, byte)public SymmetricTensor(AsymmetricTensor asym_tensor)
AsymmetricTensor instance.asym_tensor - the asymmetric instanceAsymmetricTensor,
SymmetricTensor(double[][][], int, byte)public SymmetricTensor(double[][][] asym_tensor,
int N,
byte k)
asym_tensor - the tensor weightsN - the number of nodesk - the orderSymmetricTensor(int, byte)public double getBest(int child,
int[] par,
byte k)
k nodes from the (encoded) set par to the node
child.child - the target nodepar - an encoded set, elements are sorted and for all elements
e >= child the real value is (e+1),
e.g. child = 3 and possible parents
= {5,2,0,6,1} then
par = {0,1,2,4,5}k - the number of parents used from parpublic int[] getEdgeFromIndex(int idx,
int k)
idx - the encoded indexk - the orderpublic int[] getMaximalEdgeFor(byte k,
int child,
int... parents)
Tensorpermute(parents[0],...,parents[k-1]) -> child that maximizes
the score.getMaximalEdgeFor in class Tensork - 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 double getRootValue(int child)
Tensorchild as root.getRootValue in class Tensorchild - the name of the nodepublic int getTrueIndexForLastGetBest()
getBest(int, int[], byte) in an encoded
index.getBest(int, int[], byte) in an encoded
indexgetBest(int, int[], byte)public double getValue(byte k,
int child,
int... parents)
Tensorparents[0],...,parents[k-1] -> child.public void resetValue(byte k,
int child,
int... parents)
parents -> child to
Double.NEGATIVE_INFTINITY.resetValue in class Tensork - the orderchild - the index of the child nodeparents - the indices of the parent nodespublic void setRootValue(int child,
double val)
Tensorval for the root node child.setRootValue in class Tensorchild - the name of the nodeval - the value for the nodepublic void setValue(byte k,
double val,
int child,
int... parents)