- Slides
- Video
Stuart McMurray:
| import random | |
| def rps(n,x,y): | |
| print('-----------------------') | |
| print('Rock, Paper, Scissors!!') | |
| mode = int(input('(1) Vs. Computer (2) Multiplayer')) | |
| if mode == 1: | |
| print('Wins: ' + str(n)) | |
| user = str(input('Rock (R/r), Paper (P/p) or Scissors (S/s)?')).lower() |
| # simpleLP1.py | |
| # Python 2.7.6 | |
| """ | |
| Python script to solve Linear Programming problems | |
| Uses Pulp library | |
| Problem statement: (src - http://fisher.osu.edu/~croxton.4/tutorial/) | |
| 1) Objective Function - |
| #!/usr/bin/python3 | |
| # Simple TicTacToe game in Python - EAO | |
| import random | |
| import sys | |
| board=[i for i in range(0,9)] | |
| player, computer = '','' | |
| # Corners, Center and Others, respectively | |
| moves=((1,7,3,9),(5,),(2,4,6,8)) |
| def display_board(board): | |
| for i in range(3): | |
| print " ", | |
| for j in range(3): | |
| if board[i*3+j] == 1: | |
| print 'X', | |
| elif board[i*3+j] == 0: |
| #Implementation of Two Player Tic-Tac-Toe game in Python. | |
| ''' We will make the board using dictionary | |
| in which keys will be the location(i.e : top-left,mid-right,etc.) | |
| and initialliy it's values will be empty space and then after every move | |
| we will change the value according to player's choice of move. ''' | |
| theBoard = {'7': ' ' , '8': ' ' , '9': ' ' , | |
| '4': ' ' , '5': ' ' , '6': ' ' , | |
| '1': ' ' , '2': ' ' , '3': ' ' } |
| import itertools | |
| class Board(object): | |
| def __init__(self): | |
| self.rows = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']] | |
| @property | |
| def diagonals(self): |
Stuart McMurray:
| import os | |
| import numpy as np | |
| from sklearn.metrics import log_loss | |
| """ | |
| - HARDCODED FORMULAE | |
| - In this gist, we shall almost always use probabilities and not unscaled logits | |
| """ | |
| ## BINARY CLASS CROSS ENTROPY | |
| y_true = [0,0,0,1] # 4 observations |
| import numpy as np | |
| def crossEntropy(Y, P): | |
| Y = np.float_(Y) | |
| P = np.float_(P) | |
| CE = -np.sum(Y*np.log(P) + (1-Y)*np.log(1-P)) | |
| return CE |
| #Travel times between each crop for each direction | |
| right = [0.42666667, 0.55466667, 0.56533333, 0.576, 0.576, 0.448, 0.59733333, 0.576, 0.56533333, 0.46933333, 0.58666667] | |
| left = [0.71466667, 0.55466667, 0.69333333, 0.59733333, 0.69333333, 0.576, 0.71466667, 0.58666667, 0.576, 0.69333333, 0.576] | |
| up = [0.58666667, 0.45866667, 0.59733333, 0.58666667, 0.576, 0.58666667, 0.46933333, 0.576, 0.55466667] | |
| down = [0.59733333, 0.576, 0.58666667, 0.59733333, 0.45866667, 0.576, 0.56533333, 0.576, 0.448] | |
| #Set arbitrary starting vertex and initialise w(s, s) as 0 and direction as empty in Q | |
| s = 30 | |
| Q = np.array([[s, None, 0]]) |