public final boolean execute(int value) { return that.contains(value); } });
/** * Tests the set to determine if all of the elements in * <tt>array</tt> are present. * * @param array an <code>array</code> of int primitives. * @return true if all elements were present in the set. */ public boolean containsAll(int[] array) { for (int i = array.length; i-- > 0;) { if (! contains(array[i])) { return false; } } return true; }
/** * Get the relevant documents for a given relevance grade. * @param grade The given relevance grade. * @return The identifiers of the relevant documents with the given relevance * grade. */ public THashSet<String> getRelevantDocuments(int grade){ if (!relGrade.contains(grade)) return null; return (THashSet<String>)relGradeDocnosMap.get(grade); }
/** * Get the relevant documents for a given relevance grade. * @param grade The given relevance grade. * @return The identifiers of the relevant documents with the given relevance * grade. */ public THashSet<String> getRelevantDocuments(int grade){ if (!relGrade.contains(grade)) return null; return (THashSet<String>)relGradeDocnosMap.get(grade); }
public TIntDoubleHashMap getTable() { TIntDoubleHashMap rank = new TIntDoubleHashMap((int) (testSize + testSize * 0.25), (float) 0.75); for (int docId = 0; docId < testSize; docId++) { Set<Entry<Short, ClassifierRangeWithScore>> entries = classification.getDocumentScoresAsSet(docId); Iterator<Entry<Short, ClassifierRangeWithScore>> iterator = entries.iterator(); double sum = 0.0; while (iterator.hasNext()) { Entry<Short, ClassifierRangeWithScore> next = iterator.next(); if (categoriesFilter.contains(next.getKey()) && docCategoriesFilter[docId].contains(next.getKey())) { ClassifierRangeWithScore value = next.getValue(); sum += probability(Math.abs(value.score - value.border), next.getKey()); //System.out.println(docId + " " + next.getKey() + " " + probability(Math.abs(value.score - value.border), next.getKey())); //System.out.println(next.getKey() + " " + slopes[next.getKey()] + " " + value.score); } } rank.put(docId, sum); } return rank; }
private TIntHashSet filterByTopProbabilities(int docId, int topK) { TIntDoubleHashMap topProbRank = new TIntDoubleHashMap((int) (testSize + testSize * 0.25), (float) 0.75); Set<Entry<Short, ClassifierRangeWithScore>> entries = classification.getDocumentScoresAsSet(docId); Iterator<Entry<Short, ClassifierRangeWithScore>> iterator = entries.iterator(); while (iterator.hasNext()) { Entry<Short, ClassifierRangeWithScore> next = iterator.next(); if (categoriesFilter.contains(next.getKey())) { ClassifierRangeWithScore value = next.getValue(); topProbRank.put(next.getKey(), probability(Math.abs(value.score - value.border), next.getKey())); } } Ranker r = new Ranker(); return new TIntHashSet(r.get(topProbRank).toNativeArray(0, topK)); }
if (val instanceof Integer) { int v = unwrap(val); if (_set.contains(v)) {
/** * * @param alevel Level (depth) of the desired ancestor * @param ancPath A list to be populated with indices of nodes searched (starting with the current node), provided that an ancestor node at the specified level exists; or null. * @param alreadySearched Indices of nodes which have already been searched. If non-null, 'this' will be returned if (and only if) a member of this set is encountered in the ancestor path. * @return Ancestor node of the current node whose level is 'alevel', or null if no such ancestor exists. A node is not considered to be its own ancestor. * @author Nathan Schneider (nschneid) */ @SuppressWarnings("unchecked") public T getAncestorAtLevel(int alevel, TIntArrayList ancPath, TIntHashSet alreadySearched) { if (alevel < 0 || alevel >= this.depth) // A node at this level is not strictly an ancestor return null; TreeNode<T> node = this; for (int d=this.depth; d>alevel; d--) { if (ancPath!=null) ancPath.add(node.index); if (alreadySearched!=null && alreadySearched.contains(node.index)) return (T)this; node = node.getParent(); } return (T)node; }
public Incremental(int trainSize, ClassificationScoreDB classification, TIntHashSet categoriesFilter, EstimationType estimation, ContingencyTableSet evaluation, IGain gain, IGain firstRankGain, double[] probabilitySlope, double[] prevalencies) { super(trainSize, classification, categoriesFilter, estimation, evaluation, firstRankGain, probabilitySlope, prevalencies); macroRankTable = new TIntDoubleHashMap((int) (testSize + testSize * 0.25), (float) 0.75); microRankTable = new TIntDoubleHashMap((int) (testSize + testSize * 0.25), (float) 0.75); macroAlreadySeen = new TIntHashSet((int) (testSize + testSize * 0.25), (float) 0.75); microAlreadySeen = new TIntHashSet((int) (testSize + testSize * 0.25), (float) 0.75); probabilities = new double[testSize][numOfCategories]; for (int docId = 0; docId < testSize; docId++) { Set<Entry<Short, ClassifierRangeWithScore>> entries = classification.getDocumentScoresAsSet(docId); Iterator<Entry<Short, ClassifierRangeWithScore>> iterator = entries.iterator(); while (iterator.hasNext()) { Entry<Short, ClassifierRangeWithScore> next = iterator.next(); ClassifierRangeWithScore value = next.getValue(); if (categoriesFilter.contains(next.getKey())) { probabilities[docId][catMap.get(next.getKey())] = probability(Math.abs(value.score - value.border), next.getKey()); } } } }
/** * Get the relevant documents for a given relevance grade. * @param grade The given relevance grade. * @return The identifiers of the relevant documents with the given relevance * grade. */ public String[] getRelevantDocumentsToArray(int grade){ if (!relGrade.contains(grade)) return null; THashSet<String> docnos = (THashSet<String>)relGradeDocnosMap.get(grade); return (String[])docnos.toArray(new String[docnos.size()]); } /**
/** * Get the relevant documents for a given relevance grade. * @param grade The given relevance grade. * @return The identifiers of the relevant documents with the given relevance * grade. */ public String[] getRelevantDocumentsToArray(int grade){ if (!relGrade.contains(grade)) return null; THashSet<String> docnos = (THashSet<String>)relGradeDocnosMap.get(grade); return (String[])docnos.toArray(new String[docnos.size()]); } /**
/** * return intersection between two int[] * @param arr1 * @param arr2 * @return intersection */ public static int[] intersection(int[] arr1, int[] arr2) { TIntHashSet set = new TIntHashSet(); set.addAll(arr1); Arrays.sort(arr2); TIntArrayList list = new TIntArrayList(); for (int i : arr2) { if (set.contains(i)) { list.add(i); } } return list.toNativeArray(); }
/** * return intersection between two int[] * @param arr1 * @param arr2 * @return intersection */ public static int[] intersection(int[] arr1, int[] arr2) { TIntHashSet set = new TIntHashSet(); set.addAll(arr1); Arrays.sort(arr2); TIntArrayList list = new TIntArrayList(); for (int i : arr2) { if (set.contains(i)) { list.add(i); } } return list.toNativeArray(); }
/** * Add an identifier of a relevant document with its relevance grade. * @param docno The identifier of the given relevant document. * @param grade The relevance grade of the given relevant document. */ public void insertRelDocno(String docno, int grade){ if (!relGrade.contains(grade)){ relGrade.add(grade); THashSet<String> gradeDocnos = new THashSet<String>(); gradeDocnos.add(docno); relGradeDocnosMap.put(grade, gradeDocnos); }else{ ((THashSet<String>)relGradeDocnosMap.get(grade)).add(docno); } }
/** * Add an identifier of a relevant document with its relevance grade. * @param docno The identifier of the given relevant document. * @param grade The relevance grade of the given relevant document. */ public void insertRelDocno(String docno, int grade){ if (!relGrade.contains(grade)){ relGrade.add(grade); THashSet<String> gradeDocnos = new THashSet<String>(); gradeDocnos.add(docno); relGradeDocnosMap.put(grade, gradeDocnos); }else{ ((THashSet<String>)relGradeDocnosMap.get(grade)).add(docno); } }
public TIntDoubleHashMap getTable(double[][] utilities) { TIntDoubleHashMap rank = new TIntDoubleHashMap( (int) (testSize + testSize * 0.25), (float) 0.75); for (int docId = 0; docId < testSize; docId++) { double sum = 0.0; for (TIntIterator it = categoriesFilter.iterator(); it.hasNext(); ) { int catId = it.next(); if (docCategoriesFilter[docId].contains(catId)) { sum += utilities[docId][catMap.get(catId)]; } } rank.put(docId, sum); } return rank; }
public void computeTSR(IIndex index, IIndex testindex){ selectBestFeatures(index); // Select the features to remove from DB. JatecsLogger .status() .print("Selecting worst features to remove from DB and removing it..."); TIntArrayList toRemove = new TIntArrayList(); IIntIterator it = index.getFeatureDB().getFeatures(); while(it.hasNext()){ int featID = it.next(); if (!_bestFeatsSet.contains(featID)){ toRemove.add(featID); } } TIntArrayListIterator toRemoveIt=new TIntArrayListIterator(toRemove); // Remove the features from DB. index.removeFeatures(toRemoveIt); if(testindex!=null){ toRemoveIt.begin(); testindex.removeFeatures(toRemoveIt); } JatecsLogger.status().println("done."); JatecsLogger.status().println("Round-robin TSR: "+_bestFeatsSet.size()+" features globally selected, "+_rounds+" features for each category"); } }
protected ResultSet _testOneDocumentTwoTermsNegativeMatch() throws Exception { Index index = IndexTestUtils.makeIndex( new String[]{"doc1", "doc2"}, new String[]{ "The quick brown fox jumps over the lazy dog", "how much is that dog in the window"}); System.err.println("testTwoDocumentsNegativeMatch: " + index.toString()); assertNotNull(index); assertEquals(2, index.getCollectionStatistics().getNumberOfDocuments()); Manager matching = new LocalManager(index); assertNotNull(matching); ResultSet rs; SearchRequest search = matching.newSearchRequest("test", "dog -window"); search.setControl(SearchRequest.CONTROL_WMODEL, DPH.class.getName()); //search.addMatchingModel("Matching", "DPH"); search.setOriginalQuery("dog -window"); matching.runSearchRequest(search); rs = ((Request)search).getResultSet(); assertNotNull(rs); assertEquals(1, rs.getResultSize()); TIntHashSet docids = new TIntHashSet(rs.getDocids()); System.err.println("" + rs.getDocids()[0] + " "+ rs.getScores()[0]); assertTrue(docids.contains(0)); assertEquals(0, rs.getDocids()[0]); assertTrue(rs.getScores()[0] > 0); return rs; }
TIntHashSet docids = new TIntHashSet(rs.getDocids()); System.err.println("" + rs.getDocids()[0] + " "+ rs.getScores()[0]); assertTrue(docids.contains(1)); assertEquals(1, rs.getDocids()[0]); assertTrue(rs.getScores()[0] > 0);