- A set is an unordered collection of unique elements. Examples are natural numbers, integers, rational numbers, and real numbers
- Cartesian product of
$A$ and$B$ is$A \times B = \lbrace(a, b) : a \in A, b \in B\rbrace$ - A function from set
$A$ to set$B$ is a rule of correspondence that assigns each element$x \in A$ to uniquely determined element$f(x) \in B$ - Set
$A$ is called the domain of$f$ - Set
$B$ is the codomain of$f$ - The set
$f(A) = \lbrace(x) : x \in A\rbrace$ is called the range of$f$ - Althought
$D(f) = A$ , we only have$R(f) \subseteq B$
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 qiskit as qk | |
# Load saved account from memory | |
qk.IBMQ.load_accounts() | |
n = 3 | |
q = qk.QuantumRegister(n) | |
c = qk.ClassicalRegister(n) | |
circ = qk.QuantumCircuit(q, c) |
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 | |
import torch.nn as nn | |
import torch.nn.functional as F | |
""" | |
Creating tensors | |
""" | |
a = torch.rand(...) # returns a torch.Tensor | |
b = torch.LongTensor(10).random_(0, 2) # 10-dim vector from [0, 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
import os | |
import numpy as np | |
import random | |
import tensorflow as tf | |
from tfdeterminism import patch | |
def seed(s=42): | |
random.seed(s) | |
np.random.seed(s) | |
tf.random.set_seed(s) |
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
PATH = "./my_dataset/" # path to dataset on Colab instance | |
TRAIN_PATH = PATH + "train/" | |
VAL_PATH = PATH + "val/" | |
# your custom augmentations | |
T = transforms.Compose([ | |
transforms.ToTensor(), | |
... | |
]) |
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
device = xm.xla_device() | |
# define some hyper-params you'd feed into your model | |
in_channels = ... | |
random_param = ... | |
# create model using appropriate hyper-params | |
net = MyCustomNet(...) | |
# seat it atop the TPU worker device and switch it to train mode |
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
''' | |
num_replicas is the total number of times we'll replicate | |
the batch samples for all cores. | |
''' | |
train_sampler = torch.utils.data.distributed.DistributedSampler( | |
im_train, | |
num_replicas=xm.xrt_world_size(), | |
rank=xm.get_ordinal(), | |
shuffle=True | |
) |
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
!wget http://www.some_dataset_website.com/my_dataset.tar.gz | |
!tar -xvzf my_dataset.tar.gz |
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 | |
import torch.nn as nn | |
import torch.nn.functional as F | |
from torchvision import transforms | |
import numpy as np | |
from PIL import Image | |
import matplotlib.pyplot as plt | |
from patchify import patchify, unpatchify # pip install patchify |
NewerOlder