aboutsummaryrefslogtreecommitdiff
path: root/src/gensvm_simplex.c
blob: 1fd5f1458290d92e4c48cf0fed2c29e10e4e7a91 (plain)
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
43
44
45
/**
 * @file gensvm_simplex.c
 * @author Gertjan van den Burg
 * @date May, 2016
 * @brief Function for generating the simplex matrix
 *
 * @details
 * Contains the function for generating the simplex matrix for a given number
 * of classes.
 *
 */

#include "gensvm_simplex.h"

/**
 * @brief Generate matrix of simplex vertex coordinates
 *
 * @details
 * Generate the simplex matrix. Each row of the created
 * matrix contains the coordinate vector of a single
 * vertex of the K-simplex in K-1 dimensions. The simplex
 * generated is a special simplex with edges of length 1.
 * The simplex matrix U must already have been allocated.
 *
 * @param[in] 		K 	number of classes
 * @param[in,out] 	U 	simplex matrix of size K * (K-1)
 */
void gensvm_simplex(long K, double *U)
{
	long i, j;
	for (i=0; i<K; i++) {
		for (j=0; j<K-1; j++) {
			if (i <= j) {
				matrix_set(U, K-1, i, j,
					       	-1.0/sqrt(2.0*(j+1)*(j+2)));
			} else if (i == j+1) {
				matrix_set(U, K-1, i, j,
					       	sqrt((j+1)/(2.0*(j+2))));
			} else {
				matrix_set(U, K-1, i, j, 0.0);
			}
		}
	}
}