org.knowceans.topics.cgen
Class MixNode

java.lang.Object
  extended by org.knowceans.topics.cgen.MixItem
      extended by org.knowceans.topics.cgen.MixNode
Direct Known Subclasses:
MixNodeFastSerial

public class MixNode
extends MixItem

represents a mixture node.

TODO: this may be subclassed for node data types


Field Summary
(package private)  java.lang.String alpha
          hyperparameter name
static int C1ASINGLE
          C1A single input, non-root edge (e.g., LDA: phi[k])
static int C1BSEQADD
          C1B single input added sequence (e.g., PAM: theta[m,x])
static int C1INPUT
          any C1 input
static int C1ROOT
          single input, root edge (e.g., LDA: theta[m]), Note: this is different from SEQUENCE, where a single C1 sequence input among many leads to the classification)
static int C2MULTI
          C2 multiple non-sequence input edges (w/kSel, e.g., Bi-LDA: phi[u,m])
static int C3MERGED
          C3 merged component C3 (NOT using kSel, novel structure)
static int C4SWITCH
          C4 switched input C4 (using kSel, e.g., Multi-grain LDA)
static int C5COUPLED
          C5 coupled node C5 (using coupledNodes)
static int C5MAIN
          C5 main node: all parameters and hyperparameters in coupledNodes are deferred to this node
(package private)  java.lang.String constK
          constant value for K
(package private)  MixNode coupledMainNode
          main node in a coupled group
(package private)  java.util.List<MixNode> coupledNodes
          nodes this shares parameters with (only one for now)
(package private)  int dimAlpha
          dimension of alpha: 0..2
static int E2SPLIT
          E2 multiple output sequences
(package private)  boolean fixedAlpha
          don't estimate alpha
static int HIDDEN
          summarising hidden structures
(package private)  java.lang.String j
          component group name
 java.lang.String J
          component group index range (elements of alpha)
(package private)  java.lang.String jSel
          component group selector (Java expression as in j = )
(package private)  java.lang.String k
          component name
(package private)  java.lang.String K
          component count = domain (= range of kSel over all inputs)
(package private)  java.lang.String kSel
          component selector (Java expression as in k = )
static int N6AGGREG
          N6 aggregation node
static java.util.List<MixEdge> NOEDGE
          represents the empty edge set
(package private)  java.lang.String ntheta
          count name
(package private)  java.lang.String nthetasum
          sum count name
static int SEQINPUT
          any sequence input: state by no parameters at query-time
static int SEQUENCE
          sequence node (will generate query-time structure)
(package private)  boolean sparse
          sparse representation of visible nodes: by a label sequence
(package private)  java.lang.String T
          outgoing edge count = T of first edge
(package private)  java.lang.String theta
          parameter name
static int TOPIC
          topic node (global scope)
static int VISIBLE
          is this node observed (set a priori)
 
Fields inherited from class org.knowceans.topics.cgen.MixItem
children, datatype, indent, linktype, name, parents, UNRECOG
 
Constructor Summary
MixNode(java.lang.String name, java.lang.String theta, boolean sparse)
          create a visible node
MixNode(java.lang.String name, java.lang.String theta, java.lang.String alpha)
          constructs a hidden node
 
