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
#include <iostream> | |
#include <vector> | |
#include <assert.h> | |
#include <cmath> | |
#include <png++/png.hpp> | |
using namespace std; | |
typedef vector<double> Array; | |
typedef vector<Array> Matrix; |
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
all: | |
g++ main.cpp -o main -std=c++11 `sdl2-config --cflags --libs` | |
./main |
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 sys | |
import getch | |
from collections import defaultdict | |
class Oracle: | |
def __init__(self, window_size: int): | |
self.window_size = window_size | |
self.window: str = '' | |
self.patterns: defaultdict[str, dict[str, int]] = defaultdict(lambda: defaultdict(int)) |
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
<canvas id="canvas"></canvas> | |
<script> | |
const WIDTH = 1500 | |
const HEIGHT = 800 | |
const canvas = document.getElementById("canvas") | |
const ctx = canvas.getContext("2d") | |
canvas.width = WIDTH | |
canvas.height = HEIGHT |
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
def print_cells(cells: list[int]): | |
print(''.join('■' if i == 1 else ' ' for i in cells)) | |
def next_step(cells: list[int], rules: list[int]) -> list[int]: | |
new_cells: list[int] = [False] * len(cells) | |
for i in range(len(cells)): | |
left = cells[(i - 1) % len(cells)] | |
right = cells[(i + 1) % len(cells)] | |
idx = int(''.join([str(left), str(cells[i]), str(right)]), 2) |
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 | |
import matplotlib.pyplot as plt | |
width = 300 | |
height = 200 | |
camera = np.array([0, 0, 1]) | |
ratio = float(width) / height | |
screen = (-1, 1 / ratio, 1, -1 / ratio) # left, top, right, bottom |
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 cv2 | |
import numpy as np | |
size = 28 | |
drawing = False | |
win_name = "Draw digit" | |
def draw(event, x, y, flags, *param): | |
global drawing | |
if event == cv2.EVENT_LBUTTONDOWN: |
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 layer import Layer | |
import numpy as np | |
# inherit from base class Layer | |
class FCLayer(Layer): | |
# input_size = number of input neurons | |
# output_size = number of output neurons | |
def __init__(self, input_size, output_size): | |
self.weights = np.random.rand(input_size, output_size) - 0.5 | |
self.bias = np.random.rand(1, output_size) - 0.5 |
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
class Network: | |
def __init__(self): | |
self.layers = [] | |
self.loss = None | |
self.loss_prime = None | |
# add layer to network | |
def add(self, layer): | |
self.layers.append(layer) |
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 | |
from network import Network | |
from fc_layer import FCLayer | |
from activation_layer import ActivationLayer | |
from activations import tanh, tanh_prime | |
from losses import mse, mse_prime | |
# training data | |
x_train = np.array([[[0,0]], [[0,1]], [[1,0]], [[1,1]]]) |
NewerOlder