0% found this document useful (0 votes)
2 views

AI Lab M.Tech

The document is a lab manual from Bheemanna Khandre Institute of Technology detailing various algorithms and implementations in the field of computer science and engineering. It includes examples of linear regression, support vector machines, case-based reasoning, decision trees, artificial neural networks, KNN for regression, distance metrics, and KNN for classification using the Iris dataset. Each section provides code snippets and explanations for the algorithms implemented.

Uploaded by

Minhaj Choudhry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

AI Lab M.Tech

The document is a lab manual from Bheemanna Khandre Institute of Technology detailing various algorithms and implementations in the field of computer science and engineering. It includes examples of linear regression, support vector machines, case-based reasoning, decision trees, artificial neural networks, KNN for regression, distance metrics, and KNN for classification using the Iris dataset. Each section provides code snippets and explanations for the algorithms implemented.

Uploaded by

Minhaj Choudhry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

BHEEMANNA KHANDRE INSTITUTE OF

TECHNOLOGY BHALKI

Dept. of Computer Science and Engineering


(PG)

ALGORITHMS
&
AI LABORATORY
MCSL106

Lab Manual

1|Page
1. Implement a simple linear regression algorithm to predict a continuous target variable
based on a given dataset.

import numpy as np

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.metrics import mean_squared_error

# Generate synthetic data

np.random.seed(42)

X = 2 * np.random.rand(100, 1)

y = 4 + 3 * X + np.random.randn(100, 1)

# Split data into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Implement Linear Regression using Normal Equation

X_b = np.c_[np.ones((X_train.shape[0], 1)), X_train] # Add bias term

theta_best = np.linalg.inv(X_b.T.dot(X_b)).dot(X_b.T).dot(y_train)

# Make predictions

X_test_b = np.c_[np.ones((X_test.shape[0], 1)), X_test]

y_pred = X_test_b.dot(theta_best)

# Compute mean squared error

mse = mean_squared_error(y_test, y_pred)

print(f"Mean Squared Error: {mse:.4f}")

# Plot results

plt.scatter(X_test, y_test, color='blue', label='Actual data')

plt.plot(X_test, y_pred, color='red', linewidth=2, label='Regression line')

plt.xlabel("X")

2|Page
plt.ylabel("y")

plt.legend()

plt.show()

Output:

3|Page
2. Develop a program to implement a Support Vector Machine for binary classification.
Use a sample dataset and visualize the decision boundary.

import numpy as np

import matplotlib.pyplot as plt

from sklearn import datasets

from sklearn.model_selection import train_test_split

from sklearn.svm import SVC

from sklearn.metrics import accuracy_score

# Generate a synthetic dataset

X, y = datasets.make_classification(n_samples=100, n_features=2, n_classes=2,


n_clusters_per_class=1, random_state=42)

# Split into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train SVM classifier

svm_classifier = SVC(kernel='linear')

svm_classifier.fit(X_train, y_train)

# Make predictions

y_pred = svm_classifier.predict(X_test)

# Calculate accuracy

accuracy = accuracy_score(y_test, y_pred)

print(f"Accuracy: {accuracy:.4f}")

# Visualize decision boundary

def plot_decision_boundary(X, y, model):

x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1

y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1

xx, yy = np.meshgrid(np.linspace(x_min, x_max, 100), np.linspace(y_min, y_max, 100))

4|Page
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])

Z = Z.reshape(xx.shape)

plt.contourf(xx, yy, Z, alpha=0.3)

plt.scatter(X[:, 0], X[:, 1], c=y, edgecolor='k')

plt.xlabel("Feature 1")

plt.ylabel("Feature 2")

plt.title("SVM Decision Boundary")

plt.show()

plot_decision_boundary(X, y, svm_classifier)

5|Page
3. Develop a simple case-based reasoning system that stores instances of past cases.
Implement a retrieval method to find the most similar cases and make
predictions based on them.

import numpy as np

from scipy.spatial import distance

# Define a simple case-based reasoning system

class CaseBasedReasoning:

def init (self):

self.case_base = [] # Stores past cases as tuples (features, label)

def add_case(self, features, label):

"""Adds a case to the case base."""

self.case_base.append((np.array(features), label))

def retrieve_similar(self, query_features, k=1):

"""Finds the k most similar cases based on Euclidean distance."""

query_features = np.array(query_features)

distances = [(case, distance.euclidean(query_features, case[0])) for case in self.case_base]

distances.sort(key=lambda x: x[1]) # Sort by distance

return [case[0] for case in distances[:k]] # Return the k closest cases

def predict(self, query_features, k=1):

"""Predicts the label based on the k most similar cases."""

similar_cases = self.retrieve_similar(query_features, k)

labels = [case[1] for case in similar_cases]

6|Page
return max(set(labels), key=labels.count) # Majority vote

# Example usage

cbr = CaseBasedReasoning()

cbr.add_case([2, 3], "Class A")

cbr.add_case([1, 5], "Class B")

cbr.add_case([3, 4], "Class A")

cbr.add_case([5, 6], "Class B")

# Query case

query = [3, 3]

predicted_label = cbr.predict(query, k=2)

print(f"Predicted class for {query}: {predicted_label}")

Output;

Predicted class for [3, 5]: Class B

7|Page
4. Write a program to demonstrate the ID3 decision tree algorithm using an
appropriate dataset for classification.

import numpy as np

import pandas as pd

from sklearn.model_selection import train_test_split

from sklearn.tree import DecisionTreeClassifier, plot_tree

import matplotlib.pyplot as plt

from sklearn.metrics import accuracy_score

# Sample dataset: Play Tennis

