SHARE
TWEET

HMM

a guest Jun 26th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // V. Computational methods and algorithms:
  2.  
  3.     /**
  4.      * Chooses the next state using the transition matrix
  5.      *
  6.      * @param k current state
  7.      * @return next state
  8.      */
  9.     public int chooseNextState(int k) {
  10.         int nextState = k;
  11.         for (int i = 0; i < numStates; i++) {
  12.             if (stateNames[i] == k) {
  13.                 for (int j = 0; j < stateNames.length; j++) {
  14.  
  15.                 }
  16.             }
  17.         }
  18.         return nextState;
  19.     }
  20.  
  21.     /**
  22.      * Chooses a symbol to emit
  23.      *
  24.      * @param k the current state
  25.      * @return the number of the emitted symbol
  26.      */
  27.     public int emitSymbol(int k) {
  28.         int symbol = -1;
  29.         for (int i = 0; i < numStates; i++) {
  30.             if (stateNames[i] == k) {
  31.                 for (int j = 0; j < symbolNames.length; j++) {
  32.  
  33.                 }
  34.             }
  35.         }
  36.         return symbol;
  37.     }
  38.  
  39.     /**
  40.      * Randomly generate a sequence of symbols using the HMM,
  41.      * the state path used to generate the symbols can be accessed using
  42.      * getGeneratingPath().
  43.      *
  44.      * @return the sequence of emitted symbols
  45.      */
  46.     public String generateSequence() {
  47.         StringBuilder symbols = new StringBuilder(); // the emitted symbols
  48.         StringBuilder path = new StringBuilder(); // the state path used
  49.  
  50.         int state = 0; // initialise in starting state
  51.         int symbol = 0; // declare variable
  52.  
  53.         // choose first state after start
  54.         state = chooseNextState(state);
  55.         path.append(stateNames[state]);
  56.  
  57.         // run algorithm while not back in end state
  58.         while (state != 0 && state <= numStates) {
  59.             symbol = emitSymbol(state); // get symbol for current stae
  60.             symbols.append(symbol); // add symbol to string of emitted symbols
  61.             state = chooseNextState(state); // calculate new state
  62.             path.append(stateNames[state]); // add new state to state path
  63.         }
  64.  
  65.         generatingPath = path.toString(); // access via getGeneratingPath
  66.         return symbols.toString();
  67.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top