com.ailab.hmm
Class Model

java.lang.Object
  |
  +--com.ailab.hmm.Model

public class Model
extends java.lang.Object
implements java.io.Serializable

Markov model with symbol-generation probabilities. The class Hmm is built on top of this class. Please refer to Rabiner 1989.

See Also:
Serialized Form

Constructor Summary
Model()
          Construct Model with a minimum size (number of states: 1, number of symbols: 1).
Model(boolean bRandomize)
          Construct Model with a minimum size (number of states: 1, number of symbols: 1).
Model(int nstates, int nsymbols)
          Construct Model by specifying dimensions.
Model(int nstates, int nsymbols, boolean bRandomize)
          Construct Model by specifying dimensions.
Model(int nstates, int nsymbols, int llb, int urb)
          Construct Model by specifying dimensions.
Model(int nstates, int nsymbols, int llb, int urb, boolean bRandomize)
          Construct Model by specifying dimensions.
Model(java.lang.String file)
          Construct Model by loading model parameters from a file.
 
Method Summary
 double[][] getA()
           
 double[] getA(int i)
           
 double getA(int i, int j)
           
 double[][] getB()
           
 double[] getB(int i)
           
 double getB(int i, int k)
           
 int getLLimit(int i)
           
static int getMaxNumStates()
           
static int getMaxNumSymbols()
           
static double getMinProb()
           
 int getNumStates()
           
 int getNumSymbols()
           
 double[] getPi()
           
 double getPi(int j)
           
 double getPi(int t, int j)
           
 int getRLimit(int i)
           
 void loadModel(java.lang.String file)
          Load model parameters from a file.
static void main(java.lang.String[] args)
           
 void saveModel(java.lang.String file)
          Save model parameters to a given file.
 void setA()
          Initialize the state-transition matrix A with random values.
 void setA(boolean bRandomize)
          Initialize the state-transition matrix A.
 void setA(double[][] p)
           
 boolean setA(double[][] p, boolean bNormalize)
           
 void setA(int i, double[] p)
           
 boolean setA(int i, double[] p, boolean bNormalize)
           
 void setA(int i, int j, double p)
           
 boolean setA(int i, int j, double p, boolean bCheck)
           
 void setB()
          Initialize the symbol-generation matrix B with random values.
 void setB(boolean bRandomize)
          Initialize the symbol-generation matrix B.
 void setB(double[][] p)
           
 boolean setB(double[][] p, boolean bNormalize)
           
 void setB(int i, double[] p)
           
 boolean setB(int i, double[] p, boolean bNormalize)
           
 void setB(int i, int k, double p)
           
 boolean setB(int i, int k, double p, boolean bCheck)
           
static double setMinProb(double p)
           
 void setPi()
          Initialize the initial-state row vector Pi with random values.
 void setPi(boolean bRandomize)
          Initialize the initial-state row vector Pi.
 void setPi(double[] p)
           
 boolean setPi(double[] p, boolean bNormalize)
           
 void setPi(int j, double p)
           
 boolean setPi(int j, double p, boolean bCheck)
           
 void setProbability()
          Intialize probability matrices, A, B, and Pi, with random values.
 void setProbability(boolean bRandomize)
          Intialize probability matrices, A, B, and Pi.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Model

public Model()
Construct Model with a minimum size (number of states: 1, number of symbols: 1). The elements of the matrices are initialized by random values.

Model

public Model(boolean bRandomize)
Construct Model with a minimum size (number of states: 1, number of symbols: 1).
Parameters:
bRandomize - If true, the elements of the matrices are initialized by random values

Model

public Model(int nstates,
             int nsymbols)
Construct Model by specifying dimensions. The elements of the matrices are initialized by random values.
Parameters:
nstates - Number of states of a Markov model
nsymbols - Number of symbols generated by the model

Model

public Model(int nstates,
             int nsymbols,
             boolean bRandomize)
Construct Model by specifying dimensions.
Parameters:
nstates - Number of states of a Markov model
nsymbols - Number of symbols generated by the model
bRandomize - If true, the elements of the matrices are initialized by random values

Model

public Model(int nstates,
             int nsymbols,
             int llb,
             int urb)
Construct Model by specifying dimensions. The elements of the matrices are initialized by random values.
Parameters:
nstates - Number of states of a Markov model
nsymbols - Number of symbols generated by the model
llb - Lower-left bound of the non-zero band of the transition matrix (diagonal: 0)
urb - Upper-right bound of the non-zero band of the transition matrix (diagonal: 0)

Model

public Model(int nstates,
             int nsymbols,
             int llb,
             int urb,
             boolean bRandomize)
Construct Model by specifying dimensions.
Parameters:
nstates - Number of states of a Markov model
nsymbols - Number of symbols generated by the model
llb - Lower-left bound of the non-zero band of the transition matrix (diagonal: 0)
urb - Upper-right bound of the non-zero band of the transition matrix (diagonal: 0)
bRandomize - If true, the elements of the matrices are initialized by random values

Model

public Model(java.lang.String file)
Construct Model by loading model parameters from a file.
Parameters:
file - Name of input file
Method Detail

getMaxNumStates

public static int getMaxNumStates()

getMaxNumSymbols

public static int getMaxNumSymbols()

getMinProb

public static double getMinProb()

setMinProb

public static double setMinProb(double p)

getNumStates

public int getNumStates()
Returns:
Number of states in the Markov model

getNumSymbols

public int getNumSymbols()
Returns:
Number of observable symbols

getLLimit

public int getLLimit(int i)
Parameters:
i - Row number of the state-transition matrix A
Returns:
Left limit (column number) outside of which the transition probability is zero

getRLimit

public int getRLimit(int i)
Parameters:
i - Row number of the state-transition matrix A
Returns:
Right limit (column number) outside of which the transition probability is zero

setA

public void setA()
Initialize the state-transition matrix A with random values.

setA

public void setA(boolean bRandomize)
Initialize the state-transition matrix A.
Parameters:
bRandomize - If true, initialize A with random values

setA

public void setA(int i,
                 int j,
                 double p)
Parameters:
i - Row number of the state-transition matrix A
j - Column number of state-transition matrix A
p - Probability value

setA

public boolean setA(int i,
                    int j,
                    double p,
                    boolean bCheck)
Parameters:
i - Row number of the state-transition matrix A
j - Column number of state-transition matrix A
p - Probability value
bCheck - If true, check the index bounds and the range of p
Returns:
true, if successful

setA

public void setA(int i,
                 double[] p)
Parameters:
i - Row number of the state-transition matrix A
p - Row vector of probability values

setA

public boolean setA(int i,
                    double[] p,
                    boolean bNormalize)
Parameters:
i - Row number of the state-transition matrix A
p - Row vector of probability values
bNormalize - If true, renormalize the row in case p is not normalized
Returns:
false, if A is unnormalized

setA

public void setA(double[][] p)
Parameters:
p - Matrix of probability values

setA

public boolean setA(double[][] p,
                    boolean bNormalize)
Parameters:
p - Matrix of probability values
bNormalize - If true, renormalize each row in case p is not normalized
Returns:
false, if A is unnormalized

setB

public void setB()
Initialize the symbol-generation matrix B with random values.

setB

public void setB(boolean bRandomize)
Initialize the symbol-generation matrix B.
Parameters:
bRandomize - If true, initialize B with random values

setB

public void setB(int i,
                 int k,
                 double p)
Parameters:
i - Row number of the symbol-generation matrix B
k - Column number of symbol-generation matrix B
p - Probability value

setB

public boolean setB(int i,
                    int k,
                    double p,
                    boolean bCheck)
Parameters:
i - Row number of the symbol-generation matrix B
k - Column number of symbol-generation matrix B
p - Probability value
bCheck - If true, check the index bounds and the range of p
Returns:
true, if successful

setB

public void setB(int i,
                 double[] p)
Parameters:
i - Row number of the symbol-generation matrix B
p - Row vector of probability values

setB

public boolean setB(int i,
                    double[] p,
                    boolean bNormalize)
Parameters:
i - Row number of the symbol-generation matrix B
p - Row vector of probability values
bNormalize - If true, renormalize the row in case p is not normalized
Returns:
false, if B is unnormalized

setB

public void setB(double[][] p)
Parameters:
p - Matrix of probability values

setB

public boolean setB(double[][] p,
                    boolean bNormalize)
Parameters:
p - Matrix of probability values
bNormalize - If true, renormalize each row in case p is not normalized
Returns:
false, if B is unnormalized

setPi

public void setPi()
Initialize the initial-state row vector Pi with random values.

setPi

public void setPi(boolean bRandomize)
Initialize the initial-state row vector Pi.
Parameters:
bRandomize - If true, initialize Pi with random values

setPi

public void setPi(int j,
                  double p)
Parameters:
j - Column number of initial-state row vector Pi
p - Probability value

setPi

public boolean setPi(int j,
                     double p,
                     boolean bCheck)
Parameters:
j - Column number of initial-state row vector Pi
p - Probability value
bCheck - If true, check the index bounds and the range of p
Returns:
true, if successful

setPi

public void setPi(double[] p)

setPi

public boolean setPi(double[] p,
                     boolean bNormalize)
Parameters:
p - Row vector of probability values
bNormalize - If true, renormalize Pi in case p is not normalized
Returns:
false, if Pi is unnormalized

getA

public double getA(int i,
                   int j)
Parameters:
i - Row number of the state-transition matrix A
j - Column number of state-transition matrix A
Returns:
Probability value of A[i][j]

getA

public double[] getA(int i)
Parameters:
i - Row number of the state-transition matrix A
Returns:
Row vector of probability values of A[i][]

getA

public double[][] getA()
Returns:
State-transition matrix A

getB

public double getB(int i,
                   int k)
Parameters:
i - Row number of the symbol-generation matrix B
k - Column number of symbol-generation matrix B
Returns:
Probability value of B[i][k]

getB

public double[] getB(int i)
Parameters:
i - Row number of the symbol-generation matrix B
Returns:
Row vector of probability value of B[i][]

getB

public double[][] getB()
Returns:
Symbol-generation matrix B

getPi

public double getPi(int j)
Parameters:
j - Column number of inital-state row vector Pi
Returns:
Probability value of Pi[j]

getPi

public double[] getPi()
Returns:
Inital-state row vector Pi

getPi

public double getPi(int t,
                    int j)
Parameters:
t - Index of observation sequence
j - Column number of state vector Pi[t][] at time t
Returns:
Probability value of Pi[t][j]

setProbability

public void setProbability()
Intialize probability matrices, A, B, and Pi, with random values.

setProbability

public void setProbability(boolean bRandomize)
Intialize probability matrices, A, B, and Pi.
Parameters:
bRandomize - If true, initialize probability matrices with random values

loadModel

public void loadModel(java.lang.String file)
Load model parameters from a file.
Parameters:
file - Name of input file

saveModel

public void saveModel(java.lang.String file)
Save model parameters to a given file.
Parameters:
file - Name of output file

main

public static void main(java.lang.String[] args)