#driver for integration

from montecarlo import *
import math
from hermitepoly import *
import numpy as np
 
def simple(x):
	return x

def parabola(x):
	return x*x

def equation(x):
	return 1/math.sqrt(1-pow(x,2))

def gauss(x):
	return np.exp(-pow(x,2))

data = open('montedata','w')
a = []
points = 10
while points < 10e8:
	val = montecarlo(simple,0,1,points)
	a.append(val)
	data.write('%s %s\n' % (points, val))
	points = points * 10

print a
Beispiel #2
0
# In[16]:

import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

from sarsa import *
from montecarlo import *

value = np.zeros((2, 11, 22))
counter = np.zeros((2, 11, 22))

for i in xrange(1000000):
    value, counter = montecarlo(value, counter)

bestval = np.amax(value, axis=0)
bestval = bestval.T
fig = plt.figure()
ha = fig.add_subplot(111, projection='3d')
x = range(10)
y = range(21)
X, Y = np.meshgrid(x, y)
print X.shape, Y.shape, bestval.shape
ha.plot_wireframe(X + 1, Y + 1, bestval[1:, 1:])

ha.set_xlabel("dealer starting card")
ha.set_ylabel("player current sum")
ha.set_zlabel("value of state")
plt.show()
Beispiel #3
0
def main():
    montecarlo = {'--Cr': montecarloCr, '--Ti': montecarloTi,
                  '--AlCu': montecarloAlCu}[sys.argv[1]]
    montecarlo(sys.argv[2], sys.argv[3], sys.argv[4])
Beispiel #4
0
ax.set_xlabel("Player sum")
x = range(10)
y = range(21)
X, Y = np.meshgrid(y, x)
ax.plot_wireframe(X + 1, Y + 1, v_sarsa[1:, 1:])
plt.show()

#----------------RESET VALUES
q_mc = np.zeros((2, 11, 22))
counter = np.zeros((2, 11, 22))
q_sarsa = np.zeros((2, 11, 22))
counter_sarsa = np.zeros((2, 11, 22))
#-----------------------------

#-------------------------------MSE between MC and Sarsa vs. lambda values [0, 1] steps of 0.1-------------------------------------------------------------
for k in range(12):
    print(k)
    lambda_var = lambda_var + 0.1
    for j in range(1001):
        q_mc, counter = montecarlo(q_mc, counter)
        q_sarsa, counter_sarsa = sarsa(q_sarsa, counter_sarsa, lambda_var)
    mse[k - 1] = np.sum(np.square(q_mc - q_sarsa))
print(lambdas)
print(mse)

plt.plot(lambdas, mse)
plt.xlabel("Lambda")
plt.ylabel("MSE")
plt.title("MSE vs Lambda values")
plt.show()