private boolean isValidWeights(Vector weights) {
   for (int i = 0; i < weights.size(); i++) {
     double d = weights.apply(i);
     if (Double.isNaN(d) || Double.isInfinite(d)) {
       return false;
     }
   }
   return true;
 }
 private String vectorToString(Vector weights) {
   StringBuilder sb = new StringBuilder();
   for (int i = 1; i <= weights.size(); i++) {
     double d = weights.apply(i - 1);
     sb.append(d);
     if (i != weights.size()) {
       sb.append(",");
     }
   }
   return sb.toString();
 }