Advertisement
Guest User

current_code

a guest
May 29th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import re
  2. import numpy as np
  3.  
  4. class MDP:
  5.         m = None
  6.         n = None
  7.         beta = None
  8.         delta = None
  9.         matrix = []
  10.         reward    = []
  11.        
  12.         def __init__(self, file):
  13.         f = open(file)
  14.             n = 0
  15.             m = 0
  16.             matrix = []
  17.             i = -1 #so that we allocate to the correct group
  18.             for line in f:
  19.                 temp = line.replace('\n', '').replace('    ', ' ').split(' ')
  20.                 if len(temp) == 1:
  21.                         i += 1
  22.                         matrix.append([])
  23.                         continue
  24.                 elif len(temp) == 2:
  25.                         temp = map(int, temp)
  26.                         n = temp[0]
  27.                     m = temp[1]
  28.                 elif len(temp) == n:
  29.                         temp = map(float, temp)
  30.                         matrix[i].append(temp)
  31.             reward = matrix[i][0]
  32.             matrix.pop(i)
  33.         self.n = n
  34.         self.m = m
  35.         self.matrix = matrix
  36.         self.reward = reward
  37.  
  38.         def calc_delta(self):
  39.                 num = (1 * np.exp(-10)) * np.power((1 - self.beta), 2)
  40.                 den = 2 * np.power(self.beta, 2)
  41.                 self.delta = num / den
  42.  
  43.         def set_beta(self, b):
  44.                 self.beta = b
  45.  
  46.         def optimal_utility(self):
  47.                 return None
  48.  
  49.         def optimal_policy(self):
  50.                 return None
  51.  
  52. if __name__ == "__main__":
  53.     array = MDP('test-data-for-MDP.txt')
  54.     print array.reward
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement