Many Machine Learning problems involve thousands or even millions of features for each training instance. Not only does this make training extremely slow, it can also make it much harder to find a good solution, as we will see. This problem is often referred to as the curse of dimensionality. Fortunately, in real-world problems, it is often possible to reduce the number of features considerably, turning an intractable problem into a tractable one.
Here we will discuss some of the most popular dimensionality reduction techniques: the principal component analysis (PCA), Kernel PCA, and Locally Linear Embedding (LLE). Furthermore, we will start by looking at some simple preprocessing of the data which allow us to rescale the data.
Principal component analysis and its various variants deal with the problem of fitting a low-dimensional affine subspace to a set of of data points in a high-dimensional space. With its family of methods it is one of the most used tools in data modeling, compression and visualization.
Before we proceed however, we will discuss how to preprocess our data. Till now and in connection with our previous examples we have not met so many cases where we are too sensitive to the scaling of our data. Normally the data may need a rescaling and/or may be sensitive to extreme values. Scaling the data renders our inputs much more suitable for the algorithms we want to employ.
Scikit-Learn has several functions which allow us to rescale the data, normally resulting in much better results in terms of various accuracy scores. The StandardScaler function in Scikit-Learn ensures that for each feature/predictor we study the mean value is zero and the variance is one (every column in the design/feature matrix). This scaling has the drawback that it does not ensure that we have a particular maximum or minimum in our data set. Another function included in Scikit-Learn is the MinMaxScaler which ensures that all features are exactly between \( 0 \) and \( 1 \). The
The Normalizer scales each data point such that the feature vector has a euclidean length of one. In other words, it projects a data point on the circle (or sphere in the case of higher dimensions) with a radius of 1. This means every data point is scaled by a different number (by the inverse of it’s length). This normalization is often used when only the direction (or angle) of the data matters, not the length of the feature vector.
The RobustScaler works similarly to the StandardScaler in that it ensures statistical properties for each feature that guarantee that they are on the same scale. However, the RobustScaler uses the median and quartiles, instead of mean and variance. This makes the RobustScaler ignore data points that are very different from the rest (like measurement errors). These odd data points are also called outliers, and might often lead to trouble for other scaling techniques.
# Common imports
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sklearn.linear_model as skl
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler, StandardScaler, Normalizer
from sklearn.svm import SVR
# Where to save the figures and data files
PROJECT_ROOT_DIR = "Results"
FIGURE_ID = "Results/FigureFiles"
DATA_ID = "DataFiles/"
if not os.path.exists(PROJECT_ROOT_DIR):
os.mkdir(PROJECT_ROOT_DIR)
if not os.path.exists(FIGURE_ID):
os.makedirs(FIGURE_ID)
if not os.path.exists(DATA_ID):
os.makedirs(DATA_ID)
def image_path(fig_id):
return os.path.join(FIGURE_ID, fig_id)
def data_path(dat_id):
return os.path.join(DATA_ID, dat_id)
def save_fig(fig_id):
plt.savefig(image_path(fig_id) + ".png", format='png')
def FrankeFunction(x,y):
term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
return term1 + term2 + term3 + term4
def create_X(x, y, n ):
if len(x.shape) > 1:
x = np.ravel(x)
y = np.ravel(y)
N = len(x)
l = int((n+1)*(n+2)/2) # Number of elements in beta
X = np.ones((N,l))
for i in range(1,n+1):
q = int((i)*(i+1)/2)
for k in range(i+1):
X[:,q+k] = (x**(i-k))*(y**k)
return X
# Making meshgrid of datapoints and compute Franke's function
n = 5
N = 1000
x = np.sort(np.random.uniform(0, 1, N))
y = np.sort(np.random.uniform(0, 1, N))
z = FrankeFunction(x, y)
X = create_X(x, y, n=n)
# split in training and test data
X_train, X_test, y_train, y_test = train_test_split(X,z,test_size=0.2)
svm = SVR(gamma='auto',C=10.0)
svm.fit(X_train, y_train)
# The mean squared error and R2 score
print("MSE before scaling: {:.2f}".format(mean_squared_error(svm.predict(X_test), y_test)))
print("R2 score before scaling {:.2f}".format(svm.score(X_test,y_test)))
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
print("Feature min values before scaling:\n {}".format(X_train.min(axis=0)))
print("Feature max values before scaling:\n {}".format(X_train.max(axis=0)))
print("Feature min values after scaling:\n {}".format(X_train_scaled.min(axis=0)))
print("Feature max values after scaling:\n {}".format(X_train_scaled.max(axis=0)))
svm = SVR(gamma='auto',C=10.0)
svm.fit(X_train_scaled, y_train)
print("MSE after scaling: {:.2f}".format(mean_squared_error(svm.predict(X_test_scaled), y_test)))
print("R2 score for scaled data: {:.2f}".format(svm.score(X_test_scaled,y_test)))
We show here how we can use a simple regression case on the breast cancer data using support vector machines (SVM) as algorithm for classification.
import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.svm import SVC
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
print(X_train.shape)
print(X_test.shape)
svm = SVC(C=100)
svm.fit(X_train, y_train)
print("Test set accuracy: {:.2f}".format(svm.score(X_test,y_test)))
from sklearn.preprocessing import MinMaxScaler, StandardScaler
scaler = MinMaxScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
print("Feature min values before scaling:\n {}".format(X_train.min(axis=0)))
print("Feature max values before scaling:\n {}".format(X_train.max(axis=0)))
print("Feature min values before scaling:\n {}".format(X_train_scaled.min(axis=0)))
print("Feature max values before scaling:\n {}".format(X_train_scaled.max(axis=0)))
svm.fit(X_train_scaled, y_train)
print("Test set accuracy scaled data with Min-Max scaling: {:.2f}".format(svm.score(X_test_scaled,y_test)))
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
svm.fit(X_train_scaled, y_train)
print("Test set accuracy scaled data with Standar Scaler: {:.2f}".format(svm.score(X_test_scaled,y_test)))
import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
cancer = load_breast_cancer()
# Set up training data
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
logreg = LogisticRegression()
logreg.fit(X_train, y_train)
print("Test set accuracy: {:.2f}".format(logreg.score(X_test,y_test)))
# Scale data
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
logreg.fit(X_train_scaled, y_train)
print("Test set accuracy scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
In addition to the plot of the features, we study now also the covariance (and the correlation matrix). We use also Pandas to compute the correlation matrix.
import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
cancer = load_breast_cancer()
import pandas as pd
# Making a data frame
cancerpd = pd.DataFrame(cancer.data, columns=cancer.feature_names)
fig, axes = plt.subplots(15,2,figsize=(10,20))
malignant = cancer.data[cancer.target == 0]
benign = cancer.data[cancer.target == 1]
ax = axes.ravel()
for i in range(30):
_, bins = np.histogram(cancer.data[:,i], bins =50)
ax[i].hist(malignant[:,i], bins = bins, alpha = 0.5)
ax[i].hist(benign[:,i], bins = bins, alpha = 0.5)
ax[i].set_title(cancer.feature_names[i])
ax[i].set_yticks(())
ax[0].set_xlabel("Feature magnitude")
ax[0].set_ylabel("Frequency")
ax[0].legend(["Malignant", "Benign"], loc ="best")
fig.tight_layout()
plt.show()
import seaborn as sns
correlation_matrix = cancerpd.corr().round(1)
# use the heatmap function from seaborn to plot the correlation matrix
# annot = True to print the values inside the square
sns.heatmap(data=correlation_matrix, annot=True)
plt.show()
#print eigvalues of correlation matrix
EigValues, EigVectors = np.linalg.eig(correlation_matrix)
print(EigValues)
In the above example we note two things. In the first plot we display the overlap of benign and malignant tumors as functions of the various features in the Wisconsing breast cancer data set. We see that for some of the features we can distinguish clearly the benign and malignant cases while for other features we cannot. This can point to us which features may be of greater interest when we wish to classify a benign or not benign tumour.
In the second figure we have computed the so-called correlation matrix, which in our case with thirty features becomes a \( 30\times 30 \) matrix.
We constructed this matrix using pandas via the statements
cancerpd = pd.DataFrame(cancer.data, columns=cancer.feature_names)
and then
correlation_matrix = cancerpd.corr().round(1)
Diagonalizing this matrix we can in turn say something about which features are of relevance and which are not. But before we proceed we need to define covariance and correlation matrices. This leads us to the classical Principal Component Analysis (PCA) theorem with applications.
The principal component analysis deals with the problem of fitting a low-dimensional affine subspace \( S \) of dimension \( d \) much smaller than the totaldimension \( D \) of the problem at hand (our data set). Mathematically it can be formulated as a statistical problem or a geometric problem. In our discussion of the theorem for the classical PCA, we will stay with a statistical approach. This is also what set the scene historically which for the PCA.
We have a data set defined by a design/feature matrix \( \boldsymbol{X} \) (see below for its definition)
Before we discuss the PCA theorem, we need to remind ourselves about the definition of the covariance and the correlation function. These are quantities
Suppose we have defined two vectors \( \hat{x} \) and \( \hat{y} \) with \( n \) elements each. The covariance matrix \( \boldsymbol{C} \) is defined as $$ \boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} \mathrm{cov}[\boldsymbol{x},\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] \\ \mathrm{cov}[\boldsymbol{y},\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{y},\boldsymbol{y}] \\ \end{bmatrix}, $$ where for example $$ \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] =\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})(y_i- \overline{y}). $$ With this definition and recalling that the variance is defined as $$ \mathrm{var}[\boldsymbol{x}]=\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})^2, $$ we can rewrite the covariance matrix as $$ \boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} \mathrm{var}[\boldsymbol{x}] & \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] \\ \mathrm{cov}[\boldsymbol{x},\boldsymbol{y}] & \mathrm{var}[\boldsymbol{y}] \\ \end{bmatrix}. $$
The covariance takes values between zero and infinity and may thus lead to problems with loss of numerical precision for particularly large values. It is common to scale the covariance matrix by introducing instead the correlation matrix defined via the so-called correlation function $$ \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}]=\frac{\mathrm{cov}[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{\mathrm{var}[\boldsymbol{x}] \mathrm{var}[\boldsymbol{y}]}}. $$
The correlation function is then given by values \( \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}] \in [-1,1] \). This avoids eventual problems with too large values. We can then define the correlation matrix for the two vectors \( \boldsymbol{x} \) and \( \boldsymbol{y} \) as $$ \boldsymbol{K}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} 1 & \mathrm{corr}[\boldsymbol{x},\boldsymbol{y}] \\ \mathrm{corr}[\boldsymbol{y},\boldsymbol{x}] & 1 \\ \end{bmatrix}, $$
In the above example this is the function we constructed using pandas.
In our derivation of the various regression algorithms like Ordinary Least Squares or Ridge regression we defined the design/feature matrix \( \boldsymbol{X} \) as $$ \boldsymbol{X}=\begin{bmatrix} x_{0,0} & x_{0,1} & x_{0,2}& \dots & \dots x_{0,p-1}\\ x_{1,0} & x_{1,1} & x_{1,2}& \dots & \dots x_{1,p-1}\\ x_{2,0} & x_{2,1} & x_{2,2}& \dots & \dots x_{2,p-1}\\ \dots & \dots & \dots & \dots \dots & \dots \\ x_{n-2,0} & x_{n-2,1} & x_{n-2,2}& \dots & \dots x_{n-2,p-1}\\ x_{n-1,0} & x_{n-1,1} & x_{n-1,2}& \dots & \dots x_{n-1,p-1}\\ \end{bmatrix}, $$ with \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predictors/features \( p \) refering to the column numbers and the entries \( n \) being the row elements. We can rewrite the design/feature matrix in terms of its column vectors as $$ \boldsymbol{X}=\begin{bmatrix} \boldsymbol{x}_0 & \boldsymbol{x}_1 & \boldsymbol{x}_2 & \dots & \dots & \boldsymbol{x}_{p-1}\end{bmatrix}, $$ with a given vector $$ \boldsymbol{x}_i^T = \begin{bmatrix}x_{0,i} & x_{1,i} & x_{2,i}& \dots & \dots x_{n-1,i}\end{bmatrix}. $$
With these definitions, we can now rewrite our \( 2\times 2 \) correaltion/covariance matrix in terms of a moe general design/feature matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \). This leads to a \( p\times p \) covariance matrix for the vectors \( \boldsymbol{x}_i \) with \( i=0,1,\dots,p-1 \) $$ \boldsymbol{C}[\boldsymbol{x}] = \begin{bmatrix} \mathrm{var}[\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_{p-1}]\\ \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_0] & \mathrm{var}[\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_{p-1}]\\ \mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_1] & \mathrm{var}[\boldsymbol{x}_2] & \dots & \dots & \mathrm{cov}[\boldsymbol{x}_2,\boldsymbol{x}_{p-1}]\\ \dots & \dots & \dots & \dots & \dots & \dots \\ \dots & \dots & \dots & \dots & \dots & \dots \\ \mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_1] & \mathrm{cov}[\boldsymbol{x}_{p-1},\boldsymbol{x}_{2}] & \dots & \dots & \mathrm{var}[\boldsymbol{x}_{p-1}]\\ \end{bmatrix}, $$ and the correlation matrix $$ \boldsymbol{K}[\boldsymbol{x}] = \begin{bmatrix} 1 & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_1] & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_2] & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_0,\boldsymbol{x}_{p-1}]\\ \mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_0] & 1 & \mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_2] & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_1,\boldsymbol{x}_{p-1}]\\ \mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_0] & \mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_1] & 1 & \dots & \dots & \mathrm{corr}[\boldsymbol{x}_2,\boldsymbol{x}_{p-1}]\\ \dots & \dots & \dots & \dots & \dots & \dots \\ \dots & \dots & \dots & \dots & \dots & \dots \\ \mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & \mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_1] & \mathrm{corr}[\boldsymbol{x}_{p-1},\boldsymbol{x}_{2}] & \dots & \dots & 1\\ \end{bmatrix}, $$
The Numpy function np.cov calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values. The following simple function uses the np.vstack function which takes each vector of dimension \( 1\times n \) and produces a \( 2\times n \) matrix \( \boldsymbol{W} \) $$ \boldsymbol{W} = \begin{bmatrix} x_0 & y_0 \\ x_1 & y_1 \\ x_2 & y_2\\ \dots & \dots \\ x_{n-2} & y_{n-2}\\ x_{n-1} & y_{n-1} & \end{bmatrix}, $$
which in turn is converted into into the \( 2\times 2 \) covariance matrix \( \boldsymbol{C} \) via the Numpy function np.cov(). We note that we can also calculate the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy function np.mean(x). We can also extract the eigenvalues of the covariance matrix through the np.linalg.eig() function.
# Importing various packages
import numpy as np
n = 100
x = np.random.normal(size=n)
print(np.mean(x))
y = 4+3*x+np.random.normal(size=n)
print(np.mean(y))
W = np.vstack((x, y))
C = np.cov(W)
print(C)
The previous example can be converted into the correlation matrix by simply scaling the matrix elements with the variances. We should also subtract the mean values for each column. This leads to the following code which sets up the correlations matrix for the previous example in a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the \( 2\times 2 \) correlation matrix (since we have only two vectors).
import numpy as np
n = 100
# define two vectors
x = np.random.random(size=n)
y = 4+3*x+np.random.normal(size=n)
#scaling the x and y vectors
x = x - np.mean(x)
y = y - np.mean(y)
variance_x = np.sum(x@x)/n
variance_y = np.sum(y@y)/n
print(variance_x)
print(variance_y)
cov_xy = np.sum(x@y)/n
cov_xx = np.sum(x@x)/n
cov_yy = np.sum(y@y)/n
C = np.zeros((2,2))
C[0,0]= cov_xx/variance_x
C[1,1]= cov_yy/variance_y
C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
C[1,0]= C[0,1]
print(C)
We see that the matrix elements along the diagonal are one as they should be and that the matrix is symmetric. Furthermore, diagonalizing this matrix we easily see that it is a positive definite matrix.
The above procedure with numpy can be made more compact if we use pandas.
We whow here how we can set up the correlation matrix using pandas, as done in this simple code
import numpy as np
import pandas as pd
n = 10
x = np.random.normal(size=n)
x = x - np.mean(x)
y = 4+3*x+np.random.normal(size=n)
y = y - np.mean(y)
X = (np.vstack((x, y))).T
print(X)
Xpd = pd.DataFrame(X)
print(Xpd)
correlation_matrix = Xpd.corr()
print(correlation_matrix)
We expand this model to the Franke function discussed above.
# Common imports
import numpy as np
import pandas as pd
def FrankeFunction(x,y):
term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
return term1 + term2 + term3 + term4
def create_X(x, y, n ):
if len(x.shape) > 1:
x = np.ravel(x)
y = np.ravel(y)
N = len(x)
l = int((n+1)*(n+2)/2) # Number of elements in beta
X = np.ones((N,l))
for i in range(1,n+1):
q = int((i)*(i+1)/2)
for k in range(i+1):
X[:,q+k] = (x**(i-k))*(y**k)
return X
# Making meshgrid of datapoints and compute Franke's function
n = 4
N = 100
x = np.sort(np.random.uniform(0, 1, N))
y = np.sort(np.random.uniform(0, 1, N))
z = FrankeFunction(x, y)
X = create_X(x, y, n=n)
Xpd = pd.DataFrame(X)
# subtract the mean values and set up the covariance matrix
Xpd = Xpd - Xpd.mean()
covariance_matrix = Xpd.cov()
print(covariance_matrix)
We note here that the covariance is zero for the first rows and columns since all matrix elements in the design matrix were set to one (we are fitting the function in terms of a polynomial of degree \( n \)).
This means that the variance for these elements will be zero and will cause problems when we set up the correlation matrix. We can simply drop these elements and construct a correlation matrix without these elements.
We can rewrite the covariance matrix in a more compact form in terms of the design/feature matrix \( \boldsymbol{X} \) as $$ \boldsymbol{C}[\boldsymbol{x}] = \frac{1}{n}\boldsymbol{X}\boldsymbol{X}^T= \mathbb{E}[\boldsymbol{X}\boldsymbol{X}^T]. $$
To see this let us simply look at a design matrix \( \boldsymbol{X}\in {\mathbb{R}}^{2\times 2} \) $$ \boldsymbol{X}=\begin{bmatrix} x_{00} & x_{01}\\ x_{10} & x_{11}\\ \end{bmatrix}=\begin{bmatrix} \boldsymbol{x}_{0} & \boldsymbol{x}_{1}\\ \end{bmatrix}. $$
If we then compute the expectation value $$ \mathbb{E}[\boldsymbol{X}\boldsymbol{X}^T] = \frac{1}{n}\boldsymbol{X}\boldsymbol{X}^T=\begin{bmatrix} x_{00}^2+x_{01}^2 & x_{00}x_{10}+x_{01}x_{11}\\ x_{10}x_{00}+x_{11}x_{01} & x_{10}^2+x_{11}^2\\ \end{bmatrix}, $$ which is just $$ \boldsymbol{C}[\boldsymbol{x}_0,\boldsymbol{x}_1] = \boldsymbol{C}[\boldsymbol{x}]=\begin{bmatrix} \mathrm{var}[\boldsymbol{x}_0] & \mathrm{cov}[\boldsymbol{x}_0,\boldsymbol{x}_1] \\ \mathrm{cov}[\boldsymbol{x}_1,\boldsymbol{x}_0] & \mathrm{var}[\boldsymbol{x}_1] \\ \end{bmatrix}, $$ where we wrote $$\boldsymbol{C}[\boldsymbol{x}_0,\boldsymbol{x}_1] = \boldsymbol{C}[\boldsymbol{x}]$$ to indicate that this the covariance of the vectors \( \boldsymbol{x} \) of the design/feature matrix \( \boldsymbol{X} \).
It is easy to generalize this to a matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \).
We have that the covariance matrix (the correlation matrix involves a simple rescaling) is given as $$ \boldsymbol{C}[\boldsymbol{x}] = \frac{1}{n}\boldsymbol{X}\boldsymbol{X}^T= \mathbb{E}[\boldsymbol{X}\boldsymbol{X}^T]. $$ Let us now assume that we can perform a series of orthogonal transformations where we employ some orthogonal matrices \( \boldsymbol{S} \). These matrices are defined as \( \boldsymbol{S}\in {\mathbb{R}}^{p\times p} \) and obey the orthogonality requirements \( \boldsymbol{S}\boldsymbol{S}^T=\boldsymbol{S}^T\boldsymbol{S}=\boldsymbol{I} \). The matrix can be written out in terms of the column vectors \( \boldsymbol{s}_i \) as \( \boldsymbol{S}=[\boldsymbol{s}_0,\boldsymbol{s}_1,\dots,\boldsymbol{s}_{p-1}] \) and \( \boldsymbol{s}_i \in {\mathbb{R}}^{p} \).
Assume also that there is a transformation \( \boldsymbol{S}\boldsymbol{C}[\boldsymbol{x}]\boldsymbol{S}^T=\boldsymbol{C}[\boldsymbol{y}] \) such that the new matrix \( \boldsymbol{C}[\boldsymbol{y}] \) is diagonal with elements \( [\lambda_0,\lambda_1,\lambda_2,\dots,\lambda_{p-1}] \).
That is we have $$ \boldsymbol{C}[\boldsymbol{y}] = \mathbb{E}[\boldsymbol{S}\boldsymbol{X}\boldsymbol{X}^T\boldsymbol{S}^T]=\boldsymbol{S}\boldsymbol{C}[\boldsymbol{x}]\boldsymbol{S}^T, $$ since the matrix \( \boldsymbol{S} \) is not a data dependent matrix. Multiplying with \( \boldsymbol{S}^T \) from the left we have $$ \boldsymbol{S}^T\boldsymbol{C}[\boldsymbol{y}] = \boldsymbol{C}[\boldsymbol{x}]\boldsymbol{S}^T, $$ and since \( \boldsymbol{C}[\boldsymbol{y}] \) is diagonal we have for a given eigenvalue \( i \) of the covariance matrix that $$ \boldsymbol{S}^T_i\lambda_i = \boldsymbol{C}[\boldsymbol{x}]\boldsymbol{S}^T_i. $$
In the derivation of the PCA theorem we will assume that the eigenvalues are ordered in descending order, that is \( \lambda_0 > \lambda_1 > \dots > \lambda_{p-1} \).
The eigenvalues tell us then how much we need to stretch the corresponding eigenvectors. Dimensions with large eigenvalues have thus large variations (large variance) and define therefore useful dimensions. The data points are more spread out in the direction of these eigenvectors. Smaller eigenvalues mean on the other hand that the corresponding eigenvectors are shrunk accordingly and the data points are tightly bunched together and there is not much variation in these specific directions. Hopefully then we could leave it out dimensions where the eigenvalues are very small. If \( p \) is very large, we could then aim at reducing \( p \) to \( l < < p \) and handle only \( l \) features/predictors.
Here's how we would proceed in setting up the algorithm for the PCA, see also discussion below here.
We will use a simple example first with two-dimensional data drawn from a multivariate normal distribution with the following mean and covariance matrix: $$ \mu = (-1,2) \qquad \Sigma = \begin{bmatrix} 4 & 2 \\ 2 & 2 \end{bmatrix} $$ Note that the mean refers to each column of data. We will generate \( n = 1000 \) points \( X = \{ x_1, \ldots, x_N \} \) from this distribution, and store them in the \( 1000 \times 2 \) matrix \( \boldsymbol{X} \).
The following Python code aids in setting up the data and writing out the design matrix. Note that the function multivariate returns also the covariance discussed above and that it is defined by dividing by \( n-1 \) instead of \( n \).
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import display
n = 10000
mean = (-1, 2)
cov = [[4, 2], [2, 2]]
X = np.random.multivariate_normal(mean, cov, n)
Now we are going to implement the PCA algorithm. We will break it down into various substeps.
The first step of PCA is to compute the sample mean of the data and use it to center the data. Recall that the sample mean is $$ \mu_n = \frac{1}{n} \sum_{i=1}^n x_i $$ and the mean-centered data \( \bar{X} = \{ \bar{x}_1, \ldots, \bar{x}_n \} \) takes the form $$ \bar{x}_i = x_i - \mu_n. $$ When you are done with these steps, print out \( \mu_n \) to verify it is close to \( \mu \) and plot your mean centered data to verify it is centered at the origin! Compare your code with the functionality from Scikit-Learn discussed above. The following code elements perform these operations using pandas or using our own functionality for doing so. The latter, using numpy is rather simple through the mean() function.
df = pd.DataFrame(X)
# Pandas does the centering for us
df = df -df.mean()
# we center it ourselves
X_centered = X - X.mean(axis=0)
Alternatively, we could use the functions we discussed earlier for scaling the data set. That is, we could have used the StandardScaler function in Scikit-Learn, a function which ensures that for each feature/predictor we study the mean value is zero and the variance is one (every column in the design/feature matrix). You would then not get the same results, since we divide by the variance. The diagonal covariance matrix elements will then be one, while the non-diagonal ones need to be divided by \( 2\sqrt{2} \) for our specific case.
Now we are going to use the mean centered data to compute the sample covariance of the data by using the following equation $$ \begin{equation*} \Sigma_n = \frac{1}{n-1} \sum_{i=1}^n \bar{x}_i^T \bar{x}_i = \frac{1}{n-1} \sum_{i=1}^n (x_i - \mu_n)^T (x_i - \mu_n) \end{equation*} $$ where the data points \( x_i \in \mathbb{R}^p \) (here in this example \( p = 2 \)) are column vectors and \( x^T \) is the transpose of \( x \). We can write our own code or simply use either the functionaly of numpy or that of pandas, as follows
print(df.cov())
print(np.cov(X_centered.T))
Note that the way we define the covariance matrix here has a factor \( n-1 \) instead of \( n \). This is included in the cov() function by numpy and pandas. Our own code here is not very elegant and asks for obvious improvements. It is tailored to this specific \( 2\times 2 \) covariance matrix.
# extract the relevant columns from the centered design matrix of dim n x 2
x = X_centered[:,0]
y = X_centered[:,1]
Cov = np.zeros((2,2))
Cov[0,1] = np.sum(x.T@y)/(n-1.0)
Cov[0,0] = np.sum(x.T@x)/(n-1.0)
Cov[1,1] = np.sum(y.T@y)/(n-1.0)
Cov[1,0]= Cov[0,1]
print("Centered covariance using own code")
print(Cov)
plt.plot(x, y, 'x')
plt.axis('equal')
plt.show()
Depending on the number of points \( n \), we will get results that are close to the covariance values defined above. The plot shows how the data are clustered around a line with slope close to one. Is this expected?
Now we are ready to solve for the principal components! To do so we diagonalize the sample covariance matrix \( \Sigma \). We can use the function np.linalg.eig to do so. It will return the eigenvalues and eigenvectors of \( \Sigma \). Once we have these we can perform the following tasks:
Collecting all these steps we can write our own PCA function and compare this with the functionality included in Scikit-Learn.
The code here outlines some of the elements we could include in the analysis. Feel free to extend upon this in order to address the above questions.
# diagonalize and obtain eigenvalues, not necessarily sorted
EigValues, EigVectors = np.linalg.eig(Cov)
# sort eigenvectors and eigenvalues
#permute = EigValues.argsort()
#EigValues = EigValues[permute]
#EigVectors = EigVectors[:,permute]
print("Eigenvalues of Covariance matrix")
for i in range(2):
print(EigValues[i])
FirstEigvector = EigVectors[:,0]
SecondEigvector = EigVectors[:,1]
print("First eigenvector")
print(FirstEigvector)
print("Second eigenvector")
print(SecondEigvector)
#thereafter we do a PCA with Scikit-learn
from sklearn.decomposition import PCA
pca = PCA(n_components = 2)
X2Dsl = pca.fit_transform(X)
print("Eigenvector of largest eigenvalue")
print(pca.components_.T[:, 0])
This code does not contain all the above elements, but it shows how we can use Scikit-Learn to extract the eigenvector which corresponds to the largest eigenvalue. Try to address the questions we pose before the above code. Try also to change the values of the covariance matrix by making one of the diagonal elements much larger than the other. What do you observe then?
We assume now that we have a design matrix \( \boldsymbol{X} \) which has been centered as discussed above. For the sake of simplicity we skip the overline symbol. The matrix is defined in terms of the various column vectors \( [\boldsymbol{x}_0,\boldsymbol{x}_1,\dots, \boldsymbol{x}_{p-1}] \) each with dimension \( \boldsymbol{x}\in {\mathbb{R}}^{n} \).
We assume also that we have an orthogonal transformation \( \boldsymbol{W}\in {\mathbb{R}}^{p\times p} \). We define the reconstruction error (which is similar to the mean squared error we have seen before) as $$ J(\boldsymbol{W},\boldsymbol{Z}) = \frac{1}{n}\sum_i (\boldsymbol{x}_i - \overline{\boldsymbol{x}}_i)^2, $$ with \( \overline{\boldsymbol{x}}_i = \boldsymbol{W}\boldsymbol{z}_i \), where \( \boldsymbol{z}_i \) is a row vector with dimension \( {\mathbb{R}}^{n} \) of the matrix \( \boldsymbol{Z}\in{\mathbb{R}}^{p\times n} \). When doing PCA we want to reduce this dimensionality.
The PCA theorem states that minimizing the above reconstruction error corresponds to setting \( \boldsymbol{W}=\boldsymbol{S} \), the orthogonal matrix which diagonalizes the empirical covariance(correlation) matrix. The optimal low-dimensional encoding of the data is then given by a set of vectors \( \boldsymbol{z}_i \) with at most \( l \) vectors, with \( l < < p \), defined by the orthogonal projection of the data onto the columns spanned by the eigenvectors of the covariance(correlations matrix).
The proof which follows will be updated by mid January 2020.
To show the PCA theorem let us start with the assumption that there is one vector \( \boldsymbol{w}_0 \) which corresponds to a solution which minimized the reconstruction error \( J \). This is an orthogonal vector. It means that we now approximate the reconstruction error in terms of \( \boldsymbol{w}_0 \) and \( \boldsymbol{z}_0 \) as $$ J(\boldsymbol{w}_0,\boldsymbol{z}_0)= \frac{1}{n}\sum_i (\boldsymbol{x}_i - z_{i0}\boldsymbol{w}_0)^2=\frac{1}{n}\sum_i (\boldsymbol{x}_i^T\boldsymbol{x}_i - 2z_{i0}\boldsymbol{w}_0^T\boldsymbol{x}_i+z_{i0}^2\boldsymbol{w}_0^T\boldsymbol{w}_0), $$ which we can rewrite due to the orthogonality of \( \boldsymbol{w}_i \) as $$ J(\boldsymbol{w}_0,\boldsymbol{z}_0)=\frac{1}{n}\sum_i (\boldsymbol{x}_i^T\boldsymbol{x}_i - 2z_{i0}\boldsymbol{w}_0^T\boldsymbol{x}_i+z_{i0}^2). $$ Minimizing \( J \) with respect to the unknown parameters \( z_{0i} \) we obtain that $$ z_{i0}=\boldsymbol{w}_0^T\boldsymbol{x}_i, $$ where the vectors on the rhs are known.
We have now found the unknown parameters \( z_{i0} \). These correspond to the projected coordinates and we can write $$ J(\boldsymbol{w}_0)= \frac{1}{p}\sum_i (\boldsymbol{x}_i^T\boldsymbol{x}_i - z_{i0}^2)=\mathrm{const}-\frac{1}{n}\sum_i z_{i0}^2. $$
We can show that the variance of the projected coordinates defined by \( \boldsymbol{w}_0^T\boldsymbol{x}_i \) are given by $$ \mathrm{var}[\boldsymbol{w}_0^T\boldsymbol{x}_i] = \frac{1}{n}\sum_i z_{i0}^2, $$ since the expectation value of $$ \mathbb{E}[\boldsymbol{w}_0^T\boldsymbol{x}_i] = \mathbb{E}[z_{i0}]= \boldsymbol{w}_0^T\mathbb{E}[\boldsymbol{x}_i]=0, $$ where we have used the fact that our data are centered.
Recalling our definition of the covariance as $$ \boldsymbol{C}[\boldsymbol{x}] = \frac{1}{n}\boldsymbol{X}\boldsymbol{X}^T=\mathbb{E}[\boldsymbol{X}\boldsymbol{X}^T], $$ we have thus that $$ \mathrm{var}[\boldsymbol{w}_0^T\boldsymbol{x}_i] = \frac{1}{n}\sum_i z_{i0}^2=\boldsymbol{w}_0^T\boldsymbol{C}[\boldsymbol{x}]\boldsymbol{w}_0. $$
We are almost there, we have obtained a relation between minimizing the reconstruction error and the variance and the covariance matrix. Minimizing the error is equivalent to maximizing the variance of the projected data.
We could trivially maximize the variance of the projection (and thereby minimize the error in the reconstruction function) by letting the norm-2 of \( \boldsymbol{w}_0 \) go to infinity. However, this norm since we want the matrix \( \boldsymbol{W} \) to be an orthogonal matrix, is constrained by \( \vert\vert \boldsymbol{w}_0 \vert\vert_2^2=1 \). Imposing this condition via a Lagrange multiplier we can then in turn maximize $$ J(\boldsymbol{w}_0)= \boldsymbol{w}_0^T\boldsymbol{C}[\boldsymbol{x}]\boldsymbol{w}_0+\lambda_0(1-\boldsymbol{w}_0^T\boldsymbol{w}_0). $$ Taking the derivative with respect to \( \boldsymbol{w}_0 \) we obtain $$ \frac{\partial J(\boldsymbol{w}_0)}{\partial \boldsymbol{w}_0}= 2\boldsymbol{C}[\boldsymbol{x}]\boldsymbol{w}_0-2\lambda_0\boldsymbol{w}_0=0, $$ meaning that $$ \boldsymbol{C}[\boldsymbol{x}]\boldsymbol{w}_0=\lambda_0\boldsymbol{w}_0. $$ The direction that maximizes the variance (or minimizes the construction error) is an eigenvector of the covariance matrix! If we left multiply with \( \boldsymbol{w}_0^T \) we have the variance of the projected data is $$ \boldsymbol{w}_0^T\boldsymbol{C}[\boldsymbol{x}]\boldsymbol{w}_0=\lambda_0. $$
If we want to maximize the variance (minimize the construction error) we simply pick the eigenvector of the covariance matrix with the largest eigenvalue. This establishes the link between the minimization of the reconstruction function \( J \) in terms of an orthogonal matrix and the maximization of the variance and thereby the covariance of our observations encoded in the design/feature matrix \( \boldsymbol{X} \).
The proof for the other eigenvectors \( \boldsymbol{w}_1,\boldsymbol{w}_2,\dots \) can be established by applying the above arguments and using the fact that our basis of eigenvectors is orthogonal, see Murphy chapter 12.2. The discussion in chapter 12.2 of Murphy's text has also a nice link with the Singular Value Decomposition theorem. For categorical data, see chapter 12.4 and discussion therein.
Additional part of the proof for the other eigenvectors will be added by mid January 2020.
This material will be added by mid January 2020.
Principal Component Analysis (PCA) is by far the most popular dimensionality reduction algorithm. First it identifies the hyperplane that lies closest to the data, and then it projects the data onto it.
The following Python code uses NumPy’s svd() function to obtain all the principal components of the training set, then extracts the first two principal components. First we center the data using either pandas or our own code
import numpy as np
import pandas as pd
from IPython.display import display
np.random.seed(100)
# setting up a 10 x 5 vanilla matrix
rows = 10
cols = 5
X = np.random.randn(rows,cols)
df = pd.DataFrame(X)
# Pandas does the centering for us
df = df -df.mean()
display(df)
# we center it ourselves
X_centered = X - X.mean(axis=0)
# Then check the difference between pandas and our own set up
print(X_centered-df)
#Now we do an SVD
U, s, V = np.linalg.svd(X_centered)
c1 = V.T[:, 0]
c2 = V.T[:, 1]
W2 = V.T[:, :2]
X2D = X_centered.dot(W2)
print(X2D)
PCA assumes that the dataset is centered around the origin. Scikit-Learn’s PCA classes take care of centering the data for you. However, if you implement PCA yourself (as in the preceding example), or if you use other libraries, don’t forget to center the data first.
Once you have identified all the principal components, you can reduce the dimensionality of the dataset down to \( d \) dimensions by projecting it onto the hyperplane defined by the first \( d \) principal components. Selecting this hyperplane ensures that the projection will preserve as much variance as possible.
W2 = V.T[:, :2]
X2D = X_centered.dot(W2)
Scikit-Learn’s PCA class implements PCA using SVD decomposition just like we did before. The following code applies PCA to reduce the dimensionality of the dataset down to two dimensions (note that it automatically takes care of centering the data):
#thereafter we do a PCA with Scikit-learn
from sklearn.decomposition import PCA
pca = PCA(n_components = 2)
X2D = pca.fit_transform(X)
print(X2D)
After fitting the PCA transformer to the dataset, you can access the principal components using the components variable (note that it contains the PCs as horizontal vectors, so, for example, the first principal component is equal to
pca.components_.T[:, 0].
Another very useful piece of information is the explained variance ratio of each principal component, available via the \( explained\_variance\_ratio \) variable. It indicates the proportion of the dataset’s variance that lies along the axis of each principal component.
import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
logreg = LogisticRegression()
logreg.fit(X_train, y_train)
print("Train set accuracy from Logistic Regression: {:.2f}".format(logreg.score(X_train,y_train)))
# We scale the data
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Then perform again a log reg fit
logreg.fit(X_train_scaled, y_train)
print("Train set accuracy scaled data: {:.2f}".format(logreg.score(X_train_scaled,y_train)))
#thereafter we do a PCA with Scikit-learn
from sklearn.decomposition import PCA
pca = PCA(n_components = 2)
X2D_train = pca.fit_transform(X_train_scaled)
# and finally compute the log reg fit and the score on the training data
logreg.fit(X2D_train,y_train)
print("Train set accuracy scaled and PCA data: {:.2f}".format(logreg.score(X2D_train,y_train)))
We see that our training data after the PCA decomposition has a performance similar to the non-scaled data.
Instead of arbitrarily choosing the number of dimensions to reduce down to, it is generally preferable to choose the number of dimensions that add up to a sufficiently large portion of the variance (e.g., 95%). Unless, of course, you are reducing dimensionality for data visualization — in that case you will generally want to reduce the dimensionality down to 2 or 3. The following code computes PCA without reducing dimensionality, then computes the minimum number of dimensions required to preserve 95% of the training set’s variance:
pca = PCA()
pca.fit(X)
cumsum = np.cumsum(pca.explained_variance_ratio_)
d = np.argmax(cumsum >= 0.95) + 1
You could then set \( n\_components=d \) and run PCA again. However, there is a much better option: instead of specifying the number of principal components you want to preserve, you can set \( n\_components \) to be a float between 0.0 and 1.0, indicating the ratio of variance you wish to preserve:
pca = PCA(n_components=0.95)
X_reduced = pca.fit_transform(X)
One problem with the preceding implementation of PCA is that it requires the whole training set to fit in memory in order for the SVD algorithm to run. Fortunately, Incremental PCA (IPCA) algorithms have been developed: you can split the training set into mini-batches and feed an IPCA algorithm one minibatch at a time. This is useful for large training sets, and also to apply PCA online (i.e., on the fly, as new instances arrive).
Scikit-Learn offers yet another option to perform PCA, called Randomized PCA. This is a stochastic algorithm that quickly finds an approximation of the first d principal components. Its computational complexity is \( O(m \times d^2)+O(d^3) \), instead of \( O(m \times n^2) + O(n^3) \), so it is dramatically faster than the previous algorithms when \( d \) is much smaller than \( n \).
The kernel trick is a mathematical technique that implicitly maps instances into a very high-dimensional space (called the feature space), enabling nonlinear classification and regression with Support Vector Machines. Recall that a linear decision boundary in the high-dimensional feature space corresponds to a complex nonlinear decision boundary in the original space. It turns out that the same trick can be applied to PCA, making it possible to perform complex nonlinear projections for dimensionality reduction. This is called Kernel PCA (kPCA). It is often good at preserving clusters of instances after projection, or sometimes even unrolling datasets that lie close to a twisted manifold. For example, the following code uses Scikit-Learn’s KernelPCA class to perform kPCA with an
from sklearn.decomposition import KernelPCA
rbf_pca = KernelPCA(n_components = 2, kernel="rbf", gamma=0.04)
X_reduced = rbf_pca.fit_transform(X)
Locally Linear Embedding (LLE) is another very powerful nonlinear dimensionality reduction (NLDR) technique. It is a Manifold Learning technique that does not rely on projections like the previous algorithms. In a nutshell, LLE works by first measuring how each training instance linearly relates to its closest neighbors (c.n.), and then looking for a low-dimensional representation of the training set where these local relationships are best preserved (more details shortly).
There are many other dimensionality reduction techniques, several of which are available in Scikit-Learn.
Here are some of the most popular:


|
document2html
1.0
Documents to HTML converter
|
Evaluating formulas operands. More...
#include <formula.hpp>
Public Member Functions | |
| Operand (int kind=-5, const std::vector< Ref3D > &value={}, int rank=0, const std::string &text="?", const std::string &textValue="") | |
Public Attributes | |
| std::vector< Ref3D > | m_value |
| std::string | m_textValue |
| int | m_kind = oUNK |
| std::string | m_text = "?" |
| int | m_rank |
Evaluating formulas operands.
The following table describes kinds and how their values are represented
| Kind symbol | Kind number | Value representation |
|---|---|---|
| oBOOL | 3 | Boolean: 0 => False; 1 => True |
| oERR | 4 | None, or error code (same as XL_CELL_ERROR in CELL class) |
| oMSNG | 5 | Used by Excel as placeholder for missing function argument |
| oNUM | 2 | Float. Note that there is no way of distinguishing dates |
| oREF | -1 | Value is either None or non-empty list of absolute Ref3D instances |
| oREL | -2 | Value is None or non-empty list of fully/partially relative Ref3D instances |
| oSTRG | 1 | Unicode string |
| oUNK | 0 | Kind is unknown or ambiguous. Value is None |
| excel::Operand::Operand | ( | int | kind = -5 , |
| const std::vector< Ref3D > & | value = {} , |
||
| int | rank = 0 , |
||
| const std::string & | text = "?" , |
||
| const std::string & | textValue = "" |
||
| ) |
| int excel::Operand::m_kind = oUNK |
Operand kind. oUNK means that kind of operand is not known unambiguously
| int excel::Operand::m_rank |
Operand rank
| std::string excel::Operand::m_text = "?" |
Reconstituted text of original formula. Function names will be in English irrespective of original language, which doesn't seem to be recorded anywhere. Separator is ",", not ";" or whatever else might be more appropriate for end-user's locale
| std::string excel::Operand::m_textValue |
Operand constant text value
| std::vector<Ref3D> excel::Operand::m_value |
Operand value. None means that actual value of operand is a variable (depends on cell data), not a constant


redis_cache.rb |
|
|---|---|
|
RedisCache is a middleware that sits at the top of the Rails middleware
stack. In other words, it’s the first middleware to be hit. This is set in
|
|
The Middleware |
class RedisCache |
|
Instantiate a Rack |
def initialize(app, options={})
@app = app
@redis = Redis::Namespace.new(Rails.env.to_s, :redis => Redis.new)
end
def call(env) |
|
Grab the relative path from the request. |
path = Rack::Request.new(env).path |
|
Is the path saved in Redis as a key? If so, log the hit and serve the key’s value immediately. |
if cached_content = @redis.get(path)
Rails.logger.info "RedisCache hit for #{path} at #{Time.now}"
[200, {'Content-Type' => 'text/html'}, [cached_content]] |
|
Otherwise, continue down the Rails middleware stack. |
else
@app.call(env)
end
end
end |


New on the block: Privé launches across from Tiong Bahru Market
by Coconuts SingaporeA Privé outlet launched yesterday in the prominent corner space across from always-busy Tiong Bahru Market that was vacated by Tiong Bahru Social Club a few months ago.
This location serves an extensive list of food all day long, from coffee to small bites to breakfast to heavy dinners and happy-hour drinks.
Food buzz: Tiong Bahru Club relocating to Little India, Prive potentially taking over former space
The highlight dishes (recommended by the Privé representative who chatted with Coconuts Singapore online yesterday) include Middle Eastern Avocado Toast (poached eggs or cumin-lime roasted chickpeas, served with pomegranate, pumpkin seed dukkah, chilli flakes, chipotle-cumin hummus for S$18), Truffled Mushroom Swiss Burger (mushrooms, vegan swiss cheese sauce, caramelised onions, vegan truffle mayonnaise, vegan bun for S$21) and Tracy’s Favourite Salad (baby spinach, kale, broccoli, avocado, hummus, quinoa, goji berries, pomegranate, jalapeño, garlic chips, edamame, pumpkin and chilli-chimichurri dressing for S$18).
Now you know what you should order!
At the branch, vegetarians and vegans can rejoice with the wide selection of plant-based dishes. So, don’t be shy to ask if your favorite items can be made vegan or vegetarian.
Months ago, Privé Group set its sights on Tiong Bahru for its ninth branch. The other branches include the locations at Keppel Bay, Asian Civilisations Museum, Clarke Quay and Jewel Changi Airport.
FIND IT:
Privé Tiong Bahru
57 Eng Hoon Street, Block 57, Singapore
7:30am – 10pm daily (last orders 10pm)
Phone: +65 6776 0777
Related:
Food buzz: Tiong Bahru Club relocating to Little India, Prive potentially taking over former space


{% extends "base_generic.html" %} {% block pagetitle %}Your Checked-out Assets{% endblock %} {% block content %}
The following domains are currently checked-out for {{ request.user.get_username }}:
| Domain | Health | Project | Purpose |
Check-in Date
This is the date your domain will be automatically released back into the pool. Edit your check-out to extend the time. |
Release | |
|---|---|---|---|---|---|---|
| {{ entry.domain.name }} | {% if entry.domain.health_status.health_status == "Healthy" %}{{ entry.domain.health_status }} | {% else %}{{ entry.domain.health_status }} | {% endif %}{{ entry.project}} | {{ entry.activity_type}} | {{ entry.end_date }} |
There are no domains currently checked-out for your account.
{% endif %}The following servers are currently checked-out for {{ request.user.get_username }}:
| IP Address | Project | Purpose | Role |
Check-in Date
This is the date your server will be automatically released back into the pool. Edit your check-out to extend the time. |
Release |
|---|---|---|---|---|---|
| {{ entry.server.ip_address }} | {{ entry.project}} | {{ entry.activity_type}} | {{ entry.server_role}} | {{ entry.end_date }} |
There are no servers currently checked-out for your account.
{% endif %} {% endblock %} {% block morescripts %} {% endblock %}


PIC: Getting Creative With “Meat” As Austerity Measures Bite Hard
by Timothy NdoroAusterity Measures Bite Hard
It seems like the season for austerity measures may not be going away just yet. Impoverished Zimbabweans who are struggling from the economic hardships plaguing he country noted that the austerity measures seem to be biting hard across the border as well.
Weary Zimbabweans smiled in solidarity after seeing images which seem to be from Botswana of what is labelled as “Cook Bones”. This appears to be a euphemism as the cook bones are actually leftover chicken bones which seem to have been gathered from a fast-food restaurant.
It seems highly unlikely that the “cook bones” are meant for human consumption and may have been meant dogs. However, this is the first time that many have come across leftovers being repackaged in this way for consumption either by humans or animals.
Related Content,
-
“What I eat is what you eat, what I wear is also what you wear” – Mnangagwa Says He Also Facing Austerity Measures
-
‘Varakashi,’ Zanu-PF Apologists Castigate ‘Lamborghini MP’ For His Extravagance During Time Of Austerity
-
‘One-Sided Austerity Must Stop…It’s Treasonous’ -Former Minister Lashes Out At Mthuli Ncube & Mangudya After Spike In Prices
-
Austerity Hits Poly As Meat & Breakfast Are Removed From Meal Plans
Trending Stories
-
Statehouse Gunshots Soldier ENGAGES in FISTFIGHT with COMMANDER!
-
WATCH: When You Have A PHD In “Thievery”…Bulawayo Lady Performs Amazing “Disappearing Trick” In Shop
-
Mother Mary Relives? As PREGNANT Teen Found To Be A VIRGIN
-
PICS: Popular Prophet, T Freddy, Spotted In The Notorious Red Light District In The Avenues?
To View and Apply for the latest Jobs and Vacancies in Zimbabwe, Please Visit our Sister website iHarare Jobs


Promoted to Principle Developer at Zenman, in charge of all development-related company activities.
Promoted to Lead Developer at Zenman for demonstrating my leadership and mentoring capacity.
Promoted to Senior Developer at Zenman for exhibiting advanced development skills.
Earned a 4.0 GPA.
Earned Marine Corps Certificate of Commendation for outstanding achievement in duties.
Earned a 4.0 GPA.
Earned the Outstanding Achievement award in the Professional and Technical Communication Program.


There's no particular reason to the identifiers assigned to the various cipher suites. They're just a sequential list of every combination that the writers of the specification could think of. They're not even grouped together meaningfully; the RSA key exchange cipher suites aren't all in the same place because after the specification was drafted, new cipher suites that used the RSA key exchange method were identified. It would certainly have been nicer, from an implementer's perspective, if they had allocated, say, three bits to identify the key exchange, five bits to identify the symmetric cipher, two for the MAC, and so on. 笔记：这里解释了为什么cipher suites的identifier和value之间没有规律
TLS_NULL_WITH_NULL_NULL
indicates that there's no encryption, no MAC and no key exchange.
This is the default state for a TLS handshake — the state it starts out in.
Cipher suites TLS_RSA_WITH_NULL_MD5
and TLS_RSA_WITH_NULL_SHA
allow a non-encrypted, but MAC'ed, cipher suite to be negotiated.
This can actually be pretty handy when you're trying to debug something and you don't want to have to decrypt what you're trying to debug.
Unfortunately for the would-be debugger, for obvious security reasons, most servers won't allow you to negotiate this cipher suite by default.


Philippines
About
Map
'
The country is known for having its rich biosectionersity as its main tourist attraction.


Citta italiane
Click the circles to discover some of Italy's major cities.
Facts about Italy
Population: 58,742,000
Capital: Rome
Area: 301,333 square kilometers
Language: Italian, German, French, Slovene
Religion: Roman Catholic
Currency: Euro
Pisa
Click the circles to discover major monuments in Pisa.
Subsoil profile
Click the circles to discover what the different layers are made of.
The water table in horizon A is 1 to 2 m below the ground. Pumping from the lower sand (in horizon C) has create downward seepage from horizon A. The average settlement of the Tower is approximately 3 m.


{% extends "vpool/view.html" %} {% block page_title %} {{ super() }} {% endblock %} {% block menu %} {{ super() }} {% endblock %} {% block container %}
Are you sure you want to remove the following done VMs in {{ pool.name }}?
The below VMs will be deleted in ONE:


Backround: I have been smoking weed for over a decade at first it was all I did. I fell in love with the drug immediatley. Possibly due to an abusive upbringing. The first time I smoked I felt 'happy' for the first time in my life. I finally understood why people smiled. I rapidly fell into the culture. Peaking out in college smoking 7-10 grams a day, selling over ten lbs. a week. I was living a wild life, doing anything and everything that would set my synapses firing, letting the drug and money take over my life.
A series of scary near-jail experiences causing me to tone down my act. I have since, many years later, developed a healthy respect for the plant and it for me. Pot helped me kick cigarettes. Whenever I felt the need for a cigaarette I would pull out my 'bat' and have a hit or two. This would relax me and help me feel better, yet would leave me with an anxious hopped up feeling. I decided I needed to do something to get rid of this excess energy. I started to run.
Preperation: It's a mental game.  I would get higher and higher. I would take a few more hits. 'You have to do something you can't just sit around here getting high all day hiding out' I would say to my self. The weed would make me very introspective. I would make myself start to strech out in preperation for the run, not really knowing what I was doing aping the movements of people I had seen in the park. Feeling my body and my muscles starting to scream at me in pain. Back it off just a little bit just a little pain concentrating on the streching feeling in the back of my legs the way my gut curled up along my chest when I bent over the feeling of my back streching out starting to breathe deeper 'making friends with my body' I would call it.
The weed slowed me down enough where I could concentrate on the minor feelings of my own body being self aware. Take a couple more tokes. Put on an old pair of shorts and some good running shoes. Wow, I'm almost out the door. Time to go. At first I would go a half a mile or so the euphoria would be mild but the satisfaction was intense. I was out doing something and after jogging I din't want to smoke a cigarette for at least a little while. Fuck, I could barely breathe. For years I progressed like this.
Now it's a perfect science and the perfect buzz. I stay sober all day no substances. Water and normal meals only. Three hours before a run I stop drinking and eating. A half an hour before a run I take 25mg of ephedra mixed with 50mg of caffeine. I stretch for ten minutes. As I'm stretching I take hits off a small pipe smoking a medium sized bowl of mid-grade bud. A mixed tape plays in my ears of some up-tempo dance music. I start to get chills as my body readys for the rush. When the bowl's finished I'm off.
Concentrating on the form of the run the swing of the arms. The movement of the torso the pumping of the legs the landing of the feet. Practicing production of power from different parts of the body the legs, the stomach, the butt, my arms, my back, working together appreciating the syncronicity of the body. Picking up the pace being aware of the resperation, the production of the energy and the sweat running to the beat of my favorite ministry song, truly burning inside.
The euphoria now kicks in around the three mile mark. It used to happen earlier. Some times it is painful. My diaphram cramps, my legs ache. This is my pain it was given to me to work with to cherish to empathize with. If I'm not careful I ocassonally get an over-use injury. One time scraping away the material under my kneecap from to much running. Wating for it to grow back caused me some depression. I've learned to be friends with my body through this wierd ritual.
I feel the weed allows me to enjoy the enviorment while I'm running and to be aware of my body in a way that is not possible when I'm sober. I feel it allows me to be more introspective and less judgemental to figure out problems, slows me down mentally. Opening those mental filters slowing my reaction to outside stimuli, keeping me from making rash judgments.
After a while the running carried over into other aspects of my life making it easier for me to deal with situations whrere my heart rate would be elevated. Helping me deal with and process mental and physical pain. I feel much more confident when I am physicaly fit. Oddly, I feel the herb has help me become more physically fit. For personal reasons I've been forced to stop my cannabis intake as of late. I miss the relaxation and introspection very much and am looking forward to being able to continue with this 'ritual'. Exercise without weed is very bland now, an exercise in getting it over with. A means to an end. Weed helps make it an end in it self.
In Addition, I have found that diffuculty quitting smoking weed at various times in my life is directly related to quality of life.  I find it much easier to stop if I am content with my current life condition. If I am not happy with my life (people, surroundings, job Etc.) it is exponentionally more diffcult. I pray for a day when Americans are able to legally make there own decisions about what is right for there own bodies and minds.
Experience Reports are the writings and opinions of the individual authors who submit them.
Some of the activities described are dangerous and/or illegal and none are recommended by Erowid.


Unit testing in Legacy Projects: VB6
Even older 4GL languages have unit testing capabilities
27 December 2016 | 5 December 2018
unit testing VB6Thanks to the Postmodern VB6 article I’ve found on the internetz, I decided to give SimplyVBUnit a try. My job requires sporadic visual basic 6 code changes in the big legacy project we’re converting to C#. It’s an administrative system bound to Belgium laws so as you can imagine they change every few months and the old software still has to be complaint to those crazy new rules. As a result, we sometimes dabble in VB6 code. It feels more like drowning, really.
Unit testing is what keeps me from rage-quitting on every project. The SimplyVBUnit syntax is quite nice if you’re used to writing NUnit tests: they also work with Assert.That
for instance:
Public Sub MyTestMethod_WithSomeArg_ShouldReturn45
Dim isType As Boolean
isType = MyTestMethod(arg1)
Assert.That isType, Iz.EqualTo(45)
End Sub
The test code is very readable thanks to the NUnit influence on SimplyVBUnit. The package is very easy to install, but there are a few gotcha’s. You need to create a separate VBP file (Visual Basic Project) which acts as your UnitTest project with a reference to the SimplyVBUnit package. That’s easy enough, but it’s a project. That means it can’t reference other projects! Our software is basically one large project with heaps of muddy code. Compiling the EXE and referencing that one is not an option for us. That leaves us with a few alternatives:
- Package the test runner and the dependency in your production code. (Hmmm…)
- Create a DLL project and move the test code to the DLL. This requires another build step in our already-too-long-manual-deployment procedure. Nope.
- Create a group (vbg), include both projects, and include modules/forms/class modules to be tested in the unit test project as an existing file. This means both projects will include the same source files. SourceSafe actually notices this if you have a file checked out and will ask you to update the “other” file in the second project.
The group makes it possible to open everything at once. Unit tests live in a subfolder. This is our vbg file:
VBGROUP 5.0
Project=program.vbp
StartupProject=UnitTests\UnitTests.vbp
Utilizing two projects in one group means switching between both as a startup project. One could use the group to develop and start tests but the vbps for debugging or so. It’s all still fairly new for us so we’ll see where this will end. Unit tests are useless if they aren’t run (automatically). At this moment we try to avoid coding anything in VB6 at all. If we do, we run the tests manually. At least some parts of the code are tested without bootstrapping the whole application and plowing through various forms to get to the part where you actually changed something…


--- title: Contact slug: contact ---
Email:
qqi @hainanu.edu.cn,
or qiqi789 @ gmail.com
My department address:
Computer Science department
Hainan University
Renmin avenue #58
Haikou, Hainan, 570228
China


HTML, CSS & DOM - Part Two
- What is grid based design?
- Whats all the hype about responsive webpages?
- What is semantic structure?
- Any other points you found interesting and want to reflect on.
Grid based design is used to place boxes (or other shapes) within a webpage. You can define the width of the webpage itself and fill the page with content of differing sizes. For example, if you defined the page as being 12 columns wide there could be 4 x 3 column wide boxes or a single 1 x 12 box. There is lots of room to customise here. A grid based approach will help content stay in a particular alignment when the webpage is responsive in nature. The grid isn't static and if you define 12 columns regardless of the page width, 12 columns will appear either side by side or stacked one above another. If we weren't using grid based design principles, it would be a mission plotting out a static area using x and y axis to create content. Furthermore, if the page shrinks you'd lose the content from the current view.
Responsive webpages are very important as a myriad of devices are in existance. We don't have one set aspect ratio and screen resolution anymore. Tablets, cell phones, laptops and ultra wide monitors to name a few. When creating webpages we need to be cautious that our content is visible on mobile and desktop devices. When building my blog from the start, I've been using percentages in order to achieve a responsive web page. This way, if the window is resized, my content within will still be 60% or 20% of the page, and shrink along with the browser window. To take this further, I look forward to integrating a hamburger navbar menu - as the number of blog posts grow my navbar will start to struggle on a mobile device. It worked as of HTML, CSS & DOM Part One - but it'll be interesting to see how many blogs it can take before not looking nice on mobile.
I understand semantic structure as being the correct layout (organisation) for a website. This can be as simple as having the correct order of elements (head, body, etc). Semantic structure also goes deeper. If you're using a stylesheet, you wouldn't expect to see font coloring defined using HTML and font face (or style) set using CSS. In addition, ID's, classes and other attributes should have names that make sense. The top navbar wouldn't be called 'footer' or 'content'. Usually, it would have the name navbar or navigation. Comments can be really helpful in defining structure and personally I use div container a lot as this makes it easy to find where the actual content begins.
I found my paragraph tags failed verification. Generally, you wouldn't have paragraph tags inside a list item element. However, further research shows while it's not semantic (or perfect), the functionality of the page isn't impacted at all. I'll have to clarify with a tutor to see what other options are available. I tried using span tags, but those also didn't pass. I did further research but couldn't find a conclusive answer. Maybe there isn't one.


--- layout: post title: Fun with AngularJS Filters - Paleo Edition! date: 2013-06-18 17:52:42.000000000 -07:00 type: post published: true status: publish categories: - AngularJS - JavaScript tags: [] meta: _edit_last: '1' image: '' _layout: layout-default _thumbnail_id: '738' _thesis_post_image: a:1:{s:5:"image";a:4:{s:3:"url";s:0:"";s:6:"height";s:0:"";s:5:"width";s:0:"";s:2:"id";s:0:"";}} _thesis_post_thumbnail: a:1:{s:5:"image";a:4:{s:3:"url";s:0:"";s:6:"height";s:0:"";s:5:"width";s:0:"";s:2:"id";s:0:"";}} _nina_cross_promo: a:1:{s:8:"template";s:17:"custom_1399328552";} author: login: ohmadmin email<EMAIL_ADDRESS>display_name: Lukas Ruebbelke first_name: Lukas last_name: Ruebbelke ---
My friend Anthony posted a question the other day about how to bind two select inputs together. Using that as a starting point, I dug into a few fun things that you can do with AngularJS filters and supporting cast.
Paleo edition shout out to my bro Ben Nadel who happens to be one of my favorite bloggers. Check him out here http://www.bennadel.com/
[youtube width="854" height="480"]http://www.youtube.com/watch?v=XYYi2x19ZTg[/youtube]
Code can be downloaded here https://github.com/simpulton/angularjs-filters-paleo
I hope you like it and thanks for the great question Anthony!


For my final Advanced Audio-Visual Coursework Project, I chose to take what is typically thought of as an introductory audio processing concept and transform it into an in-depth, interactive audio-visualization tool illustrating frequency modulation (FM) and amplitude modulation (AM).
On the left half of the screen, you will see the FM modulation demonstration. The size of the modulating solid circle is controlled by the current output frequency, and the sizes of the outlined circles illustrate the frequencies of the carrier wave and the modulating wave. By manipulating the carrier frequency, modulation frequency, and modulation index, the user can visualize how each of these parameters directly affect the output sound.
On the right, the AM modulation demonstration allows the user to manipulate the carrier wave and modulating wave frequency, as well as a final amplitude multiplier to demonstrate the pulsing effects of basic AM. In this case, the amplitude now controls the size of the circles.
I have also implemented a saw-tooth, square, and triangle wave option for both modulation demos, which can be selected by holding down different keys listed on the screen and provide some interesting visual and audio results.
I hope that students and teachers alike will use this tool in the future to gain a deeper understanding of FM and AM modulation through this nuanced audiovisual representation.


% include /partials/head %>
<% include /partials/nav %>This sample app is meant as a starting point and example for your NodeJS QuickBooks Online integrations.
Choose an operation below to continue
| This operation will create an invoice for an item and a customer | |
| This operation will create an item | |
| This operation will create a customer | |
| This operation will create a Sales Receipt for an item and a customer | |
| This operation will run an Inventory Report |


https://mg.docs.wso2.com/en/latest/getting-started/quick-start-guide/quick-start-guide-docker/
Reporting Issues
We encourage you to report issues, documentation faults, and feature requests regarding WSO2 API Microgateway through the Github Issues.
Contributing Code
Read through project Contribution Guidelines to learn how to contribute with code.
Mailing Lists
Join our mailing list and receive updates on product development. Developer List<EMAIL_ADDRESS>--WSO2 API Manager Team--


{% extends 'base.html' %} {% block title %}VisARTM | Segmentation assessment problem {% endblock %} {% block content %}
Problem: {{problem}}
| Assessor | Tasks done | Tasks skipped | Current tasks | Segments selected | Words selected | Watch segments |
| {{x.user}} | {{x.done_tasks}} | {{x.skipped_tasks}} | {{x.current_tasks}} | {{x.segments_count}} | {{x.words_count}} | html, xls |


How to create Maurer Rose graphics with P5.js
In this article, I will show you how to create a Maurer Rose SVG generator using the library p5.js from the Processing foundation. First of all, I want to mention that most of the code I used is strongly inspired by a tutorial of Daniel Shiffman. The library p5.js aims to provide a tool for making coding in the context of "visual art" more accessible for artists, designers and everybody else interested in this topic.
The Maurer Rose algorithm was first published in 1987 by Peter M. Maurer and allows to create beautiful geometric roses by coding. The playground is the polar coordinate system where the following formula is applied: r = sin(nθ). In this example, n is a positive integer. If n is odd, the rose is going to have n petals, and 2n if n is even. The rose itself consists of walking along a n or 2n leafed rose in 360 steps of a fixed number d (degrees) including all cosets. More information can be found on Wikipedia or in the published paper of Peter M. Maurer.
The code example in p5.js has two main functions, the setup() and the draw() function. The setup() function is called once when the page is initialized. Environment parameters such screen size, fonts or background colors are declared here. The following block is showing the configuration used by the Maurer Rose generator. First, a canvas is created and two sliders are defined. Using the sliders the user can interact and create different parameter combinations at a later stage that allow for the creation of beautiful Maurer roses.
Called directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called.
As shown in the code snipped below, the first two lines in the draw() function set the background color to black and the stroke color to the defines RGB colors (see code of maurer_rose_full.js at the end of the article), followed by the assignment of the slider values to the variables n and d. On the next line, some stroke properties are set as noFill() and strokeWeight(). Finally, we get to the core part of the draw() function. This consists of a for - loop which iterates over 360 points and connects them depending on the parameters n and d. The vertex() function is used to move the drown shape to the center of the canvas. At this point, the shape is closed by endShape() and the parameters n and d are displayed in the canvas. But the maurer rose is not completed yet. The structure is finalized but the petals of the rose are not present yet. In order to achieve this, we have to repeat the loop using a slightly adapted algorithm. For this purpose, we change the color to blue and the value k is now calculated without the parameter d (d is set to 1).
The second part of the of the Maurer Rose SVG generator deals with the generation of a SVG graphic from the displayed maurer rose for downloading it. Thus, a new function doubleClicked() is created. This function can be executed by a double click on the canvas. This method generates the exact same maurer rose as displayed and saves it to an SVG graphic with the parameters n and d as part of the file name.
I hope you enjoyed this article and are ready for some fun. Check out the Demo.


Flex
Overflow
Interview Questions
Forum
About
Project
Logout
Generate a new question to test your knowledge!
Generate new question
Question
Show Answer!
Answer
Example


COUNTRIES |
Afghanistan, Albania, Algeria, American Samoa, Andorra, Angola, Antigua and Barbuda, Argentina, Armenia, Aruba, Australia, Austria, Azerbaijan, Bahamas, Bahrain, Bangladesh, Barbados, Belarus, Belgium, Belize, Benin, Bermuda, Bhutan, Bolivia, Bosnia and Herzegovina, Botswana, Brazil, Brunei Darussalam, Bulgaria, Burkina Faso, Burundi, Cambodia, Cameroon, Canada, Cape Verde,, Cayman Islands, Central African Republic, Chad, Chile, Chinese Taipei Colombia, Comoros, Congo, Cook Islands, Costa Rica, Côte d'Ivoire,, Croatia, Cuba, Cyprus, Czech Republic, Democratic People's Republic of Korea, Democratic Republic of the Congo, Denmark, Djibouti, Dominican Republic, Dominique, Ecuador, Egypt, El Salvador, Equatorial Guinea, Eritrea, Estonia, Eswatini, Ethiopia, Federated States of Micronesia, Fiji, Finland, France, Gabon, Gambia, Georgia, Germany, Ghana, Great Britain, Greece, Grenada, Guam, Guatemala, Guinea, Guinea-,Bissau Guyana, Haiti, Honduras, Hong Kong, China, Hungary, Iceland,, India, Indonesia, Iraq, Ireland, Islamic Republic of Iran, Israel, Italy, Jamaica, Japan, Jordan, Kazakhstan, Kenya, Kiribati, Kosovo, Kuwait, Kyrgyzstan, Lao People's Democratic Republic, Latvia, Lebanon, Lesotho, Liberia, Libya, Liechtenstein, Lithuania, Luxembourg, Madagascar, Malawi, Malaysia, Maldives, Mali, Malta, Marshall Islands, Mauritania, Mauritius, Mexico, Monaco, Mongolia, Montenegro, Morocco, Mozambique, Myanmar, Namibia, Nauru, Nepal, Netherlands, New Zealand, Nicaragua, Niger, Nigeria, Norway, Oman, Pakistan, Palau, Palestine, Panama, Papua New Guinea, Paraguay, People's Republic of China, Peru, Philippines, Poland, Portugal, Puerto Rico, Qatar, Republic of Korea, Republic of Moldova, Romania, Russian Federation, Rwanda, Saint Kitts and Nevis, Saint Lucia, Samoa (until 1996 Western Samoa), San Marino, Sao Tome and Principe, Saudi Arabia, Senegal, Serbia, Seychelles, Sierra Leone, Singapore, Slovakia, Slovenia, Solomon Islands, Somalia, South Africa, South Sudan, Spain, Sri Lanka, St Vincent and the Grenadines, Sudan, Suriname, Sweden, Switzerland, Syrian Arab Republic, Tajikistan, Thailand, The Former Yugoslav Republic of Macedonia, Timor-Leste, Togo, Tonga, Trinidad and Tobago, Tunisia, Turkey, Turkmenistan, Tuvalu, Uganda, Ukraine, United Arab Emirates, United Republic of Tanzania, United States of America, Uruguay, Uzbekistan, Vanuatu, Venezuela, Vietnam, Virgin Islands, British, Virgin Islands, US, Yemen, Zambia, Zimbabwe .


Home
High
Medium
Low
Completed
Inbox
Team Killin' It
Team Members: Alex Okeson, Paige Johnson, Bader Alshemaimri, Zhongzhi Zhang, Andrew Krodinger, and Kieran Czerwinski
Tasks


Software Analysis is a way of checking how good your software application is, in terms of how well it performs the tasks it’s supposed to perform; how robust it is and how fast it does those tasks.
Software Analysis is done by extracting the models of software systems and these models are simulated. This can provide insight into some specific software systems and provide data to create general insights. An example of this may improving a web searching application by analysing the algorithm that it uses and possibly changing it to a better one. There are research being done to create software that can automate the process of software analysis.
There are two types of software analysis:
• Instrumentation
It involves placing markers in the code to monitor the level of the code’s performance. This is done by using instructions to log activity of specific parts of the system. This is useful to analyse areas with potential problems while leaving the checked areas. It does have limitations, it can only be used if the code that is to be checked is actually executed. If the program never reaches that point, then instrumentation at that point will not collect any data. Some types of instrumentation can cause the execution time to increase.
• Code Sampling
This is done by inspecting the execution of code at fixed intervals. This is less accurate then Instrumentation but gives a wider coverage of the code. Since the method is less accurate, there is more of a chance for errors to be missed.
There are various types of software analysis tools. They are Code Coverage; Instruction Trace; Memory analysis and Performance analysis.
• Code coverage measures how much code has been executed
• Instruction trace creates a log of exactly what happens as the code runs.
• Memory analysis looks at the memory usage of the code and finds errors.
• Performance analysis finds performance bottle necks to improve execution speed.
This is similar to a method of testing software called debugging. Debugging is used to find a known problem in the code.
It also involves tracing the code execution and monitoring the variables.
The main difference between software analysis and debugging is that software analysis can be carried out while the program is running and not have to pause.
This is especially important if the software is an embedded one where the system cannot always be halted.
The advantages of using software analysis are: accelerating the development of software, improving the software quality and creating software that gives maximum performance.
By analysing software, developers can write software in a shorter time. More efficient software can be created, which is heavily used in real time systems that require it.
There is currently research being carried out in the Centre for Research and Testing (CREST) into new methods of software analysis.
One method they found is genetic improvement. It involves treating the source code of a program as genetic material.
This means that small edits are made to the source code and then algorithms are used to find versions of the code that are improved from the original.
This allows programs to be upgraded without losing core functionality. An example of this is Java byte code produced from existing human written programs being improved using genetic improvement.
Genetic improvement can be used to target areas of mobile apps which can be improved such as energy and bandwidth usage.
It can also create multiple versions of a program that are tailored to a particular use. Which can make producing bespoke software much easier.


Faraday Future Reveals Lavishly High-Tech FF 91 Interior
It has 11 screens.
by Anthony AlanizThe Faraday Future FF 91 debuted nearly three years ago to a ton of fanfare – and a bit of embarrassment. The FF 91 has yet to enter production with a ton of drama happening behind the scenes. But Faraday Future isn’t throwing in the towel yet. The company released new images of the interior, calling it the “third internet living space,” along with a host of new details should the EV ever enter production.
Large screens dominate the dashboard with a tablet-like infotainment display in the center and another screen in the dash for the passenger. Another screen sits high on the dash in front of the steering wheel, integrating the instrument cluster information. Faraday also integrates screens into the doors that house the controls for seat setting, climate control, individual sound zones, and more.
The EV Scene Has Changed Since 2017:
The rear treats passengers to even more luxury with the zero-gravity seats. Faraday claims they offer “industry-leading” 60-degree rear-seat reclining angles. The massaging heated and cooled seats also offer lower leg, lumbar, and upper back adjustments. Each seat is 14-way adjustable with 4-way lumbar support. There’s also a “Spa Mode” that can change the lighting and audio.
Faraday can’t have its “third internet living space” without the internet, so Faraday is packing three modems into the vehicle. One is dedicated to vehicle diagnostics and over-the-air updates while the other two focus on handling data for in-vehicle connectivity and entertainment, including streaming video while on the go. There’s a 27-inch ultra-wide screen that flips down from the roof, too.
Gallery: Faraday Future FF 91 Interior
Faraday is also integrating FFAI, an artificial intelligence that uses the car’s sensors, cameras, and software – more than three years in development – to create a custom user experience. The system can use facial recognition, voice recognition, and the person’s weight to tailor individual seat settings, including setting the right temperature and sound volume level.
Faraday boasts that there are at least 11 different screens inside the FF 91, which seems like a lot. But automakers are quickly abandoning knobs, buttons, and switches, for the versatility of a screen. If the FF 91 enters production, it could change the way automakers think of interiors going forward. But that’s a big if. It certainly looks ready for production.
Source: Faraday Future
Show press release
Faraday Future Reveals Its New Concept of the Third Internet Living Space
LOS ANGELES, Nov. 19, 2019 -- Faraday Future (FF), a California-based global shared intelligent mobility ecosystem company, today revealed additional details on its FF 91 ultra-luxury vehicle, including the concept of third internet living space that integrated many of AI, internet, luxury and comfort functions as well as the new features of its high-tech interior, as a part of Automobility LA at the Los Angeles Auto Show. Built upon the company’s Variable Platform Architecture (VPA), FF 91 represents a bold new species of electric mobility that combines supercar performance, precise handling, the comfort of an ultra-luxury passenger vehicle, and a unique collection of intelligent internet features.
The Smart phone was introduced first back in 2007 and changed everyone’s digital life on the go. The Smart TV was introduced first in 2013 and changed the way we access digital contents at home. Faraday Future’s mission is to change the concept of digital life when we are in our vehicles.
FF 91 introduces the “third internet living space,” the conduit between one’s home and destination (office, school etc.).
“We are now living an increasingly busy lifestyle, and we demand to be continuously connected anytime and anywhere. As we typically travel between home and our destinations every day, the car provides a safe and comfortable means of transportation, however, the time in transit is often considered “down” time. FF is here to change that,” said Carsten Breitfeld, CEO of Faraday Future. “Our goal is to make your daily commute the highlight of your day through a rich digital experience and give you back more time in your day.”
DESIGN WITHOUT BOUNDARIES, FIRST CLASS COMFORT
Riding in FF 91, users will feel more rested and energized, even after being stuck in traffic for hours. The rear seats deliver industry-leading 60-degree rear-seat reclining angles, putting passengers in the biomechanically and ergonomically optimal position for comfort. This first-class rear seating experience provides lower leg, lumbar, and upper back adjustments and support. The seats also offer massage, heating, and ventilation for cooling.
Like a private jet on 22-inch wheels, FF 91 is designed to ensconce its passengers in a relaxing, lounge-like experience, from departure to destination. Every element of the interior contributes its small part to creating an experience rather than simply another ultra-luxury means of transporting passengers down the road.
Zero-Gravity Seats
In the back of FF 91 are two Zero-Gravity Seats, taking principles learned from NASA’s space experiments and co-opting to create Neutral Body Posture, optimally distributing the user’s body weight to provide a more relaxing, rejuvenating experience. The rear chairs are each 14-way adjustable in addition to having 4-way adjustable lumbar support.
Further, they can recline up to 60◦, the greatest recline of any production vehicle, with full lower leg, back and lumbar adjustment.
Complementing the experience is FF 91’s “Spa Mode,” which, in addition to heated and ventilated chairs, adjusts ambient mood lighting and limo lighting, as well as visual and audio effects, helping soothe the soul. Rear chairs also feature integrated cushion massaging.
Connectivity
When you want to keep abreast of the outside world, FF 91 is able to provide a full suite of office-level connectivity, including rear monitors with conference-calling ability, multiple 4G LTE modems allowing for primary and backup connectivity, integrated Alexa, Sharedrop, facial recognition and front and rear sound zones.
ISZ integrates the personal audio needs of each passenger while managing the sonic harmony of the overall vehicle cabin, with the ability to pair up to four Bluetooth devices to the FFAI infotainment system at one time.
Light speed connection with Multi-Modem Solutions
FF 91 supports three modems, each connected at 4G LTE speeds—one for vehicle diagnostics and over-the-air software updates and two focused on the robustness of FF 91’s in-vehicle connectivity and entertainment. Those modems allow not only internet use while in motion as a hotspot but also seamless connectivity to livestreaming, such as with Sling TV. While many 4G LTE devices could stream video, doing so at highway speeds in terrains with limited cellular reception might diminish video playback quality or download speeds. The system is powered by Qualcomm Snapdragon 820A chips, among the most powerful available for automotive applications. Stacked systems ultimately allow users in all seats access to entertainment and social media platforms.
FFAI: Artificial Intelligence That Anticipates Your Needs
The heart of FF 91’s infotainment technologies is its coalescence of sensors, cameras and proprietary software more than three years in the making that make up FFAI. FFAI is an all-in-one, high-tech solution that anticipates the needs of its users from every seat with the goal to allow users to live and breathe more freely.
Using facial recognition, FFAI is able to tailor individual settings in each of FF 91’s seats—right down to temperature and volume levels.
Upon entering FF 91, the experience is tailored, adapting to the user’s mood with adjustments in temperature, music and even scent.
Inside, each user enjoys a personalized experience, every time. Every seat has individual interior cameras, speakers, microphones, and other sensors, recognizing users by their faces, voice and weight, customizing the experience based on his or her unique FFID.
Seamless Entry System
FF 91 is equipped with Seamless Entry System, which provides an effortless experience when entering. Using low-energy Bluetooth frequencies from the user’s smartphone, Seamless Entry “awakens” your vehicle before getting inside, tailoring settings to the user’s preferences, including seats, mirrors, temperature, music and digital screens.
The goal with Seamless Entry is to be able to transition from your home to your phone and then to your car without interruption.
FFID
FFID ensures a consistent experience across the FF Ecosystem, recognizing the user’s profile no matter where he or she is or which FF 91 he or she is driving. Its Map IQ function tailors itself to the user’s driving patterns, tailoring navigation routes quicker and more consistently.
Climate IQ not only tailors itself to the user, but it also accounts for different factors, such as changing seasons and different geographies.
Ultimate Luxury, Ultimate Serenity
FF 91 boasts as many as 11 screens throughout its interior. Upon entering FF 91’s coach doors, users are treated to luxury that delights and an experience that anticipates needs. Not only are the doors beautiful in form and function; they are equipped with sensors that prevent opening too widely in crowded parking lots and offer easy access for convenient passenger pickup.
FF 91’s Rear Cinema Experience complements its serenity, with an ultra-wide 27-inch screen that descends from its roof, displaying an HD picture comparable with a high-end living room experience.
Speaking of monitors, FF 91 features a Central Hub Display up front, with a 15.4-inch center display, Predictive Home Screen that tailors itself to destinations in your navigation and frequented apps and offers recommendations for music and media based on preferences.
The user driving FF 91 is treated to the largest heads-up display in the industry that projects as if it were 2.7 meters in front of the driver to help keep the driver’s eyes on the road.
Below the heads-up display is the instrument panel, which stretches 11.6 inches, wrapping around the driver’s periphery, providing a synchronized experience with the heads-up display. The rearview display is a 10.1-inch digital screen, combining an array of rear and side cameras to paint a fuller picture of the road for optimal vision.
Finally, each door also features screens that replace traditional switches to configure seat settings, climate control, individual sound zones, entertainment and other interaction points with FF 91.
NEXT-GENERATION CONNECTIVITY, SEAMLESS PERSONALIZATION
Similarly, interior cameras recognize users and automatically adjust interior settings to their preferences. FF 91 recognizes faces, facial expressions and moods, which it uses to auto-prompt an experience to match, using music, temperature, scent, content, massage and more. Users’ facial recognition data is saved natively and securely in the vehicle.
In addition to adjusting interior preferences via facial recognition or mobile device connectivity, FF 91 is the first car where you don’t need a key. The keyless welcoming system recognizes users as they approach the vehicle, greets users by opening the door and proactively adjusts the interior to customized FFID settings.
THE NEW PERFORMANCE
FF’s proprietary VPA is a flexible powertrain system featuring a monocoque vehicle structure in which the chassis and body are a single form – providing measurable improvements in overall vehicle rigidity, safety and handling. An available all-wheel drive system offers greater traction, control and precise power distribution. The VPA also houses class-leading battery technology, multiple motor and battery configurations, as well as the company’s first of many patents: the FF Echelon Inverter.
FF 91’s powertrain features a multi-motor setup, enabling real-time torque vectoring to the rear wheels. This technology delivers superior acceleration and safety while leveraging rear-wheel steering for agile cornering, allowing drivers to confidently execute maneuvers like merging onto freeways or accelerating out of dangerous scenarios.
Peak motor power is 783 kW, equating up to 1050 HP, delivering a record-breaking 0-60 mph time in less than 3 seconds.
FF 91’s battery technology doesn’t sacrifice range for performance. Outfitted with a 130 kWh battery, FF 91 achieves a range of 378 miles (EPA est.) and over 700 km (NEDC est.) from the world’s highest energy density battery. Similarly, the system’s compact design enables more cabin space for greater comfort and safety. FF 91 also has the fastest charge speed currently available, with the ability to charge at more than 500 miles per hour. The home charger, included with the vehicle, achieves a 50 percent to full charge in under 4.5 hours at 240V.
“Everything about our cutting-edge vehicle and technology was created to make the lives of our users more connected, more engaging and more effortless.


|
#%in1%#
|
Account Created
#%hide_confirmation_begin%#Now please check your email for a confirmation email. You will need to go to the link in the email to confirm your membership. Unconfirmed accounts are automatically deleted after #%days%# days.#%hide_confirmation_end%#
#%hide_continue_begin%#Now please login here.#%hide_continue_end%#
|
|
|


Cheatsheets are great for refreshing your memory and finding new functions and plots to use.
Help > Cheatsheets >
ggplot
’ing options.From your browser
From within R
Books
Searching online
r
or rstats
+ the question
[r]
tagInside R
?arrange()
or help(dplyr)
Email us!
These are a few of the things we personally forget to do all the time and cause 90% of our errors. They’re good first checks if R starts throwing errors or behaving strangely.
(
has a corresponding closing )
.\
backward slashes like Windows, check that they didn’t sneak into your expression somewhere. When in doubt use the /
forward slash.If you think you have completed typing your code, and instead of seeing the >
command prompt at the console you see the +
character instead. That’s a good sign that either R is still thinking very-very hard, or it is still waiting for you to complete your expression. You can hit Esc
or Ctrl-C
to force your way back to the console and try typing your code again.
R is very picking about spelling. So are meteorologists when talking about lighting storms.
ggplot
we build up plots one piece at a time by adding expressions to one another with the +
character. When doing this, make sure the +
goes at the end of each line, and not the beginning.Put the +
sign here to make ggplot
happy:
ggplot(data = mpg, aes(x = displ, y = hwy)) +
geom_point()
Put it on the next line to make ggplot
sad:
ggplot(data = mpg, aes(x = displ, y = hwy))
+ geom_point()
Not all error messages are helpful or easy to interpret, but they do seem to be getting better in many R packages. When googling an error message it can help to put the entire message in quotes. For the error below we would search for "Error in fit[5, 100, ] : subscript out of bounds"
.


We’ve worked on many great projects, focused on enriching our clients lives and experiences. Take a look at our growing portfolio and list of accomplishments.
HEALTHCARE
DETROIT MEDICAL CENTER CHILDREN’S HOSPITAL
Autism Center
DESIGN BUILD
NOVI, MI
DETROIT MEDICAL CENTER
Receiving Hospital
Pre and Post Operating & Emergency Room
RENOVATION
DETROIT, MI
HENRY FORD HEALTH SYSTEMS
Operating Room Expansion, Doctors’ Suites, and Phase 3 Prep Recovery
RENOVATION
DETROIT, MI
DETROIT MEDICAL CENTER CHILDREN’S HOSPITAL
Sleep Suite 5V
RENOVATION
NOVI, MI
DETROIT MEDICAL CENTER
Sinai Grace Hospital Retail Pharmacy
RENOVATION
DETROIT, MI
VETERAN’S HOSPITAL
Dental Suites and Wind Turbine
RENOVATION
ANN ARBOR, MI
DETROIT MEDICAL CENTER
Harper Hospital Retail Pharmacy
DESIGN BUILD
DETROIT, MI
DETROIT MEDICAL CENTER
Sinai Grace Hospital POB Pharmacy
RENOVATION
DETROIT, MI
HOSPITALITY
DETROIT MEDICAL CENTER CHILDREN’S HOSPITAL
Autism Center
DESIGN BUILD
NOVI, MI
DETROIT MEDICAL CENTER
Receiving Hospital
Pre and Post Operating & Emergency Room
RENOVATION
DETROIT, MI
HENRY FORD HEALTH SYSTEMS
Operating Room Expansion, Doctors’ Suites, and Phase 3 Prep Recovery
RENOVATION
DETROIT, MI
DETROIT MEDICAL CENTER CHILDREN’S HOSPITAL
Sleep Suite 5V
RENOVATION
NOVI, MI
DETROIT MEDICAL CENTER
Sinai Grace Hospital Retail Pharmacy
RENOVATION
DETROIT, MI
VETERAN’S HOSPITAL
Dental Suites and Wind Turbine
RENOVATION
ANN ARBOR, MI
DETROIT MEDICAL CENTER
Harper Hospital Retail Pharmacy
DESIGN BUILD
DETROIT, MI
DETROIT MEDICAL CENTER
Sinai Grace Hospital POB Pharmacy
RENOVATION
DETROIT, MI
COMMERCIAL
DETROIT MEDICAL CENTER CHILDREN’S HOSPITAL
Autism Center
DESIGN BUILD
NOVI, MI
DETROIT MEDICAL CENTER
Receiving Hospital
Pre and Post Operating & Emergency Room
RENOVATION
DETROIT, MI
HENRY FORD HEALTH SYSTEMS
Operating Room Expansion, Doctors’ Suites, and Phase 3 Prep Recovery
RENOVATION
DETROIT, MI
DETROIT MEDICAL CENTER CHILDREN’S HOSPITAL
Sleep Suite 5V
RENOVATION
NOVI, MI
DETROIT MEDICAL CENTER
Sinai Grace Hospital Retail Pharmacy
RENOVATION
DETROIT, MI
VETERAN’S HOSPITAL
Dental Suites and Wind Turbine
RENOVATION
ANN ARBOR, MI
DETROIT MEDICAL CENTER
Harper Hospital Retail Pharmacy
DESIGN BUILD
DETROIT, MI
DETROIT MEDICAL CENTER
Sinai Grace Hospital POB Pharmacy
RENOVATION
DETROIT, MI
OTHER
DETROIT MEDICAL CENTER CHILDREN’S HOSPITAL
Autism Center
DESIGN BUILD
NOVI, MI
DETROIT MEDICAL CENTER
Receiving Hospital
Pre and Post Operating & Emergency Room
RENOVATION
DETROIT, MI
HENRY FORD HEALTH SYSTEMS
Operating Room Expansion, Doctors’ Suites, and Phase 3 Prep Recovery


Corinne Bassin, Christine Stawitz
ECS Federal in support of NOAA Fisheries S&T
The NOAA Fisheries Integrated Toolbox (NOAA FIT) is an interdisciplinary, web-based portal of operational tools that can be used for a variety of applications, including stock assessment modeling, forecasting, and data preparation for fish and protected species, as well as economic and ecosystem modeling.
Caveat: we are a team of three people, and the UI is still a work in progress
We seek to be inclusive; tools that are of use in NOAA products are our primary focus. There must be at least one tool owner we can work with to implement version control, etc. We recommend including the latest stable version in the toolbox. Research and development can continue elsewhere on new tool features.
Initial authors of a tool fill out a meta-data form about their tool which includes background informtation that can be made public on the tools landing page.
All code needs to be under version control, locally and on a server. Basic information about version control and best practices for the toolbox are available.
NOAA has specific guidelines that cover the use of GitHub for version control . We can fork from existing Git repos, create Git repos from Vlab, or help you set up git. Only NOAA affiliated personal will be able to directly push to an NOAA GitHub repository but the code is publicly available. Outside collaborators will be able to suggest changes and perform a pull-request to have their changes accepted.
After these steps have been completed, the toolbox team will review your git repository and file issues about specific items that need to be resolved for inclusion in the toolbox.
Link to tool: The tool receives a landing page and link on the toolbox website
Basic support level determined : Depending on the collaborators affiliations and development state of the tool, each tool recieves differing levels of support from the NOAA National Modeling Team.
When tools are all shared and under version control, we can more easily work with individual tool developers to standardize and simplify.
Example: lookup table for stock assessment model names; automate writes to SIS
Standard formats for inputs and outputs make it easier to average model results. Instead of custom code, pulling results from multiple output files with consistent formatting makes it easy to add to ensembles.
Common inputs will also allow us to develop common user interfaces that write model inputs. Standard output files make it easier to visualize output and generate reports.
Example: A standard package for plotting stock assessment output; creating new web-based UI for legacy desktop applications.
Management by FIT reduces the burden on tool developers since we can monitor issues and help support users.
We're also working on support blog and trainings (at NSAW) to teach about git, software best practices, etc.
Software peer review a.la rOpenSci?
Steering committee, or leverage existing committees
The toolbox uses badges to communicate the most up-to-date versions of tools. We can also monitor the Github repositories of tools and encourage splitting into versions during the code review process. (e.g. GMACs)


Favorite
Cocktail Name
Ingredient
Category
Alcohol/Non-Alcohol
Home Page
Welcome to the favorite section.
Manage the list.
List
Id
Name
Image
Remove
Instructions
Ingredients & Measure