Skip to content

Instantly share code, notes, and snippets.

@piyush01123
piyush01123 / Gaussin_Processes_Bayesian_Optimization.ipynb
Last active March 16, 2023 01:36
Gaussian processes regression and Bayesian Optimization using GP
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@piyush01123
piyush01123 / integral.py
Created April 23, 2020 05:32
Definite integral as sum
import numpy as np
def integrate(f,start,end,dx=.001):
x_points = np.arange(start,end,dx)
y_points = [f(x) for x in x_points]
area = dx*(sum(y_points[1:-1])+0.5*(y_points[0]+y_points[-1]))
# area = dx*sum(y_points)
return area
def main():
#include <iostream>
void printArray(int *A, int n){
for (int i=0;i<n;i++){ std::cout<<A[i]<<' ';}
std::cout<<'\n';
}
void merge(int *A, int *left, int *right, int n1, int n2){
int i=0,j=0,k=0;
while (i<n1 && j<n2){
if (left[i]<right[j]){A[k]=left[i];i++;k++;}
else {A[k]=right[j];j++;k++;}
@piyush01123
piyush01123 / huffman.cpp
Last active November 17, 2022 06:25
Huffman Encoding
/*
Huffman Encoding: Given a frequency map of signs, create a new compressed representation.
Algorithm:
1. Create a data structure for node with prob, sign, left, right pointers
2. Create a min heap of nodes with prob as key. For each item in frequency map; insert node(p, s, NULL, NULL) into the min heap.
3. while the min heap has more than 1 element: Do
a) pop two nodes
b) create a parent node with these two nodes as its children
c) push parent node into the min heap
4. The last remaining node in the min heap is the root of the Huffman Tree.
@piyush01123
piyush01123 / visualize_first_layer_cnn.py
Last active January 16, 2020 00:50
Visualize First layer of popular trained CNNs
from torchvision import models
import torch
import cv2
import numpy as np
items = ['alexnet', 'densenet121', 'densenet161', 'densenet169', 'densenet201',
'googlenet', 'mnasnet0_5', 'mnasnet0_75', 'mnasnet1_0', 'mnasnet1_3',
'mobilenet_v2', 'resnet101', 'resnet152', 'resnet18', 'resnet34', 'resnet50',
'shufflenet_v2_x0_5', 'shufflenet_v2_x1_0', 'shufflenet_v2_x1_5', 'shufflenet_v2_x2_0',
@piyush01123
piyush01123 / linear_clustering.ipynb
Last active November 14, 2019 10:52
Clustering along lines
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@piyush01123
piyush01123 / gmm.ipynb
Last active November 18, 2019 08:00
Gaussian Mixture Model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@piyush01123
piyush01123 / ensemble_error_limit.ipynb
Created November 12, 2019 14:14
Ensemble Error Limit
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@piyush01123
piyush01123 / roc_auc.py
Created November 11, 2019 03:31
ROC-AUC score
# demonstrates plotting ROC curve and getting AUC score
import numpy as np
def roc_curve(y_true, y_pred):
fpr = []
tpr = []
thresholds = np.arange(0.0, 1.01, .01)
P = sum(y_true)
N = len(y_true) - P
@piyush01123
piyush01123 / naiveBayes.py
Last active March 16, 2023 01:37
Naive Bayes classification of MNIST images http://web.iitd.ac.in/~bspanda/BY.pdf
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
import scipy.stats
digits = datasets.load_digits()
trainX, testX, trainY, testY = train_test_split(digits.images, digits.target, test_size=.2)
Y_freq = {y: sum(trainY==y) for y in range(10)}