A distance of 0 should count much more than non-0. Also, penalize mismatches closer to current token than those farther away.
(FeatureMetaData[] featureTypes, int[] A, int[] B)
| 439 | * mismatches closer to current token than those farther away. |
| 440 | */ |
| 441 | public static double weightedL0_Distance(FeatureMetaData[] featureTypes, int[] A, int[] B) { |
| 442 | double count = 0; // count how many mismatched categories there are |
| 443 | for (int i=0; i<A.length; i++) { |
| 444 | FeatureType type = featureTypes[i].type; |
| 445 | if ( type==FeatureType.TOKEN || |
| 446 | type==FeatureType.RULE || |
| 447 | type==FeatureType.INT || |
| 448 | type==FeatureType.BOOL) |
| 449 | { |
| 450 | if ( A[i] != B[i] ) { |
| 451 | count += featureTypes[i].mismatchCost; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | return count; |
| 456 | } |
| 457 | |
| 458 | public static double sigmoid(int x, float center) { |
| 459 | return 1.0 / (1.0 + Math.exp(-0.9*(x-center))); |