def main(): x_train_start, x_val_start, x_train_end, x_val_end = 0, 0.05, math.pi * 2, math.pi * 2 noise = True # sigma = 0.1 train_sin = sin(x_train_start, x_train_end, 0.1, noise = noise) val_sin = sin(x_val_start, x_val_end, 0.1, noise = noise) train_square = square(x_train_start, x_train_end, 0.1, noise = noise) val_square = square(x_val_start, x_val_end, 0.1, noise = noise) # batch_learning(train_square, val_square, name = "Batch Square w. Noise") # delta_learning(train_square, val_square, name = "Delta Square w. Noise") # grid_search(train_square, val_square) perceptron_learning(train_square, val_square)
def move(): "Move snake forward one segment." head = snake[-1].copy() head.move(aim) if not inside(head) or head in snake: square(head.x, head.y, 9, 'red') update() return snake.append(head) if head == food: print('Snake:', len(snake)) food.x = randrange(-15, 15) * 10 food.y = randrange(-15, 15) * 10 else: snake.pop(0) clear() for body in snake: square(body.x, body.y, 9, 'black') square(food.x, food.y, 9, 'green') update() ontimer(move, 100)
def draw(): "Advance players and draw game." p1xy.move(p1aim) p1head = p1xy.copy() p2xy.move(p2aim) p2head = p2xy.copy() if not inside(p1head) or p1head in p2body: print('Player blue wins!') return if not inside(p2head) or p2head in p1body: print('Player red wins!') return p1body.add(p1head) p2body.add(p2head) square(p1xy.x, p1xy.y, 3, 'red') square(p2xy.x, p2xy.y, 3, 'blue') update() ontimer(draw, 50)
def render_data(self): """Summary """ row_list = [] weekdays = [ d[:3].lower() for d in calendar.day_name if d not in ['Saturday', 'Sunday'] ] for day in weekdays: row = OrderedDict() item = int(getattr(self, day, None)) row.update({'day': day}) if day in ['thu', 'fri']: double_value = utils.double(item) row.update({ 'description': ' '.join([ getattr(self, 'description', None), str(double_value) ]) }) row.update({'double': double_value}) else: square_value = utils.square(item) row.update({ 'description': ' '.join([ getattr(self, 'description', None), str(square_value) ]) }) row.update({'square': square_value}) row.update({'value': item}) row_list.append(row) return json.loads(json.dumps(row_list))
def get_reward(self, d): #R = (100*d + 10*u.square(d) - 0.5*u.cube(d) -2100)*10 R = (3 * d + 10 * u.square(d) - 0.25 * u.cube(d)) #R = (0.3*d + 0.2*0.05*u.square(d) + 0.5*10000/u.square(d)-40) return R
def get_reward(self, d): R = (3 * d + 10 * u.square(d) - 0.5 * u.cube(d) - 620) #R = (0.3*d + 0.2*0.05*u.square(d) + 0.5*10000/u.square(d)-40) return R
def prob6(): sum_of_squares = sum(map(utils.square, range(1,101))) square_of_sums = utils.square(sum(range(1,101))) return abs(sum_of_squares - square_of_sums)
# from utils import check_even_odd(num) #from nomecartella.utils import check_even_odd(num) asknum = False if asknum == True: while True: try: num = int(input("Inserisci un numero: ")) print("il numero scelto è ", num) utils.check_even_odd(num) break except (ValueError): print("Devi inseire un numero") print("il quadrato di ", num, "è", utils.square(num)) print("il quadrato di ", num, "è", numpy.square(num)) print("La lista dei sottomultippli di ", num, " è ", utils.events(num)) ''' stringa="stringa di prova" stringa2="Mi devo andare a prendere il caffè" for c in stringa2: print (c) start1=timeit.default_timer() lista_quadrati=[] for c in range(10): lista_quadrati.append(numpy.square(c)) #print(lista_quadrati)
def prob6(): sum_of_squares = sum(map(utils.square, range(1, 101))) square_of_sums = utils.square(sum(range(1, 101))) return abs(sum_of_squares - square_of_sums)
def test_invalid_square(self): """test invalid square method """ with self.assertRaises(ValueError): utils.square('invalid_input')
def test_valid_square(self): """test valid square method """ self.assertEqual(utils.square(3), 9)
def get_reward(self, d): R = 0.3*d + 0.2*0.05*u.square(d) - 0.5*10000/u.square(d) + 10 return R