def run(batchID: str, divisionDatasetPercentualSize: int, uBehaviour: str, repetition: int, jobID: str): aConf: AML1MConf = AML1MConf(batchID, divisionDatasetPercentualSize, uBehaviour, repetition) pDescr: APortfolioDescription = None if jobID == "CosCBmax": pDescr = Portfolio1MethDescription( "CosCBmax", "cosCBmax", InputRecomDefinition.exportRDescCBmean(aConf.datasetID)) elif jobID == "CosCBwindow3": pDescr = Portfolio1MethDescription( "CosCBwindow3", "cosCBwindow3", InputRecomDefinition.exportRDescCBwindow3(aConf.datasetID)) elif jobID == "TMPopular": pDescr = Portfolio1MethDescription( "TMPopular", "theMostPopular", InputRecomDefinition.exportRDescTheMostPopular( aConf.datasetID)) elif jobID == "TMPopular": pDescr = Portfolio1MethDescription( "W2vPosnegMean", "w2vPosnegMean", InputRecomDefinition.exportRDescW2vPosnegMean(aConf.datasetID)) elif jobID == "W2vPosnegWindow3": pDescr = Portfolio1MethDescription( "W2vPosnegWindow3", "w2vPosnegWindow3", InputRecomDefinition.exportRDescW2vPosnegWindow3( aConf.datasetID)) model: DataFrame = pd.DataFrame() eTool: List = EToolSingleMethod({}) aConf.run(pDescr, model, eTool)
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 test01(): print("Simulation: ML TheMostPopular") rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescTheMostPopular() pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.THE_MOST_POPULAR.title(), InputRecomMLDefinition.THE_MOST_POPULAR, rDescr) batchID:str = "ml1mDiv90Ulinear0109R1" dataset:DatasetML = DatasetML.readDatasets() behaviourFile:str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109) behavioursDF:DataFrame = BehavioursML.readFromFileMl1m(behaviourFile) # remove old results #path:str = ".." + os.sep + "results" + os.sep + batchID #try: # os.remove(path + os.sep + "computation-theMostPopular.txt") # os.remove(path + os.sep + "historyOfRecommendation-theMostPopular.txt") # os.remove(path + os.sep + "portfModelTimeEvolution-theMostPopular.txt") #except: # print("An exception occurred") # simulation of portfolio simulator:Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
def test02(): print("Test 02") rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescTheMostPopular( ) recommenderID: str = InputRecomRRDefinition.THE_MOST_POPULAR rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescKNN() recommenderID: str = InputRecomRRDefinition.KNN rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMFIMPL( ) recommenderID: str = InputRecomRRDefinition.BPRMFIMPL rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescVMContextKNN( ) recommenderID: str = InputRecomRRDefinition.VMC_KNN rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescCosineCB( ) recommenderID: str = InputRecomRRDefinition.COSINECB rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescW2V() recommenderID: str = InputRecomRRDefinition.W2V pDescr: Portfolio1MethDescription = Portfolio1MethDescription( recommenderID.title(), recommenderID, rDescr) dataset: ADataset = DatasetRetailRocket.readDatasetsWithFilter( minEventCount=50) behavioursDF: DataFrame = BehavioursRR.readFromFileRR( BehavioursRR.getFile("static08")) history: AHistory = HistoryDF("test") p: APortfolio = pDescr.exportPortfolio("jobID", history) p.train(history, dataset) argsSimulationDict: Dict[str, str] = { SimulationRR.ARG_WINDOW_SIZE: 50, SimulationRR.ARG_RECOM_REPETITION_COUNT: 1, SimulationRR.ARG_NUMBER_OF_RECOMM_ITEMS: 100, SimulationRR.ARG_NUMBER_OF_AGGR_ITEMS: InputSimulatorDefinition.numberOfAggrItems, SimulationRR.ARG_DIV_DATASET_PERC_SIZE: 90, SimulationRR.ARG_HISTORY_LENGTH: 10 } # simulation of portfolio simulator: Simulator = Simulator("test", SimulationRR, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF("a")])
def run(self, batchID:str, jobID:str): divisionDatasetPercentualSize:int uBehaviour:str repetition:int divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition().getBatchParameters(self.datasetID)[batchID] rDescr:RecommenderDescription = self.getParameters()[jobID] recommenderID:str = "W2V" + jobID pDescr:APortfolioDescription = Portfolio1MethDescription(recommenderID.title(), recommenderID, rDescr) simulator:Simulator = InputSimulatorDefinition().exportSimulatorRetailRocket( batchID, divisionDatasetPercentualSize, uBehaviour, repetition) 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 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 test11(): print("Simulation: RR TheMostPopular") rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescTheMostPopular() pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.THE_MOST_POPULAR.title(), InputRecomMLDefinition.THE_MOST_POPULAR, rDescr) batchID:str = "retailrocketDiv90Ulinear0109R1" dataset:DatasetRetailRocket = DatasetRetailRocket.readDatasets() behaviourFile:str = BehavioursRR.getFile(BehavioursRR.BHVR_LINEAR0109) behavioursDF:DataFrame = BehavioursRR.readFromFileRR(behaviourFile) # simulation of portfolio simulator:Simulator = Simulator(batchID, SimulationRR, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
def test03(): print("Simulation: ML KNN") rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescKNN() pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.KNN.title(), InputRecomMLDefinition.KNN, rDescr) batchID:str = "ml1mDiv90Ulinear0109R1" dataset:DatasetML = DatasetML.readDatasets() behaviourFile:str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109) behavioursDF:DataFrame = BehavioursML.readFromFileMl1m(behaviourFile) # simulation of portfolio simulator:Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
def test02(): print("Simulation: ML W2V") rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescW2Vtpositivei50000ws1vs32upsweightedMeanups3() pDescr:APortfolioDescription = Portfolio1MethDescription("W2vPositiveMax", "w2vPositiveMax", rDescr) batchID:str = "ml1mDiv90Ulinear0109R1" dataset:DatasetML = DatasetML.readDatasets() behaviourFile:str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109) behavioursDF:DataFrame = BehavioursML.readFromFileMl1m(behaviourFile) # simulation of portfolio simulator:Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
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 run(self, batchID:str, jobID:str): divisionDatasetPercentualSize:int uBehaviour:str repetition:int divisionDatasetPercentualSize, uBehaviour, repetition = InputABatchDefinition().getBatchParameters(self.datasetID)[batchID] kI:str = self.getParameters()[jobID] recommenderID:str = "RecommendervmContextKNN" + "K" + str(kI) rVMCtKNN:RecommenderDescription = RecommenderDescription(RecommenderVMContextKNN, { RecommenderVMContextKNN.ARG_K: kI}) pDescr:APortfolioDescription = Portfolio1MethDescription(recommenderID.title(), recommenderID, rVMCtKNN) simulator:Simulator = InputSimulatorDefinition().exportSimulatorSlantour( batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
def test04(): print("Simulation: ML CB") #rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescCBmean() rDescr:RecommenderDescription = InputRecomMLDefinition.exportRDescCosineCBcbdOHEupsmaxups1() #pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.COS_CB_MEAN.title(), # InputRecomMLDefinition.COS_CB_MEAN, rDescr) pDescr:APortfolioDescription = Portfolio1MethDescription(InputRecomMLDefinition.COS_CB_WINDOW3.title(), InputRecomMLDefinition.COS_CB_WINDOW3, rDescr) batchID:str = "ml1mDiv90Ulinear0109R1" dataset:DatasetML = DatasetML.readDatasets() behaviourFile:str = BehavioursML.getFile(BehavioursML.BHVR_LINEAR0109) behavioursDF:DataFrame = BehavioursML.readFromFileMl1m(behaviourFile) # simulation of portfolio simulator:Simulator = Simulator(batchID, SimulationML, argsSimulationDict, dataset, behavioursDF) simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], [HistoryHierDF(pDescr.getPortfolioID())])
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] datasetID: str = "ml1m" + "Div" + str(divisionDatasetPercentualSize) recommenderID: str = self.getParameters()[jobID] rDescr: RecommenderDescription = InputRecomDefinition.exportInputRecomDefinition( recommenderID, datasetID) pDescr: APortfolioDescription = Portfolio1MethDescription( recommenderID.title(), recommenderID, rDescr) simulator: Simulator = InputSimulatorDefinition.exportSimulatorML1M( batchID, divisionDatasetPercentualSize, uBehaviour, repetition) simulator.simulate([pDescr], [DataFrame()], [EToolSingleMethod({})], HistoryHierDF)
def test01(): print("Test 01") rDescr: RecommenderDescription = RecommenderDescription( RecommenderTheMostPopular, {}) recommenderID: str = "TheMostPopular" pDescr: Portfolio1MethDescription = Portfolio1MethDescription( recommenderID.title(), recommenderID, rDescr) dataset: ADataset = DatasetML.readDatasets() history: AHistory = HistoryDF("test") p: APortfolio = pDescr.exportPortfolio("jobID", history) p.train(history, dataset) # r, rwr = p.recommend(1, DataFrame(), {APortfolio.ARG_NUMBER_OF_AGGR_ITEMS:20}) # rItemID1 = r[0] # rItemID2 = r[1] # rItemID3 = r[2] # # print(r) # print("rItemID1: " + str(rItemID1)) # print("rItemID2: " + str(rItemID2)) # print("rItemID3: " + str(rItemID3)) testRatingsDF: DataFrame = DataFrame(columns=[ Ratings.COL_USERID, Ratings.COL_MOVIEID, Ratings.COL_RATING, Ratings.COL_TIMESTAMP ]) timeStampI: int = 1000 userID1: int = 1 userID2: int = 2 userID3: int = 3 rItemID1: int = 9001 rItemID2: int = 9002 rItemID3: int = 9003 # training part of dataset for i in [i + 0 for i in range(5 * 8)]: timeStampI = timeStampI + 1 testRatingsDF.loc[i] = [userID1] + list([9000, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID2] + list( [rItemID1, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID2] + list( [rItemID2, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID3] + list( [rItemID3, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID2] + list( [rItemID2, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID2] + list( [rItemID2, 5, timeStampI]) # testing part of dataset userID11: int = 11 userID12: int = 12 timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID11] + list( [rItemID1, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID11] + list( [rItemID2, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID11] + list( [rItemID3, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID12] + list( [rItemID2, 5, timeStampI]) timeStampI = timeStampI + 1 testRatingsDF.loc[len(testRatingsDF)] = [userID11] + list( [rItemID2, 5, timeStampI]) print("len(testRatingsDF): " + str(len(testRatingsDF))) print(testRatingsDF.head(20)) print(testRatingsDF.tail(20)) datasetMy: ADataset = DatasetML("", testRatingsDF, dataset.usersDF, dataset.itemsDF) behavioursDF: DataFrame = DataFrame( columns=[BehavioursML.COL_REPETITION, BehavioursML.COL_BEHAVIOUR]) for ratingIndexI in range(len(testRatingsDF)): for repetitionI in range(5): behavioursDF.loc[ratingIndexI * 5 + repetitionI] = list( [repetitionI, [True] * 20]) print(behavioursDF.head(20)) argsSimulationDict: Dict[str, str] = { SimulationML.ARG_WINDOW_SIZE: 5, SimulationML.ARG_RECOM_REPETITION_COUNT: 1, SimulationML.ARG_NUMBER_OF_RECOMM_ITEMS: 100, SimulationML.ARG_NUMBER_OF_AGGR_ITEMS: InputSimulatorDefinition.numberOfAggrItems, SimulationML.ARG_DIV_DATASET_PERC_SIZE: 90, SimulationML.ARG_HISTORY_LENGTH: 10 } # simulation of portfolio simulator: Simulator = Simulator("test", SimulationML, argsSimulationDict, datasetMy, behavioursDF) simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})], HistoryHierDF)