Skip to content

Instantly share code, notes, and snippets.

View Anjum48's full-sized avatar

Anjum Sayed Anjum48

View GitHub Profile
@Anjum48
Anjum48 / fresh_install.sh
Last active April 24, 2024 08:33
Instructions for a fresh Ubuntu 22.04 install
sudo apt update && sudo apt upgrade -y
sudo apt -y install build-essential git zsh python3-pip gnome-shell-extension-manager openssh-server curl nodejs htop mdadm ffmpeg lm-sensors npm tree
sudo apt -y install linux-headers-$(uname -r)
sudo apt-key del 7fa2af80
# Latest driver download
# https://www.nvidia.co.uk/download/driverResults.aspx/205541/en-uk
wget https://uk.download.nvidia.com/XFree86/Linux-x86_64/535.54.03/NVIDIA-Linux-x86_64-535.54.03.run
import numpy as np
import matplotlib.pyplot as plt
import random
import matplotlib.animation as animation
from matplotlib import cm
# s curve function
def _f(a,b,c,t):
return c*1/(1+a*np.exp(-b*t))
# function for s curve with added noise
@Anjum48
Anjum48 / hard_sample_mining.py
Created July 8, 2020 06:24
Hard sample mining in PyTorch
class HardMiningBatchSampler(BatchSampler):
"""
Creates batches that only contain a class once and and chosen based on embedding distance.
Used for NPairLoss
"""
def __init__(self, labels, batch_size, drop_last=True, classes=None):
self.labels = labels
self.batch_size = batch_size
# self.C = batch_size * 2 if classes is None else classes
@Anjum48
Anjum48 / nested_cv_wrapper.py
Created February 5, 2020 06:13
A first pass of a Nested CV wrapper for category encoders
from category_encoders import utils
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.model_selection import StratifiedKFold
import category_encoders as encoders
import pandas as pd
import numpy as np
import copy
class NestedCVWrapper(BaseEstimator, TransformerMixin):
@Anjum48
Anjum48 / siamese_train.py
Last active January 16, 2019 06:02
PyTorch crashes
import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import Dataset, DataLoader
@Anjum48
Anjum48 / ddpg_gym.py
Last active May 15, 2019 13:03
Pendulum-v0 submission using DDPG without batch normalisation
"""
Implementation of DDPG - Deep Deterministic Policy Gradient
Algorithm and hyperparameter details can be found here: http://arxiv.org/pdf/1509.02971v2.pdf
Variance scaling paper: https://arxiv.org/pdf/1502.01852v1.pdf
Thanks to GitHub users yanpanlau, pemami4911, songrotek and JunhongXu for their DDPG examples
Batch normalisation on the actor accelerates learning but has poor long term stability. Applying to the critic breaks
it, particularly on the state branch. Not sure why but I think this issue is specific to this environment
"""
import numpy as np