Skip to content

Instantly share code, notes, and snippets.

@mw3i
mw3i / pca_in_numpy.py
Last active June 17, 2019 16:03
PCA in pure Numpy (based on Sebastian Raschka tutorial)
'''
Implementation of PCA with Numpy (using covariance), based on this tutorial by Sebastian Raschka: https://sebastianraschka.com/Articles/2014_pca_step_by_step.html
'''
import numpy as np
def get_components(data: np.ndarray) -> np.ndarray:
cov_mat = np.cov(data.T) # <-- get the covariance matrix
## calculate eigenvalues of the covariance matrix
eig_val, eig_vec = np.linalg.eig(cov_mat)
@mw3i
mw3i / lda_in_numpy.py
Created June 17, 2019 16:04
LDA in pure Numpy
'''
Implementation of LDA with Numpy (using covariance & scatter matrix), based on this tutorial by Sebastian Raschka: https://sebastianraschka.com/Articles/2014_python_lda.html
'''
import numpy as np
def get_components(data: np.ndarray, labels: np.ndarray) -> np.ndarray: # <-- using covariance method
label_set = np.unique(labels)
class_means = np.array([
data[labels == label,:].mean(axis = 0, keepdims = True)
for label in label_set
@mw3i
mw3i / ff_neural_classifyer_ag.py
Last active June 27, 2019 15:29
Feed Forward Neural Net Classifier using Autograd
## ext requirements
import autograd.numpy as anp
from autograd import grad
# - - - - - - - - - - - - - - - - - -
# -- Model --
# - - - - - - - - - - - - - - - - - -
@mw3i
mw3i / ff_neural_classifyer_np.py
Last active June 27, 2019 15:29
Feed Forward Neural Net Classifier in Numpy
## ext requirements
import numpy as np
# - - - - - - - - - - - - - - - - - -
# -- Model --
# - - - - - - - - - - - - - - - - - -
## produces model outputs
@mw3i
mw3i / cnn_classifier_in_autograd.py
Created June 28, 2019 00:42
Convolutional Net in Autograd
## std lib
import sys, os
## ext req
import autograd.numpy as np
from autograd import grad
import autograd.scipy.signal as signal
## _ _ _ Get Model Output _ _ _
@mw3i
mw3i / simple_shell.py
Created July 20, 2019 16:28
A simple shell in python
## Python Commander
class simple_shell():
def __init__(self):
while True:
self.listener()
## Listener Function (required)
def listener(self):
self.user_input = input('---\nuser: ').split(' ')
try:
# Creates ".bashtrash" directory if it doesn't exist; then it moves things to it
function trash {
if [ ! -d "$HOME/.bashtrash" ]
then
mkdir "$HOME/.bashtrash"
fi
mv "$@" "$HOME/.bashtrash"
}
@mw3i
mw3i / thesis.md
Last active May 28, 2022 17:11
Markdown + Latex Template for a Masters or Dissertation Thesis (following the guidelines of Binghamton University)

documentclass: book bibliography: ./path/to/bibfile.bib csl: .csl fontsize: 12pt classoption: oneside link-citations: true color-links: true

linkcolor: BrickRed

urlcolor: "blue"

@mw3i
mw3i / coverletter.md
Last active July 20, 2022 19:07
Pandoc Markdown -> Latex Template for a Cover Letter


\flushright

My Name

My Street Address My City, MY STATE my zip code (My) Phone-Number

@mw3i
mw3i / rundown.py
Last active March 9, 2023 13:49
Hastly thrown together way of executing all python codeblocks in a markdown file
#!/usr/local/bin/python3
'''
This site is very useful for regex testing: https://pythex.org/
'''
import re, argparse
args = argparse.ArgumentParser(description = 'Execute all the blocks in a markdown script')
args.add_argument('file_path', help = 'File you want to execute')
args = args.parse_args()
with open(args.file_path, 'r') as file: