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 matplotlib.pyplot as plt | |
import numpy as np | |
import seaborn as sns | |
from gymnasium import spaces | |
from stable_baselines3 import PPO | |
from stable_baselines3.common.env_util import make_vec_env | |
from stable_baselines3.common.vec_env import VecEnvWrapper | |
sns.set_theme() |
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
# ----------------------------------------------------------------------------- | |
# AI-powered Git Commit Function | |
# Copy paste this gist into your ~/.bashrc or ~/.zshrc to gain the `gcm` command. It: | |
# 1) gets the current staged changed diff | |
# 2) sends them to an LLM to write the git commit message | |
# 3) allows you to easily accept, edit, regenerate, cancel | |
# But - just read and edit the code however you like | |
# the `llm` CLI util is awesome, can get it here: https://llm.datasette.io/en/stable/ | |
gcm() { |
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 gymnasium as gym | |
import numpy as np | |
from gymnasium.envs.mujoco.mujoco_env import MujocoEnv | |
# Env initialization | |
env = gym.make("HalfCheetah-v4", render_mode="human") | |
# Wrap to have reward statistics | |
env = gym.wrappers.RecordEpisodeStatistics(env) | |
mujoco_env = env.unwrapped | |
n_joints = 6 |
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 gymnasium as gym | |
import numpy as np | |
from gymnasium.envs.mujoco.mujoco_env import MujocoEnv | |
# Env initialization | |
env = gym.make("Swimmer-v4", render_mode="human") | |
# Wrap to have reward statistics | |
env = gym.wrappers.RecordEpisodeStatistics(env) | |
mujoco_env = env.unwrapped | |
n_joints = 2 |
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
Pretty print tables summarizing properties of tensor arrays in numpy, pytorch, jax, etc. | |
Now on pip! `pip install arrgh` https://github.com/nmwsharp/arrgh |
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 urllib.request | |
from datetime import datetime | |
import wandb | |
import yaml | |
from yaml.loader import SafeLoader | |
atari_ids = [ | |
# "AdventureNoFrameskip-v4", | |
# "AirRaidNoFrameskip-v4", |
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 cv2 | |
import pygame | |
import numpy | |
import functools | |
# WHAT IS THIS? | |
# This script is a simple ascii video player made in Python / pygame | |
# It allows you to drop in videos, or to use the webcam | |
pygame.init() |
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
# A very useful script for giving credit where it is due: by replacing (most) variable names by the authors who wrote them. | |
# Requirements: pip install gitpython | |
# Usage: python3 assign-credits.py <input_file> <output_file> | |
# Example: python3 assign-credits.py ./src/main.py ./src/main-credited.py | |
# NOTE that this is an awful idea with an awful implementation. The "generated" code likely does not work | |
# (e.g. typing stuff is skipped, class attribute names are replaced). The "author" is decided by the current HEAD of git repo, and whoever | |
# defines the variable first will get the credits (hahaa dunno if even this is right). | |
# It is getting late and I am tired of typing so I will let Github Copilot write something for me. |
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
#!/usr/bin/python3 | |
""" | |
WARNING: The code you are about to view is DISGUSTING | |
I wrote most of it months ago, so don't ask me what it's doing, or why. | |
""" | |
import struct | |
import sys |
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 torch, torch.nn as nn, torch.nn.functional as F | |
import numpy as np | |
import torch.optim as optim | |
# tied autoencoder using off the shelf nn modules | |
class TiedAutoEncoderOffTheShelf(nn.Module): | |
def __init__(self, inp, out, weight): | |
super().__init__() | |
self.encoder = nn.Linear(inp, out, bias=False) | |
self.decoder = nn.Linear(out, inp, bias=False) |
NewerOlder