Пример #1
0
    def testGreedyMC2(self): 
        list1 = [2, 1, 3, 4, 5, 0]
        list2 = [3, 2, 5, 0, 4, 1]
        list3 = [3, 4, 2, 5, 1, 0]
        list4 = [3, 4, 5, 0, 1, 2]
        lists = [list1, list2, list3, list4]
        
        itemList = [0, 1, 2, 3, 4, 5]
        topQList = [3, 4, 5] 
        
        n = 3
        print("Running test")
        outputInds = RankAggregator.greedyMC2(lists, itemList, topQList, n)
        print("Done")
        self.assertEquals(outputInds, [3])        
        
        list1 = [2, 1, 3, 4, 5, 0]
        list2 = [3, 2, 5, 4, 0, 1]
        list3 = [4, 3, 2, 5, 1, 0]
        list4 = [3, 4, 0, 5, 1, 2]
        lists = [list1, list2, list3, list4]

        outputInds = RankAggregator.greedyMC2(lists, itemList, topQList, n)
        
        newLists = []
        for ind in outputInds: 
            newLists.append(lists[ind])
            
        outputList, scores = RankAggregator.MC2(newLists, itemList)
        self.assertEquals(outputList[0:3], [3, 4, 5])
Пример #2
0
 def testBorda(self): 
     list1 = [5, 4, 3, 2, 1, 0]
     list2 = [5, 4, 3, 2, 1, 0]  
     
     outList = RankAggregator.borda(list1, list2)
     
     nptst.assert_array_equal(outList, numpy.array([5,4,3,2,1,0]))
     
     list2 = [4, 3, 2, 5, 1, 0]
     outList = RankAggregator.borda(list1, list2)
     nptst.assert_array_equal(outList, numpy.array([4,5,3,2,1,0]))
Пример #3
0
 def testSpearmanFootrule(self): 
     list1 = [5, 4, 3, 2, 1, 0]
     list2 = [5, 4, 3, 2, 1, 0]
     
     dist = RankAggregator.spearmanFootrule(list1, list2)
     
     self.assertEquals(dist, 0)
     
     list2 = [5, 4, 3, 2, 0, 1]
     dist = RankAggregator.spearmanFootrule(list1, list2)
     
     self.assertEquals(dist, 1.0/9)
     
     list2 = [0, 1, 2, 3, 4, 5]
     dist = RankAggregator.spearmanFootrule(list1, list2)
     self.assertEquals(dist, 1.0)
Пример #4
0
    def testSupervisedMC22(self): 
        list1 = [2, 1, 3, 4, 5, 0]
        list2 = [3, 2, 5, 0, 4, 1]
        list3 = [3, 4, 2, 5, 1, 0]
        list4 = [5, 0, 3, 4, 1, 2]
        lists = [list1, list2, list3, list4]
        
        itemList = [0, 1, 2, 3, 4, 5]
        topQList = [5, 4, 3, 2, 1, 0]

        
        outputList, scores = RankAggregator.supervisedMC22(lists, itemList, topQList)
Пример #5
0
        for i, n in enumerate(ns):     
            for j, trainOutputList in enumerate(trainOutputLists): 
                testOutputList = testOutputLists[j]                
                
                trainPrecisions[i, j] = Evaluator.precisionFromIndLists(trainExpertMatchesInds, trainOutputList[0:n]) 
                testPrecisions[i, j] = Evaluator.precisionFromIndLists(testExpertMatchesInds, testOutputList[0:n]) 
                averageTrainPrecisions[s, i, j] = Evaluator.averagePrecisionFromLists(trainExpertMatchesInds, trainOutputList[0:n], n)
                averageTestPrecisions[s, i, j] = Evaluator.averagePrecisionFromLists(testExpertMatchesInds, testOutputList[0:n], n) 

        #Now look at rank aggregations
        relevantItems = set([])
        for trainOutputList in trainOutputLists: 
            relevantItems = relevantItems.union(trainOutputList)
        relevantItems = list(relevantItems)
        
        listInds = RankAggregator.greedyMC2(trainOutputLists, relevantItems, trainExpertMatchesInds, 20) 
        
        newOutputList = []
        for listInd in listInds: 
            newOutputList.append(testOutputLists[listInd])
        
        """
        newOutputList = []
        newOutputList.append(testOutputLists[0])
        newOutputList.append(testOutputLists[1])
        newOutputList.append(testOutputLists[2])
        newOutputList.append(testOutputLists[3])
        #newOutputList.append(testOutputLists[4])
        newOutputList.append(testOutputLists[5])
        #newOutputList.append(testOutputLists[6])
        """
Пример #6
0
        #outputListsE.append(expertAuthorsInds)#Add BM25 Listto the outputList in order to aggregate scores later
        for line in outputListsE:
         ListeAuthorsFinale = authorIndexer1.reverseTranslate(line)
         #fich.write(' '.join(map(str, ListeAuthorsFinale)))
         fich.write(str(ListeAuthorsFinale)+"\n")
        #Save relevant authors 
        #numpy.save(dataset.dataDir  + "relevantAuthorsReputation" + field +  ".txt", outputLists)
        fich.write("-----------------------------------------------")  
          
        #for line in outputLists:  
         #fich.write(line[i]) 
        #Ajout du score de l'expertise
        #outputLists.append(expertAuthorsInds)

         
        itemList = RankAggregator.generateItemList(outputLists)
        methodNames = graphRanker.getNames()
        
        if runLSI: 
            outputFilename = dataset.getOutputFieldDir(field) + "outputListsLSI.npz"
        else: 
            outputFilename = dataset.getOutputFieldDir(field) + "outputListsLDA.npz"
            
        Util.savePickle([outputLists, trainExpertMatchesInds, testExpertMatchesInds], outputFilename, debug=True)
        
        numMethods = len(outputLists)
        precisions = numpy.zeros((len(ns), numMethods))
        averagePrecisions = numpy.zeros(numMethods)
        
        for i, n in enumerate(ns):     
            for j in range(len(outputLists)):