コード例 #1
0
ファイル: chapter02_22.py プロジェクト: halilagin/d3studies
 def draw_fig(self):
       
     plt.figure(1)
     
     plt.subplot(131)
     bp.bar_plot(self.prior,title="prior", ylim=(0,.4))
     
     plt.subplot(132)
     bp.bar_plot(self.posterior,title="posterior", ylim=(0,.4))
     
     plt.subplot(133)
     bp.bar_plot(self.prior2,title="prior2", ylim=(0,.4))
     
     plt.show()
コード例 #2
0
 def draw_fig(self):
     bp.bar_plot(self.belief)
コード例 #3
0
import code.book_plots as bp
import code.gh_internal as gh
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import numpy as np;
from filterpy.discrete_bayes import normalize



def scaled_update (hall, belief, z, prob):
    scale_ = prob/(1-prob)
    belief[hall==1] *=scale_
    normalize(belief)
    
    
belief = np.array([0.1]*10)
hallway = np.array([1, 1, 0, 0, 0, 0, 0, 0, 1, 0])
reading = 1
scaled_update(hallway, belief, reading, prob=0.75)

belief /= sum(belief);
print("belief:", belief)
print ("sum = ", sum(belief))

plt.figure()
bp.bar_plot(belief).show()
コード例 #4
0
import code.book_plots as bp
import code.gh_internal as gh
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import numpy as np
from filterpy.discrete_bayes import normalize


def perfect_predict(belief, move):
    n = len(belief)
    result = np.zeros(n)
    for i in range(n):
        result[i] = belief[(i - move) % n]
    return result


plt.figure(1)
belief = np.array([.35, .1, .2, .3, 0, 0, 0, 0, 0, .05])
plt.subplot(121)
bp.bar_plot(belief, ylim=(0, .4))

newBelief = perfect_predict(belief, 1)
plt.subplot(122)
bp.bar_plot(newBelief, ylim=(0, .4))

plt.show()
コード例 #5
0
ファイル: chapter04_06.py プロジェクト: halilagin/d3studies
 def draw_fig_posterior(self):
     bp.bar_plot(self.posterior,
                 title="posterior-" + str(self.loopIdx),
                 ylim=(0, .4))
コード例 #6
0
ファイル: chapter02_21.py プロジェクト: halilagin/d3studies
 def draw_fig(self):
     bp.bar_plot(self.prior, ylim=(0,0.6))
コード例 #7
0
ファイル: chapter02_18.py プロジェクト: halilagin/d3studies
 def draw_fig(self):
     bp.bar_plot(self.belief, ylim=(0, 0.6))
コード例 #8
0
import matplotlib.pyplot as plt
import numpy as np;
from filterpy.discrete_bayes import normalize


def update(likelihood, belief):
    return normalize( likelihood * belief)

def lh_hallway(hall, belief, z, prob):
    try:
        scale = prob / (1. - prob)
    except ZeroDivisionError:
        scale = 1e8

    likelihood = np.ones(len(hall))
    likelihood[hall==z] *= scale
    return likelihood
    
    
belief = np.array([0.1]*10)
hallway = np.array([1, 1, 0, 0, 0, 0, 0, 0, 1, 0])
reading = 1
likelihood = lh_hallway(hallway, belief, reading, prob=0.75)
postreiorBelief = update(likelihood,belief)

print("belief:", postreiorBelief)
print ("sum = ", sum(postreiorBelief))

plt.figure()
bp.bar_plot(postreiorBelief).show()
コード例 #9
0
import code.book_plots as bp
import code.gh_internal as gh
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import numpy as np
from filterpy.discrete_bayes import normalize


def scaled_update(hall, belief, z, prob):
    scale_ = prob / (1. - prob)
    likelihood = np.ones(len(hall))
    print("su.likelihood:", likelihood)
    likelihood[hall == z] *= scale_
    print("su.likelihood:", likelihood)
    print("su.belief:", belief)
    newhyp = likelihood * belief
    print("su.lik*bel:", newhyp)
    n = normalize(newhyp)
    print("su.posterior:", n)
    return n


belief = np.array([0.1] * 10)
hallway = np.array([1, 1, 0, 0, 0, 0, 0, 0, 1, 0])
reading = 1
newhyp = scaled_update(hallway, belief, reading, prob=0.75)

plt.figure()
bp.bar_plot(newhyp).show()
コード例 #10
0
# def predict( belief, move, p_correct, p_under, p_over):
# 	n = len(belief)
# 	result = np.zeros( n )
# 	w = [p_under, p_correct, p_over]
# 	V = move
# 	for i in range( n ):
# 		result[i] = (
# 			belief[(i-V)%n] * p_correct + belief[(i-V-1)%n] * p_over +
# 			belief[(i-V+1)%n] * p_under)
# 	belief[:] = result

# belief = np.array([0., 0., 0., 1., 0., 0., 0., 0., 0., 0.])
# predict( belief, 2, .8, .1, .1)
# bp.bar_plot( belief )
# grid()
# show()

#
#
#
#
belief = np.array([1/10.]*10)
np.set_printoptions(precision=3)
print belief

hallway = np.array( [1,1,0,0,0,0,0,0,1,0])
belief = hallway*1./3
set_figsize( y=2 )
bp.bar_plot( belief )