Skip to content

Instantly share code, notes, and snippets.

View masterdezign's full-sized avatar

masterdezign

View GitHub Profile
import numpy as np
def spirals(n_samples=400):
N = n_samples
theta = np.sqrt(np.random.rand(N))*2*np.pi
r_a = 2*theta + np.pi
data_a = np.array([np.cos(theta)*r_a, np.sin(theta)*r_a]).T
x_a = data_a + np.random.randn(N,2)
@masterdezign
masterdezign / charnn.py
Last active April 1, 2024 20:02
Character-level text generation with PyTorch LSTM
# Based on min-char-rnn.py
# https://gist.github.com/karpathy/d4dee566867f8291f086
import torch as th
import torch.nn as nn
import numpy as np
class Model(nn.Module):
def __init__(self, hidden_size, vocab_size, num_layers):
@masterdezign
masterdezign / buffers.py
Last active April 8, 2024 08:32
Recurrent replay buffer
from copy import deepcopy
from typing import Any, Dict, Generator, List, Optional, Union
from typing import NamedTuple, Tuple
from gymnasium import spaces
import numpy as np
import torch as th
from stable_baselines3.common.buffers import BaseBuffer
from stable_baselines3.common.vec_env import VecNormalize
@masterdezign
masterdezign / Dockerfile
Last active December 20, 2023 20:00
Configuration for reinforcement learning with Gymnasium
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
ARG USER="user"
ARG UID="1000"
ARG GID="100"
USER "root"
RUN apt-get update && apt-get install -y gnupg
@masterdezign
masterdezign / docker-compose.yml
Created March 3, 2022 15:51
Docker compose MySQL + PHPMyadmin
version: '3.1'
services:
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: CHANGE_THIS_PASSWORD
MYSQL_DATABASE: test_db
@masterdezign
masterdezign / cuda_11.2_installation_on_Ubuntu_20.04
Created February 16, 2022 10:32 — forked from Mahedi-61/cuda_11.8_installation_on_Ubuntu_22.04
Instructions for CUDA v11.2 and cuDNN 8.1 installation on Ubuntu 20.04 for Pytorch 1.8 & Tensorflow 2.7.0
#!/bin/bash
### steps ####
# verify the system has a cuda-capable gpu
# download and install the nvidia cuda toolkit and cudnn
# setup environmental variables
# verify the installation
###
### to verify your gpu is cuda enable check
import pandas as pd
# .read_csv()
# .shape
# .head(N) .tail(N)
# .dtypes
# .loc[3, 'sepal_length'] .iloc
# .to_csv()
# pd.set_option('max_columns', 2)
@masterdezign
masterdezign / eval.py
Last active August 13, 2021 11:47
Simple RL environment
import sys
import gym
from gym.envs.registration import register
from tensorforce.environments import Environment
from tensorforce.agents import Agent
if len(sys.argv) < 2:
print("Usage: python {} path/to/checkpoint".format(sys.argv[0]))
@masterdezign
masterdezign / m5stickc-timer.ino
Last active May 24, 2020 18:04
M5StickC timer
/* NB: HAT speaker needs to be connected */
#include <M5StickC.h>
#include "esp32-hal-timer.h"
volatile int interruptCounter;
int totalInterruptCounter;
// https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
hw_timer_t * timer = NULL; //Created Hardware Timer
@masterdezign
masterdezign / basics.py
Created May 14, 2020 18:09
BCI 101: MNE workshop by David Haslacher
#%%
import os
import numpy as np
import mne
from mne.preprocessing import compute_current_source_density
# %matplotlib qt
# First, we need to load the data
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',