/** {@inheritDoc} */ public int[] toArray( int[] dest ) { return TIntDoubleHashMap.this.keys( dest ); }
/** {@inheritDoc} */ public int[] toArray() { return TIntDoubleHashMap.this.keys(); }
/** * {@inheritDoc} */ public int[] getNonZeroIndices() { if (nonZeroIndices == null) nonZeroIndices = vector.keys(); return nonZeroIndices; }
/** {@inheritDoc} */ @Override public int[] toArray() { return TIntDoubleHashMap.this.keys(); }
/** {@inheritDoc} */ public int[] toArray() { return TIntDoubleHashMap.this.keys(); }
/** {@inheritDoc} */ @Override public int[] toArray( int[] dest ) { return TIntDoubleHashMap.this.keys( dest ); }
/** {@inheritDoc} */ public int[] toArray( int[] dest ) { return TIntDoubleHashMap.this.keys( dest ); }
/** {@inheritDoc} */ public int[] toArray() { return TIntDoubleHashMap.this.keys(); }
@Override public int[] indices() { return data.keys(); }
/** {@inheritDoc} */ public int[] toArray( int[] dest ) { return TIntDoubleHashMap.this.keys( dest ); }
/** {@inheritDoc} */ public int[] toArray() { return TIntDoubleHashMap.this.keys(); }
/** {@inheritDoc} */ public int[] toArray( int[] dest ) { return TIntDoubleHashMap.this.keys( dest ); }
/** * {@inheritDoc} */ public int[] getNonZeroIndices() { if (nonZeroIndices == null) { nonZeroIndices = vector.keys(); Arrays.sort(nonZeroIndices); } return nonZeroIndices; }
/** * {@inheritDoc} */ public double[] toArray() { double[] array = new double[length()]; for (int i : vector.keys()) array[i] = vector.get(i); return array; }
/** * {@inheritDoc} */ public double[] toArray() { double[] array = new double[length()]; for (int i : vector.keys()) array[i] = vector.get(i); return array; }
@Override public void update(int nb_probes) { double activity, oldmA, U; for (int k : Av.keys()) { activity = Av.get(k); oldmA = mAv.get(k); U = activity - oldmA; mAv.adjustValue(k, U / nb_probes); } }
@Override public SRResultList predictMostSimilar(List<SRResultList> scores, int maxResults, TIntSet validIds) { int numMetrics = scores.size(); TIntDoubleHashMap scoreMap = new TIntDoubleHashMap(); for (SRResultList resultList : scores){ for (SRResult result : resultList){ double value = result.getScore()/numMetrics; scoreMap.adjustOrPutValue(result.getId(),value,value); } } List<SRResult> resultList = new ArrayList<SRResult>(); for (int id : scoreMap.keys()){ resultList.add(new SRResult(id,scoreMap.get(id))); } Collections.sort(resultList); Collections.reverse(resultList); SRResultList result = new SRResultList(maxResults); for (int i=0; i<maxResults&&i<resultList.size();i++){ result.set(i,resultList.get(i)); } return result; }
@Override public LocalPage getClosestCategory(LocalPage page, Set<LocalPage> candidates, boolean weightedDistance) throws DaoException { CategoryGraph graph = getGraph(page.getLanguage()); CategoryBfs bfs = new CategoryBfs(graph, page.getLocalId(), page.getLanguage(), Integer.MAX_VALUE, null, this); bfs.setAddPages(false); bfs.setExploreChildren(false); Map<Integer, LocalPage> indexToCandidates = new HashMap<Integer, LocalPage>(); for (LocalPage c : candidates) { indexToCandidates.put(graph.catIdToIndex(c.getLocalId()), c); } List<LocalPage> matches = new ArrayList<LocalPage>(); while (bfs.hasMoreResults() && matches.isEmpty()) { CategoryBfs.BfsVisited visited = bfs.step(); for (int catId : visited.cats.keys()) { if (indexToCandidates.containsKey(catId)) { matches.add(indexToCandidates.get(catId)); } } } if (matches.isEmpty()) { return null; } else { return matches.get(new Random().nextInt(matches.size())); } }
int[] idsOriginal = fMap.keys(); int[] ids = new int[idsOriginal.length]; System.arraycopy(idsOriginal, 0, ids, 0, ids.length);
@Override public SRResultList mostSimilar(int pageId, int maxResults, TIntSet validIds) throws DaoException { if (!mostSimilarIsTrained()) { return new SRResultList(0); } SRResultList results = getCachedMostSimilar(pageId, maxResults, validIds); if (results != null) { return results; } CategoryBfs bfs = new CategoryBfs(graph,pageId,getLanguage(), maxResults, validIds, catHelper); while (bfs.hasMoreResults()) { bfs.step(); } results = new SRResultList(bfs.getPageDistances().size()); int i = 0; for (int pageId2: bfs.getPageDistances().keys()) { results.set(i++, pageId2, distanceToScore(bfs.getPageDistances().get(pageId2))); } results.sortDescending(); return normalize(results); }