Search in sources :

Example 1 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project pinot by linkedin.

the class StarTreeJsonNode method build.

private int build(StarTreeIndexNodeInterf indexNode, StarTreeJsonNode json) {
    Iterator<? extends StarTreeIndexNodeInterf> childrenIterator = indexNode.getChildrenIterator();
    if (!childrenIterator.hasNext()) {
        return 0;
    }
    int childDimensionId = indexNode.getChildDimensionName();
    String childDimensionName = dimensionNameToIndexMap.inverse().get(childDimensionId);
    Dictionary dictionary = dictionaries.get(childDimensionName);
    int totalChildNodes = indexNode.getNumChildren();
    Comparator<Pair<String, Integer>> comparator = new Comparator<Pair<String, Integer>>() {

        @Override
        public int compare(Pair<String, Integer> o1, Pair<String, Integer> o2) {
            return -1 * Integer.compare(o1.getRight(), o2.getRight());
        }
    };
    MinMaxPriorityQueue<Pair<String, Integer>> queue = MinMaxPriorityQueue.orderedBy(comparator).maximumSize(MAX_CHILDREN).create();
    StarTreeJsonNode allNode = null;
    while (childrenIterator.hasNext()) {
        StarTreeIndexNodeInterf childIndexNode = childrenIterator.next();
        int childDimensionValueId = childIndexNode.getDimensionValue();
        String childDimensionValue = "ALL";
        if (childDimensionValueId != StarTreeIndexNodeInterf.ALL) {
            childDimensionValue = dictionary.get(childDimensionValueId).toString();
        }
        StarTreeJsonNode childJson = new StarTreeJsonNode(childDimensionValue);
        totalChildNodes += build(childIndexNode, childJson);
        if (childDimensionValueId != StarTreeIndexNodeInterf.ALL) {
            json.addChild(childJson);
            queue.add(ImmutablePair.of(childDimensionValue, totalChildNodes));
        } else {
            allNode = childJson;
        }
    }
    //put ALL node at the end
    if (allNode != null) {
        json.addChild(allNode);
    }
    if (totalChildNodes > MAX_CHILDREN) {
        Iterator<Pair<String, Integer>> qIterator = queue.iterator();
        Set<String> topKDimensions = new HashSet<>();
        topKDimensions.add("ALL");
        while (qIterator.hasNext()) {
            topKDimensions.add(qIterator.next().getKey());
        }
        Iterator<StarTreeJsonNode> iterator = json.getChildren().iterator();
        while (iterator.hasNext()) {
            StarTreeJsonNode next = iterator.next();
            if (!topKDimensions.contains(next.getName())) {
                iterator.remove();
            }
        }
    }
    return totalChildNodes;
}
Also used : Dictionary(com.linkedin.pinot.core.segment.index.readers.Dictionary) StarTreeIndexNodeInterf(com.linkedin.pinot.core.startree.StarTreeIndexNodeInterf) Comparator(java.util.Comparator) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashSet(java.util.HashSet)

Example 2 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project deeplearning4j by deeplearning4j.

the class FirstIterationFunctionAdapter method call.

@Override
public Iterable<Map.Entry<VocabWord, INDArray>> call(Iterator<Tuple2<List<VocabWord>, Long>> pairIter) {
    while (pairIter.hasNext()) {
        List<Pair<List<VocabWord>, Long>> batch = new ArrayList<>();
        while (pairIter.hasNext() && batch.size() < batchSize) {
            Tuple2<List<VocabWord>, Long> pair = pairIter.next();
            List<VocabWord> vocabWordsList = pair._1();
            Long sentenceCumSumCount = pair._2();
            batch.add(Pair.of(vocabWordsList, sentenceCumSumCount));
        }
        for (int i = 0; i < iterations; i++) {
            //System.out.println("Training sentence: " + vocabWordsList);
            for (Pair<List<VocabWord>, Long> pair : batch) {
                List<VocabWord> vocabWordsList = pair.getKey();
                Long sentenceCumSumCount = pair.getValue();
                double currentSentenceAlpha = Math.max(minAlpha, alpha - (alpha - minAlpha) * (sentenceCumSumCount / (double) totalWordCount));
                trainSentence(vocabWordsList, currentSentenceAlpha);
            }
        }
    }
    return indexSyn0VecMap.entrySet();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) VocabWord(org.deeplearning4j.models.word2vec.VocabWord) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project deeplearning4j by deeplearning4j.

the class SecondIterationFunctionAdapter method call.

