Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import numpy as np import matplotlib.pyplot as plt import seaborn from mpl _ toolkits.mplot 3 d import Axes 3 D class HMM ( object )

import numpy as np
import matplotlib.pyplot as plt
import seaborn
from mpl_toolkits.mplot3d import Axes3D
class HMM(object):
def __init__(self, transition_matrix_matrix,current_state):
self.transition_matrix = transition_matrix
self.current_state = current_state
def filtering(self,observation_matrix):
new_state = np.dot(observation_matrix,np.dot(self.transition_matrix,self.current_state))
new_state_normalized = new_state/np.sum(new_state)
self.current_state = new_state_normalized
return new_state_normalized
def prediction(self):
new_state = np.dot(self.transition_matrix,self.current_state)
new_state_normalized = new_state/np.sum(new_state)
self.current_state=new_state_normalized
return new_state_normalized
def plot_state(self):
fig = plt.figure()
ax1= fig.add_subplot(111, projection='3d')
xpos =[0,0,1,2,2,1]
ypos =[0,1,1,1,0,0]
zpos = np.zeros(len(initial_state.shape))
dx = np.ones(len(initial_state.shape))
dy = np.ones(len(initial_state.shape))
dz = self.current_state
ax1.bar3d(xpos, ypos, zpos, dx, dy, dz, color='#ce8900')
ax1.set_xticks([0.,1.,2.,3.])
ax1.set_yticks([0.,1.,2.])
plt.show()
def create_observation_matrix(self,error_rate, no_discrepancies):
sensor_list=[]
for number in no_discrepancies:
probability=(1-error_rate)**(4-number)*error_rate**number
sensor_list.append(probability)
observation_matrix = np.zeros((len(sensor_list),len(sensor_list)))
np.fill_diagonal(observation_matrix,sensor_list)
return observation_matrix
# step 1: define initial_state
# initial_state
# step 2: compute transition matrix
# transition_matrix
# step 3: based on the given observations from sensor readings, compute the observation matrix, the error rate is 0.25
# sensor reading: [SWE, NW, N, NE]
Model = HMM(transition_matrix,initial_state)
Model2= HMM(transition_matrix,initial_state)
# localize of the robot using filtering
state_1= Model.filtering(observation_matrix_SWE)
Model.plot_state()
state_2= Model.filtering(observation_matrix_NW)
Model.plot_state()
state_3= Model.filtering(observation_matrix_N)
Model.plot_state()
state_4= Model.filtering(observation_matrix_NE)
Model.plot_state()
state_5= Model.filtering(observation_matrix_SWE)
Model.plot_state()
# localize of the robot using filtering (three first timesteps) and prediction (two last timesteps)
state_6= Model2.filtering(observation_matrix_SWE)
Model2.plot_state()
state_7= Model2.filtering(observation_matrix_NW)
Model2.plot_state()
state_8= Model2.filtering(observation_matrix_N)
Model2.plot_state()
prediction_1= Model2.prediction()
Model2.plot_state()
prediction_2= Model2.prediction()
Model2.plot_state()
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

1. What is your age? 45 or younger 4655 5665 6675 7685 86 or older

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago