Scoring the postal code mismatch
I have two postal code (fixed size of 6 digits) to compare and return the mismatch score. where the mismatch weight of initial indexes are higher, then keep reducing.
Example postal code 123456, with index[0] ==> 1 is northern region, and if index[0] ==> 2 is southern region. so it should have very high mismatch score 123456 and 223456. index[1] represents sub-region like state, index[3] is like county/district, and so on..
But may be 111156 and 111160 are nearer sub locality should be having less mismatch score.
Output of my result should match score in percentile.
To achieve this, if i take weights like this Sum[0.45, 0.15, 0.1, 0.1, 0.1, 0.1] == 100% but fixed weights cannot differentiate index base, e.g. for input source postal 111111 than searching with 111152 is greater mismatch than searching with 111125 as if we sum the mismatch scores. 60
Mismatch weights percentile [0.45, 0.15, 0.1, 0.1, 0.1, 0.1] states if there is mismatch happens at index 2, 3, 4, 5 all has penalty of 10%, but this results 111152 and 111125 will have same mismatch score for actual postal code 11111. So we cannot differentiate 111152 and 111125. But you see 111125 is closer to 111111.
This makes me to think of cumulative percentile index percentile like [1, 0.55, 0.4, 0.3, 0.2, 0.1] but this also doesn't work. As sum of mismatch score going more than 1.
Also it is not worthy to rely on the difference of postal code, like 111000 - 110999, though it has difference 1, this difference same for 111000 - 111001. Hence (((double)diff/Math.pow(10, diff.length())) is also not working to compute. So taking diff between two postal code as 123 then 123/1000 * (penalty[diff.length()]) wont work, as we cannot directly rely on difference.
Examples:
If i prefer mismatch penalty like { 0.8d, 0.7d, 0.6d, 0.3d, 0.15d, .05d }
0.05% penalty if the last char is not matched.
0.80% penalty if the first char is not matched.
Apply some minor penalty every mismatch; after the first mismatch.
{"input" , "toBeCompared", "matchScore"}
{"999999", "989999", 0.29}, //71% mismatched, 29% matched
{"999999", "998999", 0.39},
{"999999", "999899", 0.7 },
{"999999", "999989", 0.85},
{"999999", "999998", 0.95}, //95% matched
Also should be able to differentiate scores between varying numbers.
{"111225", "111223", 0.949},
{"111225", "111229", 0.948},
How to achieve this? Kindly help. 60