@Override
public Iterable<Entry<VocabWord, INDArray>> call(Iterator<Tuple2<List<VocabWord>, Long>> pairIter) {
    this.vocabHolder = VocabHolder.getInstance();
    this.vocabHolder.setSeed(seed, vectorLength);
    if (negative > 0) {
        negativeHolder = NegativeHolder.getInstance();
        negativeHolder.initHolder(vocab, expTable, this.vectorLength);
    }
    while (pairIter.hasNext()) {
        List<Pair<List<VocabWord>, Long>> batch = new ArrayList<>();
        while (pairIter.hasNext() && batch.size() < batchSize) {
            Tuple2<List<VocabWord>, Long> pair = pairIter.next();
            List<VocabWord> vocabWordsList = pair._1();
            Long sentenceCumSumCount = pair._2();
            batch.add(Pair.of(vocabWordsList, sentenceCumSumCount));
        }
        for (int i = 0; i < iterations; i++) {
            //System.out.println("Training sentence: " + vocabWordsList);
            for (Pair<List<VocabWord>, Long> pair : batch) {
                List<VocabWord> vocabWordsList = pair.getKey();
                Long sentenceCumSumCount = pair.getValue();
                double currentSentenceAlpha = Math.max(minAlpha, alpha - (alpha - minAlpha) * (sentenceCumSumCount / (double) totalWordCount));
                trainSentence(vocabWordsList, currentSentenceAlpha);
            }
        }
    }
    return vocabHolder.getSplit(vocab);
}
Also used : ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) VocabWord(org.deeplearning4j.models.word2vec.VocabWord) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair)

Example 4 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method prepareRequestResponsePair.

private Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> prepareRequestResponsePair(String resourcePath, String selectorString, String extension) {
    final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(aemContext.resourceResolver(), aemContext.bundleContext());
    final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    Resource resource = resourceResolver.getResource(resourcePath);
    request.setResource(resource);
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSelectorString(selectorString);
    requestPathInfo.setExtension(extension);
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(SlingBindings.RESPONSE, response);
    bindings.put(SlingBindings.SLING, aemContext.slingScriptHelper());
    bindings.put(SlingBindings.RESOLVER, resourceResolver);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return new Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse>() {

        @Override
        public MockSlingHttpServletRequest getLeft() {
            return request;
        }

        @Override
        public MockSlingHttpServletResponse getRight() {
            return response;
        }

        @Override
        public MockSlingHttpServletResponse setValue(MockSlingHttpServletResponse value) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) SlingBindings(org.apache.sling.api.scripting.SlingBindings) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project ORCID-Source by ORCID.

the class OrgDisambiguatedDaoImpl method findDisambuguatedOrgsWithIncorrectPopularity.

@Override
public List<Pair<Long, Integer>> findDisambuguatedOrgsWithIncorrectPopularity(int maxResults) {
    Query query = entityManager.createNativeQuery("SELECT od1.id, actual.popularity FROM org_disambiguated od1 JOIN" + " (SELECT od2.id id, COUNT(*) popularity FROM org_disambiguated od2 JOIN org o ON o.org_disambiguated_id = od2.id JOIN org_affiliation_relation oar ON oar.org_id = o.id GROUP BY od2.id)" + " actual ON actual.id = od1.id WHERE od1.popularity <> actual.popularity");
    query.setMaxResults(maxResults);
    @SuppressWarnings("unchecked") List<Object[]> results = query.getResultList();
    List<Pair<Long, Integer>> pairs = new ArrayList<>();
    for (Object[] row : results) {
        Long id = ((BigInteger) row[0]).longValue();
        Integer popularity = ((BigInteger) row[1]).intValue();
        Pair<Long, Integer> pair = new ImmutablePair<Long, Integer>(id, popularity);
        pairs.add(pair);
    }
    return pairs;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) BigInteger(java.math.BigInteger) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

Pair (org.apache.commons.lang3.tuple.Pair)596 ArrayList (java.util.ArrayList)176 Test (org.junit.Test)136 List (java.util.List)115 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)115 HashMap (java.util.HashMap)109 Collectors (java.util.stream.Collectors)96 Map (java.util.Map)87 Message (com.microsoft.azure.sdk.iot.device.Message)71 MutablePair (org.apache.commons.lang3.tuple.MutablePair)64 IOException (java.io.IOException)57 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)52 java.util (java.util)48 Set (java.util.Set)45 File (java.io.File)44 StringUtils (org.apache.commons.lang3.StringUtils)41 HashSet (java.util.HashSet)38 Optional (java.util.Optional)37 Arrays (java.util.Arrays)31 Collections (java.util.Collections)31