Method Summary
 java.lang.String assignVarsInput()
          assign input to the variables of this edge
 boolean check(java.io.PrintStream out)
          check node consistency
 boolean classify()
          classify the data and linking types of this node.
 void coupleNode(MixNode node)
          couple the node with the argument.
 void coupleParams()
          couple the parameters of coupled nodes
 java.lang.String declareVars()
          declare node structures
 java.lang.String expandSelector(MixSequence seq, boolean theta, boolean alpha, java.util.List<MixEdge> ee, boolean q)
          expand selector code, replacing indices appropriately.
 java.lang.String getAlphaEstimator()
          generate a hyperparameter estimator for this node, based on DirichletEstimation methods
 MixEdge getChildEdge(int i)
           
 MixEdge getChildEdge(java.lang.String x)
           
 java.util.List<MixEdge> getChildren()
           
 java.lang.String getComponentCount()
          get the count of the components according to the kSel expression.
 java.util.List<MixNode> getCoupledNodes()
          get couple nodes as a shortcut to resolving a C3 structure.
 MixEdge getEdge(java.lang.String x)
          get the edge from its variable.
 java.lang.String getGibbsTerm(MixSequence seq, java.util.List<MixEdge> ee, boolean q)
           
 java.lang.String getLatexGibbsTerm(MixSequence seq, java.util.List<MixEdge> ee, boolean q, boolean mathml)
          latex description of this node's inference term
 java.lang.String getLikelihoodTerm(MixSequence seq, java.util.List<MixEdge> ee)
          get the likelihood term for this node
 java.lang.String getName()
          short name of this node
 MixEdge getParentEdge(int i)
           
 MixEdge getParentEdge(java.lang.String x)
           
 java.util.List<MixEdge> getParents()
           
 java.lang.String getThetaEstimator(boolean q)
          generate a parameter estimator, based on the Dirichlet posterior mean
 java.lang.String getVariable()
           
 java.lang.String incNode(MixSequence seq, java.util.List<MixEdge> ee, boolean inc, boolean q, boolean synced)
          return code to increment this node's counts
 java.lang.String initVars(boolean q)
          initialise this node
 int intersection(java.util.List<MixEdge> eeSamp)
          checks whether the set of edges intersects with the node, i.e., whether one of its elements is a parent or child edge of this node
(package private)  java.lang.String kIndex(MixSequence seq, java.util.List<MixEdge> ee)
          return the index that expandIndex assigns a value to, so the result of expandIndex is directly used in computations.
 java.lang.String listTypedVarsInput(java.util.Set<java.lang.String> unique)
          list the variables for this node comma-separated, adding to the set unique and ignoring variables already in it.
 java.lang.String listVarsInput(java.util.Set<java.lang.String> unique)
          list the variables for this node comma-separated, adding to the set unique and ignoring variables already in it.
 void nameEmptyVars()
          complete the selector and index structures after the network has been connected and classified
 java.lang.String printDetails()
           
 java.lang.String printSelector()
          print selector string (may be large)
 java.lang.String printType()
          print the type of this node
 void setConstants(java.util.Map<java.lang.String,java.lang.String> constants)
          set any constant for this node
(package private)  java.lang.String[] tIndex(MixSequence seq, java.util.List<MixEdge> ee, boolean forQuery)
          determine the index of the output edge, given the active edges ee (qualified by h) and the current sequence
 java.lang.String toString()
           
 
Methods inherited from class org.knowceans.topics.cgen.MixItem
typeString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VISIBLE

public static final int VISIBLE
is this node observed (set a priori)

See Also:
Constant Field Values

SEQUENCE

public static final int SEQUENCE
sequence node (will generate query-time structure)

See Also:
Constant Field Values

TOPIC

public static final int TOPIC
topic node (global scope)

See Also:
Constant Field Values

HIDDEN

public static final int HIDDEN
summarising hidden structures

See Also:
Constant Field Values

N6AGGREG

public static final int N6AGGREG
N6 aggregation node

See Also:
Constant Field Values

C1ROOT

public static final int C1ROOT
single input, root edge (e.g., LDA: theta[m]), Note: this is different from SEQUENCE, where a single C1 sequence input among many leads to the classification)

See Also:
Constant Field Values

C1ASINGLE

public static final int C1ASINGLE
C1A single input, non-root edge (e.g., LDA: phi[k])

See Also:
Constant Field Values

C1BSEQADD

public static final int C1BSEQADD
C1B single input added sequence (e.g., PAM: theta[m,x])

See Also:
Constant Field Values

C2MULTI

public static final int C2MULTI
C2 multiple non-sequence input edges (w/kSel, e.g., Bi-LDA: phi[u,m])

See Also:
Constant Field Values

C3MERGED

public static final int C3MERGED
C3 merged component C3 (NOT using kSel, novel structure)

See Also:
Constant Field Values

C4SWITCH

public static final int C4SWITCH
C4 switched input C4 (using kSel, e.g., Multi-grain LDA)

See Also:
Constant Field Values

C5COUPLED

public static final int C5COUPLED
C5 coupled node C5 (using coupledNodes)

See Also:
Constant Field Values

C5MAIN

public static final int C5MAIN
C5 main node: all parameters and hyperparameters in coupledNodes are deferred to this node

See Also:
Constant Field Values

SEQINPUT

public static final int SEQINPUT
any sequence input: state by no parameters at query-time

See Also:
Constant Field Values

C1INPUT

public static final int C1INPUT
any C1 input

See Also:
Constant Field Values

E2SPLIT

public static final int E2SPLIT
E2 multiple output sequences

See Also:
Constant Field Values

theta

java.lang.String theta
parameter name


ntheta

java.lang.String ntheta
count name


nthetasum

java.lang.String nthetasum
sum count name


k

java.lang.String k
component name


K

java.lang.String K
component count = domain (= range of kSel over all inputs)


constK

java.lang.String constK
constant value for K


T

java.lang.String T
outgoing edge count = T of first edge


alpha

java.lang.String alpha
hyperparameter name


dimAlpha

int dimAlpha
dimension of alpha: 0..2


fixedAlpha

boolean fixedAlpha
don't estimate alpha


j

java.lang.String j
component group name


J

public java.lang.String J
component group index range (elements of alpha)


kSel

java.lang.String kSel
component selector (Java expression as in k = )


jSel

java.lang.String jSel
component group selector (Java expression as in j = )


NOEDGE

public static java.util.List<MixEdge> NOEDGE
represents the empty edge set


coupledNodes

java.util.List<MixNode> coupledNodes
nodes this shares parameters with (only one for now)


coupledMainNode

MixNode coupledMainNode
main node in a coupled group


sparse

boolean sparse
sparse representation of visible nodes: by a label sequence

Constructor Detail

MixNode

public MixNode(java.lang.String name,
               java.lang.String theta,
               java.lang.String alpha)
constructs a hidden node

Parameters:
name -
theta -
alpha -

MixNode

public MixNode(java.lang.String name,
               java.lang.String theta,
               boolean sparse)
create a visible node

Parameters:
name -
theta -
sparse - whether it is connected with a label sequence (like authors) that associates only the non-null subset of the domain
Method Detail

coupleNode

public void coupleNode(MixNode node)
couple the node with the argument. For a group of coupled nodes, there is one main node. If node is the main node of a group, the complete group is added to this node.

Parameters:
node -

classify

public boolean classify()
classify the data and linking types of this node. Assumes that edges have been classified already.

Specified by:
classify in class MixItem
Returns:
false if invalid

nameEmptyVars

public void nameEmptyVars()
complete the selector and index structures after the network has been connected and classified


coupleParams

public void coupleParams()
couple the parameters of coupled nodes


intersection

public int intersection(java.util.List<MixEdge> eeSamp)
checks whether the set of edges intersects with the node, i.e., whether one of its elements is a parent or child edge of this node

Parameters:
n -
eeSamp -
Returns:
0 for no intersection, 1 for parent intersection, 2 for child intersection

getCoupledNodes

public java.util.List<MixNode> getCoupledNodes()
get couple nodes as a shortcut to resolving a C3 structure.

Returns:

getChildEdge

public MixEdge getChildEdge(int i)

getChildEdge

public MixEdge getChildEdge(java.lang.String x)

getParentEdge

public MixEdge getParentEdge(int i)

getParentEdge

public MixEdge getParentEdge(java.lang.String x)

getParents

public java.util.List<MixEdge> getParents()
Overrides:
getParents in class MixItem

getChildren

public java.util.List<MixEdge> getChildren()
Overrides:
getChildren in class MixItem

getComponentCount

public java.lang.String getComponentCount()
get the count of the components according to the kSel expression. This assumes that each dimension is fully used, which (for now) excludes models like hPAM that linearise a hierarchical structure.

Alternatively, an expression in K may be used.

Returns:

getEdge

public MixEdge getEdge(java.lang.String x)
get the edge from its variable. If two such variables exist, the first one found is returned. However, variable names should be unique.

