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
# Testing parents | |
test_parents <- matrix(c(1:8, c(2, 4, 6, 8, 7, 5, 3, 1)), nrow=2, byrow=T) | |
# Test 1 | |
cxPoints_test1 <- c(1, 3, 5, 8) | |
# Test 2 | |
cxPoints_test2 <- c(2, 3, 6) | |
########## | |
# gaperm_pbxCrossover_R has been *slightly* modified merely for pbx crossover testing purposes | |
########## |
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
# Load lpSolve | |
require(lpSolve) | |
## Set the coefficients of the decision variables -> C | |
C <- c(30, 40, 80) | |
# Create constraint martix B | |
A <- matrix(c(1, 1, -10, | |
4, 3, -20, | |
1, 0, -2, |
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
#------------------------------------------------------------------------------- | |
# Setup | |
require(dplyr) | |
require(e1071) | |
load(file="images_formatted.Rdata") | |
D <- out; rm(out) | |
# Scale the data. Note that scale returns a matrix |
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
#------------------------------------------------------------------------------- | |
# With built-in prcomp function: | |
# Compute PCA | |
pc <- prcomp(D, center = T, scale. = T) | |
# Eigenvalues | |
(pc$sdev^2)[1:20] | |
# Eigenvectors (loadings) |
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
#------------------------------------------------------------------------------- | |
# Projection of the average face onto the eigenvenctor space | |
# From a feature vector to a feature vector in the reduced feature space | |
proj_face_0 <- as.matrix(AverageFace[1, 2:4097]) %*% eigenvectors # for label 0 | |
proj_face_1 <- as.matrix(AverageFace[2, 2:4097]) %*% eigenvectors # for label 1 | |
proj_face_2 <- as.matrix(AverageFace[3, 2:4097]) %*% eigenvectors # for label 2 | |
# Every face has different projection on eigenvector space. | |
# We can use these new fewer values for a classification task. |
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
#------------------------------------------------------------------------------- | |
# Plot of eigenfaces | |
# First 4 eigenfaces | |
plt_img(eigenvectors[, 1]) # Eigenface 1 | |
plt_img(eigenvectors[, 2]) # Eigenface 2 | |
plt_img(eigenvectors[, 3]) # Eigenface 3 | |
plt_img(eigenvectors[, 4]) # Eigenface 4 | |
plt_img(eigenvectors[, 20]) # Eigenface 20 | |
# ... |
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
#------------------------------------------------------------------------------- | |
# Perform PCA on the data | |
# Step 1: scale data | |
# Scale as follows: mean equal to 0, stdv equal to 1 | |
D <- scale(D) | |
# Step 2: calculate covariance matrix | |
A <- cov(D) | |
A_ <- t(D) %*% D / (nrow(D)-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
rm(list=ls()) | |
require(dplyr) | |
load(file="images_formatted.Rdata") | |
D <- out; rm(out) | |
#------------------------------------------------------------------------------- | |
# Brief description of the data | |
# D is a 399x4096 matrix. It contains 399 images (rows) of 64x64 grayscale pixels (4096 columns) |
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
################################################################################ | |
# This script converts the images in the following format: | |
# | |
# X -> converted to a 399x4096 matrix. Each row represents an image of 64x64 | |
# greyscale pixels | |
# | |
# y -> labels of the images | |
# | |
################################################################################ |
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
# Imports | |
from sklearn.datasets import fetch_olivetti_faces | |
import numpy as np | |
# Download Olivetti faces dataset | |
olivetti = fetch_olivetti_faces() | |
x = olivetti.images | |
y = olivetti.target | |
# Print info on shapes and reshape where necessary |
NewerOlder