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())])
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 getFuzzyDHontThompsonSamplingINF(): taskID:str = "Web" + "FuzzyDHondtThompsonSamplingINF" + "Fixed" + "OLin0802HLin1002" selector:ADHondtSelector = TheMostVotedItemSelector({}) penalization:APenalization = PenalizationToolDefinition.exportProbPenaltyToolOLin0802HLin1002(20) aDescDHont:AggregationDescription = InputAggrDefinition.exportADescDHondtThompsonSamplingINF(selector, penalization) rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs() pDescr:Portfolio1AggrDescription = Portfolio1AggrDescription( taskID, rIDs, rDescs, aDescDHont) history:AHistory = HistoryHierDF(taskID) dataset:ADataset = DatasetST.readDatasets() port:APortfolio = pDescr.exportPortfolio(taskID, history) port.train(history, dataset) model:DataFrame = PModelDHondtBanditsVotes(pDescr.getRecommendersIDs()) evalTool:AEvalTool = EvalToolDHondtBanditVotes({}) return (taskID, port, model, evalTool, history)
def getFuzzyDHontINF(): #taskID:str = "Web" + "FuzzyDHondtINF" + "Roulette1" taskID:str = "Web" + "FuzzyDHondt" + "Fixed" dataset:ADataset = DatasetST.readDatasets() #selector:ADHondtSelector = RouletteWheelSelector({RouletteWheelSelector.ARG_EXPONENT: 1}) selector:ADHondtSelector = TheMostVotedItemSelector({}) pToolOLin0802HLin1002:APenalization = PenalizationToolDefinition.exportPenaltyToolOLin0802HLin1002( InputSimulatorDefinition.numberOfAggrItems) aDescDHont:AggregationDescription = InputAggrDefinition.exportADescDHondtINF(selector, pToolOLin0802HLin1002) rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs() pDescr:Portfolio1AggrDescription = Portfolio1AggrDescription( taskID, rIDs, rDescs, aDescDHont) history:AHistory = HistoryHierDF(taskID) port:APortfolio = pDescr.exportPortfolio(taskID, history) port.train(history, dataset) model:DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) evalTool:AEvalTool = EvalToolDHondt({EvalToolDHondt.ARG_LEARNING_RATE_CLICKS: 0.03, EvalToolDHondt.ARG_LEARNING_RATE_VIEWS: 0.03 / 500}) return (taskID, port, model, evalTool, history)
def getContextFuzzyDHondtDirectOptimizeINF(): # taskID:str = "Web" + "ContextFuzzyDHondtDirectOptimizeINF" + "Roulette1" taskID:str = "Web" + "ContextFuzzyDHondtDirectOptimizeINF" + "Fixed" dataset:ADataset = DatasetST.readDatasets() # selector:ADHondtSelector = RouletteWheelSelector({RouletteWheelSelector.ARG_EXPONENT: 1}) selector:ADHondtSelector = TheMostVotedItemSelector({}) pToolOLin0802HLin1002:APenalization = PenalizationToolDefinition.exportProbPenaltyToolOLin0802HLin1002( InputSimulatorDefinition.numberOfAggrItems) rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs() history:AHistory = HistoryHierDF(taskID) # Init eTool evalTool:AEvalTool = EvalToolContext({ EvalToolContext.ARG_ITEMS: dataset.serialsDF, # ITEMS EvalToolContext.ARG_EVENTS: dataset.eventsDF, # EVENTS (FOR CALCULATING HISTORY OF USER) EvalToolContext.ARG_DATASET: "st", # WHAT DATASET ARE WE IN EvalToolContext.ARG_HISTORY: history}) # empty instance of AHistory is OK for ST dataset aDescDHont:AggregationDescription = InputAggrDefinition.exportADescDContextHondtDirectOptimizeINF(selector, pToolOLin0802HLin1002, evalTool) pDescr:Portfolio1AggrDescription = Portfolio1AggrDescription( taskID, rIDs, rDescs, aDescDHont) port:APortfolio = pDescr.exportPortfolio(taskID, history) port.train(history, dataset) model:DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) return (taskID, port, model, evalTool, history)
def test03(): print("Test 03") print("Running Recommender BPRMF on ST:") batchID: str = "batchID" dataset: ADataset = DatasetST.readDatasets() history: AHistory = HistoryHierDF(["aa"]) argumentsDict: Dict[str, object] = { RecommenderBPRMF.ARG_EPOCHS: 2, RecommenderBPRMF.ARG_FACTORS: 10, RecommenderBPRMF.ARG_LEARNINGRATE: 0.05, RecommenderBPRMF.ARG_UREGULARIZATION: 0.0025, RecommenderBPRMF.ARG_BREGULARIZATION: 0, RecommenderBPRMF.ARG_PIREGULARIZATION: 0.0025, RecommenderBPRMF.ARG_NIREGULARIZATION: 0.00025 } r: ARecommender = RecommenderBPRMF(batchID, argumentsDict) r.train(history, dataset) numberOfItems: int = 20 userId: int = 62302 res = r.recommend(userId, numberOfItems, argumentsDict) print(res) userId: int = 3462303 res = r.recommend(userId, numberOfItems, argumentsDict) print(res)
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 test03(): print("Test 03") print("Running RecommenderW2V ST:") dataset: DatasetST = DatasetST.readDatasets() trainDataset: DatasetST = dataset eventsDF: DataFrame = dataset.eventsDF # train recommender argsDict: Dict[str, str] = { RecommenderW2V.ARG_ITERATIONS: 50000, RecommenderW2V.ARG_TRAIN_VARIANT: 'all', RecommenderW2V.ARG_USER_PROFILE_SIZE: 5, RecommenderW2V.ARG_USER_PROFILE_STRATEGY: 'weightedMean', RecommenderW2V.ARG_VECTOR_SIZE: 32, RecommenderW2V.ARG_WINDOW_SIZE: 1, RecommenderW2V.ARG_ALLOWED_ITEMIDS: list(range(0, 1000)) } rec: ARecommender = RecommenderW2V("RecommenderW2V", argsDict) rec.train(HistoryDF("test03"), trainDataset) uDF: DataFrame = DataFrame([eventsDF.iloc[9000]]) print(uDF) rec.update(uDF, argsDict) r: Series = rec.recommend(2760420, 50, argsDict) print(r)
def test01(): print("Test 01") rDescr: RecommenderDescription = RecommenderDescription( RecommenderTheMostPopular, {}) recommenderID: str = "TheMostPopular" pDescr: Portfolio1MethDescription = Portfolio1MethDescription( recommenderID.title(), recommenderID, rDescr) dataset: ADataset = DatasetST.readDatasets() history: AHistory = HistoryDF("test") p: APortfolio = pDescr.exportPortfolio("jobID", history) portFolioModel: DataFrame = DataFrame() p.train(history, dataset) df: DataFrame = DataFrame( [[1, 555]], columns=[Events.COL_USER_ID, Events.COL_OBJECT_ID]) p.update(ARecommender.UPDT_CLICK, df) userID: int = 1 r, rp = p.recommend(userID, portFolioModel, {APortfolio.ARG_NUMBER_OF_AGGR_ITEMS: 20}) print(r)
def test04(): print("Test 04") print("Running Recommender BPRMF on SL:") from datasets.slantour.events import Events # class dataset: DatasetST = DatasetST.readDatasets() trainDataset: DatasetST = dataset eventsDF: DataFrame = dataset.eventsDF uIDMax: int = eventsDF[Events.COL_USER_ID].max() print("uIDMax: " + str(uIDMax)) iIDMax: int = eventsDF[Events.COL_OBJECT_ID].max() print("iIDMax: " + str(iIDMax)) # train recommender rec: ARecommender = RecommenderBPRMFImplicit( "test", { RecommenderBPRMFImplicit.ARG_FACTORS: 20, RecommenderBPRMFImplicit.ARG_ITERATIONS: 50, RecommenderBPRMFImplicit.ARG_LEARNINGRATE: 0.003, RecommenderBPRMFImplicit.ARG_REGULARIZATION: 0.003 }) rec.train(HistoryDF("test04"), trainDataset) uDF1: DataFrame = DataFrame([eventsDF.iloc[9000]]) print(uDF1) rec.update(uDF1, {}) userID1: int = uIDMax + 1 itemID1: int = iIDMax + 1 itemID2: int = iIDMax + 2 # update with unknown user and unknown item uDF2: DataFrame = DataFrame( columns=[Events.COL_USER_ID, Events.COL_OBJECT_ID]) uDF2.loc[0] = [userID1, itemID1] print(uDF2) rec.update(uDF2, {}) # update with unknown item uDF3: DataFrame = DataFrame( columns=[Events.COL_USER_ID, Events.COL_OBJECT_ID]) uDF3.loc[0] = [userID1, itemID2] print(uDF3) rec.update(uDF3, {}) r: Series = rec.recommend(23, 50, {}) print(r) print() # recommend for unknown user r: Series = rec.recommend(userID1, 50, {}) print(r)
def test01(): print("Test 01") dataset: ADataset = DatasetST.readDatasets() print(dataset.serialsDF.columns) print(dataset.serialsDF.head(10)) print(dataset.eventsDF.columns) print(dataset.eventsDF.head(10))
def test03(): print("Test 03") print("Running RecommenderCosineCB ST:") dataset: DatasetST = DatasetST.readDatasets() args: dict = { RecommenderCosineCB.ARG_CB_DATA_PATH: Configuration.cbSTDataFileWithPathTFIDF, # RecommenderCosineCB.ARG_CB_DATA_PATH:Configuration.cbSTDataFileWithPathOHE, RecommenderCosineCB.ARG_USER_PROFILE_SIZE: 5, RecommenderCosineCB.ARG_USER_PROFILE_STRATEGY: "max", RecommenderCosineCB.ARG_USE_DIVERSITY: False, RecommenderCosineCB.ARG_ALLOWED_ITEMIDS: list(range(0, 1000)) } #True rec: ARecommender = RecommenderCosineCB("test", args) rec.train(HistoryDF("test"), dataset) #eventsDFDFUpdate:DataFrame = dataset.eventsDF.iloc[5003:5004] #print(eventsDFDFUpdate) #rec.update(eventsDFDFUpdate, args) # user with very outdated profile - no recent objects r: Series = rec.recommend(3500678, 10, args) #print(type(r)) print(r) args: dict = { RecommenderCosineCB.ARG_CB_DATA_PATH: Configuration.cbSTDataFileWithPathTFIDF, # RecommenderCosineCB.ARG_CB_DATA_PATH:Configuration.cbSTDataFileWithPathOHE, RecommenderCosineCB.ARG_USER_PROFILE_SIZE: 5, RecommenderCosineCB.ARG_USER_PROFILE_STRATEGY: "max", RecommenderCosineCB.ARG_USE_DIVERSITY: True, RecommenderCosineCB.ARG_MMR_LAMBDA: 0.5, RecommenderCosineCB.ARG_ALLOWED_ITEMIDS: list(range(0, 1000)) } #True rec: ARecommender = RecommenderCosineCB("test", args) rec.train(HistoryDF("test"), dataset) r: Series = rec.recommend(3500678, 10, args) print(r) """
def test03(): print("Test 03") dataset: ADataset = DatasetST.readDatasets() print(dataset.getTheMostSold()) #eventsDF:DataFrame = dataset.eventsDF #eventsDF = eventsDF.loc[eventsDF[Events.COL_OBJECT_ID] != 0] print(dataset.eventsDF.columns) print(dataset.serialsDF.columns) print(dataset.eventsDF["userID"].max())
def test03(): print("Test 03") print("Running RecommenderVSKNN ST:") dataset: DatasetST = DatasetST.readDatasets() testD = dataset.eventsDF.iloc[4000:10000] dataset.eventsDF = dataset.eventsDF.iloc[0:4000] # train recommender rec: ARecommender = RecommenderVMContextKNN("test", {}) start = time.time() rec.train(HistoryDF("test03"), dataset) end = time.time() print("Time to train: " + str(end - start)) i = 0 """ maxI = 5990 while i < maxI: eventsDFDFUpdate:DataFrame = dataset.eventsDF.iloc[i:i+1] rec.update(rec.UPDT_CLICK, eventsDFDFUpdate) i = i+1 if i%100 == 0: print(i) """ r: Series = rec.recommend(3342336, 20, {rec.ARG_ALLOWED_ITEMIDS: list(range(0, 1000))}) print(type(r)) print(r) r: Series = rec.recommend(2035310, 20, {rec.ARG_ALLOWED_ITEMIDS: list(range(0, 1000))}) print(type(r)) print(r) r: Series = rec.recommend(3342341, 20, {rec.ARG_ALLOWED_ITEMIDS: list(range(0, 1000))}) print(type(r)) print(r) # testing of a non-existent user r: Series = rec.recommend(10000, 50, {rec.ARG_ALLOWED_ITEMIDS: list(range(0, 1000))}) print(type(r)) print(r) print("================== END OF TEST 03 ======================\n\n\n\n\n")
def run(self, batchID: str, jobID: str): divisionDatasetPercentualSize: int uBehaviour: str repetition: int divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition( ).getBatchParameters(self.datasetID)[batchID] selector: ADHondtSelector selector, negativeImplFeedback = self.getParameters()[jobID] portfolioID: str = self.getBatchName() + jobID history: AHistory = HistoryHierDF(portfolioID) dataset: ADataset = DatasetST.readDatasets() events = dataset.eventsDF serials = dataset.serialsDF historyDF: AHistory = HistoryHierDF("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 rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs( ) aDescContextDHont: AggregationDescription = InputAggrDefinition.exportADescDContextHondtINF( selector, negativeImplFeedback, evalTool) pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( portfolioID, rIDs, rDescs, aDescContextDHont) model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) simulator: Simulator = InputSimulatorDefinition( ).exportSimulatorSlantour(batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [model], [evalTool], [history])
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())])
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())])
def test02(): print("Test 02") dataset: ADataset = DatasetST.readDatasets() pd.set_option('display.max_rows', None) pd.set_option('display.max_columns', None) pd.set_option('display.width', None) pd.set_option('display.max_colwidth', -1) eventsDF: DataFrame = dataset.eventsDF eventsDF = eventsDF.loc[eventsDF[Events.COL_OBJECT_ID] != 0] print(eventsDF.columns) print(eventsDF[[ Events.COL_VISIT_ID, Events.COL_USER_ID, Events.COL_OBJECT_ID ]].head(100))
def test13(): print("Test 13") print("Running Recommender BPRMF on ST:") from datasets.slantour.events import Events # class batchID: str = "batchID" trainDataset: ADataset testDataset: ADataset trainDataset, testDataset = DatasetST.readDatasets().divideDataset(90) testUserIDs: ndarray = testDataset.eventsDF[Events.COL_USER_ID].unique() history: AHistory = HistoryHierDF(["aa"]) numberOfItems: int = 20 rd: RecommenderDescription = InputRecomSTDefinition.exportRDescBPRMFIMPLf50i20lr01r003( ) rd: RecommenderDescription = InputRecomSTDefinition.exportRDescBPRMF() #rd:RecommenderDescription = InputRecomSTDefinition.exportRDescTheMostPopular() #rd:RecommenderDescription = InputRecomSTDefinition.exportRDescKNN() #rd:RecommenderDescription = InputRecomSTDefinition.exportRDescCosineCBcbdOHEupsweightedMeanups5() #rd:RecommenderDescription = InputRecomSTDefinition.exportRDescW2Vtalli100000ws1vs32upsmaxups1() #rd:RecommenderDescription = InputRecomSTDefinition.exportRDescW2talli200000ws1vs64upsweightedMeanups5() r: ARecommender = rd.exportRecommender("aaa") argumentsDict: Dict = rd.getArguments() r.train(history, trainDataset) numberOfHit: int = 0 for userIdI in testUserIDs[0:1000]: 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_USER_ID] == userIdI][ Events.COL_OBJECT_ID].unique() itemIdsHitted: List[int] = list(set(recItemIDsI) & set(windowItemIds)) numberOfHit += len(itemIdsHitted) print("") print("numberOfHit: " + str(numberOfHit))
def getW2Vtalli100000ws1vs32upsmaxups1(): taskID:str = "Web" + "W2Vtalli100000ws1vs32upsmaxups1" rDescr:RecommenderDescription = InputRecomSTDefinition.exportRDescW2Vtalli100000ws1vs32upsmaxups1() recommenderID:str = "W2V" pDescr:Portfolio1MethDescription = Portfolio1MethDescription(recommenderID.title(), recommenderID, rDescr) dataset:ADataset = DatasetST.readDatasets() history:AHistory = HistoryHierDF(taskID) port:APortfolio = pDescr.exportPortfolio(taskID, history) port.train(history, dataset) model:DataFrame = DataFrame() evalTool:AEvalTool = EToolDoNothing({}) return (taskID, port, model, evalTool, history)
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)
def visualizationST(): print("visualizationST") from datasets.slantour.events import Events # class # dataset reading dataset: ADataset = DatasetST.readDatasets() #dataset:ADataset = DatasetST.readDatasetsSkipOutlierUsers(500) print(dataset.eventsDF.head()) userIdsWithDuplicites: List[int] = dataset.eventsDF[ Events.COL_USER_ID].tolist() userIds: List[int] = list(set(userIdsWithDuplicites)) plt.hist(userIdsWithDuplicites, len(userIds), None, fc='none', lw=1.5, histtype='step') plt.ticklabel_format(style='plain') plt.show()
def visualizationST2(): print("visualizationST2") from datasets.slantour.events import Events # class dataset: ADataset = DatasetST.readDatasets() eventsDF: Events = dataset.eventsDF eventsDF.sort_values(by=[Events.COL_START_DATE_TIME], inplace=True) userIdsWithDuplicites: List[int] = eventsDF[Events.COL_USER_ID].tolist() userIds: List[int] = list(set(userIdsWithDuplicites)) print("userIdsCount: " + str(len(userIds))) #return for userIdI in userIds: indexesOfUserI: List[int] = eventsDF[eventsDF[Events.COL_USER_ID] == userIdI].index.tolist() print(indexesOfUserI) distanceI: int = max(indexesOfUserI) - min(indexesOfUserI) print(distanceI)
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())])
def test03(): # First get Dataset Data dataset: ADataset = DatasetST.readDatasets() events = dataset.eventsDF serials = dataset.serialsDF # I created some dummy data, but each key,value pair should be result list from a recommender # (=what recommender recommended) 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") } # init votes for each recommender portfolioModelData = [['metoda1', 0.6], ['metoda2', 0.4]] portfolioModelDF: DataFrame = pd.DataFrame(portfolioModelData, columns=["methodID", "votes"]) portfolioModelDF.set_index("methodID", inplace=True) userID = 1 itemID = 20 historyDF: AHistory = HistoryDF("test01") # WHAT EVALUATIOR NEEDS into dictionary! evaluationDict: dict = { EvalToolContext.ARG_USER_ID: userID, EvalToolContext.ARG_ITEM_ID: itemID, # ITEMID (not mandatory if EvalToolContext.ARG_PAGE_TYPE != "zobrazit") EvalToolContext.ARG_SENIORITY: 5, # SENIORITY OF USER EvalToolContext.ARG_PAGE_TYPE: "zobrazit", # TYPE OF PAGE ("zobrazit", "index" or "katalog) EvalToolContext.ARG_ITEMS_SHOWN: 10 # HOW MANY ITEMS ARE SHOWN TO USER } # Init eTool eToolContext = 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 ) aggr: AggrContextFuzzyDHondt = AggrContextFuzzyDHondt( historyDF, { # empty instance of AHistory is OK for ST dataset AggrContextFuzzyDHondt.ARG_EVAL_TOOL: eToolContext, # eTool AggrContextFuzzyDHondt.ARG_SELECTOR: TheMostVotedItemSelector( {}) # ? FuzzyDHondt needs this, not contextAggr }) # Get data from aggregator rItemsWithResponsibility = aggr.runWithResponsibility( methodsResultDict, portfolioModelDF, userID, numberOfItems=5, argumentsDict=evaluationDict) # call click & displayed methods l1 = eToolContext.displayed(rItemsWithResponsibility, portfolioModelDF, evaluationDict) # rItemsWithResponsibility[0][0] is clicked item print(rItemsWithResponsibility) l1 = eToolContext.click(rItemsWithResponsibility, rItemsWithResponsibility[0][0], portfolioModelDF, evaluationDict) # ... # ... # ... # user is now on "index" page type, so we have to change page type in evaluationDict (!) evaluationDict[EvalToolContext.ARG_PAGE_TYPE] = "index" # same as before # Get data from aggregator rItemsWithResponsibility = aggr.runWithResponsibility( methodsResultDict, portfolioModelDF, userID, numberOfItems=5, argumentsDict=evaluationDict) # call click & displayed methods l1 = eToolContext.displayed(rItemsWithResponsibility, portfolioModelDF, evaluationDict) # rItemsWithResponsibility[0][0] is clicked item l1 = eToolContext.click(rItemsWithResponsibility, rItemsWithResponsibility[0][0], portfolioModelDF, evaluationDict)