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())])
Exemple #2
0
    def getParameters(self):
        aDict:Dict[str,object] = {}
        for selectorIDI in self.selectorIDs:
            for lrClickJ in self.lrClicks:
                for lrViewDivisorK in self.lrViewDivisors:
                    for normOfResponsL in self.normOfRespons:

                        keyIJ:str = selectorIDI + "Clk" + str(lrClickJ).replace(".", "") + "ViewDivisor" + str(lrViewDivisorK).replace(".", "") + "NR" + str(normOfResponsL)
                        lrViewIJK:float = lrClickJ / lrViewDivisorK
                        eToolIJK:AEvalTool = EvalToolDHondtPersonal({
                                        EvalToolDHondtPersonal.ARG_LEARNING_RATE_CLICKS: lrClickJ,
                                        EvalToolDHondtPersonal.ARG_LEARNING_RATE_VIEWS: lrViewIJK,
                                        EvalToolDHondtPersonal.ARG_NORMALIZATION_OF_RESPONSIBILITY: normOfResponsL})
                        selectorIJK:ADHondtSelector = BatchDefMLFuzzyDHondt().getAllSelectors()[selectorIDI]
                        aDict[keyIJ] = (selectorIJK, eToolIJK)
        return aDict
    def getParameters(self):
        aDict: Dict[str, object] = {}
        for selectorIDI in self.selectorIDs:
            for gLrClickJ in self.mGlobalLrClicks:
                for gLrViewDivisorK in self.mGlobalLrViewDivisors:
                    for gNormOfResponsL in self.mGlobalNormOfRespons:
                        for pLrClickM in self.mPersonLrClicks:
                            for pLrViewDivisorN in self.mPersonLrViewDivisors:
                                for pLrViewDivisorO in self.mPersonNormOfRespons:

                                    gjk: str = "Clk" + str(gLrClickJ).replace(
                                        ".", "") + "ViewDivisor" + str(
                                            gLrViewDivisorK).replace(
                                                ".", "") + "NR" + str(
                                                    gNormOfResponsL)
                                    pjk: str = "Clk" + str(pLrClickM).replace(
                                        ".", "") + "ViewDivisor" + str(
                                            pLrViewDivisorN).replace(
                                                ".", "") + "NR" + str(
                                                    pLrViewDivisorO)
                                    keyIJ: str = selectorIDI + gjk + pjk
                                    lrViewJK: float = gLrClickJ / gLrViewDivisorK
                                    lrViewLM: float = pLrClickM / pLrViewDivisorN
                                    evalToolMGlobal: EvalToolDHondt = EvalToolDHondt({
                                        EvalToolDHondt.ARG_LEARNING_RATE_CLICKS:
                                        gLrClickJ,
                                        EvalToolDHondt.ARG_LEARNING_RATE_VIEWS:
                                        lrViewJK,
                                        EvalToolDHondt.ARG_NORMALIZATION_OF_RESPONSIBILITY:
                                        gNormOfResponsL
                                    })
                                    evalToolMPerson: EvalToolDHondt = EvalToolDHondtPersonal({
                                        EvalToolDHondtPersonal.ARG_LEARNING_RATE_CLICKS:
                                        pLrClickM,
                                        EvalToolDHondtPersonal.ARG_LEARNING_RATE_VIEWS:
                                        lrViewLM,
                                        EvalToolDHondtPersonal.ARG_NORMALIZATION_OF_RESPONSIBILITY:
                                        pLrViewDivisorO
                                    })
                                    eToolIJK: AEvalTool = EToolHybrid(
                                        evalToolMGlobal, evalToolMPerson, {})
                                    selectorIJK: ADHondtSelector = BatchDefMLFuzzyDHondt(
                                    ).getSelectorParameters()[selectorIDI]
                                    aDict[keyIJ] = (selectorIJK, eToolIJK)
        return aDict
