private static int MedianBit(BinaryVector x) {
   var activeIndices = x.Select((b, i) => new { b, i }).Where(v => v.b).ToList();
   if (activeIndices.Count > 0)
     return activeIndices[activeIndices.Count / 2].i;
   else
     return 0;
 }
 private static double AverageBit(BinaryVector x) {
   return x.Select((b, i) => new { b, i }).Where(v => v.b).Average(v => v.i);
 }