org.knowceans.topics.cgen
Class MixNetKernelGenerator

java.lang.Object
  extended by org.knowceans.topics.cgen.MixNetKernelGenerator

public class MixNetKernelGenerator
extends java.lang.Object

reimplementation of generator code for support of: multiple sequences, sparse label indexing, parallelisms, fast sampling state, independent samplers and novel C3 and C5 mixnet structures.

Alternative development method: Start (1) generate existing LDA code programmatically, (2) parametrise the variable names in a MixNet structure that is created programmatically, (3) generalise structures, and (4) hook to mixnet script parser. (5) and (6) are parallel and serial accelerations.

This implementation directly makes use of the mixnet structural primitives, simplifying the generic solver into a straight-forward rule-based system.

Author:
gregor

Field Summary
 double alpha
          standard value for alpha
 java.lang.String corpus
          standard value for corpus
static boolean directAssignments
          use direct assignments of samples in edge sequences z[m][n] etc., otherwise use temporary variables hz etc.
 boolean fastParallel
          generate parallelisation structures (copied counts)
 boolean fastSerial
          generate a fast sampling state (bounds-based method)
 boolean formatCode
          whether to format the code, default = true
 boolean indepSamplers
          generate each variable in its own sampler, ignoring dependencies
 int iter
          standard value for iterations
 int iterq
          standard value for query iterations
 int K
          standard value for K
 boolean nameSuffix
          add a suffix to the model name of the generated class, indicating independent, serial and parallel accellerations
 int parallelMode
          parallelisation model: 0 = active waiting, 1 = semaphore
static boolean runModel
          whether to directly run the model
(package private) static java.util.Set<java.lang.String> uniqueVars
           
 
Constructor Summary
MixNetKernelGenerator(MixNet model)
           
 
Method Summary
 java.lang.String beginClass()
           
 java.lang.String beginInit(boolean q)
           
 java.lang.String beginKernel(boolean q)
           
 java.lang.String beginMain()
           
 java.lang.String codeName()
          get the name as it should be used in the code
 java.lang.String computeWeights(MixSequence seq, boolean q, java.util.List<MixEdge> eeSamp)
          compute the weights for sampling
 java.lang.String constructor()
          create a standard constructor
 java.lang.String declareSelectors(boolean theta, boolean alpha)
          declare all selectors of the associated nodes
 java.lang.String endClass()
           
 java.lang.String endInit(boolean q)
           
 java.lang.String endKernel(boolean q)
           
 java.lang.String endMain()
           
 java.lang.String fields()
          generate the fields of a given MN, both for training and querying
 java.lang.String generateClassCode(MixNet lda)
           
 java.lang.String genVars()
          creates generic variables
 java.lang.String header()
           
 java.lang.String incTopics(MixSequence seq, boolean q, boolean inc, java.util.List<MixEdge> eeSamp)
          decrement topics of this sequence, basically decrementing nodes belonging to the edges ee
 java.lang.String init(boolean q)
          create an init routine
 java.lang.String kernel(boolean q)
          generate a calculation kernel
static void main(java.lang.String[] args)
           
 java.lang.String makeMain()
          generate main method with standard calls to include corpus and run training and queries
 java.lang.String makePpx()
           
 java.lang.String makeToString()
           
 java.lang.String printWeights(MixSequence seq, boolean q, java.util.List<MixEdge> eeSamp, boolean mathml)
          compute the weights for sampling
 java.lang.String sampleTopics(java.util.List<MixEdge> eeSamp, boolean q)
          sample topics of all or active edges
 java.lang.String weightsArray()
          creates the array for sampling topics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uniqueVars

static java.util.Set<java.lang.String> uniqueVars

indepSamplers

public boolean indepSamplers
generate each variable in its own sampler, ignoring dependencies


formatCode

public boolean formatCode
whether to format the code, default = true


fastSerial

public boolean fastSerial
generate a fast sampling state (bounds-based method)


fastParallel

public boolean fastParallel
generate parallelisation structures (copied counts)


parallelMode

public int parallelMode
parallelisation model: 0 = active waiting, 1 = semaphore

TODO: change this to parallelisation modes in thesis


directAssignments

public static boolean directAssignments
use direct assignments of samples in edge sequences z[m][n] etc., otherwise use temporary variables hz etc. default = true


nameSuffix

public boolean nameSuffix
add a suffix to the model name of the generated class, indicating independent, serial and parallel accellerations


runModel

public static boolean runModel
whether to directly run the model


K

public int K
standard value for K


alpha

public double alpha
standard value for alpha


corpus

public java.lang.String corpus
standard value for corpus


iter

public int iter
standard value for iterations


iterq

public int iterq
standard value for query iterations

Constructor Detail

MixNetKernelGenerator

public MixNetKernelGenerator(MixNet model)
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

generateClassCode

public java.lang.String generateClassCode(MixNet lda)

beginClass

public java.lang.String beginClass()

makeMain

public java.lang.String makeMain()
generate main method with standard calls to include corpus and run training and queries

Returns:

codeName

public java.lang.String codeName()
get the name as it should be used in the code

Returns:

beginMain

public java.lang.String beginMain()

endMain

public java.lang.String endMain()

endClass

public java.lang.String endClass()

header

public java.lang.String header()

fields

public java.lang.String fields()
generate the fields of a given MN, both for training and querying

Returns:

genVars

public java.lang.String genVars()
creates generic variables

Parameters:
u -
Returns:

weightsArray

public java.lang.String weightsArray()
creates the array for sampling topics

Parameters:
u -
Returns:

declareSelectors

public java.lang.String declareSelectors(boolean theta,
                                         boolean alpha)
declare all selectors of the associated nodes

Returns:

constructor

public java.lang.String constructor()
create a standard constructor

Returns:

init

public java.lang.String init(boolean q)
create an init routine

Parameters:
q - for querying
Returns:

beginInit

public java.lang.String beginInit(boolean q)
Parameters:
u -
q - for querying
Returns:

endInit

public java.lang.String endInit(boolean q)

kernel

public java.lang.String kernel(boolean q)
generate a calculation kernel

Returns:

beginKernel

public java.lang.String beginKernel(boolean q)

endKernel

public java.lang.String endKernel(boolean q)

computeWeights

public java.lang.String computeWeights(MixSequence seq,
                                       boolean q,
                                       java.util.List<MixEdge> eeSamp)
compute the weights for sampling

Parameters:
sequence -
u -
q -
eeSamp - if non-null, the edges to sample, otherwise all edges
Returns:

sampleTopics

public java.lang.String sampleTopics(java.util.List<MixEdge> eeSamp,
                                     boolean q)
sample topics of all or active edges

Parameters:
u -
eeSamp - active edges
Returns:

incTopics

public java.lang.String incTopics(MixSequence seq,
                                  boolean q,
                                  boolean inc,
                                  java.util.List<MixEdge> eeSamp)
decrement topics of this sequence, basically decrementing nodes belonging to the edges ee

Parameters:
u -
q -
inc - false for dec
ee - list of active edges
Returns:

makePpx

public java.lang.String makePpx()

makeToString

public java.lang.String makeToString()

printWeights

public java.lang.String printWeights(MixSequence seq,
                                     boolean q,
                                     java.util.List<MixEdge> eeSamp,
                                     boolean mathml)
compute the weights for sampling

Parameters:
sequence -
u -
q -
eeSamp - if non-null, the edges to sample, otherwise all edges
mathml - or latex (if false)
Returns: