Lattice

From Open Ideas

Jump to: navigation, search

A Lattice is a set of points ordered like a tree: There is a primely point at time zero, where the lattice starts, like the trunk of the tree. In the next time step this trunk devides into several (editable) children. These children generate again the same number of children in the next step. It is possible that one point has two or more different parents, this means, there are some possible ways to reach that point. An important part of a lattice are the weights, meaning the probabilities of reaching a child, these are assigned to the way from a point to a child.

Contents

Describtion in qff

In qff, a lattice is realized as a tree of points, a markov chain can reach in a finite number of time steps. The basic abstract class all lattices in qff based on is BaseLattice. Like in grid there are two possible "points": You can of course just use double values as points with the class AbstractDoubleLattice, but its also possible to choose other data with the class AbstractLattice. This general data class is not checked yet and barely used, so we concentrate on the first classes. First class one can really create is CachedDoubleLattice(1D,2D). Here you have to decide whether your children should be in one dimension or in two. If you take two, you get at every time step a rectangular of points.

Every lattice has a weight structure, so you have to specify it:

* WeightsStructure.HETEROGENEUOUS,
* .TIMEDEPENDENT,
* .LEVELDEPENDENT and
* .HOMOGENEOUS

Heterogeneuous means that every child has different weights. Timedependent declares the weights of one point to its children and every point at that time takes over this values. Leveldependent means that every point at the same level has the same weights, for example if the first one (at time zero) has values, then the point at time two (if you go up and down) has the same. Last, the easiest is homogeneous, here, you define the weights of the first point and all other points take this, too.

With help of CompoundDoubleLattice(1D,2D) it is possible to bind two lattices of the same size. GeneratedDoubleLattice(1D,2D) provides the alternative to define the points with help of a Function.

Codebook

First we define a simple one-dimensional lattice with two children, 3 periods and homogeneous weight structure.

CachedDoubleLattice1D lattice1 = new CachedDoubleLattice1D(3, 2, WeightsStructure.HOMOGENEOUS);

Now, it is possible to assign values and weights to the points of the lattice.

double[] values = {100.0, 95.0,105.0, 90.0,100.0,110.0, 85.0,95.0,105.0,115.0};
lattice1.setNodes(values);
double[] weights = {0.6, 0.4};
lattice1.setWeights(weights);

The values are set to the lattice by the following rule: The first value (here 100) is assigned to the trunk. The next two (in general: number of children) are assigned bottom-up to the points at time 1 and so on. If we have a two-dimensional lattice, the values are assigned such that the first variable runs faster.

The weights in this case are easy, because from every point they are the same, so the weight from any point (i.e. 100) to the lower child (here 95) is 0.6, and so on. If one took the weight structure TIMEDEPENDENT or HETEROGENEUOUS there are more weights which are assigned to the points at time 1, 2... . Just like the values, in case of a two-dimensional lattice, the first variable runs faster during assigning the weights. But attention if you choose LEVELDEPENDENT: In this case the first weights are not assigned to the trunk, but to that point with the lowest level. This means in our case, the first weight would be assigned to the way from point 90 to the child 85. After assigning all children of this first point, the next one is that point, which now has the lowest level, that doesn't have to be a point at the same timestep. And you hve to pay attention in case of two dimension: In case at least the number of children in one dimension is even, the program expects more weights than really needed. Here, some weights will be skipped or ignored.

It is also possible to set the values seperately for a single point or one timestep:

lattice1.setNode(1, -1, 96.0);
double[] someValues = {91.0, 101.0, 111.0};
lattice1.setNode(2, someValues);

There is a chance to control the settings: The methods nodes(int) and node(int, int) returns the values of the nodes of one time step and the value of a special node. In two dimensions the feature of setting the weights for one timestep or a single weight is embedded. First we create a new 2-dim. lattice with 2 children along the first axis and 3 along the second. Then we assign weights for time zero:

CachedDoubleLattice2D lattice2 = new CachedDoubleLattice2D(3, 2,3, WeightsStructure.HETEROGENEUOUS);
double[] someWeights = {0.2, 0.8, 0.4, 0.6, 0.5, 0.5};
lattice2.setWeights(0, someWeights);
lattice2.setWeight(1, -1,0, -2,1, 0.33);

The last command sets the weight from the point at time 1 at level (-1,0) to the point at level (-2,1) onto 0.33. Here, as in one dimension, you can check your input: weights() returns a double field where all weights are listed; started with them based on the trunk, them based on time one, and so on. If you only want to see the weights at one time, use weights(int) or you look up the weights of a special point with weights(int, int...).

Methods

In the following, we will give the dependencies of the methods for the one-dimensional case, for two dimensions they are equal or respectively. Of course, there are some methods to get the values of the lattices. These are dimension(), numberOfChildren(), getChildren(), getChildren(int), getWeightStructure(), getPeriods(), which are all self-describing. To check, if the combination of time step and level really represends a node, there is isValidNode(int, int). Another way to get the "coordinates" of a node is to ask for it: nodesIndices(int from, int to) will return the indices of the nodes 'from' up to 'to'. If the interesting nodes are the children of a single node, childNodesIndices(int, int...) returns all indices of the children. You can also get all valid time indices with timeIndices(). As well, you can check a certain time using isValidTime(int). The method isValidLevel(int axis, int time, int level) checks whether the level exists at the specified time and axis.

Quite useful method is absLevelBound(int axis, int time), which returns the maximal level the nodes of the lattice can reach at the specified time and axis. Especially intern this method is used often. The method toString() returns a String representation of the lattice. With the help of assign(DoubleFunction, int fromTime, int toTime) it is possible to apply a Function to all nodes between fromTime and toTime.

See also

Personal tools