Exemple #1
0
def test01():
    print("Test 01")

    m = PModelBandit(["r1", "r2"])
    print(m.head(10))
    print("")

    df = DataFrame([[0, 1, 1, 1, 1]], columns=PModelBandit.getColumns())
    df.set_index(PModelBandit.COL_METHOD_ID, inplace=True)
    df.__class__ = PModelBandit
Exemple #2
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())])
Exemple #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())])
Exemple #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())])
Exemple #5
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)
Exemple #6
0
    scores: List[float] = [x[1] for x in result]
    resultSer: Series = Series(scores, index=itemsIDs)

    finalScores = normalize(np.expand_dims(resultSer.values, axis=0))[0, :]
    resultNorm: List[tuple] = zip(resultSer.index, finalScores.tolist())

    return resultNorm


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

    rItemIdsWitRespons: List[tuple] = [(11, 'metoda1'), (21, 'metoda2')]

    modelData: List[tuple] = [['metoda1', 5, 10, 1,
                               1], ['metoda2', 1, 10, 1, 1],
                              ['metoda3', 2, 20, 1, 1]]
    modelDF: DataFrame = pd.DataFrame(
        modelData, columns=["methodID", "r", "n", "alpha0", "beta0"])
    modelDF.set_index("methodID", inplace=True)

    modelDF: DataFrame = PModelBandit(['metoda1', 'metoda2', 'metoda3'])

    print("Model:")
    print(modelDF)
    print("")

    result: List[tuple] = countAggrBanditsResponsibility(
        rItemIdsWitRespons, modelDF)
    print("Result:")
    print(result)