开发者

Efficient Array Normalization of Approximate Values

开发者 https://www.devze.com 2023-01-14 05:55 出处:网络
I\'m looking for the efficient way of replacing approximate values (ushort[100]) for their target values.

I'm looking for the efficient way of replacing approximate values (ushort[100]) for their target values.

There are two target values (ushort x, 2x), each value in the ushort[] approximates one of thes开发者_运维百科e two.


  • make a sorted array with the expected values
  • for every approx, binary search for the closest expected
  • replace


You could always just define a distance metric that allows you to assigns each of the approximate values to the expected values, considering those to be "bins", as in a histogram. Processing the values then means replacing the approximate value with the known value that has the smallest distance to that value.


var a = target1 > words[i] ? target1 - words[i] : words[i] - target1;
var b = target2 > words[i] ? target2 - words[i] : words[i] - target2;
(OR)
var as = target1 - words[i];
var bs = target2 - words[i];
a = as + (as >> 31) ^ (as >> 31);
b = bs + (bs >> 31) ^ (bs >> 31);

if (a < b)
   normalized[i] = target1;
else
   normalized[i] = target2;
0

精彩评论

暂无评论...
验证码 换一张
取 消