de.jstacs.algorithms.graphs.tensor
Class SymmetricTensor

java.lang.Object
  extended by de.jstacs.algorithms.graphs.tensor.Tensor
      extended by de.jstacs.algorithms.graphs.tensor.SymmetricTensor

public class SymmetricTensor
extends Tensor

This class can be used for Tensors with a special symmetry property. This property states that for a given target node and for all permutations of parents 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.

Author:
Jens Keilwagen

Field Summary
 
Fields inherited from class de.jstacs.algorithms.graphs.tensor.Tensor
L, order, powers
 
Constructor Summary
SymmetricTensor(AsymmetricTensor asym_tensor)
           
SymmetricTensor(double[][][] asym_tensor, int N, byte k)
           
SymmetricTensor(int n, byte k)
           
SymmetricTensor(SymmetricTensor[] parts, double[] weights)
          The constructor can be used creating a new SymmetricTensor as weighted sum of SymmetricTensors
 
Method Summary
 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)
           
 int[] getMaximalEdgeFor(byte k, int child, int... parents)
          Returns the edge permute(parents[0],...
 double getRootValue(int child)
          Returns the value for child as root.
 int getTrueIndexForLastGetBest()
          Returns the edge from getBest in an endcoded index.
 double getValue(byte k, int child, int... parents)
          Returns the value for the edge parents[0],...
 void resetValue(byte k, int child, int... parents)
          Set 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
 
Methods inherited from class de.jstacs.algorithms.graphs.tensor.Tensor
getAsymIndex, getNumberOfNodes, getOrder, readTensorFromFile, toDouble3DArray, writeTensorToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SymmetricTensor

public SymmetricTensor(int n,
                       byte k)

SymmetricTensor

public SymmetricTensor(SymmetricTensor[] parts,
                       double[] weights)
                throws IllegalArgumentException
The constructor can be used creating a new SymmetricTensor as weighted sum of SymmetricTensors

Parameters:
parts - the SymmetricTensors
weights - the weight for each SymmetricTensor
Throws:
IllegalArgumentException - if something went wrong

SymmetricTensor

public SymmetricTensor(AsymmetricTensor asym_tensor)

SymmetricTensor

public SymmetricTensor(double[][][] asym_tensor,
                       int N,
                       byte k)
Method Detail

getBest

public 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.

Parameters:
child - the target node
par - 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} than par = {0,1,2,4,5}
k - the number of parentes used from par
Returns:
the best (=maximal) weight

getEdgeFromIndex

public int[] getEdgeFromIndex(int idx,
                              int k)

getMaximalEdgeFor

public int[] getMaximalEdgeFor(byte k,
                               int child,
                               int... parents)
Description copied from class: Tensor
Returns the edge permute(parents[0],...,parents[k-1]) -> child that maximizes the score.

Specified by:
getMaximalEdgeFor in class Tensor

getRootValue

public double getRootValue(int child)
Description copied from class: Tensor
Returns the value for child as root.

Specified by:
getRootValue in class Tensor
Parameters:
child - the name of the node
Returns:
the value for the node

getTrueIndexForLastGetBest

public int getTrueIndexForLastGetBest()
Returns the edge from getBest in an endcoded index.

See Also:
getBest(int, int[], byte)

getValue

public double getValue(byte k,
                       int child,
                       int... parents)
Description copied from class: Tensor
Returns the value for the edge parents[0],...,parents[k-1] -> child.

Specified by:
getValue in class Tensor
Parameters:
k - the number parents to be used
child - the child node
parents - the parents nodes (only the first k will be used
Returns:
the value for the edge parents[0],...,parents[k-1] -> child

resetValue

public void resetValue(byte k,
                       int child,
                       int... parents)
Set the value for the edge parents -> child to Double.NEGATIVE_INFTINITY.

Specified by:
resetValue in class Tensor
Parameters:
k - the number parents to be used
child - the child node
parents - the parents nodes (only the first k will be used

setRootValue

public void setRootValue(int child,
                         double val)
Description copied from class: Tensor
Sets the value val for the root node child.

Specified by:
setRootValue in class Tensor
Parameters:
child - the name of the node
val - the value for the node

setValue

public 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

Specified by:
setValue in class Tensor
Parameters:
k - the number parents to be used
val - the new value
child - the child node
parents - the parents nodes (only the first k will be used