This file contains hidden or 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
#include <iostream> | |
#include <vector> | |
#include <cassert> | |
#include <algorithm> | |
/* | |
O(n^2) in avg and worst. | |
*/ | |
// Implementation using std::find_if |
This file contains hidden or 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
#include <iostream> | |
#include <vector> | |
#include <cassert> | |
#include <algorithm> | |
/* | |
O(n^2) in avg and worst. | |
Can be done easily at space complexity O(n). | |
*/ |
This file contains hidden or 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
#include <iostream> | |
#include <vector> | |
#include <cassert> | |
#include <algorithm> | |
// Implementation | |
void print_vector(std::vector<int> array, std::string title) { | |
cout << title << ": " << "["; | |
for(int i : array) |
This file contains hidden or 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 numpy as np | |
from PIL import Image | |
from torchvision import transforms | |
from sklearn.datasets import fetch_olivetti_faces | |
faces, _ = fetch_olivetti_faces(data_home='../data/', return_X_y=True, shuffle=True, random_state=np.random.RandomState(0)) | |
faces = torch.from_numpy(faces) | |
n = faces.shape[0] |
This file contains hidden or 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 | |
x = np.array([-0.5, -0.43, -0.23, 0.12, 0.40, 0.71, 1]).reshape(-1, 1) | |
y = np.array([-2, -0.2, 0.1, 0.83, 1.4, 0.98, 2.2]).reshape(-1, 1) | |
# Add a column of ones to the input data for the intercept term | |
X = np.concatenate((np.ones_like(x), x), axis=1) | |
xxT = X.T.dot(X) | |
inv = np.linalg.inv(xxT) |