Package org.apache.mahout.math.map

Examples of org.apache.mahout.math.map.OpenIntIntHashMap


  }

  @Test
  @Repeat(iterations = 20)
  public void testAgainstReferenceOpenIntIntHashMap() {
    OpenIntIntHashMap base = new OpenIntIntHashMap();
    HashMap<Integer, Integer> reference = new HashMap<Integer, Integer>();

    List<Operation> ops = Lists.newArrayList();
    addOp(ops, Operation.ADD, 60);
    addOp(ops, Operation.REMOVE, 30);
    addOp(ops, Operation.INDEXOF, 30);
    addOp(ops, Operation.CLEAR, 5);
    addOp(ops, Operation.ISEMPTY, 2);
    addOp(ops, Operation.SIZE, 2);

    int max = randomIntBetween(1000, 20000);
    for (int reps = 0; reps < max; reps++) {
      // Ensure some collisions among keys.
      int k = randomIntBetween(0, max / 4);
      int v = randomInt();
      switch (randomFrom(ops)) {
        case ADD:
          Integer prevValue = reference.put(k, v);

          if (prevValue == null) {
            assertEquals(true, base.put(k, v));
          } else {
            assertEquals(prevValue.intValue(), base.get(k));
            assertEquals(false, base.put(k, v));
          }
          break;

        case REMOVE:
          assertEquals(reference.containsKey(k), base.containsKey(k));

          Integer removed = reference.remove(k);
          if (removed == null) {
            assertEquals(false, base.removeKey(k));
          } else {
            assertEquals(removed.intValue(), base.get(k));
            assertEquals(true, base.removeKey(k));
          }
          break;

        case INDEXOF:
          assertEquals(reference.containsKey(k), base.containsKey(k));
          break;

        case CLEAR:
          reference.clear();
          base.clear();
          break;

        case ISEMPTY:
          assertEquals(reference.isEmpty(), base.isEmpty());
          break;

        case SIZE:
          assertEquals(reference.size(), base.size());
          break;

        default:
          throw new RuntimeException();
      }
View Full Code Here


    for (int i = 0; i < tree.getHeaderTableCount(); i++) {
      int currentAttribute = tree.getAttributeAtIndex(i);
      int nextNode = tree.getHeaderNext(currentAttribute);

      OpenIntIntHashMap prevNode = new OpenIntIntHashMap();
      int justPrevNode = -1;
      while (nextNode != -1) {

        int parent = tree.parent(nextNode);

        if (prevNode.containsKey(parent)) {
          int prevNodeId = prevNode.get(parent);
          if (tree.childCount(prevNodeId) <= 1 && tree.childCount(nextNode) <= 1) {
            tree.addCount(prevNodeId, tree.count(nextNode));
            tree.addCount(nextNode, -1 * tree.count(nextNode));
            if (tree.childCount(nextNode) == 1) {
              tree.addChild(prevNodeId, tree.childAtIndex(nextNode, 0));
              tree.setParent(tree.childAtIndex(nextNode, 0), prevNodeId);
            }
            tree.setNext(justPrevNode, tree.next(nextNode));
          }
        } else {
          prevNode.put(parent, nextNode);
        }
        justPrevNode = nextNode;
        nextNode = tree.next(nextNode);
      }
    }
View Full Code Here

  }

  private void initCaches() {
    this.caches = new OpenIntIntHashMap[getProbes()];
    for (int ii = 0; ii < getProbes(); ii++) {
      caches[ii] = new OpenIntIntHashMap();
    }
  }
View Full Code Here

  }

  private void initCaches() {
    this.caches = new OpenIntIntHashMap[getProbes()];
    for (int ii = 0; ii < getProbes(); ii++) {
      caches[ii] = new OpenIntIntHashMap();
    }
  }
