コード例 #1
0
def test01():

    print("Simulation: ML BanditTS")

    jobID: str = "BanditTS"

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

    rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs()

    pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
        "BanditTS" + jobID, rIDs, rDescs,
        InputAggrDefinition.exportADescBanditTS(selector))

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

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

    # simulation of portfolio
    simulator: Simulator = Simulator(batchID, SimulationML, argsSimulationDict,
                                     dataset, behavioursDF)
    simulator.simulate([pDescr], [model], [EvalToolBanditTS({})],
                       [HistoryHierDF(pDescr.getPortfolioID())])
コード例 #2
0
    def run(self, batchID: str, jobID: str):

        from execute.generateBatches import BatchParameters  #class
        divisionDatasetPercentualSize: int
        uBehaviour: str
        repetition: int
        divisionDatasetPercentualSize, uBehaviour, repetition = BatchParameters.getBatchParameters(
        )[batchID]

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

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

        rIDs, rDescs = InputRecomDefinition.exportPairOfRecomIdsAndRecomDescrs(
            datasetID)

        pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription(
            "BanditTS" + jobID, rIDs, rDescs,
            InputAggrDefinition.exportADescBanditTS(selector))

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

        simulator: Simulator = InputSimulatorDefinition.exportSimulatorML1M(
            batchID, divisionDatasetPercentualSize, uBehaviour, repetition)
        simulator.simulate([pDescr], [model], [eTool], HistoryHierDF)
コード例 #3
0
    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 = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs(
        )

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

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

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

        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())])
コード例 #5
0
def test01():
    print("Test 01")

    print("Running EvalToolBanditTS:")

    rItemIDsWithResponsibility: List = [(1, 'metoda1'), (32, 'metoda1'),
                                        (2, 'metoda1'), (8, 'metoda1'),
                                        (6, 'metoda2'), (4, 'metoda1'),
                                        (7, 'metoda3'), (5, 'metoda2'),
                                        (64, 'metoda3'), (77, 'metoda3'),
                                        (12, 'metoda3')]

    # methods parametes
    portfolioModelData: List[tuple] = [['metoda1', 5, 10, 1, 1],
                                       ['metoda2', 5, 12, 1, 1],
                                       ['metoda3', 6, 13, 1, 1]]
    portfolioModelDF: DataFrame = pd.DataFrame(
        portfolioModelData, columns=["methodID", "r", "n", "alpha0", "beta0"])
    portfolioModelDF.set_index("methodID", inplace=True)

    print("Definition:")
    print(portfolioModelDF)
    print()

    evaluationDict: dict = {}

    print("Clicked:")
    EvalToolBanditTS.click(rItemIDsWithResponsibility, 1, portfolioModelDF,
                           evaluationDict)
    print()

    print("Clicked:")
    EvalToolBanditTS.click(rItemIDsWithResponsibility, 32, portfolioModelDF,
                           evaluationDict)
    print()

    print("Clicked:")
    EvalToolBanditTS.click(rItemIDsWithResponsibility, 6, portfolioModelDF,
                           evaluationDict)
    print()

    print("Displayed:")
    rItemIDsWithResponsibility1: List[tuple] = [(1, 'metoda1'),
                                                (32, 'metoda1'),
                                                (2, 'metoda1'), (8, 'metoda1')]
    for i in [0, 1, 2]:
        EvalToolBanditTS.displayed(rItemIDsWithResponsibility1,
                                   portfolioModelDF, evaluationDict)
        print(portfolioModelDF)
コード例 #6
0
def getBanditTS():
  taskID:str = "Web" + "BanditTS" + "Roulette1"

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

  rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs()

  pDescr:Portfolio1AggrDescription = Portfolio1AggrDescription(
    taskID, rIDs, rDescs, InputAggrDefinition.exportADescBanditTS(selector))

  dataset:DatasetST = DatasetST.readDatasets()
  history:AHistory = HistoryHierDF(taskID)

  port:APortfolio = pDescr.exportPortfolio(taskID, history)
  port.train(history, dataset)

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

  return (taskID, port, model, evalTool, history)