Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import numpy as np
- class MDP:
- m = None
- n = None
- beta = None
- delta = None
- matrix = []
- reward = []
- def __init__(self, file):
- f = open(file)
- n = 0
- m = 0
- matrix = []
- i = -1 #so that we allocate to the correct group
- for line in f:
- temp = line.replace('\n', '').replace(' ', ' ').split(' ')
- if len(temp) == 1:
- i += 1
- matrix.append([])
- continue
- elif len(temp) == 2:
- temp = map(int, temp)
- n = temp[0]
- m = temp[1]
- elif len(temp) == n:
- temp = map(float, temp)
- matrix[i].append(temp)
- reward = matrix[i][0]
- matrix.pop(i)
- self.n = n
- self.m = m
- self.matrix = matrix
- self.reward = reward
- def calc_delta(self):
- num = (1 * np.exp(-10)) * np.power((1 - self.beta), 2)
- den = 2 * np.power(self.beta, 2)
- self.delta = num / den
- def set_beta(self, b):
- self.beta = b
- def optimal_utility(self):
- return None
- def optimal_policy(self):
- return None
- if __name__ == "__main__":
- array = MDP('test-data-for-MDP.txt')
- print array.reward
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement