Package de.lmu.ifi.dbs.elki.database.ids

Examples of de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs


    StringBuffer msg = new StringBuffer();
    if(logger.isDebugging()) {
      msg.append("interval ").append(interval);
    }

    ModifiableDBIDs childIDs = DBIDUtil.newHashSet(superSetIDs.size());

    Map<DBID, Double> minima = f_minima.get(interval);
    Map<DBID, Double> maxima = f_maxima.get(interval);
    if(minima == null || maxima == null) {
      minima = new HashMap<DBID, Double>();
      f_minima.put(interval, minima);
      maxima = new HashMap<DBID, Double>();
      f_maxima.put(interval, maxima);
    }

    for(DBID id : superSetIDs) {
      Double f_min = minima.get(id);
      Double f_max = maxima.get(id);

      if(f_min == null) {
        ParameterizationFunction f = database.get(id);
        HyperBoundingBox minMax = f.determineAlphaMinMax(interval);
        f_min = f.function(SpatialUtil.getMin(minMax));
        f_max = f.function(SpatialUtil.getMax(minMax));
        minima.put(id, f_min);
        maxima.put(id, f_max);
      }

      if(logger.isDebugging()) {
        msg.append("\n\nf_min ").append(f_min);
        msg.append("\nf_max ").append(f_max);
        msg.append("\nd_min ").append(d_min);
        msg.append("\nd_max ").append(d_max);
      }

      if(f_min - f_max > ParameterizationFunction.DELTA) {
        throw new IllegalArgumentException("Houston, we have a problem: f_min > f_max! " + "\nf_min[" + FormatUtil.format(SpatialUtil.centroid(interval)) + "] = " + f_min + "\nf_max[" + FormatUtil.format(SpatialUtil.centroid(interval)) + "] = " + f_max + "\nf " + database.get(id));
      }

      if(f_min <= d_max && f_max >= d_min) {
        childIDs.add(id);
        if(logger.isDebugging()) {
          msg.append("\nid ").append(id).append(" appended");
        }
      }

      else {
        if(logger.isDebugging()) {
          msg.append("\nid ").append(id).append(" NOT appended");
        }
      }
    }

    if(logger.isDebugging()) {
      msg.append("\nchildIds ").append(childIDs.size());
      logger.debugFine(msg.toString());
    }

    if(childIDs.size() < minPts) {
      return null;
    }
    else {
      return childIDs;
    }
View Full Code Here


      // left child
      else {
        max[splitDim - 1] = splitPoint;
      }

      ModifiableDBIDs childIDs = split.determineIDs(getIDs(), new HyperBoundingBox(min, max), d_min, d_max);
      if(childIDs != null) {
        // right child
        if(i == 0) {
          rightChild = new CASHInterval(min, max, split, childIDs, splitDim, childLevel, d_min, d_max);
        }
View Full Code Here

  @Override
  public DistanceParsingResult<D> parse(InputStream in) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    int lineNumber = 0;

    ModifiableDBIDs ids = DBIDUtil.newHashSet();
    Map<DBIDPair, D> distanceCache = new HashMap<DBIDPair, D>();
    try {
      for(String line; (line = reader.readLine()) != null; lineNumber++) {
        if(lineNumber % 10000 == 0 && logger.isDebugging()) {
          logger.debugFine("parse " + lineNumber / 10000);
          // logger.fine("parse " + lineNumber / 10000);
        }
        if(!line.startsWith(COMMENT) && line.length() > 0) {
          List<String> entries = tokenize(line);
          if(entries.size() != 3) {
            throw new IllegalArgumentException("Line " + lineNumber + " does not have the " + "required input format: id1 id2 distanceValue! " + line);
          }

          DBID id1, id2;
          try {
            id1 = DBIDUtil.importInteger(Integer.parseInt(entries.get(0)));
          }
          catch(NumberFormatException e) {
            throw new IllegalArgumentException("Error in line " + lineNumber + ": id1 is no integer!");
          }

          try {
            id2 = DBIDUtil.importInteger(Integer.parseInt(entries.get(1)));
          }
          catch(NumberFormatException e) {
            throw new IllegalArgumentException("Error in line " + lineNumber + ": id2 is no integer!");
          }

          try {
            D distance = distanceFunction.getDistanceFactory().parseString(entries.get(2));
            put(id1, id2, distance, distanceCache);
            ids.add(id1);
            ids.add(id2);
          }
          catch(IllegalArgumentException e) {
            throw new IllegalArgumentException("Error in line " + lineNumber + ":" + e.getMessage(), e);
          }
        }
      }
    }
    catch(IOException e) {
      throw new IllegalArgumentException("Error while parsing line " + lineNumber + ".");
    }

    if(logger.isDebugging()) {
      logger.debugFine("check");
    }

    // check if all distance values are specified
    for(DBID id1 : ids) {
      for(DBID id2 : ids) {
        if(id2.getIntegerID() < id1.getIntegerID()) {
          continue;
        }
        if(!containsKey(id1, id2, distanceCache)) {
          throw new IllegalArgumentException("Distance value for " + id1 + " - " + id2 + " is missing!");
        }
      }
    }

    if(logger.isDebugging()) {
      logger.debugFine("add to objectAndLabelsList");
    }

    // This is unusual for ELKI, but here we really need an ArrayList, not a
    // DBIDs object. So convert.
    List<DBID> objects = new ArrayList<DBID>(ids.size());
    for(DBID id : ids) {
      objects.add(id);
    }
    return new DistanceParsingResult<D>(MultipleObjectsBundle.makeSimple(TypeUtil.DBID, objects), distanceCache);
  }
View Full Code Here

    WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(relationx.getDBIDs(), DataStoreFactory.HINT_STATIC);
    DoubleMinMax mm = new DoubleMinMax(0.0, 0.0);

    // Outlier detection loop
    {
      ModifiableDBIDs idview = DBIDUtil.newHashSet(relationx.getDBIDs());
      ProxyView<V> proxy = new ProxyView<V>(relationx.getDatabase(), idview, relationx);

      double phialpha = NormalDistribution.standardNormalProbit(1.0 - alpha / 2);
      // Detect outliers while significant.
      while(true) {
        Pair<DBID, Double> candidate = singleIteration(proxy, relationy);
        if(candidate.second < phialpha) {
          break;
        }
        scores.putDouble(candidate.first, candidate.second);
        if (!Double.isNaN(candidate.second)) {
          mm.put(candidate.second);
        }
        idview.remove(candidate.first);
      }

      // Remaining objects are inliers
      for(DBID id : idview) {
        scores.putDouble(id, 0.0);
View Full Code Here

      }

      // Fill the neighborhood matrix F:
      {
        KNNResult<D> neighbors = knnQuery.getKNNForDBID(id, k + 1);
        ModifiableDBIDs neighborhood = DBIDUtil.newArray(neighbors.size());
        for(DistanceResultPair<D> dpair : neighbors) {
          if(id.equals(dpair.getDBID())) {
            continue;
          }
          neighborhood.add(dpair.getDBID());
        }
        // Weight object itself positively.
        F.set(i, i, 1.0);
        final int nweight = -1 / neighborhood.size();
        // We need to find the index positions of the neighbors, unfortunately.
        for(DBID nid : neighborhood) {
          int pos = ids.binarySearch(nid);
          assert (pos >= 0);
          F.set(pos, i, nweight);
View Full Code Here

      FiniteProgress progress = logger.isVerbose() ? new FiniteProgress("Expanding neighborhoods", database.size(), logger) : null;
      for(final DBID id : database.iterDBIDs()) {
        HashSetModifiableDBIDs res = DBIDUtil.newHashSet(id);
        DBIDs todo = id;
        for(int i = 0; i < steps; i++) {
          ModifiableDBIDs ntodo = DBIDUtil.newHashSet();
          for(final DBID oid : todo) {
            DBIDs add = innerinst.getNeighborDBIDs(oid);
            if(add != null) {
              for(DBID nid : add) {
                if(res.contains(nid)) {
                  continue;
                }
                ntodo.add(nid);
                res.add(nid);
              }
            }
          }
          if(ntodo.size() == 0) {
            continue;
          }
          todo = ntodo;
        }
        store.put(id, res);
View Full Code Here

    return 1.0 - (tsteps / (float) (steps + 1));
  }

  @Override
  public Collection<DoubleObjPair<DBID>> getWeightedNeighbors(DBID reference) {
    ModifiableDBIDs seen = DBIDUtil.newHashSet();
    List<DoubleObjPair<DBID>> result = new ArrayList<DoubleObjPair<DBID>>();

    // Add starting object
    result.add(new DoubleObjPair<DBID>(computeWeight(0), reference));
    seen.add(reference);
    // Extend.
    DBIDs cur = reference;
    for(int i = 1; i <= steps; i++) {
      final double weight = computeWeight(i);
      // Collect newly discovered IDs
      ModifiableDBIDs add = DBIDUtil.newHashSet();
      for(DBID id : cur) {
        for(DBID nid : inner.getNeighborDBIDs(id)) {
          // Seen before?
          if(seen.contains(nid)) {
            continue;
          }
          add.add(nid);
          result.add(new DoubleObjPair<DBID>(weight, nid));
        }
      }
      if(add.size() == 0) {
        break;
      }
      cur = add;
    }
    return result;
View Full Code Here

          e = exp / dist;
        }
        E.set(j, i, e);
      }
      // Convert kNN Heap into DBID array
      ModifiableDBIDs nids = DBIDUtil.newArray(heap.size());
      while(!heap.isEmpty()) {
        nids.add(heap.poll().getDBID());
      }
      neighbors.put(id, nids);
    }
    // normalize the adjacent Matrix
    // Sum based normalization - don't use E.normalizeColumns()
View Full Code Here

      // get normalization
      double[] counter = calcFastNormalization(aKey, dists);
      // System.out.println(counter[0] + " " + counter2[0] + " " + counter[1] +
      // " " + counter2[1]);
      // umsetzen von Pq zu list
      ModifiableDBIDs neighbors = DBIDUtil.newArray(nn.size());
      while(!nn.isEmpty()) {
        neighbors.add(nn.remove().getSecond());
      }
      // getFilter
      double var = getAbofFilter(kernelMatrix, aKey, dists, counter[1], counter[0], neighbors);
      pq.add(new DoubleObjPair<DBID>(var, aKey));
      // System.out.println("prog "+(prog++));
View Full Code Here

        s.put(s2);
      }
      // build variance of the observed vectors
      pq.add(new DoubleObjPair<DBID>(s.getSampleVariance(), objKey));
      //
      ModifiableDBIDs expList = DBIDUtil.newArray();
      expList.add(explain.remove().getSecond());
      while(!explain.isEmpty()) {
        DBID nextKey = explain.remove().getSecond();
        if(nextKey.equals(objKey)) {
          continue;
        }
        double max = Double.MIN_VALUE;
        for(DBID exp : expList) {
          if(exp.equals(objKey) || nextKey.equals(exp)) {
            continue;
          }
          double nenner = Math.sqrt(calcCos(kernelMatrix, objKey, nextKey)) * Math.sqrt(calcCos(kernelMatrix, objKey, exp));
          double angle = calcNumerator(kernelMatrix, objKey, nextKey, exp) / nenner;
          max = Math.max(angle, max);
        }
        if(max < 0.5) {
          expList.add(nextKey);
        }
      }
      explaintab.put(objKey, expList);
    }
    System.out.println("--------------------------------------------");
View Full Code Here

TOP

Related Classes of de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.