data = {

'Outlook': ['Sunny', 'Sunny', 'Overcast', 'Rain', 'Rain', 'Rain', 'Overcast', 'Sunny', 'Sunny', 'Rain',
'Sunny', 'Overcast', 'Overcast', 'Rain'],

'Temperature': ['Hot', 'Hot', 'Hot', 'Mild', 'Cool', 'Cool', 'Cool', 'Mild', 'Cool', 'Mild', 'Mild',
'Mild', 'Hot', 'Mild'],

'Humidity': ['High', 'High', 'High', 'High', 'Normal', 'Normal', 'Normal', 'High', 'Normal',
'Normal', 'Normal', 'High', 'Normal', 'High'],

'Wind': ['Weak', 'Strong', 'Weak', 'Weak', 'Weak', 'Strong', 'Strong', 'Weak', 'Weak', 'Weak',
'Strong', 'Strong', 'Weak', 'Strong'],

'PlayTennis': ['No', 'No', 'Yes', 'Yes', 'Yes', 'No', 'Yes', 'No', 'Yes', 'Yes', 'Yes', 'Yes', 'Yes', 'No']

df = pd.DataFrame(data)

# Convert categorical data to numerical

8|Page
df = pd.get_dummies(df, columns=['Outlook', 'Temperature', 'Humidity', 'Wind'],
drop_first=True)

# Split dataset into features and labels

X = df.drop(columns=['PlayTennis'])

y = df['PlayTennis']

# Split into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train ID3 Decision Tree Classifier

dt_classifier = DecisionTreeClassifier(criterion='entropy', random_state=42)

dt_classifier.fit(X_train, y_train)

# Make predictions

y_pred = dt_classifier.predict(X_test)

# Calculate accuracy

accuracy = accuracy_score(y_test, y_pred)

print(f"Accuracy: {accuracy:.4f}")

# Visualize the decision tree

plt.figure(figsize=(12, 8))

plot_tree(dt_classifier, feature_names=X.columns, class_names=['No', 'Yes'], filled=True)

plt.show()

9|Page
Output:

10 | P a g e
5. Build an Artificial Neural Network by implementing the Backpropagation
algorithm and test it with suitable datasets.

import numpy as np

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import StandardScaler

from sklearn.datasets import make_moons

import matplotlib.pyplot as plt

# Generate dataset

X, y = make_moons(n_samples=500, noise=0.2, random_state=42)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Normalize data

scaler = StandardScaler()

X_train = scaler.fit_transform(X_train)

X_test = scaler.transform(X_test)

# Define activation functions

def sigmoid(x):

return 1 / (1 + np.exp(-x))

def sigmoid_derivative(x):

return x * (1 - x)

# Initialize neural network parameters

input_size = 2

hidden_size = 4

output_size = 1

learning_rate = 0.1

11 | P a g e
theta1 = np.random.randn(input_size, hidden_size)

bias1 = np.zeros((1, hidden_size))

theta2 = np.random.randn(hidden_size, output_size)

bias2 = np.zeros((1, output_size))

# Train neural network using backpropagation

epochs = 10000

for epoch in range(epochs):

# Forward propagation

hidden_input = np.dot(X_train, theta1) + bias1

hidden_output = sigmoid(hidden_input)

final_input = np.dot(hidden_output, theta2) + bias2

final_output = sigmoid(final_input)

# Compute error

error = y_train.reshape(-1, 1) - final_output

# Backpropagation

d_output = error * sigmoid_derivative(final_output)

d_hidden = d_output.dot(theta2.T) * sigmoid_derivative(hidden_output)

# Update weights and biases

theta2 += hidden_output.T.dot(d_output) * learning_rate

bias2 += np.sum(d_output, axis=0, keepdims=True) * learning_rate

theta1 += X_train.T.dot(d_hidden) * learning_rate

bias1 += np.sum(d_hidden, axis=0, keepdims=True) * learning_rate

if epoch % 1000 == 0:

loss = np.mean(np.abs(error))

12 | P a g e
print(f"Epoch {epoch}, Loss: {loss:.4f}")

# Test the trained neural network

hidden_test = sigmoid(np.dot(X_test, theta1) + bias1)

final_test = sigmoid(np.dot(hidden_test, theta2) + bias2)

predictions = (final_test > 0.5).astype(int).flatten()

accuracy = np.mean(predictions == y_test)

print(f"Test Accuracy: {accuracy:.4f}")

# Plot dataset and decision boundary

def plot_decision_boundary(X, y, model_params):

theta1, bias1, theta2, bias2 = model_params

x_min, x_max = X[:, 0].min() - 0.5, X[:, 0].max() + 0.5

y_min, y_max = X[:, 1].min() - 0.5, X[:, 1].max() + 0.5

xx, yy = np.meshgrid(np.linspace(x_min, x_max, 100), np.linspace(y_min, y_max, 100))

Z = sigmoid(np.dot(sigmoid(np.dot(np.c_[xx.ravel(), yy.ravel()], theta1) + bias1), theta2) +


bias2)

Z = Z.reshape(xx.shape)

plt.contourf(xx, yy, Z, levels=[0, 0.5, 1], alpha=0.3)

plt.scatter(X[:, 0], X[:, 1], c=y, edgecolor='k')

plt.title("ANN Decision Boundary")

plt.show()

plot_decision_boundary(X_test, y_test, (theta1, bias1, theta2, bias2))

13 | P a g e
Output:

Epoch 0, Loss: 0.4881

Epoch 1000, Loss: 0.0461

Epoch 2000, Loss: 0.0390

Epoch 3000, Loss: 0.0355

Epoch 4000, Loss: 0.0334

Epoch 5000, Loss: 0.0308

Epoch 6000, Loss: 0.0290

Epoch 7000, Loss: 0.0276

Epoch 8000, Loss: 0.0266

Epoch 9000, Loss: 0.0258

Test Accuracy: 0.9600

14 | P a g e
6. Implement a KNN algorithm for regression tasks instead of classification. Use a
small dataset, and predict continuous values based on the average of the nearest
neighbors.

import numpy as np

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import StandardScaler

from sklearn.metrics import mean_squared_error

# Generate synthetic dataset

np.random.seed(42)

X = np.linspace(0, 10, 100).reshape(-1, 1)

y = np.sin(X).ravel() + np.random.normal(scale=0.2, size=X.shape[0])

# Split dataset

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Standardize features

scaler = StandardScaler()

X_train = scaler.fit_transform(X_train)

X_test = scaler.transform(X_test)

# KNN Regression Implementation

class KNNRegressor:

def init (self, k=3):

self.k = k

15 | P a g e
self.X_train = None

self.y_train = None

def fit(self, X, y):

self.X_train = X

self.y_train = y

def predict(self, X):

y_pred = []

for x in X:

distances = np.linalg.norm(self.X_train - x, axis=1)

k_neighbors = np.argsort(distances)[:self.k]

y_pred.append(np.mean(self.y_train[k_neighbors]))

return np.array(y_pred)

# Train and predict using KNN Regression

knn_regressor = KNNRegressor(k=5)

knn_regressor.fit(X_train, y_train)

y_pred = knn_regressor.predict(X_test)

# Evaluate model

mse = mean_squared_error(y_test, y_pred)

print(f"Mean Squared Error: {mse:.4f}")

# Plot results

16 | P a g e
plt.scatter(X_test, y_test, color='blue', label='Actual values')

plt.scatter(X_test, y_pred, color='red', label='Predicted values')

plt.xlabel("X")

plt.ylabel("y")

plt.legend()

plt.title("KNN Regression Predictions")

plt.show()

Output:

17 | P a g e
7. Create a program that calculates different distance metrics (Euclidean and
Manhattan) between two points in a dataset. Allow the user to input two points
and display the calculated distances.

import numpy as np

def euclidean_distance(point1, point2):

return np.sqrt(np.sum((np.array(point1) - np.array(point2)) ** 2))

def manhattan_distance(point1, point2):

return np.sum(np.abs(np.array(point1) - np.array(point2)))

# User input for two points

print("Enter coordinates for two points:")

point1 = list(map(float, input("Point 1 (comma-separated): ").split(',')))

point2 = list(map(float, input("Point 2 (comma-separated): ").split(',')))

# Calculate distances

euc_dist = euclidean_distance(point1, point2)

man_dist = manhattan_distance(point1, point2)

# Display results

print(f"Euclidean Distance: {euc_dist:.4f}")

print(f"Manhattan Distance: {man_dist:.4f}")

Output:

Enter coordinates for two points:

Point 1 (comma-separated): 10,20

Point 2 (comma-separated): 30,40

Euclidean Distance: 28.2843

Manhattan Distance: 40.0000

18 | P a g e
8. Implement the k-Nearest Neighbor algorithm to classify the Iris dataset, printing
both correct and incorrect predictions.

import numpy as np

import pandas as pd

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import StandardScaler

from sklearn.metrics import accuracy_score

from sklearn.datasets import load_iris

# Load Iris dataset

data = load_iris()

X = data.data

y = data.target

# Split dataset into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Standardize features

scaler = StandardScaler()

X_train = scaler.fit_transform(X_train)

X_test = scaler.transform(X_test)

# Implement k-NN Classifier

class KNNClassifier:

def init (self, k=3):

19 | P a g e
self.k = k

def fit(self, X, y):

self.X_train = X

self.y_train = y

def predict(self, X):

predictions = []

for x in X:

distances = np.linalg.norm(self.X_train - x, axis=1)

k_neighbors = np.argsort(distances)[:self.k]

labels, counts = np.unique(self.y_train[k_neighbors], return_counts=True)

predictions.append(labels[np.argmax(counts)])

return np.array(predictions)

# Train and predict using k-NN

knn = KNNClassifier(k=5)

knn.fit(X_train, y_train)

y_pred = knn.predict(X_test)

# Display correct and incorrect predictions

correct = (y_pred == y_test)

print("Correct Predictions:")

for i, (actual, pred) in enumerate(zip(y_test, y_pred)):

if correct[i]:

20 | P a g e
print(f"Index {i}: Actual = {actual}, Predicted = {pred}")

print("\nIncorrect Predictions:")

for i, (actual, pred) in enumerate(zip(y_test, y_pred)):

if not correct[i]:

print(f"Index {i}: Actual = {actual}, Predicted = {pred}")

# Calculate and print accuracy

accuracy = accuracy_score(y_test, y_pred)

print(f"\nAccuracy: {accuracy:.4f}")

Output:

Correct Predictions:

Index 0: Actual = 1, Predicted = 1

Index 1: Actual = 0, Predicted = 0

Index 2: Actual = 2, Predicted = 2

Index 3: Actual = 1, Predicted = 1

Index 4: Actual = 1, Predicted = 1

Index 5: Actual = 0, Predicted = 0

Index 6: Actual = 1, Predicted = 1

Index 7: Actual = 2, Predicted = 2

Index 8: Actual = 1, Predicted = 1

Index 9: Actual = 1, Predicted = 1

Index 10: Actual = 2, Predicted = 2

Index 11: Actual = 0, Predicted = 0

21 | P a g e
Index 12: Actual = 0, Predicted = 0

Index 13: Actual = 0, Predicted = 0

Index 14: Actual = 0, Predicted = 0

Index 15: Actual = 1, Predicted = 1

Index 16: Actual = 2, Predicted = 2

Index 17: Actual = 1, Predicted = 1

Index 18: Actual = 1, Predicted = 1

Index 19: Actual = 2, Predicted = 2

Index 20: Actual = 0, Predicted = 0

Index 21: Actual = 2, Predicted = 2

Index 22: Actual = 0, Predicted = 0

Index 23: Actual = 2, Predicted = 2

Index 24: Actual = 2, Predicted = 2

Index 25: Actual = 2, Predicted = 2

Index 26: Actual = 2, Predicted = 2

Index 27: Actual = 2, Predicted = 2

Index 28: Actual = 0, Predicted = 0

Index 29: Actual = 0, Predicted = 0

Incorrect Predictions:

Accuracy: 1.0000

22 | P a g e
9. Develop a program to implement the non-parametric Locally Weighted
Regression algorithm, fitting data points and visualizing results.

import numpy as np

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

# Generate synthetic dataset

np.random.seed(42)

X = np.linspace(0, 10, 100).reshape(-1, 1)

y = np.sin(X).ravel() + np.random.normal(scale=0.1, size=X.shape[0])

# Split dataset

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

def locally_weighted_regression(X_train, y_train, query_x, tau=0.5):

"""Performs Locally Weighted Regression for a given query point."""

m = X_train.shape[0]

# Compute weights

W = np.exp(-np.square(X_train - query_x) / (2 * tau ** 2))

W = np.diag(W.flatten()) # Convert into diagonal matrix

# Design matrix

23 | P a g e
X_b = np.c_[np.ones((m, 1)), X_train] # Add bias term

# Compute theta using weighted normal equation

theta = np.linalg.pinv(X_b.T @ W @ X_b) @ X_b.T @ W @ y_train

# Prediction for query_x

query_x_b = np

24 | P a g e
10. Implement a Q-learning algorithm to navigate a simple grid environment,
defining the reward structure and analyzing agent performance.

import numpy as np

import matplotlib.pyplot as plt

import random

# Define grid environment

GRID_SIZE = 5

ACTIONS = ['up', 'down', 'left', 'right']

GAMMA = 0.9 # Discount factor

ALPHA = 0.1 # Learning rate

EPSILON = 0.1 # Exploration rate

EPISODES = 500

# Initialize Q-table

Q_table = np.zeros((GRID_SIZE, GRID_SIZE, len(ACTIONS)))

# Reward structure

REWARDS = np.full((GRID_SIZE, GRID_SIZE), -1) # Default reward

REWARDS[4, 4] = 100 # Goal state

# Function to get next state

def get_next_state(state, action):

x, y = state

if action == 'up':

25 | P a g e
x = max(x - 1, 0)

elif action == 'down':

x = min(x + 1, GRID_SIZE - 1)

elif action == 'left':

y = max(y - 1, 0)

elif action == 'right':

y = min(y + 1, GRID_SIZE - 1)

return x, y

# Q-learning algorithm

def q_learning():

for episode in range(EPISODES):

state = (0, 0) # Start position

while state != (4, 4):

if random.uniform(0, 1) < EPSILON:

action_idx = random.randint(0, len(ACTIONS) - 1) # Explore

else:

action_idx = np.argmax(Q_table[state[0], state[1]]) # Exploit

next_state = get_next_state(state, ACTIONS[action_idx])

reward = REWARDS[next_state]

# Update Q-value

best_next_action = np.max(Q_table[next_state[0], next_state[1]])

26 | P a g e
Q_table[state[0], state[1], action_idx] += ALPHA * (reward + GAMMA *
best_next_action - Q_table[state[0], state[1], action_idx])

state = next_state # Move to next state

if episode % 100 == 0:

print(f"Episode {episode} completed.")

# Train the agent

q_learning()

# Display learned Q-values

print("Learned Q-values:")

print(Q_table)

# Visualize optimal policy

def visualize_policy():

policy = np.chararray((GRID_SIZE, GRID_SIZE), unicode=True)

for i in range(GRID_SIZE):

for j in range(GRID_SIZE):

if (i, j) == (4, 4):

policy[i, j] = 'G' # Goal

else:

action_idx = np.argmax(Q_table[i, j])

policy[i, j] = ACTIONS[action_idx][0].upper()

27 | P a g e
print("\nOptimal Policy:")

print(policy)

visualize_policy()

Output:

Episode 0 completed.

Episode 100 completed.

Episode 200 completed.

Episode 300 completed.

Episode 400 completed.

Learned Q-values:

[[[ 3.11282524e+01 6.31050515e+00 2.26313258e+01 4.26126590e+01]

[ 2.59001732e+01 2.71790959e+01 1.70628552e+01 4.84585100e+01]

[ 3.42559792e+01 5.49539000e+01 2.11413508e+01 6.42282122e+00]

[-7.71719092e-01 2.89730441e+01 -7.44112235e-01 -7.41262017e-01]

[-4.90099501e-01 -4.54321881e-01 -6.18339004e-01 -4.90099501e-01]]

[[-1.59557186e+00 -1.54059063e+00 -1.64587955e+00 2.61040430e+01]

[ 6.99200926e+00 -1.07542414e+00 -1.16231455e+00 5.36717435e+01]

[ 2.10490073e+01 6.21710000e+01 3.13837398e+01 3.71358190e+01]

[-4.98601901e-01 6.92074912e+01 -5.21214529e-01 2.87480186e+00]

[-3.78730900e-01 6.74465800e+01 -4.02706981e-01 -3.94039900e-01]]

[[-1.09332559e+00 -1.04532330e+00 -1.04401130e+00 -8.93931777e-01]

28 | P a g e
[-7.42731579e-01 -7.78518187e-01 -8.30191893e-01 4.54976022e+01]

[ 4.01070179e+01 2.93171209e+01 1.92590682e+01 7.01900000e+01]

[ 4.90802282e+01 3.62581143e+01 4.59195711e+01 7.91000000e+01]

[ 3.79176858e+01 8.90000000e+01 4.43522305e+01 5.24557945e+01]]

[[-7.38499011e-01 -7.90344580e-01 -6.79346521e-01 -7.15911572e-01]

[-5.22708881e-01 -4.68448201e-01 -5.29632807e-01 -1.35432267e-02]

[-3.05101900e-01 -2.80000000e-01 -1.99810000e-01 6.00261996e+01]

[ 8.06245194e-01 7.19016200e+00 4.96650042e+00 8.80274901e+01]

[ 6.10855055e+01 1.00000000e+02 6.19320717e+01 6.34673473e+01]]

[[-6.06961600e-01 -5.85198506e-01 -5.85198506e-01 -6.23450368e-01]

[-3.94236730e-01 -3.94039900e-01 -4.17928501e-01 1.11924170e-01]

[-1.99000000e-01 -1.99000000e-01 -3.13849900e-01 6.86284100e+00]

[-1.99000000e-01 -1.00000000e-01 -1.09000000e-01 5.21703100e+01]

[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]]]

Optimal Policy:

[['R' 'R' 'D' 'D' 'D']

['R' 'R' 'D' 'D' 'D']

['R' 'R' 'R' 'R' 'D']

['L' 'R' 'R' 'R' 'D']

['D' 'R' 'R' 'R' 'G']]

29 | P a g e

You might also like