Пример #1
0
    def run(self, batchID: str, jobID: str):

        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition(
        ).getBatchParameters(self.datasetID)[batchID]

        portfolioID: str = self.getBatchName() + jobID

        history: AHistory = HistoryHierDF(portfolioID)

        #eTool:AEvalTool
        selector, eTool = self.getParameters()[jobID]

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrsCluster(
        )

        aDescDHont: AggregationDescription = InputAggrDefinition.exportADescDHondt(
            selector)

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            self.getBatchName() + jobID, rIDs, rDescs, aDescDHont)

        print(pDescr.getRecommendersIDs())
        model: DataFrame = PModelDHondtPersonalised(
            pDescr.getRecommendersIDs())

        inputSimulatorDefinition = InputSimulatorDefinition()
        inputSimulatorDefinition.numberOfAggrItems = 100
        simulator: Simulator = inputSimulatorDefinition.exportSimulatorML1M(
            batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool], [history])
Пример #2
0
    def run(self, batchID: str, jobID: str):

        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition(
        ).getBatchParameters(self.datasetID)[batchID]

        selector, discFactor = self.getParameters()[jobID]

        eTool: AEvalTool = EvalToolDHondtBanditVotes({})

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        aDescDHont: AggregationDescription = InputAggrDefinition.exportADescDHondtDirectOptimizeThompsonSamplingMMR(
            selector, discFactor)

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            self.getBatchName() + jobID, rIDs, rDescs, aDescDHont)

        model: DataFrame = PModelDHondtBanditsVotes(
            pDescr.getRecommendersIDs())

        simulator: Simulator = InputSimulatorDefinition().exportSimulatorML1M(
            batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool],
                           [HistoryHierDF(pDescr.getPortfolioID())])
    def run(self, batchID:str, jobID:str):

        divisionDatasetPercentualSize:int
        uBehaviour:str
        repetition:int
        divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition().getBatchParameters(self.datasetID)[batchID]

        selector:ADHondtSelector = self.getParameters()[jobID]

        itemsDF:DataFrame = Items.readFromFileMl1m()
        usersDF:DataFrame = Users.readFromFileMl1m()

        historyDF:AHistory = HistoryHierDF("test01")

        eTool:AEvalTool = EvalToolContext({
            EvalToolContext.ARG_USERS: usersDF,
            EvalToolContext.ARG_ITEMS: itemsDF,
            EvalToolContext.ARG_DATASET: "ml",
            EvalToolContext.ARG_HISTORY: historyDF})

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs()

        aDescDHont:AggregationDescription = InputAggrDefinition.exportADescContextFuzzyDHondtDirectOptimize(selector, eTool)

        pDescr:Portfolio1AggrDescription = Portfolio1AggrDescription(
            self.getBatchName() + jobID, rIDs, rDescs, aDescDHont)

        model:DataFrame = PModelDHondt(pDescr.getRecommendersIDs())

        simulator:Simulator = InputSimulatorDefinition().exportSimulatorML1M(
                batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
Пример #4
0
    def run(self, batchID: str, jobID: str):

        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition(
        ).getBatchParameters(self.datasetID)[batchID]

        eTool: AEvalTool = EToolDoNothing({})

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        mainMethodID: str = "RecomKnn"  # the best method for ML
        aDescRandomRecsSwitching: AggregationDescription = InputAggrDefinition.exportADescRandomRecsSwitching(
            mainMethodID)

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            self.getBatchName() + jobID, rIDs, rDescs,
            aDescRandomRecsSwitching)

        model: DataFrame = DataFrame()

        simulator: Simulator = InputSimulatorDefinition().exportSimulatorML1M(
            batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool],
                           [HistoryHierDF(pDescr.getPortfolioID())])
Пример #5
0
def test01():

    print("Simulation: ML TheMostPopular")

    rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescTheMostPopular()

    pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.THE_MOST_POPULAR.title(),
                                                             InputRecomMLDefinition.THE_MOST_POPULAR, rDescr)

    batchID:str = "ml1mDiv90Ulinear0109R1"
    dataset:DatasetML = DatasetML.readDatasets()
    behaviourFile:str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109)
    behavioursDF:DataFrame = BehavioursML.readFromFileMl1m(behaviourFile)

    # remove old results
    #path:str = ".." + os.sep + "results" + os.sep + batchID
    #try:
    #    os.remove(path + os.sep + "computation-theMostPopular.txt")
    #    os.remove(path + os.sep + "historyOfRecommendation-theMostPopular.txt")
    #    os.remove(path + os.sep + "portfModelTimeEvolution-theMostPopular.txt")
    #except:
    #    print("An exception occurred")

    # simulation of portfolio
    simulator:Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
    def run(self, batchID: str, jobID: str):
        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = \
            InputABatchDefinition().getBatchParameters(self.datasetID)[batchID]

        # eTool:AEvalTool
        selector, eTool = self.getParameters()[jobID]

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        aDescDHont: AggregationDescription = InputAggrDefinition.exportADescDHondt(
            selector)

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            self.getBatchName() + jobID, rIDs, rDescs, aDescDHont)

        rIds: List[str] = pDescr.getRecommendersIDs()
        model: DataFrame = PModelHybrid(
            PModelDHondt(rIds), PModelDHondtPersonalisedStat(rIds), {
                PModelHybrid.ARG_MODE_SKIP: True,
                PModelHybrid.ARG_SKIP_CLICK_THRESHOLD: 3
            })

        simulator: Simulator = InputSimulatorDefinition().exportSimulatorML1M(
            batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool],
                           [HistoryHierDF(pDescr.getPortfolioID())])
Пример #7
0
    def run(self, batchID: str, jobID: str):

        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = \
            InputABatchDefinition().getBatchParameters(self.datasetID)[batchID]

        eTool: AEvalTool = self.getParameters()[jobID]

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        aDescWeightedAVG: AggregationDescription = InputAggrDefinition.exportADescWeightedAVGMMR(
        )

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            "WAVGMMR" + jobID, rIDs, rDescs, aDescWeightedAVG)

        model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs())

        simulator: Simulator = InputSimulatorDefinition().exportSimulatorML1M(
            batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool],
                           [HistoryHierDF(pDescr.getPortfolioID())])
Пример #8
0
    def getParameters(self):

        rIDs, rDescr = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs()

        rID1:str = "Recom" + "CosineCBcbdOHEupsweightedMeanups3" + "MMR05"
        rID2:str = "Recom" + "CosineCBcbdOHEupsmaxups1" + "MMR05"

        cosineCBMMR1:RecommenderDescription = InputRecomMLDefinition.exportRDescCosineCBcbdOHEupsweightedMeanups3()
        cosineCBMMR1.getArguments()[RecommenderCosineCB.ARG_USE_DIVERSITY] = True
        cosineCBMMR1.getArguments()[RecommenderCosineCB.ARG_MMR_LAMBDA] = 0.5

        cosineCBMMR2:RecommenderDescription = InputRecomMLDefinition.exportRDescCosineCBcbdOHEupsmaxups1()
        cosineCBMMR2.getArguments()[RecommenderCosineCB.ARG_USE_DIVERSITY] = True
        cosineCBMMR2.getArguments()[RecommenderCosineCB.ARG_MMR_LAMBDA] = 0.5


        aDict:Dict[str,object] = dict(zip(rIDs + [rID1, rID2], rDescr + [cosineCBMMR1, cosineCBMMR2]))

        return aDict
    def exportPairOfRecomIdsAndRecomDescrsRetailRocket(cls):

        recom: str = "Recom"

        rIDs: List[str] = [
            recom + InputRecomMLDefinition.THE_MOST_POPULAR.title()
        ]
        rDescs: List[RecommenderDescription] = [
            InputRecomMLDefinition.exportRDescTheMostPopular()
        ]

        return (rIDs, rDescs)
Пример #10
0
    def run(self, batchID: str, jobID: str):

        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition(
        ).getBatchParameters(self.datasetID)[batchID]

        selector: ADHondtSelector
        negativeImplFeedback: APenalization
        selector, negativeImplFeedback = self.getParameters()[jobID]

        portfolioID: str = self.getBatchName() + jobID

        history: AHistory = HistoryHierDF(portfolioID)

        dataset: ADataset = DatasetML.readDatasets()
        usersDF = dataset.usersDF
        itemsDF = dataset.itemsDF

        # Init evalTool
        evalTool: AEvalTool = EvalToolContext({
            EvalToolContext.ARG_USERS:
            usersDF,
            EvalToolContext.ARG_ITEMS:
            itemsDF,
            EvalToolContext.ARG_DATASET:
            "ml",
            EvalToolContext.ARG_HISTORY:
            history
        })

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        aDescContextDHont: AggregationDescription = InputAggrDefinition.exportADescDContextHondtINF(
            selector, negativeImplFeedback, evalTool)

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            portfolioID, rIDs, rDescs, aDescContextDHont)

        model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs())

        simulator: Simulator = InputSimulatorDefinition().exportSimulatorML1M(
            batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [evalTool], [history])
Пример #11
0
def test11():

    print("Simulation: RR TheMostPopular")

    rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescTheMostPopular()

    pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.THE_MOST_POPULAR.title(),
                                                             InputRecomMLDefinition.THE_MOST_POPULAR, rDescr)

    batchID:str = "retailrocketDiv90Ulinear0109R1"
    dataset:DatasetRetailRocket = DatasetRetailRocket.readDatasets()
    behaviourFile:str = BehavioursRR.getFile(BehavioursRR.BHVR_LINEAR0109)
    behavioursDF:DataFrame = BehavioursRR.readFromFileRR(behaviourFile)

    # simulation of portfolio
    simulator:Simulator = Simulator(batchID, SimulationRR, argsSimulationDict, dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
Пример #12
0
def test03():

    print("Simulation: ML KNN")

    rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescKNN()

    pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.KNN.title(),
                                                             InputRecomMLDefinition.KNN, rDescr)

    batchID:str = "ml1mDiv90Ulinear0109R1"
    dataset:DatasetML = DatasetML.readDatasets()
    behaviourFile:str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109)
    behavioursDF:DataFrame = BehavioursML.readFromFileMl1m(behaviourFile)

    # simulation of portfolio
    simulator:Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
Пример #13
0
def test25():

    print("Simulation: ST MF")

    rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescBPRMFIMPLf100i10lr0003r01()

    pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.BPRMFIMPLf100i10lr0003r01.title(),
                                                             InputRecomMLDefinition.BPRMFIMPLf100i10lr0003r01, rDescr)

    batchID:str = "slantourDiv90Ulinear0109R1"
    dataset:DatasetST = DatasetST.readDatasets()
    behaviourFile:str = BehavioursST.getFile(BehavioursST.BHVR_LINEAR0109)
    behavioursDF:DataFrame = BehavioursST.readFromFileST(behaviourFile)

    # simulation of portfolio
    simulator:Simulator = Simulator(batchID, SimulationST, argsSimulationDict, dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
Пример #14
0
def test24():

    print("Simulation: ST CB")

    rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescCosineCBcbdOHEupsweightedMeanups3()

    pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.COS_CB_MEAN.title(),
                                                             InputRecomMLDefinition.COS_CB_MEAN, rDescr)

    batchID:str = "slantourDiv90Ulinear0109R1"
    dataset:DatasetST = DatasetST.readDatasets()
    behaviourFile:str = BehavioursST.getFile(BehavioursST.BHVR_LINEAR0109)
    behavioursDF:DataFrame = BehavioursST.readFromFileST(behaviourFile)

    # simulation of portfolio
    simulator:Simulator = Simulator(batchID, SimulationST, argsSimulationDict, dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
Пример #15
0
def test02():

    print("Simulation: ML W2V")

    rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescW2Vtpositivei50000ws1vs32upsweightedMeanups3()

    pDescr:APortfolioDescription = Portfolio1MethDescription("W2vPositiveMax",
                                    "w2vPositiveMax", rDescr)

    batchID:str = "ml1mDiv90Ulinear0109R1"
    dataset:DatasetML = DatasetML.readDatasets()
    behaviourFile:str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109)
    behavioursDF:DataFrame = BehavioursML.readFromFileMl1m(behaviourFile)

    # simulation of portfolio
    simulator:Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
def test11():
    print("Test 11")

    print("Running Recommender BPRMF on ML:")

    batchID: str = "batchID"

    trainDataset: ADataset
    testDataset: ADataset
    trainDataset, testDataset = DatasetML.readDatasets().divideDataset(90)

    testUserIDs: ndarray = testDataset.ratingsDF[Ratings.COL_USERID].unique()

    history: AHistory = HistoryHierDF(["aa"])

    numberOfItems: int = 20

    rd: RecommenderDescription = InputRecomMLDefinition.exportRDescBPRMF()
    #rd:RecommenderDescription = InputRecomMLDefinition.exportRDescBPRMFIMPLf20i20lr0003r01()
    #rd:RecommenderDescription = InputRecomMLDefinition.exportRDescTheMostPopular()
    #rd:RecommenderDescription = InputRecomMLDefinition.exportRDescKNN()
    #rd:RecommenderDescription = InputRecomMLDefinition.exportRDescCosineCBcbdOHEupsweightedMeanups3()
    #rd:RecommenderDescription = InputRecomMLDefinition.exportRDescW2Vtpositivei50000ws1vs32upsweightedMeanups3()
    #rd:RecommenderDescription = InputRecomMLDefinition.exportRDescW2Vtpositivei50000ws1vs64upsweightedMeanups7()

    r: ARecommender = rd.exportRecommender("aaa")
    argumentsDict: Dict = rd.getArguments()

    r.train(history, trainDataset)

    numberOfHit: int = 0
    for userIdI in testUserIDs:
        recI: Series = r.recommend(int(userIdI), numberOfItems, argumentsDict)
        recItemIDsI: List[int] = [i for i in recI.keys()]

        windowItemIds: List[int] = testDataset.ratingsDF.loc[
            testDataset.ratingsDF[Ratings.COL_USERID] == userIdI][
                Ratings.COL_MOVIEID].unique()
        itemIdsHitted: List[int] = list(set(recItemIDsI) & set(windowItemIds))
        numberOfHit += len(itemIdsHitted)

    print("")
    print("numberOfHit: " + str(numberOfHit))
    def run(self, batchID:str, jobID:str):

        divisionDatasetPercentualSize:int
        uBehaviour:str
        repetition:int
        divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition().getBatchParameters(self.datasetID)[batchID]

        datasetID:str = "ml1m" + "Div" + str(divisionDatasetPercentualSize)

        recommenderID:str
        nImplFeedback:APenalization
        recommenderID, nImplFeedback = self.getParameters()[jobID]

        rDescr:RecommenderDescription = InputRecomMLDefinition.exportInputRecomDefinition(recommenderID)

        pDescr:APortfolioDescription = PortfolioNeg1MethDescription(jobID.title(), recommenderID, rDescr, nImplFeedback)

        simulator:Simulator = InputSimulatorDefinition().exportSimulatorML1M(
                batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
Пример #18
0
def test04():

    print("Simulation: ML CB")

    #rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescCBmean()
    rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescCosineCBcbdOHEupsmaxups1()


    #pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.COS_CB_MEAN.title(),
    #                                InputRecomMLDefinition.COS_CB_MEAN, rDescr)
    pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.COS_CB_WINDOW3.title(),
                                                             InputRecomMLDefinition.COS_CB_WINDOW3, rDescr)


    batchID:str = "ml1mDiv90Ulinear0109R1"
    dataset:DatasetML = DatasetML.readDatasets()
    behaviourFile:str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109)
    behavioursDF:DataFrame = BehavioursML.readFromFileMl1m(behaviourFile)

    # simulation of portfolio
    simulator:Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
Пример #19
0
    def run(self, batchID:str, jobID:str):

        divisionDatasetPercentualSize:int
        uBehaviour:str
        repetition:int
        divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition().getBatchParameters(self.datasetID)[batchID]

        selector, nImplFeedback = self.getParameters()[jobID]

        eTool:AEvalTool = EvalToolDHondt({EvalToolDHondt.ARG_LEARNING_RATE_CLICKS: 0.02,
                                           EvalToolDHondt.ARG_LEARNING_RATE_VIEWS: 1000})

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs()

        aDescFuzzyHontDirectOptimizeINF:AggregationDescription = InputAggrDefinition.exportADescDFuzzyHondtDirectOptimizeINF(selector, nImplFeedback)

        pDescr:Portfolio1AggrDescription = Portfolio1AggrDescription(
            self.getBatchName() + jobID, rIDs, rDescs, aDescFuzzyHontDirectOptimizeINF)

        model:DataFrame = PModelDHondt(pDescr.getRecommendersIDs())

        simulator:Simulator = InputSimulatorDefinition().exportSimulatorML1M(
                batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
    def run(self, batchID: str, jobID: str):

        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition(
        ).getBatchParameters(self.datasetID)[batchID]

        selector: ADHondtSelector = self.getParameters()[jobID]

        rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            self.getBatchName() + jobID, rIDs, rDescs,
            InputAggrDefinition.exportADescBanditTS(selector))

        eTool: AEvalTool = EvalToolBanditTS({})
        model: DataFrame = PModelBandit(pDescr.getRecommendersIDs())

        simulator: Simulator = InputSimulatorDefinition().exportSimulatorML1M(
            batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool],
                           [HistoryHierDF(pDescr.getPortfolioID())])