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 = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        aDescWeightedFAI: AggregationDescription = InputAggrDefinition.exportADescFAI(
        )

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            "FAI" + jobID, rIDs, rDescs, aDescWeightedFAI)

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

        simulator: Simulator = InputSimulatorDefinition(
        ).exportSimulatorRetailRocket(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]

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

        rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        p1AggrDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            "FDHont" + jobID, rIDs, rDescs,
            InputAggrDefinition.exportADescDHondt(selector))

        recommenderID: str = "TheMostPopular"
        rDescr: RecommenderDescription = RecommenderDescription(
            RecommenderTheMostPopular, {})

        pDescr: APortfolioDescription = PortfolioDynamicDescription(
            "Dynamic" + "FDHontPersStat" + jobID, recommenderID, rDescr,
            "FDHondt", p1AggrDescr)

        model: DataFrame = PModelDHondtPersonalisedStat(
            p1AggrDescr.getRecommendersIDs())

        simulator: Simulator = InputSimulatorDefinition(
        ).exportSimulatorRetailRocket(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 = self.getParameters()[jobID]

        eTool: AEvalTool = EvalToolDHondtBanditVotes({})

        rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        aDescDHont: AggregationDescription = InputAggrDefinition.exportADescDHondtDirectOptimizeThompsonSampling(
            selector)

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

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

        simulator: Simulator = InputSimulatorDefinition(
        ).exportSimulatorRetailRocket(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
        selector, eTool = self.getParameters()[jobID]

        rIDs, rDescs = InputRecomRRDefinition.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(
        ).exportSimulatorRetailRocket(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]

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

        rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

        aDescNegDHont: AggregationDescription = InputAggrDefinition.exportADescDHondtINF(
            selector, nImplFeedback)

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

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

        simulator: Simulator = InputSimulatorDefinition(
        ).exportSimulatorRetailRocket(batchID, divisionDatasetPercentualSize,
                                      uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool],
                           [HistoryHierDF(pDescr.getPortfolioID())])
def test12():
    print("Test 12")

    print("Running Recommender BPRMF on RR:")
    from datasets.retailrocket.events import Events  # class

    batchID: str = "batchID"

    trainDataset: ADataset
    testDataset: ADataset
    trainDataset, testDataset = DatasetRetailRocket.readDatasetsWithFilter(
        50).divideDataset(90)

    testUserIDs: ndarray = testDataset.eventsDF[Events.COL_VISITOR_ID].unique()

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

    numberOfItems: int = 20

    rd: RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMFIMPL()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMF()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescTheMostPopular()
    rd: RecommenderDescription = InputRecomRRDefinition.exportRDescKNN()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescCosineCBcbdOHEupsweightedMeanups3()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescW2Vtpositivei50000ws1vs32upsweightedMeanups3()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescW2Vtpositivei50000ws1vs64upsweightedMeanups7()

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

    r.train(history, trainDataset)

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

        windowItemIds: List[int] = testDataset.eventsDF.loc[
            testDataset.eventsDF[Events.COL_VISITOR_ID] == userIdI][
                Events.COL_ITEM_ID].unique()
        itemIdsHitted: List[int] = list(set(recItemIDsI) & set(windowItemIds))
        numberOfHit += len(itemIdsHitted)

    print("")
    print("numberOfHit: " + str(numberOfHit))
def test01():
    print("Test 01")

    rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs()

    mGlobal: DataFrame = PModelDHondt(rIDs)
    mPerson: DataFrame = PModelDHondtPersonalisedStat(rIDs)
    mh: DataFrame = PModelHybrid(mGlobal, mPerson)
    mh.getModel(1)
示例#8
0
    def run(self, batchID: str, jobID: str):
        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = \
            InputABatchDefinition().getBatchParameters(self.datasetID)[batchID]

        recommenderTheMPopID: str = "TheMostPopular"
        pRTheMPopDescr: RecommenderDescription = RecommenderDescription(
            RecommenderTheMostPopular, {})

        recommenderRPID: str = "RepeatedPurchase"
        pRecRPDescr: RecommenderDescription = RecommenderDescription(
            RecommenderRepeatedPurchase, {})

        selector: ADHondtSelector = self.getParameters()[jobID]
        aDescDHont: AggregationDescription = InputAggrDefinition.exportADescDHondtDirectOptimizeThompsonSampling(
            selector)
        aDescDHont: AggregationDescription = InputAggrDefinition.exportADescBanditTS(
            selector)
        #aDescDHont:AggregationDescription = InputAggrDefinition.exportADescFAI()

        rIDs: List[str]
        rDescs: List[AggregationDescription]
        rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )
        #rIDs = [recommenderTheMPopID]
        #rDescs = [pRTheMPopDescr]

        p1AggrDescrID: str = "p1AggrDescrID"
        p1AggrDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            p1AggrDescrID, rIDs, rDescs, aDescDHont)

        #pProbTool:APenalization = PenalizationToolDefinition.exportProbPenaltyToolOLin0802HLin1002(
        #    InputSimulatorDefinition().numberOfAggrItems)
        pProbTool: APenalization = PenalizationToolDefinition.exportPenaltyToolOStat08HLin1002(
            InputSimulatorDefinition().numberOfAggrItems)

        aHierDescr: AggregationDescription = AggregationDescription(
            AggrD21, {AggrD21.ARG_RATING_THRESHOLD_FOR_NEG: 0.0})

        pHierDescr: PortfolioHierDescription = PortfolioHierDescription(
            "pHierDescr", recommenderRPID, pRecRPDescr, p1AggrDescrID,
            p1AggrDescr, aHierDescr, pProbTool)

        eTool: AEvalTool = EvalToolBanditTS({})
        #eTool:AEvalTool = EToolDoNothing({})
        #model:DataFrame = PModelDHont(p1AggrDescr.getRecommendersIDs())
        model: DataFrame = PModelBandit(p1AggrDescr.getRecommendersIDs())

        simulator: Simulator = InputSimulatorDefinition(
        ).exportSimulatorRetailRocket(batchID, divisionDatasetPercentualSize,
                                      uBehaviour, repetition)
        simulator.simulate([pHierDescr], [model], [eTool],
                           [HistoryHierDF(p1AggrDescr.getPortfolioID())])
def test01():

    print("Simulation: RR Dynamic")

    lrClick: float = 0.03
    #lrView:float = lrClick / 300
    lrViewDivisor: float = 250

    jobID: str = "Fixed" + "Clk" + str(lrClick).replace(
        ".", "") + "ViewDivisor" + str(lrViewDivisor).replace(".", "")

    selector: ADHondtSelector = TheMostVotedItemSelector({})

    rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs()

    p1AggrDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
        "FDHont" + jobID, rIDs, rDescs,
        InputAggrDefinition.exportADescDHondt(selector))

    recommenderID: str = "TheMostPopular"
    rDescr: RecommenderDescription = RecommenderDescription(
        RecommenderTheMostPopular, {})

    pDescr: APortfolioDescription = PortfolioDynamicDescription(
        "Dynamic" + "FDHontPersStat" + jobID, recommenderID, rDescr, "FDHondt",
        p1AggrDescr)

    batchID: str = "rrDiv90Ulinear0109R1"
    dataset: DatasetRetailRocket = DatasetRetailRocket.readDatasetsWithFilter(
        minEventCount=50)
    behaviourFile: str = BehavioursRR.getFile(BehavioursRR.BHVR_LINEAR0109)
    behavioursDF: DataFrame = BehavioursRR.readFromFileRR(behaviourFile)

    model: DataFrame = PModelDHondtPersonalisedStat(
        p1AggrDescr.getRecommendersIDs())

    eTool: AEvalTool = EvalToolDHondtPersonal({
        EvalToolDHondt.ARG_LEARNING_RATE_CLICKS:
        lrClick,
        EvalToolDHondt.ARG_LEARNING_RATE_VIEWS:
        lrClick / lrViewDivisor
    })

    # simulation of portfolio
    simulator: Simulator = Simulator(batchID, SimulationRR, argsSimulationDict,
                                     dataset, behavioursDF)
    simulator.simulate([pDescr], [model], [eTool],
                       [HistoryHierDF(pDescr.getPortfolioID())])
示例#10
0
def test02():
    print("Test 02")

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescTheMostPopular(
    )
    recommenderID: str = InputRecomRRDefinition.THE_MOST_POPULAR

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescKNN()
    recommenderID: str = InputRecomRRDefinition.KNN

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMFIMPL(
    )
    recommenderID: str = InputRecomRRDefinition.BPRMFIMPL

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescVMContextKNN(
    )
    recommenderID: str = InputRecomRRDefinition.VMC_KNN

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescCosineCB(
    )
    recommenderID: str = InputRecomRRDefinition.COSINECB

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescW2V()
    recommenderID: str = InputRecomRRDefinition.W2V

    pDescr: Portfolio1MethDescription = Portfolio1MethDescription(
        recommenderID.title(), recommenderID, rDescr)

    dataset: ADataset = DatasetRetailRocket.readDatasetsWithFilter(
        minEventCount=50)

    behavioursDF: DataFrame = BehavioursRR.readFromFileRR(
        BehavioursRR.getFile("static08"))

    history: AHistory = HistoryDF("test")
    p: APortfolio = pDescr.exportPortfolio("jobID", history)
    p.train(history, dataset)

    argsSimulationDict: Dict[str, str] = {
        SimulationRR.ARG_WINDOW_SIZE: 50,
        SimulationRR.ARG_RECOM_REPETITION_COUNT: 1,
        SimulationRR.ARG_NUMBER_OF_RECOMM_ITEMS: 100,
        SimulationRR.ARG_NUMBER_OF_AGGR_ITEMS:
        InputSimulatorDefinition.numberOfAggrItems,
        SimulationRR.ARG_DIV_DATASET_PERC_SIZE: 90,
        SimulationRR.ARG_HISTORY_LENGTH: 10
    }

    # simulation of portfolio
    simulator: Simulator = Simulator("test", SimulationRR, argsSimulationDict,
                                     dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})],
                       [HistoryHierDF("a")])
    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 = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

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

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

        simulator: Simulator = InputSimulatorDefinition(
        ).exportSimulatorRetailRocket(batchID, divisionDatasetPercentualSize,
                                      uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool],
                           [HistoryHierDF(pDescr.getPortfolioID())])
示例#12
0
        for indexI in model.index:
            model.loc[indexI][
                PModelDHondtPersonalisedStat.COL_MODEL] = DataFrame(
                    model.loc[indexI][PModelDHondtPersonalisedStat.COL_MODEL])
        return model


if __name__ == "__main__":

    os.chdir("..")
    os.chdir("..")

    print(os.getcwd())

    rIDs, rDscrs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs()
    #print(rIDs)
    model: DataFrame = PModelDHondtPersonalisedStat(rIDs)

    userID1: int = 10

    modelInter = model.getModel(userID1)
    print(
        "Clicks: " +
        str(model.loc[userID1][PModelDHondtPersonalisedStat.COL_CLICK_COUNT]))

    model.incrementClick(userID1)
    model.incrementClick(userID1)

    print(
        "Clicks: " +
def test01():
    print("Test 01")

    recommenderID: str = "TheMostPopular"
    pRDescr: RecommenderDescription = RecommenderDescription(
        RecommenderTheMostPopular, {})

    selectorFixed: ADHondtSelector = TheMostVotedItemSelector({})
    aDescDHont: AggregationDescription = InputAggrDefinition.exportADescDHondtDirectOptimizeThompsonSampling(
        selectorFixed)

    rIDs: List[str]
    rDescs: List[AggregationDescription]
    rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs()
    rIDs = [recommenderID]
    rDescs = [pRDescr]

    p1AggrDescrID: str = "p1AggrDescrID"
    p1AggrDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
        p1AggrDescrID, rIDs, rDescs, aDescDHont)

    pProbTool: APenalization = PenalizationToolDefinition.exportProbPenaltyToolOLin0802HLin1002(
        InputSimulatorDefinition.numberOfAggrItems)
    pProbTool: APenalization = PenalizationToolDefinition.exportPenaltyToolOStat08HLin1002(
        InputSimulatorDefinition.numberOfAggrItems)

    aHierDescr: AggregationDescription = AggregationDescription(
        AggrD21, {AggrD21.ARG_RATING_THRESHOLD_FOR_NEG: 2.0})

    pHierDescr: PortfolioHierDescription = PortfolioHierDescription(
        "pHierDescr", recommenderID, pRDescr, p1AggrDescrID, p1AggrDescr,
        aHierDescr, pProbTool)

    userID: int = 1

    dataset: ADataset = DatasetRetailRocket.readDatasetsWithFilter(
        minEventCount=50)

    history: AHistory = HistoryDF("test")
    history.insertRecommendation(userID, 45, 1, False)
    history.insertRecommendation(userID, 45, 2, False)
    history.insertRecommendation(userID, 78, 3, False)

    p: APortfolio = pHierDescr.exportPortfolio("test", history)

    portFolioModel: DataFrame = PModelDHondtBanditsVotes(
        p1AggrDescr.getRecommendersIDs())

    p.train(history, dataset)

    #df:DataFrame = DataFrame([[1, 555]], columns=[Events.COL_USER_ID, Events.COL_OBJECT_ID])
    #p.update(ARecommender.UPDT_CLICK, df)

    args = {
        APortfolio.ARG_NUMBER_OF_AGGR_ITEMS: 20,
        APortfolio.ARG_ITEM_ID: 1,
        APortfolio.ARG_NUMBER_OF_RECOMM_ITEMS: 100,
        AggrD21.ARG_RATING_THRESHOLD_FOR_NEG: 0.5
    }

    r, rp = p.recommend(userID, portFolioModel, args)
    print(r)
            intersectionI: List[int] = [
                value for value in itemIDs if value in recommendationI
            ]
            #print("   " + str(len(intersectionI)))
            counter += len(intersectionI)

        print("  counter: " + str(counter))


if __name__ == "__main__":
    os.chdir("..")

    dataset: ADataset = DatasetRetailRocket.readDatasetsWithFilter(
        minEventCount=50)

    rDscrTheMostPopular: RecommenderDescription = InputRecomRRDefinition.exportRDescTheMostPopular(
    )
    rDscrItemBasedKNN: RecommenderDescription = InputRecomRRDefinition.exportRDescKNN(
    )
    rDscrBPRMF: RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMFIMPL(
    )
    rDscrVMContextKNN: RecommenderDescription = InputRecomRRDefinition.exportRDescVMContextKNN(
    )
    rDscrCosineCB: RecommenderDescription = InputRecomRRDefinition.exportRDescCosineCB(
    )
    rDscrW2V: RecommenderDescription = InputRecomRRDefinition.exportRDescW2V()

    rDscrs: List[object] = [
        rDscrTheMostPopular, rDscrItemBasedKNN, rDscrBPRMF, rDscrVMContextKNN,
        rDscrCosineCB, rDscrW2V
    ]
    rDscrs: List[object] = [rDscrW2V]