This file contains 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 | |
class Linalg(object): | |
Zero = np.array([[1.0], [0.0]]) | |
One = np.array([[0.0], [1.0]]) | |
Plus = (Zero + One)/np.linalg.norm(Zero + One) | |
P0 = np.dot(Zero, Zero.T) | |
P1 = np.dot(One, One.T) |
This file contains 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 | |
class Gate(object): | |
# Identity | |
I = np.eye(2) | |
# Hadamard | |
H = (1.0/np.sqrt(2)) * np.array([[1, 1], [1, -1]]) | |
# Pauli-X (NOT) |
This file contains 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
from CA import CARoom, CACell | |
from itertools import product | |
import multiprocessing as mp | |
import numpy as np | |
from CustomRoom import CustomRoom | |
class Experiment(object): | |
def __init__(self, repeats=30): | |
self.repeats = repeats | |
self.results = [] |
This file contains 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 pygame | |
from pygame import gfxdraw | |
from CA import CACell, CARoom | |
from random import random, randint, seed, Random | |
from CustomRoom import CustomRoom | |
class SimuPanel(object): | |
def __init__(self, room, cell_size_px): | |
self.room = room | |
self.cell_size_px = cell_size_px |
This file contains 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
from CA import CARoom, CACell | |
from itertools import product | |
from random import random, Random | |
import multiprocessing as mp | |
class CustomRoom(object): | |
@staticmethod | |
def make_2_obstacle_room(full_factor=0.67, pos_seed=None, panic_prob=0.01, exit_size=2): | |
room_w = 20 | |
room_h = 20 |
This file contains 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
from itertools import product | |
from math import ceil | |
from dijkstra import dijkstra | |
import numpy as np | |
from random import shuffle, choice, random | |
class CACell(object): | |
EMPTY_STATE = 0 | |
PERSON_STATE = 1 |
This file contains 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
from queue import PriorityQueue | |
def dijkstra(edges, start_vertex): | |
D = {v:float('inf') for v in edges} | |
D[start_vertex] = 0 | |
pq = PriorityQueue() | |
pq.put((0, start_vertex)) | |
visited = [] |
This file contains 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
get.testbed = function(arms = 10, plays = 500, u = 0, sdev.arm = 1, sdev.rewards = 1){ | |
optimal = rnorm(arms, u, sdev.arm) | |
rewards = sapply(optimal, function(x)rnorm(plays, x, sdev.rewards)) | |
list(optimal = optimal, rewards = rewards) | |
} | |
play.slots = function(arms = 10, plays = 500, u = 0, sdev.arm = 1, sdev.rewards = 1, eps = 0.1){ | |
This file contains 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
# TSP with 10 cities around a circular pattern | |
require(gaoptim) | |
op <- par(mfrow = c(2, 1)) | |
n = 10 | |
R = 10 | |
angs = seq(0, 2*pi, length = n) | |
xp = R * cos(angs) + rnorm(n) | |
yp = R * sin(angs) + rnorm(n) | |
xp = c(xp, xp[1]) |
This file contains 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
get.dist = function(x) | |
{ | |
sqrt(x[1]^2 + x[2]^2) | |
} | |
get.pairs = function(N) | |
{ | |
M = matrix(0, nrow = N * (N - 1)/2, ncol = 2) | |
x = 1:N | |
k = 1 |
NewerOlder