Skip to content

Instantly share code, notes, and snippets.

View ritwikraha's full-sized avatar
🎲
learning is probabilistic.

Ritwik Raha ritwikraha

🎲
learning is probabilistic.
View GitHub Profile
@ritwikraha
ritwikraha / wavelet-decomp.m
Created March 19, 2020 14:03
For wavelet decomposition of EEG signals
%Applying bandpass filter to filter out the unwanted signal <4 and >30Hz
yy1=bandpass(SSS1,[4 30],128);
%Apply DWT at 5 level of decomposition
waveletFunction = 'db2';
[C,L] = wavedec(yy1,5,waveletFunction);
cD11 = detcoef(C,L,1);
cD21 = detcoef(C,L,2);
cD31 = detcoef(C,L,3);
cD41 = detcoef(C,L,4);
cD51 = detcoef(C,L,5);
@ritwikraha
ritwikraha / svd_image_compression.ipynb
Created April 13, 2020 15:52
svd_image_compression.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import cv2
import numpy as np
import dlib
cap = cv2.VideoCapture(0)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
while True:
@ritwikraha
ritwikraha / pcnn_feature_map.ipynb
Created November 6, 2020 18:02
PCNN_feature_map.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
for id = 1:32
sdata = load(strcat('s',num2str(id),'.mat'));
sdata = sdata.data;
slabels = load(strcat('s',num2str(id),'.csv'));
[~,idx] = sort(slabels(:,2));
sortedlabels = slabels(idx,:);
sorteddata = sdata(idx,:,:);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ritwikraha
ritwikraha / photoshop-blend-modes.ipynb
Created November 26, 2021 09:53
Photoshop-Blend-Modes.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ritwikraha
ritwikraha / shape_list.py
Created March 24, 2022 15:57
The shape_list function from HuggingFace/transformers
def shape_list(tensor: Union[tf.Tensor, np.ndarray]) -> List[int]:
"""
Deal with dynamic shape in tensorflow cleanly.
Args:
tensor (`tf.Tensor` or `np.ndarray`): The tensor we want the shape of.
Returns:
`List[int]`: The shape of the tensor as a list.
"""
@ritwikraha
ritwikraha / Bahdanau.md
Last active August 29, 2023 12:54
why Bahdanau is Additive?

Bahdanau Attention is often called Additive Attention because of the mathematical formulation used to compute the attention scores. In contrast to Dot-Product (Multiplicative) Attention, Bahdanau Attention relies on addition and a non-linear activation function.

Let's go through the math step-by-step:

Definitions

  • ( h_i ): Hidden state of the encoder for the (i)-th time step in the source sequence.
  • ( s_t ): Hidden state of the decoder for the (t)-th time step in the target sequence.
  • ( W_1 ) and ( W_2 ): Weight matrices.
  • ( b ): Bias term.
  • ( v ): Context vector.