def test21():

    print("Simulation: ST FuzzyDHondtDirectOptimize")

    jobID: str = "Roulette1"

    selector = RouletteWheelSelector({RouletteWheelSelector.ARG_EXPONENT: 3})

    pProbToolOLin0802HLin1002: APenalization = PenalizationToolDefinition.exportProbPenaltyToolOStat08HLin1002(
        InputSimulatorDefinition.numberOfAggrItems)

    rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs()

    pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
        "FuzzyDHondtDirectOptimize" + jobID, rIDs, rDescs,
        InputAggrDefinition.exportADescDHondtDirectOptimizeThompsonSamplingINF(
            selector, pProbToolOLin0802HLin1002, "DCG"))

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

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

    #lrClick:float = 0.03
    #lrView:float = lrClick / 500
    #eTool:AEvalTool = EvalToolDHondt({EvalToolDHondt.ARG_LEARNING_RATE_CLICKS: lrClick,
    #                                  EvalToolDHondt.ARG_LEARNING_RATE_VIEWS: lrView})
    eTool: AEvalTool = EvalToolDHondtBanditVotes({})
    # simulation of portfolio
    simulator: Simulator = Simulator(batchID, SimulationST, argsSimulationDict,
                                     dataset, behavioursDF)
    simulator.simulate([pDescr], [model], [eTool],
                       [HistoryHierDF(pDescr.getPortfolioID())])
def test21():

    print("Simulation: ST DHontThompsonSampling")

    jobID: str = "Roulette1"

    selector = RouletteWheelSelector({RouletteWheelSelector.ARG_EXPONENT: 1})

    rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs()

    pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
        "DHontThompsonSampling" + jobID, rIDs, rDescs,
        InputAggrDefinition.exportADescDHondtThompsonSampling(selector))

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

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

    evalTool: AEvalTool = EvalToolDHondtBanditVotes({})

    # simulation of portfolio
    simulator: Simulator = Simulator(batchID, SimulationST, argsSimulationDict,
                                     dataset, behavioursDF)
    simulator.simulate([pDescr], [model], [evalTool],
                       [HistoryHierDF(pDescr.getPortfolioID())])
    def exportSimulatorSlantour(self, batchID: str,
                                divisionDatasetPercentualSize: int,
                                uBehaviourID: str, repetition: int):

        argsSimulationDict: dict = {
            SimulationML.ARG_WINDOW_SIZE: 5,
            SimulationML.ARG_RECOM_REPETITION_COUNT: repetition,
            SimulationML.ARG_NUMBER_OF_RECOMM_ITEMS: 100,
            SimulationML.ARG_NUMBER_OF_AGGR_ITEMS: self.numberOfAggrItems,
            SimulationML.ARG_DIV_DATASET_PERC_SIZE:
            divisionDatasetPercentualSize,
            SimulationML.ARG_HISTORY_LENGTH: 10
        }

        # dataset reading
        dataset: ADataset = DatasetST.readDatasets()

        behaviourFile: str = BehavioursST.getFile(uBehaviourID)
        behavioursDF: DataFrame = BehavioursST.readFromFileST(behaviourFile)

        # simulation of portfolio
        simulator: Simulator = Simulator(batchID, SimulationST,
                                         argsSimulationDict, dataset,
                                         behavioursDF)

        return simulator
def test21():

    print("Simulation: ST ContextDHondtINF")

    jobID: str = "Roulette1"

    selector = RouletteWheelSelector({RouletteWheelSelector.ARG_EXPONENT: 1})

    #pProbToolOLin0802HLin1002:APenalization = PenalizationToolDefinition.exportProbPenaltyToolOStat08HLin1002(
    #    InputSimulatorDefinition.numberOfAggrItems)
    pToolOLin0802HLin1002: APenalization = PenalizationToolDefinition.exportPenaltyToolOLin0802HLin1002(
        InputSimulatorDefinition.numberOfAggrItems)

    rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs()

    dataset: ADataset = DatasetST.readDatasets()
    events = dataset.eventsDF
    serials = dataset.serialsDF

    historyDF: AHistory = HistoryDF("test01")

    # Init evalTool
    evalTool: AEvalTool = EvalToolContext({
        EvalToolContext.ARG_ITEMS:
        serials,  # ITEMS
        EvalToolContext.ARG_EVENTS:
        events,  # EVENTS (FOR CALCULATING HISTORY OF USER)
        EvalToolContext.ARG_DATASET:
        "st",  # WHAT DATASET ARE WE IN
        EvalToolContext.ARG_HISTORY:
        historyDF
    })  # empty instance of AHistory is OK for ST dataset

    pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
        "ContextDHondtNIF" + jobID, rIDs, rDescs,
        InputAggrDefinition.exportADescDContextHondtINF(
            selector, pToolOLin0802HLin1002, evalTool))

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

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

    # simulation of portfolio
    simulator: Simulator = Simulator(batchID, SimulationST, argsSimulationDict,
                                     dataset, behavioursDF)
    simulator.simulate([pDescr], [model], [evalTool],
                       [HistoryHierDF(pDescr.getPortfolioID())])
Esempio n. 5
0
def test26():

    print("Simulation: ST VMCMF")

    rDescr:RecommenderDescription = InputRecomSTDefinition.exportRDescVMContextKNN()

    pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomSTDefinition.VMC_KNN.title(),
                                                             InputRecomSTDefinition.VMC_KNN, 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())])
Esempio n. 6
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())])
Esempio n. 7
0
def test21():

    print("Simulation: ST FuzzyDHondt")

    jobID: str = "Roulette1"

    selector = RouletteWheelSelector({RouletteWheelSelector.ARG_EXPONENT: 1})

    rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs()

    pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
        "FuzzyDHondt" + jobID, rIDs, rDescs,
        InputAggrDefinition.exportADescDHondt(selector))

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

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

    lrClick: float = 0.1
    lrView: float = lrClick / 300
    evalTool: AEvalTool = EvalToolDHondt({
        EvalToolDHondt.ARG_LEARNING_RATE_CLICKS:
        lrClick,
        EvalToolDHondt.ARG_LEARNING_RATE_VIEWS:
        lrView
    })

    # simulation of portfolio
    simulator: Simulator = Simulator(batchID, SimulationST, argsSimulationDict,
                                     dataset, behavioursDF)
    simulator.simulate([pDescr], [model], [evalTool],
                       [HistoryHierDF(pDescr.getPortfolioID())])