MCPcopy Create free account
hub / github.com/audeering/opensmile / svm_group_classes

Function svm_group_classes

scripts/modeltrain/libsvm-small/svm.cpp:2022–2077  ·  view source on GitHub ↗

label: label name, start: begin of each class, count: #data of classes, perm: indices to the original data perm, length l, must be allocated before calling this subroutine

Source from the content-addressed store, hash-verified

2020// label: label name, start: begin of each class, count: #data of classes, perm: indices to the original data
2021// perm, length l, must be allocated before calling this subroutine
2022void svm_group_classes(const svm_problem *prob, int *nr_class_ret, int **label_ret, int **start_ret, int **count_ret, int *perm)
2023{
2024 int l = prob->l;
2025 int max_nr_class = 16;
2026 int nr_class = 0;
2027 int *label = Malloc(int,max_nr_class);
2028 int *count = Malloc(int,max_nr_class);
2029 int *data_label = Malloc(int,l);
2030 int i;
2031
2032 for(i=0;i<l;i++)
2033 {
2034 int this_label = (int)prob->y[i];
2035 int j;
2036 for(j=0;j<nr_class;j++)
2037 {
2038 if(this_label == label[j])
2039 {
2040 ++count[j];
2041 break;
2042 }
2043 }
2044 data_label[i] = j;
2045 if(j == nr_class)
2046 {
2047 if(nr_class == max_nr_class)
2048 {
2049 max_nr_class *= 2;
2050 label = (int *)realloc(label,max_nr_class*sizeof(int));
2051 count = (int *)realloc(count,max_nr_class*sizeof(int));
2052 }
2053 label[nr_class] = this_label;
2054 count[nr_class] = 1;
2055 ++nr_class;
2056 }
2057 }
2058
2059 int *start = Malloc(int,nr_class);
2060 start[0] = 0;
2061 for(i=1;i<nr_class;i++)
2062 start[i] = start[i-1]+count[i-1];
2063 for(i=0;i<l;i++)
2064 {
2065 perm[start[data_label[i]]] = i;
2066 ++start[data_label[i]];
2067 }
2068 start[0] = 0;
2069 for(i=1;i<nr_class;i++)
2070 start[i] = start[i-1]+count[i-1];
2071
2072 *nr_class_ret = nr_class;
2073 *label_ret = label;
2074 *start_ret = start;
2075 *count_ret = count;
2076 free(data_label);
2077}
2078
2079//

Callers 2

svm_trainFunction · 0.70
svm_cross_validationFunction · 0.70

Calls 1

MallocFunction · 0.85

Tested by

no test coverage detected