Question

Observable Markov Model Given the observable Markov Model with three states, S1, S2, S3, initial probabilities...

Observable Markov Model

Given the observable Markov Model with three states, S1, S2, S3, initial probabilities \pi = [0.5, 0.2, 0.3]^T
and transition probabilities

A = [0.4 0.3 0.3
0.2 0.6 0.2
0.1 0.1 0.8]

write a code that generates
i) 20 sequences of 100 states,
ii) 20 sequences of 1000 states,
iii) 100 sequences of 100 states,
iv) 100 sequences of 1000 states.

Java or R implementation

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

/**

*

* @author RAM

*/

import java.text.*;

import java.util.*;

class Observable {

// State names and state-to-state transition probabilities

int nstate;           // number of states (incl initial state)

String[] state;       // names of the states

double[][] loga;     

// Emission names and emission probabilities

int nesym;            // number of emission symbols

String esym;         

double[][] loge;      // loge[k][ei] = log(P(emit ei in state k))

// Input:

// state = array of state names (except initial state)

// amat = matrix of transition probabilities (except initial state)

// esym = string of emission names

// emat = matrix of emission probabilities

public Observable(String[] state, double[][] amat,

             String esym, double[][] emat) {

    if (state.length != amat.length)

      throw new IllegalArgumentException("Observable: state and amat disagree");

    if (amat.length != emat.length)

      throw new IllegalArgumentException("Observable: amat and emat disagree");

    for (int i=0; i<amat.length; i++) {

      if (state.length != amat[i].length)

        throw new IllegalArgumentException("Observable: amat non-square");

      if (esym.length() != emat[i].length)

        throw new IllegalArgumentException("Observable: esym and emat disagree");

    }     

    // Set up the transition matrix

    nstate = state.length + 1;

    this.state = new String[nstate];

    loga = new double[nstate][nstate];

    this.state[0] = "S1";        // initial state

    loga[0][0] = Double.NEGATIVE_INFINITY; // = log(0)

    double fromstart = Math.log(1.0/state.length);

    for (int j=1; j<nstate; j++)

      loga[0][j] = fromstart;

    for (int i=1; i<nstate; i++) {

      // Reverse state names for efficient backwards concatenation

      this.state[i] = new StringBuffer(state[i-1]).reverse().toString();

      loga[i][0] = Double.NEGATIVE_INFINITY; // = log(0)

      for (int j=1; j<nstate; j++)

        loga[i][j] = Math.log(amat[i-1][j-1]);

    }

  

}

}

class MarklovState {

public static void main(String[] args) {

    dice();

}

static void dice() {

    String[] state = { "S1", "S2","S3" };   

    double[][] aprob = { { 0.4, 0.3,0.3},

                         { 0.2,0.6,0.2 },

                         {0.1,0.1,0.8}

                        };

    String esym = "20";

    double[][] eprob = { { 0.5,0.2,0.3}};

    Observable Observable = new Observable(state, aprob, esym, eprob);

}

}


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
Observable Markov Model Given the observable Markov Model with three states, S1, S2, S3, initial probabilities...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT