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
(prob *SVM_Problem, nr_class_ret []int, label_ret, start_ret, count_ret [][]int, perm []int)
| 1818 | // perm, length l, must be allocated before calling this subroutine |
| 1819 | |
| 1820 | func (this *SVM) SVM_group_classes(prob *SVM_Problem, nr_class_ret []int, label_ret, start_ret, count_ret [][]int, perm []int) { |
| 1821 | l := prob.l |
| 1822 | max_nr_class := 16 |
| 1823 | nr_class := 0 |
| 1824 | label := make([]int, max_nr_class) |
| 1825 | count := make([]int, max_nr_class) |
| 1826 | data_label := make([]int, l) |
| 1827 | var i int |
| 1828 | |
| 1829 | for i = 0; i < l; i++ { |
| 1830 | this_label := int(prob.y[i]) |
| 1831 | var j int |
| 1832 | for j = 0; j < nr_class; j++ { |
| 1833 | if this_label == label[j] { |
| 1834 | count[j]++ |
| 1835 | break |
| 1836 | } |
| 1837 | } |
| 1838 | data_label[i] = j |
| 1839 | if j == nr_class { |
| 1840 | if nr_class == max_nr_class { |
| 1841 | max_nr_class *= 2 |
| 1842 | new_data := make([]int, max_nr_class) |
| 1843 | //System.arraycopy(label,0,new_data,0,label.length); |
| 1844 | copy(new_data, label) |
| 1845 | label = new_data |
| 1846 | new_data = make([]int, max_nr_class) |
| 1847 | //System.arraycopy(count,0,new_data,0,count.length); |
| 1848 | copy(new_data, count) |
| 1849 | count = new_data |
| 1850 | } |
| 1851 | label[nr_class] = this_label |
| 1852 | count[nr_class] = 1 |
| 1853 | nr_class++ |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | start := make([]int, nr_class) |
| 1858 | start[0] = 0 |
| 1859 | for i = 1; i < nr_class; i++ { |
| 1860 | start[i] = start[i-1] + count[i-1] |
| 1861 | } |
| 1862 | for i = 0; i < l; i++ { |
| 1863 | perm[start[data_label[i]]] = i |
| 1864 | start[data_label[i]]++ |
| 1865 | } |
| 1866 | start[0] = 0 |
| 1867 | for i = 1; i < nr_class; i++ { |
| 1868 | start[i] = start[i-1] + count[i-1] |
| 1869 | } |
| 1870 | |
| 1871 | nr_class_ret[0] = nr_class |
| 1872 | label_ret[0] = label |
| 1873 | start_ret[0] = start |
| 1874 | count_ret[0] = count |
| 1875 | } |
| 1876 | |
| 1877 | func (this *SVM) SVM_train(prob *SVM_Problem, param *SVM_Parameter) *SVM_Model { |
no outgoing calls
no test coverage detected