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;
}
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();
}
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);
}
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();
}
};
}
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;
}
Aggregations