Parameters:
x -
Returns:
edge or null if it does not exist

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

printSelector

public java.lang.String printSelector()
print selector string (may be large)

Returns:

printType

public java.lang.String printType()
Description copied from class: MixItem
print the type of this node

Specified by:
printType in class MixItem
Returns:

printDetails

public java.lang.String printDetails()
Overrides:
printDetails in class MixItem

getVariable

public java.lang.String getVariable()
Specified by:
getVariable in class MixItem

setConstants

public void setConstants(java.util.Map<java.lang.String,java.lang.String> constants)
set any constant for this node

Overrides:
setConstants in class MixItem

check

public boolean check(java.io.PrintStream out)
check node consistency

Overrides:
check in class MixItem
Returns:

getName

public java.lang.String getName()
short name of this node

Specified by:
getName in class MixItem
Returns:

listVarsInput

public java.lang.String listVarsInput(java.util.Set<java.lang.String> unique)
list the variables for this node comma-separated, adding to the set unique and ignoring variables already in it.

Specified by:
listVarsInput in class MixItem
Returns:

listTypedVarsInput

public java.lang.String listTypedVarsInput(java.util.Set<java.lang.String> unique)
list the variables for this node comma-separated, adding to the set unique and ignoring variables already in it.

Specified by:
listTypedVarsInput in class MixItem
Returns:

assignVarsInput

public java.lang.String assignVarsInput()
assign input to the variables of this edge

Specified by:
assignVarsInput in class MixItem
Returns:

declareVars

public java.lang.String declareVars()
declare node structures

Specified by:
declareVars in class MixItem
Parameters:
u -
n -
Returns:

initVars

public java.lang.String initVars(boolean q)
initialise this node

Specified by:
initVars in class MixItem
Parameters:
q -
Returns:

expandSelector

public java.lang.String expandSelector(MixSequence seq,
                                       boolean theta,
                                       boolean alpha,
                                       java.util.List<MixEdge> ee,
                                       boolean q)
expand selector code, replacing indices appropriately. Currently, this understands comma notation and expands all parent variables as hx or x[m][n] according to the filter set ee.

TODO: allow complex statements in brackets

Parameters:
theta - expand for theta: k = kSel
alpha - expand for alpha: j = jSel
q -
Returns:
a Java expression that creates node.k or

kIndex

java.lang.String kIndex(MixSequence seq,
                        java.util.List<MixEdge> ee)
return the index that expandIndex assigns a value to, so the result of expandIndex is directly used in computations.

Parameters:
seq -
ee -
forQuery -
Returns:

tIndex

java.lang.String[] tIndex(MixSequence seq,
                          java.util.List<MixEdge> ee,
                          boolean forQuery)
determine the index of the output edge, given the active edges ee (qualified by h) and the current sequence

Parameters:
seq -
ee -
forQuery -
Returns:

getGibbsTerm

public java.lang.String getGibbsTerm(MixSequence seq,
                                     java.util.List<MixEdge> ee,
                                     boolean q)

getLatexGibbsTerm

public java.lang.String getLatexGibbsTerm(MixSequence seq,
                                          java.util.List<MixEdge> ee,
                                          boolean q,
                                          boolean mathml)
latex description of this node's inference term

Parameters:
seq -
ee -
q -
mathml - (or latex)
Returns:

incNode

public java.lang.String incNode(MixSequence seq,
                                java.util.List<MixEdge> ee,
                                boolean inc,
                                boolean q,
                                boolean synced)
return code to increment this node's counts

Parameters:
ee - active edges
inc - whether to increment or decrement
q - for querying
synced - use synchronisation
Returns:

getLikelihoodTerm

public java.lang.String getLikelihoodTerm(MixSequence seq,
                                          java.util.List<MixEdge> ee)
get the likelihood term for this node

Parameters:
seq -
ee -
Returns:

getThetaEstimator

public java.lang.String getThetaEstimator(boolean q)
generate a parameter estimator, based on the Dirichlet posterior mean


getAlphaEstimator

public java.lang.String getAlphaEstimator()
generate a hyperparameter estimator for this node, based on DirichletEstimation methods

Returns: