MCPcopy Create free account
hub / github.com/antlr/codebuff / weightedL0_Distance

Method weightedL0_Distance

src/org/antlr/codebuff/Tool.java:441–456  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)));

Callers 1

distanceMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected