コード例 #1
0
ファイル: hw2_all.py プロジェクト: jonsondag/ee365
def prob_5a():
    pi, P, T = problem_data.hw2_p5_data()
    probs = np.zeros(T)
    for time in range(T):
        probs[time] = pi[0]
        pi = np.dot(pi, P)
    utils_io.label('2.5a')
    print 'p_T for T={0:d} equals: {1:f}'.format(T-1, np.mean(probs))
コード例 #2
0
ファイル: hw2_all.py プロジェクト: jonsondag/ee365
def prob_5b():
    num_samples = np.array([10, 100, 1000, 10000])
    avg_ones = np.zeros(len(num_samples))
    pi, P, T = problem_data.hw2_p5_data()
    for idx, num in enumerate(num_samples):
        ones = []
        for sample in range(num):
            number_of_ones = 0
            next_dist = pi
            for time in range(T):
                next_idx = get_random_idx(next_dist)
                if next_idx == 0:
                    number_of_ones += 1
                next_dist = P[next_idx]
            ones.append(number_of_ones)
        avg_ones[idx] = np.mean(ones) / T
    utils_io.label('2.5b')
    print 'num in sample: ', num_samples
    print 'p_T estimate for T={0:d} equals: {1:s}'.format(T-1, avg_ones)