def test02(): print("Test 02") # methods parametes portfolioModelData1: List[tuple] = [['metoda1', 100], ['metoda2', 80], ['metoda3', 60]] portfolioModel1: DataFrame = pd.DataFrame(portfolioModelData1, columns=["methodID", "votes"]) portfolioModel1.set_index("methodID", inplace=True) portfolioModel1.__class__ = PModelDHondt #portfolioModel1.linearNormalizing() portfolioModelData2: List[tuple] = [['metoda2', 20], ['metoda3', 40], ['metoda1', 0]] portfolioModel2: DataFrame = pd.DataFrame(portfolioModelData2, columns=["methodID", "votes"]) portfolioModel2.set_index("methodID", inplace=True) portfolioModel2.__class__ = PModelDHondt #print(portfolioModel1.head()) #print(portfolioModel2.head()) rModel = PModelDHondt.sumModels(portfolioModel1, portfolioModel2) print(rModel) print() PModelDHondt.linearNormalizingPortfolioModelDHondt(rModel) print(rModel)
def getModel(self, userID:int, argsDict:dict): status:float = argsDict[ASequentialSimulation.ARG_STATUS] print("status: " + str(status)) mGlobal:DataFrame = self.getModelGlobal() if self.modeSkip: print("aaaaaaaaaaaaaaaaa") numberOfClick:int = self.getModelPersonAllUsers().getNumberOfClick(userID) print("numberOfClick: " + str(numberOfClick)) if numberOfClick < self.skipClickThreshold: return mGlobal mGlobal.linearNormalizing() #print("GLOBAL:") #print(mGlobal.head(10)) mGlobal = PModelDHondt.multiplyModel(mGlobal, 1.0 - status) mPerson:DataFrame = self.getModelPerson(userID) mPerson.linearNormalizing() mPerson = PModelDHondt.multiplyModel(mPerson, status) rPModel:DataFrame = PModelDHondt.sumModels(mGlobal, mPerson) rPModel.linearNormalizing() #print("VYSLEDNY:") #print(rPModel.head(10)) return rPModel
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 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 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] itemsDF:DataFrame = Items.readFromFileMl1m() usersDF:DataFrame = Users.readFromFileMl1m() historyDF:AHistory = HistoryHierDF("test01") eTool:AEvalTool = EvalToolContext({ EvalToolContext.ARG_USERS: usersDF, EvalToolContext.ARG_ITEMS: itemsDF, EvalToolContext.ARG_DATASET: "ml", EvalToolContext.ARG_HISTORY: historyDF}) rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs() aDescDHont:AggregationDescription = InputAggrDefinition.exportADescContextFuzzyDHondtDirectOptimize(selector, eTool) pDescr:Portfolio1AggrDescription = Portfolio1AggrDescription( self.getBatchName() + jobID, rIDs, rDescs, aDescDHont) model:DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) simulator:Simulator = InputSimulatorDefinition().exportSimulatorML1M( batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
def run(self, batchID: str, jobID: str): divisionDatasetPercentualSize: int uBehaviour: str repetition: int divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition( ).getBatchParameters(self.datasetID)[batchID] #eTool:AEvalTool selector, eTool = self.getParameters()[jobID] rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs( ) aDescDHont: AggregationDescription = InputAggrDefinition.exportADescDHondt( selector) pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( self.getBatchName() + jobID, rIDs, rDescs, aDescDHont) model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) simulator: Simulator = InputSimulatorDefinition( ).exportSimulatorSlantour(batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
def test01(): print("Simulation: ML 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 = "ml1mDiv90Ulinear0109R1" dataset: DatasetML = DatasetML.readDatasets() behaviourFile: str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109) behavioursDF: DataFrame = BehavioursML.readFromFileMl1m(behaviourFile) model: DataFrame = PModelDHondt(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 }) # simulation of portfolio simulator: Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
def run(self, batchID: str, jobID: str): divisionDatasetPercentualSize: int uBehaviour: str repetition: int divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition( ).getBatchParameters(self.datasetID)[batchID] eTool: AEvalTool = EToolDoNothing({}) rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs( ) aDescWeightedFAI: AggregationDescription = InputAggrDefinition.exportADescFAI( ) pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( "FAI" + jobID, rIDs, rDescs, aDescWeightedFAI) model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) simulator: Simulator = InputSimulatorDefinition( ).exportSimulatorRetailRocket(batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
def run(self, batchID: str, jobID: str): divisionDatasetPercentualSize: int uBehaviour: str repetition: int divisionDatasetPercentualSize, uBehaviour, repetition = \ InputABatchDefinition().getBatchParameters(self.datasetID)[batchID] # eTool:AEvalTool selector, eTool = self.getParameters()[jobID] rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs( ) aDescDHont: AggregationDescription = InputAggrDefinition.exportADescDHondt( selector) pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( self.getBatchName() + jobID, rIDs, rDescs, aDescDHont) rIds: List[str] = pDescr.getRecommendersIDs() model: DataFrame = PModelHybrid( PModelDHondt(rIds), PModelDHondtPersonalisedStat(rIds), { PModelHybrid.ARG_MODE_SKIP: True, PModelHybrid.ARG_SKIP_CLICK_THRESHOLD: 3 }) simulator: Simulator = InputSimulatorDefinition().exportSimulatorML1M( batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
def test02(): print("Test 02") rIDs, rDescr = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs() model: DataFrame = PModelDHondt(rIDs) print(model) userID: int = 1 rItemIDsWithResponsibility: List[(int, Dict)] = [(1, { rIDs[0]: 0.05, rIDs[1]: 0.05, rIDs[2]: 0.05, rIDs[3]: 0.05, rIDs[4]: 0.05, rIDs[5]: 0.05, rIDs[6]: 0.05, rIDs[7]: 0.65 })] lrClick: float = 0.03 lrView: float = lrClick / 500 evalTool: AEvalTool = EvalToolDHondt({ EvalToolDHondt.ARG_LEARNING_RATE_CLICKS: lrClick, EvalToolDHondt.ARG_LEARNING_RATE_VIEWS: lrView }) evalTool.click(userID, rItemIDsWithResponsibility, 1, model, {}) for i in range(555): evalTool.displayed(userID, rItemIDsWithResponsibility, model, {}) print(model)
def test01(): print("Test 01") rIDs, rDescs = InputRecomRRDefinition.exportPairOfRecomIdsAndRecomDescrs() mGlobal: DataFrame = PModelDHondt(rIDs) mPerson: DataFrame = PModelDHondtPersonalisedStat(rIDs) mh: DataFrame = PModelHybrid(mGlobal, mPerson) mh.getModel(1)
def __init__(self, recommendersIDs: List[str]): pM1: DataFrame = PModelDHondt(recommendersIDs) #print(pM1.head(10)) modelDHontData = [[float('nan'), pM1]] super(PModelDHondtPersonalised, self).__init__(modelDHontData, columns=[ PModelDHondtPersonalised.COL_USER_ID, PModelDHondtPersonalised.COL_MODEL ]) self.set_index(PModelDHondtPersonalised.COL_USER_ID, inplace=True)
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 test03(): print("Test 03") # methods parametes portfolioModelData1: List[tuple] = [['metoda1', 100], ['metoda2', 80], ['metoda3', 60]] portfolioModel1: DataFrame = pd.DataFrame(portfolioModelData1, columns=["methodID", "votes"]) portfolioModel1.set_index("methodID", inplace=True) portfolioModel1.__class__ = PModelDHondt #portfolioModel1.linearNormalizing() rModel = PModelDHondt.multiplyModel(portfolioModel1, 0.2) print(rModel)
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 run(self, batchID: str, jobID: str): divisionDatasetPercentualSize: int uBehaviour: str repetition: int divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition( ).getBatchParameters(self.datasetID)[batchID] selector: ADHondtSelector negativeImplFeedback: APenalization selector, negativeImplFeedback = self.getParameters()[jobID] portfolioID: str = self.getBatchName() + jobID history: AHistory = HistoryHierDF(portfolioID) dataset: ADataset = DatasetML.readDatasets() usersDF = dataset.usersDF itemsDF = dataset.itemsDF # Init evalTool evalTool: AEvalTool = EvalToolContext({ EvalToolContext.ARG_USERS: usersDF, EvalToolContext.ARG_ITEMS: itemsDF, EvalToolContext.ARG_DATASET: "ml", EvalToolContext.ARG_HISTORY: history }) rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs( ) aDescContextDHont: AggregationDescription = InputAggrDefinition.exportADescDContextHondtINF( selector, negativeImplFeedback, evalTool) pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( portfolioID, rIDs, rDescs, aDescContextDHont) model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) simulator: Simulator = InputSimulatorDefinition().exportSimulatorML1M( batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [model], [evalTool], [history])
def test01(): print("Simulation: ML ContextDHondtINF") jobID: str = "Roulette1" selector = RouletteWheelSelector({RouletteWheelSelector.ARG_EXPONENT: 1}) #pProbToolOLin0802HLin1002:APenalization = PenalizationToolDefinition.exportProbPenaltyToolOStat08HLin1002( # InputSimulatorDefinition.numberOfAggrItems) pToolOLin0802HLin1002: APenalization = PenalizationToolDefinition.exportPenaltyToolOLin0802HLin1002( InputSimulatorDefinition.numberOfAggrItems) itemsDF: DataFrame = Items.readFromFileMl1m() usersDF: DataFrame = Users.readFromFileMl1m() historyDF: AHistory = HistoryDF("test01") eTool: AEvalTool = EvalToolContext({ EvalToolContext.ARG_USERS: usersDF, EvalToolContext.ARG_ITEMS: itemsDF, EvalToolContext.ARG_DATASET: "ml", EvalToolContext.ARG_HISTORY: historyDF }) rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs() pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( "ContextDHondtINF" + jobID, rIDs, rDescs, InputAggrDefinition.exportADescDContextHondtINF( selector, pToolOLin0802HLin1002, eTool)) batchID: str = "ml1mDiv90Ulinear0109R1" dataset: DatasetML = DatasetML.readDatasets() behaviourFile: str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109) behavioursDF: DataFrame = BehavioursML.readFromFileMl1m(behaviourFile) model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) # simulation of portfolio simulator: Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
def recommend(self, userID: int, portFolioModel: DataFrame, argumentsDict: Dict[str, object]): #print("userID: " + str(userID)) if type(userID) is not int and type(userID) is not np.int64: raise ValueError("Argument userID isn't type int.") if not isinstance(portFolioModel, DataFrame): raise ValueError("Argument portFolioModel isn't type DataFrame.") if type(argumentsDict) is not dict: raise ValueError("Argument argumentsDict isn't type dict.") currentItemID: int = argumentsDict[self.ARG_ITEM_ID] numberOfRecomItems: int = argumentsDict[ self.ARG_NUMBER_OF_RECOMM_ITEMS] numberOfAggrItems: int = argumentsDict[self.ARG_NUMBER_OF_AGGR_ITEMS] arguments2Dict: Dict[str, object] = {} #arguments2Dict.update(self._recomDesc.getArguments()) arguments2Dict.update(argumentsDict) # creates model if doesn't exist modelOfUserID: DataFrame = portFolioModel.getModel(userID) if portFolioModel.loc[ userID, PModelDHondtPersonalisedStat.COL_CLICK_COUNT] < 1: print("ahoj franto") itemIDsWithResponsibility: Series = self._recommender.recommend( userID, numberOfItems=numberOfRecomItems, argumentsDict=arguments2Dict) recomItemIDs: List[int] = list( int(itemIdI) for itemIdI in itemIDsWithResponsibility.index) a = PModelDHondt.getEqualResponsibilityForAll( recomItemIDs, self.getRecommIDs()) print("recomItemIDs: " + str(recomItemIDs)) print("aaa: " + str(a)) return (recomItemIDs, a) print("cus franto") aggItemIDs, aggItemIDsWithResponsibility = self._portfolioInternal.recommend( userID, portFolioModel, argumentsDict) # Tuple return (aggItemIDs, aggItemIDsWithResponsibility)
def test21(): print("Simulation: ST FuzzyDHondtINF") 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() pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( "FuzzyDHondtINF" + jobID, rIDs, rDescs, InputAggrDefinition.exportADescDHondtINF(selector, pToolOLin0802HLin1002)) 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 test31(): print("Simulation: RR FuzzyDHondt") 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() pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( "FDHondt" + jobID, rIDs, rDescs, InputAggrDefinition.exportADescDHondt(selector)) batchID: str = "rrDiv90Ulinear0109R1" dataset: DatasetRetailRocket = DatasetRetailRocket.readDatasetsWithFilter( minEventCount=50) behaviourFile: str = BehavioursRR.getFile(BehavioursRR.BHVR_LINEAR0109) behavioursDF: DataFrame = BehavioursRR.readFromFileRR(behaviourFile) model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) print(model) evalTool: AEvalTool = EvalToolDHondt({ 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], [evalTool], [HistoryHierDF(pDescr.getPortfolioID())])
def test01(): print("Simulation: ML ContextFuzzyDHondtDirectOptimize") jobID: str = "Roulette1" selector: ADHondtSelector = RouletteWheelSelector( {RouletteWheelSelector.ARG_EXPONENT: 1}) itemsDF: DataFrame = Items.readFromFileMl1m() usersDF: DataFrame = Users.readFromFileMl1m() historyDF: AHistory = HistoryHierDF("test01") eTool: AEvalTool = EvalToolContext({ EvalToolContext.ARG_USERS: usersDF, EvalToolContext.ARG_ITEMS: itemsDF, EvalToolContext.ARG_DATASET: "ml", EvalToolContext.ARG_HISTORY: historyDF }) rIDs, rDescs = InputRecomSTDefinition.exportPairOfRecomIdsAndRecomDescrs() pDescr: Portfolio1AggrDescription = Portfolio1AggrDescription( "ContextFuzzyDHondtDirectOptimize" + jobID, rIDs, rDescs, InputAggrDefinition.exportADescContextFuzzyDHondtDirectOptimize( selector, eTool)) batchID: str = "ml1mDiv90Ulinear0109R1" dataset: DatasetML = DatasetML.readDatasets() behaviourFile: str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109) behavioursDF: DataFrame = BehavioursML.readFromFileMl1m(behaviourFile) model: DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) # simulation of portfolio simulator: Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [model], [eTool], [historyDF])
def run(self, batchID:str, jobID:str): divisionDatasetPercentualSize:int uBehaviour:str repetition:int divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition().getBatchParameters(self.datasetID)[batchID] selector, nImplFeedback = self.getParameters()[jobID] eTool:AEvalTool = EvalToolDHondt({EvalToolDHondt.ARG_LEARNING_RATE_CLICKS: 0.02, EvalToolDHondt.ARG_LEARNING_RATE_VIEWS: 1000}) rIDs, rDescs = InputRecomMLDefinition.exportPairOfRecomIdsAndRecomDescrs() aDescFuzzyHontDirectOptimizeINF:AggregationDescription = InputAggrDefinition.exportADescDFuzzyHondtDirectOptimizeINF(selector, nImplFeedback) pDescr:Portfolio1AggrDescription = Portfolio1AggrDescription( self.getBatchName() + jobID, rIDs, rDescs, aDescFuzzyHontDirectOptimizeINF) model:DataFrame = PModelDHondt(pDescr.getRecommendersIDs()) simulator:Simulator = InputSimulatorDefinition().exportSimulatorML1M( batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [model], [eTool], [HistoryHierDF(pDescr.getPortfolioID())])
def test01(): print("Test 01") m = PModelDHondt(["r1", "r2"]) print(m.head(10))