| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void trainC(ClassificationDataSet dataSet, ExecutorService threadPool) |
| 237 | { |
| 238 | final int threads_to_use; |
| 239 | if(threadPool instanceof FakeExecutor) |
| 240 | threads_to_use = 1; |
| 241 | else |
| 242 | threads_to_use = SystemInfo.LogicalCores; |
| 243 | |
| 244 | final int N = dataSet.getSampleSize(); |
| 245 | vecs = dataSet.getDataVectors(); |
| 246 | early_models = new ConcurrentHashMap<Integer, SVMnoBias>(); |
| 247 | // weights = dataSet.getDataWeights(); |
| 248 | // label = new short[N]; |
| 249 | // for(int i = 0; i < N; i++) |
| 250 | // label[i] = (short) (dataSet.getDataPointCategory(i)*2-1); |
| 251 | setCacheMode(CacheMode.NONE);//Initiates the accel cache |
| 252 | //initialize alphas array to all zero |
| 253 | alphas = new double[N];//zero is default value |
| 254 | |
| 255 | /** |
| 256 | * Used to keep track of which sub cluster each training datapoint belongs to |
| 257 | */ |
| 258 | final int[] group = new int[N]; |
| 259 | |
| 260 | /** |
| 261 | * Used to select subsamples of data points for clustering, and to map them back to their original indicies |
| 262 | */ |
| 263 | IntList indicies = new IntList(); |
| 264 | //for l = lmax, . . . , 1 do |
| 265 | for(int l = l_max; l >= l_early; l--) |
| 266 | { |
| 267 | // System.out.println("Level " + l); |
| 268 | early_models.clear(); |
| 269 | //sub-sampled dataset to use for clustering |
| 270 | ClassificationDataSet toCluster = new ClassificationDataSet(dataSet.getNumNumericalVars(), dataSet.getCategories(), dataSet.getPredicting()); |
| 271 | //Set number of clusters in the current level k_l = k^l |
| 272 | int k_l = (int) Math.pow(k, l); |
| 273 | |
| 274 | //number of datapoints to use in clustering |
| 275 | //increase M = m by default. Increase to M=7 m if less than 7 points per cluster |
| 276 | int M; |
| 277 | if( N/k_l < 7 ) |
| 278 | M = k_l*7; |
| 279 | else |
| 280 | M = m; |
| 281 | |
| 282 | if(l == l_max) |
| 283 | { |
| 284 | ListUtils.addRange(indicies, 0, N, 1); |
| 285 | Collections.shuffle(indicies); |
| 286 | for(int i = 0; i < Math.min(M, N); i++) |
| 287 | toCluster.addDataPoint(dataSet.getDataPoint(i), dataSet.getDataPointCategory(i)); |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | indicies.clear(); |
| 292 | for(int i = 0; i < N; i++) |