Exemple #4
0
def test01():
    print("Test 01")

    #print("Running Two paralel History Databases:")

    # method results, items=[1,2,4,5,6,7,8,12,32,64,77]
    methodsResultDict: dict = {
        "metoda1":
        pd.Series([0.2, 0.1, 0.3, 0.3, 0.1], [32, 2, 8, 1, 4], name="rating"),
        "metoda2":
        pd.Series([0.1, 0.1, 0.2, 0.3, 0.3], [1, 5, 32, 6, 7], name="rating"),
        "metoda3":
        pd.Series([0.3, 0.1, 0.2, 0.3, 0.1], [7, 2, 77, 64, 12], name="rating")
    }

    rItemIDsWithResponsibility: List = [(7, {
        'metoda1': 0,
        'metoda2': 24.0,
        'metoda3': 18.0
    }), (1, {
        'metoda1': 30.0,
        'metoda2': 8.0,
        'metoda3': 0
    }), (32, {
        'metoda1': 20.0,
        'metoda2': 16.0,
        'metoda3': 0
    }), (8, {
        'metoda1': 30.0,
        'metoda2': 0,
        'metoda3': 0
    }), (6, {
        'metoda1': 0,
        'metoda2': 24.0,
        'metoda3': 0
    }), (64, {
        'metoda1': 0,
        'metoda2': 0,
        'metoda3': 18.0
    }), (2, {
        'metoda1': 10.0,
        'metoda2': 0,
        'metoda3': 6.0
    }), (77, {
        'metoda1': 0,
        'metoda2': 0,
        'metoda3': 12.0
    }), (4, {
        'metoda1': 10.0,
        'metoda2': 0,
        'metoda3': 0
    }), (5, {
        'metoda1': 0,
        'metoda2': 8.0,
        'metoda3': 0
    }), (12, {
        'metoda1': 0,
        'metoda2': 0,
        'metoda3': 6.0
    })]

    # methods parametes
    portfolioModelData: List[tuple] = [['metoda1', 100], ['metoda2', 80],
                                       ['metoda3', 60]]
    portfolioModelDF: DataFrame = pd.DataFrame(
        portfolioModelData,
        columns=[PModelDHondt.COL_METHOD_ID, PModelDHondt.COL_VOTES])
    portfolioModelDF.set_index(PModelDHondt.COL_METHOD_ID, inplace=True)
    portfolioModelDF.__class__ = PModelDHondtPersonalised

    userID = 1
    clickedItemID = 101

    tool = EvalToolDHondtPersonal({
        EvalToolDHondtPersonal.ARG_LEARNING_RATE_CLICKS:
        0.2,
        EvalToolDHondtPersonal.ARG_LEARNING_RATE_VIEWS:
        1000
    })
    tool.click(userID, rItemIDsWithResponsibility, clickedItemID,
               portfolioModelDF, {})
Exemple #5
0
def test02():
    print("Test 02")

    #print("Running Two paralel History Databases:")

    # method results, items=[1,2,4,5,6,7,8,12,32,64,77]
    methodsResultDict: dict = {
        "metoda1":
        pd.Series([0.2, 0.1, 0.3, 0.3, 0.1], [32, 2, 8, 1, 4], name="rating"),
        "metoda2":
        pd.Series([0.1, 0.1, 0.2, 0.3, 0.3], [1, 5, 32, 6, 7], name="rating"),
        "metoda3":
        pd.Series([0.3, 0.1, 0.2, 0.3, 0.1], [7, 2, 77, 64, 12], name="rating")
    }

    rItemIDsWithResponsibility: List = [(7, {
        'metoda1': 0,
        'metoda2': 24.0,
        'metoda3': 18.0
    }), (1, {
        'metoda1': 30.0,
        'metoda2': 8.0,
        'metoda3': 0
    }), (32, {
        'metoda1': 20.0,
        'metoda2': 16.0,
        'metoda3': 0
    }), (8, {
        'metoda1': 30.0,
        'metoda2': 0,
        'metoda3': 0
    }), (6, {
        'metoda1': 0,
        'metoda2': 24.0,
        'metoda3': 0
    }), (64, {
        'metoda1': 0,
        'metoda2': 0,
        'metoda3': 18.0
    }), (2, {
        'metoda1': 10.0,
        'metoda2': 0,
        'metoda3': 6.0
    }), (77, {
        'metoda1': 0,
        'metoda2': 0,
        'metoda3': 12.0
    }), (4, {
        'metoda1': 10.0,
        'metoda2': 0,
        'metoda3': 0
    }), (5, {
        'metoda1': 0,
        'metoda2': 8.0,
        'metoda3': 0
    }), (12, {
        'metoda1': 0,
        'metoda2': 0,
        'metoda3': 6.0
    })]

    userID = 1

    # methods parametes
    portfolioModelDF: DataFrame = PModelDHondtPersonalised(
        ['metoda1', 'metoda2', 'metoda3'])
    pModelDF: DataFrame = portfolioModelDF.getModel(userID)
    print("11111111111111111111111111111")
    print(pModelDF)

    clickedItemID = 12

    tool = EvalToolDHondtPersonal({
        EvalToolDHondtPersonal.ARG_LEARNING_RATE_CLICKS:
        0.2,
        EvalToolDHondtPersonal.ARG_LEARNING_RATE_VIEWS:
        1000
    })
    tool.click(userID, rItemIDsWithResponsibility, clickedItemID,
               portfolioModelDF, {})
    pModelDF: DataFrame = portfolioModelDF.getModel(userID)
    print("22222222222222222222222222222")
    print(pModelDF)