Skip to content

Instantly share code, notes, and snippets.

@usernaamee
usernaamee / Backprop-derivation.md
Last active August 26, 2023 09:38
Derivation of Backpropagation algorithm in matrix form

Backpropagation : Derivation (Matrix form)

Notations

  1. Input matrix is $x_0$
  2. Layer 1 weight matrix is $W_1$
  3. Layer 1 output is $x_1 = f_1(W_1x_0)$, where $f$ is the activation function for layer 1
  4. There are 4 layers (including input layer)
  5. Hence, network output is $x_3 = f_3(W_3x_2)$
  6. Assuming MSE loss function, with $t$ as target variable, $E = \frac{1}{2}|x_3 - t|_2^2$
@usernaamee
usernaamee / otp.py
Created November 14, 2018 07:48
One time pad - pure python implementation
import os
import sys
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('infile')
parser.add_argument('padfile')
parser.add_argument('outfile')
chunksize = 8192
@usernaamee
usernaamee / change_ps1
Created March 23, 2018 08:49
some awesome ps1 prompts
function snip() {
PS1="\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e 's:/dev/::'): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] -> \[\033[0m\] "
}
function swog() {
PS1="\[\e[36;45m\]▓\[\e[m\]\[\e[36;45m\]▒\[\e[m\]\[\e[36;45m\]░\[\e[m\]\[\e[36;45m\]\u\[\e[m\]\[\e[36;45m\]@\[\e[m\]\[\e[36;45m\]\h\[\e[m\]\[\e[36;45m\]:\[\e[m\]\[\e[35;46m\]\w\[\e[m\]\[\e[35;46m\]░\[\e[m\]\[\e[35;46m\]▒\[\e[m\]\[\e[35;46m\]▓\[\e[m\]>>> "
}
@usernaamee
usernaamee / create-qgis-dock-plugin.py
Last active March 1, 2018 13:00
Dock widget based plugin builder for QGIS
"""
Replace following four appropriately first:
yourname yourcompany http://yourcompany.com http://yourcompany.com/logo.png
"""
import os
import sys
import urllib
import argparse
parser = argparse.ArgumentParser()
@usernaamee
usernaamee / compare-two-ml-models.ipynb
Created January 30, 2018 07:38
Compare the performance of two machine learning models
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@usernaamee
usernaamee / spectre.c
Created January 10, 2018 16:53 — forked from ErikAugust/spectre.c
Spectre example code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
#endif
@usernaamee
usernaamee / Bi-LSTM-kws.py
Created October 19, 2017 18:41
Bi-LSTM-kws.py
import os
import sys
import torch
import librosa
import numpy as np
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
from sklearn.model_selection import train_test_split
@usernaamee
usernaamee / wld-feature-extractor.py
Created June 9, 2017 13:31
wld-feature-extractor
import cv2
import sys
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
def get_wld_feats(gray_img):
f00 =np.array([[1, 1, 1], [1, -8, 1], [1, 1, 1]])
f10 = np.array([[0, -1, 0], [0, 0, 0], [0, 1, 0]])
f11 = np.array([[0, 0, 0], [1, 0, -1], [0, 0, 0]])
@usernaamee
usernaamee / rwa.py
Created April 10, 2017 15:12 — forked from shamatar/rwa.py
Keras (keras.is) implementation of Recurrent Weighted Average, as described in https://arxiv.org/abs/1703.01253. Follows original implementation in Tensorflow from https://github.com/jostmey/rwa. Works with fixed batch sizes, requires "batch_shape" parameter in input layer. Outputs proper config, should save and restore properly. You are welcome…
from keras.layers import Recurrent
import keras.backend as K
from keras import activations
from keras import initializers
from keras import regularizers
from keras import constraints
from keras.engine import Layer
from keras.engine import InputSpec
@usernaamee
usernaamee / binfile2pycode.py
Created March 13, 2017 19:03
Create self extracting python 2.6+ source code from any binary file
"""
:|
- Email provider doesn't allow me to send certain file types.
- I have python installed on all my machines.
- Inflates the file size by ~4.5X, still remains under 25M for me.
"""
from __future__ import print_function
import sys