예제 #1
0
 /**
  * Returns a String representation of the HyperBoundingBox.
  *
  * @param nf number format for output accuracy
  * @param pre the prefix of each line
  * @return a string representation of this hyper bounding box
  */
 public String toString(String pre, NumberFormat nf) {
   return pre
       + "[Min("
       + FormatUtil.format(min, ",", nf)
       + "), Max("
       + FormatUtil.format(max, ",", nf)
       + ")]";
 }
예제 #2
0
파일: IntParameter.java 프로젝트: fjfd/elki
 @Override
 protected Integer parseValue(Object obj) throws ParameterException {
   if (obj instanceof Integer) {
     return (Integer) obj;
   }
   try {
     final String s = obj.toString();
     return (int) FormatUtil.parseLongBase10(s, 0, s.length());
   } catch (NullPointerException e) {
     throw new WrongParameterValueException(
         "Wrong parameter format! Parameter \""
             + getName()
             + "\" requires an integer value, read: "
             + obj
             + "!\n");
   } catch (NumberFormatException e) {
     throw new WrongParameterValueException(
         "Wrong parameter format! Parameter \""
             + getName()
             + "\" requires an integer value, read: "
             + obj
             + "!\n");
   }
 }
예제 #3
0
 /**
  * Write the resulting clusters to an output stream.
  *
  * @param outStream output stream
  * @param data Generated data
  * @throws IOException thrown on write errors
  */
 public void writeClusters(OutputStreamWriter outStream, MultipleObjectsBundle data)
     throws IOException {
   int modelcol = -1;
   { // Find model column
     for (int i = 0; i < data.metaLength(); i++) {
       if (TypeUtil.MODEL.isAssignableFromType(data.meta(i))) {
         modelcol = i;
         break;
       }
     }
   }
   if (modelcol < 0) {
     throw new AbortException("No model column found in bundle.");
   }
   ArrayList<Model> models = new ArrayList<>();
   Map<Model, TIntList> modelMap = new HashMap<>();
   { // Build a map from model to the actual objects
     for (int i = 0; i < data.dataLength(); i++) {
       Model model = (Model) data.data(i, modelcol);
       TIntList modelids = modelMap.get(model);
       if (modelids == null) {
         models.add(model);
         modelids = new TIntArrayList();
         modelMap.put(model, modelids);
       }
       modelids.add(i);
     }
   }
   // compute global discard values
   int totalsize = 0, totaldisc = 0;
   for (Entry<Model, TIntList> ent : modelMap.entrySet()) {
     totalsize += ent.getValue().size();
     if (ent.getKey() instanceof GeneratorSingleCluster) {
       totaldisc += ((GeneratorSingleCluster) ent.getKey()).getDiscarded();
     }
   }
   double globdens = (double) (totalsize + totaldisc) / totalsize;
   outStream
       .append("########################################################")
       .append(LINE_SEPARATOR);
   outStream.append("## Number of clusters: " + models.size()).append(LINE_SEPARATOR);
   for (Model model : models) {
     TIntList ids = modelMap.get(model);
     outStream
         .append("########################################################")
         .append(LINE_SEPARATOR);
     outStream.append("## Size: " + ids.size()).append(LINE_SEPARATOR);
     if (model instanceof GeneratorSingleCluster) {
       GeneratorSingleCluster cursclus = (GeneratorSingleCluster) model;
       outStream
           .append("########################################################")
           .append(LINE_SEPARATOR);
       outStream.append("## Cluster: ").append(cursclus.getName()).append(LINE_SEPARATOR);
       Vector cmin = cursclus.getClipmin();
       Vector cmax = cursclus.getClipmax();
       if (cmin != null && cmax != null) {
         outStream
             .append("## Clipping: ")
             .append(cmin.toString()) //
             .append(" - ")
             .append(cmax.toString())
             .append(LINE_SEPARATOR);
       }
       outStream
           .append("## Density correction factor: " + cursclus.getDensityCorrection())
           .append(LINE_SEPARATOR);
       outStream.append("## Generators:").append(LINE_SEPARATOR);
       for (int i = 0; i < cursclus.getDim(); i++) {
         Distribution gen = cursclus.getDistribution(i);
         outStream.append("##   ").append(gen.toString()).append(LINE_SEPARATOR);
       }
       if (cursclus.getTransformation() != null
           && cursclus.getTransformation().getTransformation() != null) {
         outStream.append("## Affine transformation matrix:").append(LINE_SEPARATOR);
         outStream
             .append(FormatUtil.format(cursclus.getTransformation().getTransformation(), "## "))
             .append(LINE_SEPARATOR);
       }
       outStream
           .append(
               "## Discards: "
                   + cursclus.getDiscarded()
                   + " Retries left: "
                   + cursclus.getRetries())
           .append(LINE_SEPARATOR);
       double corf = /* cursclus.overweight */
           (double) (cursclus.getSize() + cursclus.getDiscarded()) / cursclus.getSize() / globdens;
       outStream.append("## Density correction factor estimation: " + corf).append(LINE_SEPARATOR);
     }
     outStream
         .append("########################################################")
         .append(LINE_SEPARATOR);
     for (TIntIterator iter = ids.iterator(); iter.hasNext(); ) {
       int num = iter.next();
       for (int c = 0; c < data.metaLength(); c++) {
         if (c != modelcol) {
           if (c > 0) {
             outStream.append(' ');
           }
           outStream.append(data.data(num, c).toString());
         }
       }
       outStream.append(LINE_SEPARATOR);
     }
   }
 }
예제 #4
0
 /**
  * Returns a String representation of the HyperBoundingBox.
  *
  * @return a string representation of this hyper bounding box
  */
 @Override
 public String toString() {
   return "[Min(" + FormatUtil.format(min, ",") + "), Max(" + FormatUtil.format(max, ",") + ")]";
 }