@param dots dot product between the input and each of the k hyper planes @param owned a count of how many data points are assigned to this hyper plane @param assignments maps each data point to the hyper plane that owns it. May have negative values for points not yet assigned @param assigned_positiv
(Vec dots, int indx, int k_true_max, int[] owned, int[] assignments, int assigned_positive_instances)
| 329 | * @param assigned_positive_instances the number of <bold>positive</bold> instances taht have been assigned to a hyper plane |
| 330 | */ |
| 331 | private int ASSIGN(Vec dots, int indx, int k_true_max, int[] owned, int[] assignments, int assigned_positive_instances) |
| 332 | { |
| 333 | //Done outside this function |
| 334 | // int k_true_max = 0; |
| 335 | // for(int i = 1; i < dots.length(); i++) |
| 336 | // if(dots.get(i) > dots.get(k_true_max)) |
| 337 | // k_true_max = i; |
| 338 | |
| 339 | int old_owner = assignments[indx]; |
| 340 | |
| 341 | double cur_entropy = 0; |
| 342 | double new_entropy = Double.POSITIVE_INFINITY; |
| 343 | int max_owned = 0; |
| 344 | if(assigned_positive_instances > K*10)//we have enough assignments to start estimating entropy |
| 345 | { |
| 346 | new_entropy = 0; |
| 347 | for(int i = 0; i < K; i++) |
| 348 | { |
| 349 | max_owned = Math.max(max_owned, owned[i]);//used later |
| 350 | |
| 351 | // double p_i = owned[i]/(double)assigned_positive_instances; |
| 352 | double numer = owned[i]; |
| 353 | double denom = assigned_positive_instances; |
| 354 | if(numer > 0 ) |
| 355 | // cur_entropy += -p_i * Math.log(p_i)/Math.log(2); |
| 356 | cur_entropy += -numer*(Math.log(numer)-Math.log(denom))/(Math.log(2)*denom); |
| 357 | |
| 358 | //now calculate for new_entropy |
| 359 | if(old_owner < 0)//every point has a differnt value, b/c denominator changes |
| 360 | { |
| 361 | denom++; |
| 362 | if(i == k_true_max)//numer changes here too |
| 363 | numer++; |
| 364 | if(numer > 0 ) |
| 365 | new_entropy += -numer*(Math.log(numer)-Math.log(denom))/(Math.log(2)*denom); |
| 366 | } |
| 367 | else if(old_owner == k_true_max)//no change in ownership, means no change in entropy |
| 368 | { |
| 369 | new_entropy = cur_entropy; |
| 370 | } |
| 371 | else//change in ownership, denom remains the same, numer may change |
| 372 | { |
| 373 | if(i == k_true_max) |
| 374 | numer++; |
| 375 | else if(i == old_owner) |
| 376 | numer--; |
| 377 | |
| 378 | if(numer > 0 ) |
| 379 | new_entropy += -numer*(Math.log(numer)-Math.log(denom))/(Math.log(2)*denom); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | new_entropy += cur_entropy;//new was calcualted as a delta from cur, so by adding we get the correct value |
| 384 | } |
| 385 | |
| 386 | if(new_entropy >= h)//if ENTROPY(UNADJ +(x, kunadj)) ≥ h then |
| 387 | return k_true_max; |
| 388 | //else |