Пример #1
0
    def task(self):
        throw.NUM_WEDGES = 8
        throw.wedges = [ 4, 6, 2, 7, 1, 8, 3, 5 ]
        throw.START_SCORE = 100
        throw.init_board()
	random.seed()
        throw.init_thrower()
        
         
        num_games=10
        modelfree.ACTIVE_STRATEGY = 2;	
        y1=  darts.test(num_games, "modelfree")
        modelfree.ACTIVE_STRATEGY = 2;	
	y2=  darts.test(num_games, "modelfree")
	listNames = ["Strategy 1","Strategy 2"]
	y= [y1, y2]
	listData = y
	
	chart = {"chart": {"defaultSeriesType": "line"},
                 "xAxis": {"categories": listNames},
                 "yAxis": {"title": {"text": "#Throws"}},
                 "title": {"text": "Average #throws to finish vs. #games"}, 
                 "series": [ {"name": "Average policy performance", 
	                      "data": listData} ] }
        return chart
Пример #2
0
def main():
    throw.init_board()
    num_games = 1000

#************************************************#
# Uncomment the lines below to run the mdp code, #
# using the simple dart thrower that matches     #
# the thrower specified in question 2.           #
#*************************************************

# Default is to solve MDP and play 1 game
    throw.use_simple_thrower()
    test(100, "mdp")

#*************************************************#
# Uncomment the lines below to run the modelbased #
# code using the complex dart thrower.            #
#*************************************************#

# Seed the random number generator -- the default is
# the current system time. Enter a specific number
# into seed() to keep the dart thrower constant across
# multiple calls to main().
# Then, initialize the throwing model and run
# the modelbased algorithm.
    random.seed(181)
    throw.init_thrower()
    f = open("q4a_data_strat1.csv", "w")
    f.write("EPOCH_SIZE, AVG_TURNS\n")

    avg_turns = modelbased.modelbased(GAMMA, 5, 100)
    f.write("{0}, {1}\n".format(1, avg_turns))
Пример #3
0
def main():
    throw.init_board()
    num_games = 1000

    #************************************************#
    # Uncomment the lines below to run the mdp code, #
    # using the simple dart thrower that matches     #
    # the thrower specified in question 2.           #
    #*************************************************

    # Default is to solve MDP and play 1 game
    throw.use_simple_thrower()
    test(100, "mdp")

    #*************************************************#
    # Uncomment the lines below to run the modelbased #
    # code using the complex dart thrower.            #
    #*************************************************#

    # Seed the random number generator -- the default is
    # the current system time. Enter a specific number
    # into seed() to keep the dart thrower constant across
    # multiple calls to main().
    # Then, initialize the throwing model and run
    # the modelbased algorithm.
    random.seed(181)
    throw.init_thrower()
    f = open("q4a_data_strat1.csv", "w")
    f.write("EPOCH_SIZE, AVG_TURNS\n")

    avg_turns = modelbased.modelbased(GAMMA, 5, 100)
    f.write("{0}, {1}\n".format(1, avg_turns))
Пример #4
0
def T(a, s, s_prime):
    #CENTER, INNER_RING, FIRST_PATCH, MIDDLE_RING, SECOND_PATCH, OUTER_RING, MISS = range(7)
    delta = s - s_prime
    p = 0.0
    probs = [.1, .2, .4, .2, .1]

    throw.init_board()

    if delta > 3 * throw.NUM_WEDGES or delta < 0:
        return 0

    for ri in range(5):
        for wi in range(5):
            wedge_num = throw.wedges[(throw.angles[a.wedge] - 2 + wi) %
                                     throw.NUM_WEDGES]
            ring_num = a.ring - 2 + ri
            if ring_num > 6:
                ring_num = 6
            if ring_num < 0:
                ring_num = ring_num * (-1)

            points = throw.location_to_score(
                throw.location(ring_num, wedge_num))
            if points == delta:
                p += probs[ri] * probs[wi]
    return p
Пример #5
0
def T(a, s, s_prime):
#CENTER, INNER_RING, FIRST_PATCH, MIDDLE_RING, SECOND_PATCH, OUTER_RING, MISS = range(7)
  delta = s - s_prime
  p = 0.0
  probs = [.1, .2, .4, .2, .1]
  
  throw.init_board()
  
  if delta > 3*throw.NUM_WEDGES or delta < 0:
    return 0
  
  for ri in range(5):
    for wi in range(5):
      wedge_num = throw.wedges[(throw.angles[a.wedge] - 2 + wi) %
                               throw.NUM_WEDGES]
      ring_num = a.ring - 2 + ri;
      if ring_num > 6:
        ring_num = 6
      if ring_num < 0:
        ring_num = ring_num*(-1)
      
      points = throw.location_to_score(throw.location(ring_num, wedge_num))
      if points == delta:
        p += probs[ri]*probs[wi]
  return p
Пример #6
0
def mf(strategy):

    #print "strategy, num_games, result"
    throw.NUM_WEDGES = 8
    throw.wedges = [ 4, 6, 2, 7, 1, 8, 3, 5 ]
    throw.START_SCORE = 100
    throw.init_board()
    random.seed()
    throw.init_thrower()
    a = modelfree(gamma, learning_rate, num_games, strategy)
    #print "%1d  %2d  %2d" % (strategy, num_games, a)
    return a
Пример #7
0
def mf(strategy):

    #print "strategy, num_games, result"
    throw.NUM_WEDGES = 8
    throw.wedges = [4, 6, 2, 7, 1, 8, 3, 5]
    throw.START_SCORE = 100
    throw.init_board()
    random.seed()
    throw.init_thrower()
    a = modelfree(gamma, learning_rate, num_games, strategy)
    #print "%1d  %2d  %2d" % (strategy, num_games, a)
    return a
Пример #8
0
def main():
    throw.init_board()
    num_games = 1000

#************************************************#
# Uncomment the lines below to run the mdp code, #
# using the simple dart thrower that matches     #
# the thrower specified in question 2.           #
#*************************************************

# Default is to solve MDP and play 1 game
    throw.use_simple_thrower()
    test(1, "mdp")    
Пример #9
0
def main():
    throw.init_board()
    num_games = 1000

#************************************************#
# Uncomment the lines below to run the mdp code, #
# using the simple dart thrower that matches     #
# the thrower specified in question 2.           #
#*************************************************

# Default is to solve MDP and play 1 game
    throw.use_simple_thrower()
    test(1, "mdp")    
Пример #10
0
def main():
    throw.init_board()
    num_games = 100

    # ************************************************#
    # Uncomment the lines below to run the mdp code, #
    # using the simple dart thrower that matches     #
    # the thrower specified in question 2.           #
    # *************************************************

    # # Default is to solve MDP and play 1 game
    # global GAMMA
    # throw.use_simple_thrower()
    # GAMMA = 0.
    # for i in range(0, 5):
    #     print GAMMA,
    #     test(-1, "mdp")
    #     GAMMA +=.25

    # *************************************************#
    # Uncomment the lines below to run the modelbased #
    # code using the complex dart thrower.            #
    # *************************************************#

    # Seed the random number generator -- the default is
    # the current system time. Enter a specific number
    # into seed() to keep the dart thrower constant across
    # multiple calls to main().
    # Then, initialize the throwing model and run
    # the modelbased algorithm.
    # random.seed(1)
    # throw.init_thrower()
    # print "Games: ", num_games
    # print "Strategy: ", strategy
    # for i in xrange(int(sys.argv[1]), int(sys.argv[2]), 10):
    #     EPOCH_SIZE = i
    #     print "epoch size: ", EPOCH_SIZE
    #     modelbased.modelbased(GAMMA, EPOCH_SIZE, num_games, strategy)

    # *************************************************#
    # Uncomment the lines below to run the modelfree  #
    # code using the complex dart thrower.            #
    # *************************************************#

    # Plays 1 game using a default player. No modelfree
    # code is provided.
    random.seed(1)
    throw.init_thrower()
    test(1000, "modelfree")
Пример #11
0
def main():
    scores = []
    throw.init_board()
    num_games = 100

#************************************************#
# Uncomment the lines below to run the mdp code, #
# using the simple dart thrower that matches     #
# the thrower specified in question 2.           #
#*************************************************

#Default is to solve MDP and play 1 game
    throw.use_simple_thrower()
    test(1, "mdp")    

#*************************************************#
# Uncomment the lines below to run the modelbased #
# code using the complex dart thrower.            #
#*************************************************#

# Seed the random number generator -- the default is
# the current system time. Enter a specific number
# into seed() to keep the dart thrower constant across
# multiple calls to main().
# Then, initialize the throwing model and run
# the modelbased algorithm.
    # sizes = [1,5,10,15]
    # for i in sizes:
    #     print "EPOCH SIZE: ", i
    #     random.seed()
    #     throw.init_thrower()
    #     modelbased.modelbased(GAMMA, i, num_games)

#*************************************************#
# Uncomment the lines below to run the modelfree  #
# code using the complex dart thrower.            #
#*************************************************#

# Plays 1 game using a default player. No modelfree
# code is provided. 

    learning = [0.8, 0.85, 0.9, 0.95, 1]
    for l in learning:
        print "LEARNING RATE: ", l
        random.seed()
        throw.init_thrower()
        test(1000, "modelfree", l)
Пример #12
0
def main(epoch_sz):
    throw.init_board()
    #num_games = 1000
    num_games = NUM_GAMES


#************************************************#
# Uncomment the lines below to run the mdp code, #
# using the simple dart thrower that matches     #
# the thrower specified in question 2.           #
#*************************************************

# Default is to solve MDP and play 1 game
    #throw.use_simple_thrower()
    #test(1, "mdp")    

#*************************************************#
# Uncomment the lines below to run the modelbased #
# code using the complex dart thrower.            #
#*************************************************#

# Seed the random number generator -- the default is
# the current system time. Enter a specific number
# into seed() to keep the dart thrower constant across
# multiple calls to main().
# Then, initialize the throwing model and run
# the modelbased algorithm.
    random.seed()
    throw.init_thrower()
    #modelbased.modelbased(GAMMA, EPOCH_SIZE, num_games)
    #modelbased.modelbased(GAMMA, epoch_sz, num_games)

#*************************************************#
# Uncomment the lines below to run the modelfree  #
# code using the complex dart thrower.            #
#*************************************************#

# Plays 1 game using a default player. No modelfree
# code is provided. 
    #random.seed()
    #throw.init_thrower()
    #test(1, "modelfree")
    print "RUNNING MODEL FREE!"
    modelfree.Q_learning(GAMMA, ALPHA, num_games)
Пример #13
0
def main():
    throw.init_board()
    num_games = 19

#************************************************#
# Uncomment the lines below to run the mdp code, #
# using the simple dart thrower that matches     #
# the thrower specified in question 2.           #
#*************************************************

# Default is to solve MDP and play 1 game
    #throw.use_simple_thrower()
    #test(1, "mdp")    

#*************************************************#
# Uncomment the lines below to run the modelbased #
# code using the complex dart thrower.            #
#*************************************************#

# Seed the random number generator -- the default is
# the current system time. Enter a specific number
# into seed() to keep the dart thrower constant across
# multiple calls to main().
# Then, initialize the throwing model and run
# the modelbased algorithm.
    random.seed()
    throw.init_thrower()
    for epoch in range (20):
        print "Epoch size: " + str(200 - epoch * 10)
        modelbased.modelbased(GAMMA, 200 - 10 * epoch, num_games)

#*************************************************#
# Uncomment the lines below to run the modelfree  #
# code using the complex dart thrower.            #
#*************************************************#

# Plays 1 game using a default player. No modelfree
# code is provided. 
    random.seed()
    throw.init_thrower()
    test(1, "modelfree")
Пример #14
0
    def task(self):
        throw.NUM_WEDGES = 8
        throw.wedges = [ 4, 6, 2, 7, 1, 8, 3, 5 ]
        throw.START_SCORE = 100
        throw.init_board()
	random.seed()
	throw.init_thrower()
         
        num_games=10
        epochs = [25,35,50];   	
		    	
	listNames = map(lambda x: "Epoch "+`x`, epochs);
	y= map(lambda x: modelbased.modelbased(darts.GAMMA, x, num_games,2), epochs);
	listData = y
	
	chart = {"chart": {"defaultSeriesType": "line"},
                 "xAxis": {"categories": listNames},
                 "yAxis": {"title": {"text": "#Throws"}},
                 "title": {"text": "Average #throws to finish vs. #games"}, 
                 "series": [ {"name": "Average policy performance", 
	                      "data": listData} ] }
        return chart
Пример #15
0
    def task(self):
        throw.NUM_WEDGES = 8
        throw.wedges = [4, 6, 2, 7, 1, 8, 3, 5]
        throw.START_SCORE = 100
        throw.init_board()
        random.seed()
        throw.init_thrower()

        num_games = 10
        epochs = [50]
        #25,35,50];

        listNames = map(lambda x: "Epoch " + ` x `, epochs)
        y = map(lambda x: modelbased.modelbased(darts.GAMMA, x, num_games, 1),
                epochs)
        listData = y

        chart = {
            "chart": {
                "defaultSeriesType": "line"
            },
            "xAxis": {
                "categories": listNames
            },
            "yAxis": {
                "title": {
                    "text": "#Throws"
                }
            },
            "title": {
                "text": "Average #throws to finish vs. #games"
            },
            "series": [{
                "name": "Average policy performance",
                "data": listData
            }]
        }
        return chart
Пример #16
0
def main():
    throw.init_board()
    num_games = 10

#************************************************#
# Uncomment the lines below to run the mdp code, #
# using the simple dart thrower that matches     #
# the thrower specified in question 2.           #
#*************************************************

 #Default is to solve MDP and play 1 game
    #throw.use_simple_thrower()
    #test(1, "mdp")    

#*************************************************#
# Uncomment the lines below to run the modelbased #
# code using the complex dart thrower.            #
#*************************************************#

# Seed the random number generator -- the default is
# the current system time. Enter a specific number
# into seed() to keep the dart thrower constant across
# multiple calls to main().
# Then, initialize the throwing model and run
# the modelbased algorithm.
    random.seed()
    performance = []
    epochs = range(10,21)
    throw.init_thrower()
    for i in range(len(epochs)):
      epoch = epochs[i]
      throw.init_thrower()
      performance.append(modelbased.modelbased(GAMMA, EPOCH_SIZE, 10))

    print performance
    f = open("dumpfile2","w")
    pickle.dump([epochs,performance],f)
    f.close()
Пример #17
0
    def task(self):
        throw.NUM_WEDGES = 8
        throw.wedges = [4, 6, 2, 7, 1, 8, 3, 5]
        throw.START_SCORE = 100
        throw.init_board()
        random.seed()
        throw.init_thrower()

        num_games = 10
        modelfree.ACTIVE_STRATEGY = 2
        y1 = darts.test(num_games, "modelfree")
        modelfree.ACTIVE_STRATEGY = 2
        y2 = darts.test(num_games, "modelfree")
        listNames = ["Strategy 1", "Strategy 2"]
        y = [y1, y2]
        listData = y

        chart = {
            "chart": {
                "defaultSeriesType": "line"
            },
            "xAxis": {
                "categories": listNames
            },
            "yAxis": {
                "title": {
                    "text": "#Throws"
                }
            },
            "title": {
                "text": "Average #throws to finish vs. #games"
            },
            "series": [{
                "name": "Average policy performance",
                "data": listData
            }]
        }
        return chart
Пример #18
0
    def task(self):
        throw.init_board()
	throw.use_simple_thrower()
        y1= darts.test(1, "mdp")
        
        throw.init_board()
        throw.use_simple_thrower()
        y2=darts.test(5, "mdp")    	
	
	throw.init_board()
	throw.use_simple_thrower()
        y3=darts.test(10, "mdp")    	
		    	
	listNames = ["1 game", "5 games", "10 games"]
	listData = [y1, y2, y3]
	chart = {"chart": {"defaultSeriesType": "column"},
                 "xAxis": {"categories": listNames},
                 "yAxis": {"title": {"text": "#Throws"}},
                 "title": {"text": "Average #throws to finish vs. #games"}, 
                 "series": [ {"name": "Average policy performance", 
	                      "data": listData} ] }
        return chart
Пример #19
0
    def task(self):
        throw.init_board()
        throw.use_simple_thrower()
        y1 = darts.test(1, "mdp")

        throw.init_board()
        throw.use_simple_thrower()
        y2 = darts.test(5, "mdp")

        throw.init_board()
        throw.use_simple_thrower()
        y3 = darts.test(10, "mdp")

        listNames = ["1 game", "5 games", "10 games"]
        listData = [y1, y2, y3]
        chart = {
            "chart": {
                "defaultSeriesType": "column"
            },
            "xAxis": {
                "categories": listNames
            },
            "yAxis": {
                "title": {
                    "text": "#Throws"
                }
            },
            "title": {
                "text": "Average #throws to finish vs. #games"
            },
            "series": [{
                "name": "Average policy performance",
                "data": listData
            }]
        }
        print darts.GAMMA
        return chart
Пример #20
0
def main():
    throw.init_board()
    num_games = 1000
Пример #21
0
def main():
    throw.init_board()
    num_games = 1000