-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfeature_vector.m
More file actions
42 lines (30 loc) · 854 Bytes
/
feature_vector.m
File metadata and controls
42 lines (30 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function phi=feature_vector(x,y, n_classes, feature_mapping, feature_parameters)
%{
Feature mappings
This function obtains feature vectors
Input
-----
x: new instance
y: new label
n_classes: number of classes
feature_mapping: 'linear' or 'kernel'
feature_parameters:
if feature_mapping == 'linear': feature_parameters = []
if feature_mapping == 'kernel': feature_parameters = [D, u] where
D = number of random Fourier components
u = random Fourier components
Output
------
phi: feature vector
%}
if strcmp(feature_mapping,'linear')
x_phi = [x];
elseif strcmp(feature_mapping,'RFF')
D_kernel = feature_parameters{1};
u = feature_parameters{2};
x_phi = [cos(u'*x); sin(u'*x)];
end
e = zeros(n_classes, 1);
e(y+1) = 1;
phi = kron(e, x_phi);
end