Skip to content

Instantly share code, notes, and snippets.

View jeremy9959's full-sized avatar
🏠
Working from home

Jeremy Teitelbaum jeremy9959

🏠
Working from home
View GitHub Profile
@jeremy9959
jeremy9959 / renamer.py
Created January 30, 2024 15:37
Renaming HuskyCT Files
# %%
# Needs to have roster.csv available to convert netid to student name
import os
import re
import pandas as pd
AssignmentKey = r"Final Project"
# %%
allfiles = os.listdir()
files = [f for f in allfiles if re.match(r".*\.ipynb$", f)]
@jeremy9959
jeremy9959 / gist:a2155cadbea41aa47847ada846e2cd66
Created October 20, 2023 13:25 — forked from swedishmike/gist:902fb27d627313c31a95e31c44e302ac
Adding and removing virtual environments to Jupyter notebook
## Create the virtual environment
conda create -n 'environment_name'
## Activate the virtual environment
conda activate 'environment_name'
## Make sure that ipykernel is installed
pip install --user ipykernel
## Add the new virtual environment to Jupyter
@jeremy9959
jeremy9959 / snf.py
Last active January 15, 2023 19:39
Smith Normal Form
# More for illustration than practical computation
# A "real" algorithm works modulo the determinant of the matrix to avoid blowup in the Euclid algorithm.
# See Cohen's book for details
# Note: this is designed to mimic the approach over a PID, so you can compute the generator of an ideal (a,b) but there's
# no size used (as opposed to in other implementations)
import numpy as np
def euclid(a,b):
@jeremy9959
jeremy9959 / GaussianGCD.py
Last active February 21, 2024 14:46
Euclidean Algorithm in the Gaussian Integers
class Gaussian:
"Class representing Gaussian integers, with arithmetic operations"
def __init__(self,a,b):
self._real=a
self._imag=b
def real(self):
return self._real
@jeremy9959
jeremy9959 / SmithNormalForm.py
Created September 26, 2022 16:22
Smith Normal Form (pedagogical purposes, not efficiency)
import numpy as np
from numpy.random import default_rng
rng=default_rng()
def rA(n):
"""make a random nxn integer matrix with entries in the range -30,30"""
A=rng.integers(-30,30,size=n*n).reshape(n,n)
return A
def swapcol(A,i,j):
@jeremy9959
jeremy9959 / euclid.py
Created September 1, 2022 13:21
Math 5210 Euclidean Algorithm
def euclid(a,b):
x0,x1=1,0
y0,y1=0,1
r0,r1=a,b
q=""
format_string="{:>14} {:>14} {:>14} {:>14}"
print(format_string.format("",a,x0,y0))
while r1>0:
print(format_string.format(q,r1,x1,y1))
q=r0//r1
@jeremy9959
jeremy9959 / celine.py
Created April 1, 2022 14:56
ridge regression
from sklearn.linear_model import Ridge
# generate data
x=np.random.random(n_points)
y=np.sin(2*np.pi*x)+np.random.normal(0,0.1,n_points)
# make a ridge object with alpha=whatever you want
clf = Ridge(alpha=0)
# fit the ridge object to the data
@jeremy9959
jeremy9959 / justin.py
Last active January 26, 2022 15:13
Justins Extended Euclidean Algorithm
def qr(x,y):
q=x//y
r=x-q*y
if r<0:
q+=1
r-=y
return q,r
def eea(x, y):
r0=x
@jeremy9959
jeremy9959 / experiment.md
Last active November 5, 2021 18:28
Test of VSCode GitPad

This is a test

Does the vscode gistpad extension work well?

%.html : %.md
pandoc -s --mathjax -t slidy $< -o $@
%.pdf : %.md
pandoc -s --slide-level=2 --variable classoption=t --mathjax -t beamer $< -o $@