View Full Code Here

  }

  @Test
  @Repeat(iterations = 20)
  public void testAgainstReferenceOpenIntIntHashMap() {
    OpenIntIntHashMap base = new OpenIntIntHashMap();
    HashMap<Integer, Integer> reference = new HashMap<Integer, Integer>();

    List<Operation> ops = Lists.newArrayList();
    addOp(ops, Operation.ADD, 60);
    addOp(ops, Operation.REMOVE, 30);
    addOp(ops, Operation.INDEXOF, 30);
    addOp(ops, Operation.CLEAR, 5);
    addOp(ops, Operation.ISEMPTY, 2);
    addOp(ops, Operation.SIZE, 2);

    int max = randomIntBetween(1000, 20000);
    for (int reps = 0; reps < max; reps++) {
      // Ensure some collisions among keys.
      int k = randomIntBetween(0, max / 4);
      int v = randomInt();
      switch (randomFrom(ops)) {
        case ADD:
          Integer prevValue = reference.put(k, v);

          if (prevValue == null) {
            assertEquals(true, base.put(k, v));
          } else {
            assertEquals(prevValue.intValue(), base.get(k));
            assertEquals(false, base.put(k, v));
          }
          break;

        case REMOVE:
          assertEquals(reference.containsKey(k), base.containsKey(k));

          Integer removed = reference.remove(k);
          if (removed == null) {
            assertEquals(false, base.removeKey(k));
          } else {
            assertEquals(removed.intValue(), base.get(k));
            assertEquals(true, base.removeKey(k));
          }
          break;

        case INDEXOF:
          assertEquals(reference.containsKey(k), base.containsKey(k));
          break;

        case CLEAR:
          reference.clear();
          base.clear();
          break;

        case ISEMPTY:
          assertEquals(reference.isEmpty(), base.isEmpty());
          break;

        case SIZE:
          assertEquals(reference.size(), base.size());
          break;

        default:
          throw new RuntimeException();
      }
View Full Code Here

    for (int i = 0; i < tree.getHeaderTableCount(); i++) {
      int currentAttribute = tree.getAttributeAtIndex(i);
      int nextNode = tree.getHeaderNext(currentAttribute);

      OpenIntIntHashMap prevNode = new OpenIntIntHashMap();
      int justPrevNode = -1;
      while (nextNode != -1) {

        int parent = tree.parent(nextNode);

        if (prevNode.containsKey(parent)) {
          int prevNodeId = prevNode.get(parent);
          if (tree.childCount(prevNodeId) <= 1 && tree.childCount(nextNode) <= 1) {
            tree.addCount(prevNodeId, tree.count(nextNode));
            tree.addCount(nextNode, -1 * tree.count(nextNode));
            if (tree.childCount(nextNode) == 1) {
              tree.addChild(prevNodeId, tree.childAtIndex(nextNode, 0));
              tree.setParent(tree.childAtIndex(nextNode, 0), prevNodeId);
            }
            tree.setNext(justPrevNode, tree.next(nextNode));
          }
        } else {
          prevNode.put(parent, nextNode);
        }
        justPrevNode = nextNode;
        nextNode = tree.next(nextNode);
      }
    }
View Full Code Here

    boolean laxPrecision = (flags & VectorWritable.FLAG_LAX_PRECISION) != 0;
    Preconditions.checkState(!dense && !sequential, "Only for reading sparse vectors!");

    Varint.readUnsignedVarInt(in);

    OpenIntIntHashMap values = new OpenIntIntHashMap();
    int numNonDefaultElements = Varint.readUnsignedVarInt(in);
    for (int i = 0; i < numNonDefaultElements; i++) {
      int index = Varint.readUnsignedVarInt(in);
      double value = laxPrecision ? in.readFloat() : in.readDouble();
      values.put(index, (int) value);
    }
    return values;
  }
View Full Code Here

    rowSimilarityJob.run(new String[] { "--input", inputFile.getAbsolutePath(), "--output", outputDir.getAbsolutePath(),
        "--numberOfColumns", String.valueOf(5), "--similarityClassname", TanimotoCoefficientSimilarity.class.getName(),
        "--tempDir", tmpDir.getAbsolutePath() });


    OpenIntIntHashMap observationsPerColumn =
        Vectors.readAsIntMap(new Path(tmpDir.getAbsolutePath(), "observationsPerColumn.bin"), conf);
    assertEquals(4, observationsPerColumn.size());
    assertEquals(1, observationsPerColumn.get(0));
    assertEquals(2, observationsPerColumn.get(2));
    assertEquals(2, observationsPerColumn.get(3));
    assertEquals(1, observationsPerColumn.get(4));

    Matrix similarityMatrix = MathHelper.readMatrix(conf, new Path(outputDir.getAbsolutePath(), "part-r-00000"), 3, 3);

    assertNotNull(similarityMatrix);
    assertEquals(3, similarityMatrix.numCols());
View Full Code Here

    for (int i = 0; i < tree.getHeaderTableCount(); i++) {
      int currentAttribute = tree.getAttributeAtIndex(i);
      int nextNode = tree.getHeaderNext(currentAttribute);

      OpenIntIntHashMap prevNode = new OpenIntIntHashMap();
      int justPrevNode = -1;
      while (nextNode != -1) {

        int parent = tree.parent(nextNode);

        if (prevNode.containsKey(parent)) {
          int prevNodeId = prevNode.get(parent);
          if (tree.childCount(prevNodeId) <= 1 && tree.childCount(nextNode) <= 1) {
            tree.addCount(prevNodeId, tree.count(nextNode));
            tree.addCount(nextNode, -1 * tree.count(nextNode));
            if (tree.childCount(nextNode) == 1) {
              tree.addChild(prevNodeId, tree.childAtIndex(nextNode, 0));
              tree.setParent(tree.childAtIndex(nextNode, 0), prevNodeId);
            }
            tree.setNext(justPrevNode, tree.next(nextNode));
          }
        } else {
          prevNode.put(parent, nextNode);
        }
        justPrevNode = nextNode;
        nextNode = tree.next(nextNode);
      }
    }
View Full Code Here

    boolean laxPrecision = (flags & VectorWritable.FLAG_LAX_PRECISION) != 0;
    Preconditions.checkState(!dense && !sequential, "Only for reading sparse vectors!");

    Varint.readUnsignedVarInt(in);

    OpenIntIntHashMap values = new OpenIntIntHashMap();
    int numNonDefaultElements = Varint.readUnsignedVarInt(in);
    for (int i = 0; i < numNonDefaultElements; i++) {
      int index = Varint.readUnsignedVarInt(in);
      double value = laxPrecision ? in.readFloat() : in.readDouble();
      values.put(index, (int) value);
    }
    return values;
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.map.OpenIntIntHashMap

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.