Skip to content
This repository has been archived by the owner on Sep 26, 2018. It is now read-only.

transition matrix simulation #2

Open
ulf1 opened this issue Aug 9, 2017 · 0 comments
Open

transition matrix simulation #2

ulf1 opened this issue Aug 9, 2017 · 0 comments

Comments

@ulf1
Copy link
Member

ulf1 commented Aug 9, 2017

modes

  • iterate over a fixed number of periods
  • iterate till a state reach some level
  • store all states at t

example code

def sim_migration_to_default(trans_mat, max_wgt_defaults=0.5, max_iter=1000, wgt_states=None):
    import numpy as np
    # number of states
    num_states = trans_mat.shape[0];
    # weights for each states (sum equals 1)
    if wgt_states is None:
        wgt_states = np.ones((1,num_states)) / num_states;
        #wgt_states = np.zeros((1,num_states)); wgt_states[0,0] = 1.
    # loop
    it = 1
    while wgt_states[0,-1] < max_wgt_defaults: 
        wgt_states = np.dot(wgt_states, trans_mat);
        if it >= max_iter:
            return None, wgt_states;
        else:
            it += 1;
    # in case the while loop aborted, return the periods
    return it, wgt_states;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant