This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # play_gridworld_terminal.py | |
| # Terminal-playable GridWorld + trajectory tracking (only dependency: numpy) | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from typing import Dict, List, Optional, Tuple | |
| import numpy as np | |
| @dataclass(frozen=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| # generate a random number between 0 and 1 | |
| # calculate its distance (min) to either 0 and 1 (absolute value of difference) | |
| def do_once(): | |
| x = np.random.rand() | |
| return min(abs(x - 0), abs(x - 1)) | |
| # do it many times and get the average value | |
| def do_many_times(n): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| E = { | |
| "A": [("B", 4), ("H", 8)], | |
| "B": [("A", 4), ("C", 8), ("H", 11)], | |
| "C": [("B", 8), ("D", 7), ("F", 4), ("I", 2)], | |
| "D": [("C", 7), ("E", 9), ("F", 14)], | |
| "E": [("D", 9), ("F", 10)], | |
| "F": [("C", 4), ("D", 14), ("E", 10), ("G", 2)], | |
| "G": [("F", 2), ("H", 1), ("I", 6)], | |
| "H": [("A", 8), ("B", 11), ("G", 1), ("I", 7)], | |
| "I": [("C", 2), ("G", 6), ("H", 7)], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| E = { | |
| "A": [], | |
| "B": ["A", "E"], | |
| "C": ["D", "H"], | |
| "D": ["B"], | |
| "E": ["F"], | |
| "F": [], | |
| "G": ["A"], | |
| "H": ["B", "G"], | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| E = { | |
| "A": [], | |
| "B": ["A", "E"], | |
| "C": ["D", "H"], | |
| "D": ["B"], | |
| "E": ["F"], | |
| "F": [], | |
| "G": ["A"], | |
| "H": ["B", "G"], | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| E = { "A": ["E"], | |
| "B": ["A", "C", "G"], | |
| "C": ["A"], | |
| "D": ["B", "G"], | |
| "E": ["F"], | |
| "F": [], | |
| "G": ["A", "F"], | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N = 8 | |
| def neighbors(board): | |
| occupied = set(board) | |
| for r in range(N): | |
| for c in range(N): | |
| if (r, c) not in occupied: | |
| yield board + ((r, c),) | |
| def solve_8q_one(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| import numpy as np | |
| def simulate_T(n): | |
| if n <= 1: | |
| return 0 | |
| # the pivot may end up randomly anywhere from 0 to n-1 | |
| pivot_index = random.randint(0, n - 1) | |
| first_half = simulate_T(pivot_index) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # roll out of a particular game, start at position n, and roll a coin of some prob to move up or down. | |
| # if it reaches 0, you lose | |
| def simulate_game_log_space(start_n, coin_prob): | |
| trajectory = [] | |
| n = start_n | |
| for i in range(1000): | |
| trajectory.append(n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| import cv2 | |
| import math | |
| # open the ./data_train.json | |
| GRID = 64 | |
| IMG_W = GRID * 20 |
NewerOlder