This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_n = 5 # setting the initial point | |
lr = 0.001 # setting the learning rate | |
precision = 0.000001 #setting the initial precision | |
dr = lambda x: 4 * x**3 - 9 * x**2 # set the gradient of function required | |
n = 1000000 #no of iterations | |
next_n = start_n | |
iter = 0 # set initial count to be 0 | |
for i in range(n): | |
current_n = next_n | |
next_n = current_n - lr*dr(current_n) # moving in the negative of direction of gradient calculated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def sigmoid(x): | |
return 1 / (1 + np.exp(-x)) | |
def feedforward(features, weights1,weights2, bias): | |
layer1_output = sigmoid(np.dot(weights1, features) + bias) | |
layer2_output = sigmoid(np.dot(weights2, layer1_output) + bias) | |
print(layer1_output) | |
print(layer2_output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE CANCER_DETAIL(ID INTEGER PRIMARY KEY, NAME VARCHAR (20), HAVE_CANCER INTEGER); | |
INSERT INTO CANCER_DETAIL VALUES(1, 'JOHN', 1); | |
INSERT INTO CANCER_DETAIL VALUES(2, 'JENNIFER', 0); | |
INSERT INTO CANCER_DETAIL VALUES(3, 'SHYAM', 1); | |
INSERT INTO CANCER_DETAIL VALUES(4, 'RAHUL', 0); | |
INSERT INTO CANCER_DETAIL VALUES(5, 'SOURAV', 0); | |
INSERT INTO CANCER_DETAIL VALUES(6, 'JENNY', 1); | |
INSERT INTO CANCER_DETAIL VALUES(7, 'RAHUL', 0); | |
INSERT INTO CANCER_DETAIL VALUES(8, 'ROSY', 1); | |
INSERT INTO CANCER_DETAIL VALUES(9, 'JULIA', 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create(x): | |
return torch.rand(x) > 0.5 | |
def get_parallel_db(db, index): | |
return torch.cat((db[:index], db[index + 1 :])) | |
def get_parallel_dbs(db): | |
parallel_dbs = list() | |
for i in range(len(db)): | |
pdb = get_parallel_db(db, i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def L1_senstivity(query, n_entries = 1000): | |
db, pdbs = create_db_and_paralleldbs(n_entries) | |
maximum_distance = 0 | |
total_result = query(db) | |
for pdb in pdbs: | |
current_result = query(pdb) | |
current_distance = torch.abs(current_result - total_result) | |
if(current_distance > maximum_distance): | |
maximum_distance = current_distance | |
return maximum_distance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torch import optim, nn | |
import torchvision | |
from torchvision import datasets, models, transforms | |
import numpy as np | |
import torch.nn.functional as F |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define the train and test transforms | |
# since the images are grayscale , we have only one channel for narmalizing images , here std mean and std is taken to be 0.5 | |
train_transform = transforms.Compose([transforms.ToTensor(), | |
transforms.Normalize([0.5,],[0.5,])]) | |
test_transform = transforms.Compose([transforms.ToTensor(), | |
transforms.Normalize([0.5,],[0.5,])]) | |
# choose the training and test datasets | |
train_data = datasets.FashionMNIST('data/training', train=True, | |
download=True, transform=train_transform) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_transform = transforms.Compose([transforms.RandomRotation(30),transforms.RandomResizedCrop(224),transforms.RandomHorizontalFlip(),transforms.ToTensor(), | |
transforms.Normalize([0.5,],[0.5,])]) | |
test_transform = transforms.Compose([transforms.Resize(256), | |
transforms.CenterCrop(224), | |
transforms.ToTensor(), | |
transforms.Normalize([0.5,],[0.5])]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torchvision | |
grid = torchvision.utils.make_grid(images, nrow = 20, padding = 2) | |
plt.figure(figsize = (18, 18)) | |
plt.imshow(np.transpose(grid, (1, 2, 0))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_transform = transforms.Compose([transforms.RandomRotation(30), | |
transforms.RandomResizedCrop(224), | |
transforms.RandomHorizontalFlip(), | |
transforms.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1), | |
transforms.ToTensor(), | |
transforms.Normalize([0.5,],[0.5,])]) | |
OlderNewer