Beispiel #1
0
    NoiseScale = 0.1  # standard deviation of Gaussian noise
    n_articles = 25
    n_users = 10
    poolArticleSize = None

    if actionset == "basis_vector":
        n_articles = context_dimension  # there can be at most context_dimension number of basis vectors

    ## Set Up Simulation ##
    UM = UserManager(context_dimension,
                     n_users,
                     thetaFunc=gaussianFeature,
                     argv={'l2_limit': 1})
    users = UM.simulateThetafromUsers()
    AM = ArticleManager(context_dimension,
                        n_articles=n_articles,
                        argv={'l2_limit': 1})
    articles = AM.simulateArticlePool(actionset)

    simExperiment = simulateOnlineData(
        context_dimension=context_dimension,
        testing_iterations=testing_iterations,
        plot=True,
        articles=articles,
        users=users,
        noise=lambda: np.random.normal(scale=NoiseScale),
        signature=AM.signature,
        NoiseScale=NoiseScale,
        poolArticleSize=poolArticleSize)

    ## Initiate Bandit Algorithms ##
Beispiel #2
0
    else:
        UM = UserManager(context_dimension + latent_dimension,
                         user,
                         argv={'l2_limit': 1})
    UM.CoTheta()

    rewardManagerDict['W'] = UM.getW()
    rewardManagerDict['users'] = UM.getUsers()

    articlesFilename = os.path.join(
        sim_files_folder, "articles_" + str(n_articles) + "context_" +
        str(context_dimension) + "latent_" + str(latent_dimension) +
        "Agroups" + str(ArticleGroups) + ".json")
    AM = ArticleManager(context_dimension + latent_dimension,
                        n_articles=n_articles,
                        ArticleGroups=ArticleGroups,
                        FeatureFunc=featureUniform,
                        argv={'l2_limit': 1})
    if 'load' in article and article['load']:
        articles = AM.loadArticles(
            articles['filename']
        ) if 'filename' in articles else AM.loadArticles(articlesFilename)
    elif simulating:
        articles = AM.simulateArticlePool()
        if 'save' in article and article['save']:
            AM.saveArticles(articles, articlesFilename, force=False)
    rewardManagerDict['k'] = reco['k'] if 'k' in reco else 1
    #reward_type = reco['type'] if reco.has_key('type') else 'linear'

    #PCA
    #pca_articles(articles, 'random')
Beispiel #3
0
	G_alpha = alpha
	G_lambda_ = lambda_
	Gepsilon = 1
	
	userFilename = os.path.join(sim_files_folder, "users_"+str(n_users)+"context_"+str(context_dimension)+"latent_"+str(latent_dimension)+ "Ugroups" + str(UserGroups)+".json")
	
	#"Run if there is no such file with these settings; if file already exist then comment out the below funciton"
	# we can choose to simulate users every time we run the program or simulate users once, save it to 'sim_files_folder', and keep using it.
	UM = UserManager(context_dimension+latent_dimension, n_users, UserGroups = UserGroups, thetaFunc=featureUniform, argv={'l2_limit':1})
	# users = UM.simulateThetafromUsers()
	# UM.saveUsers(users, userFilename, force = False)
	users = UM.loadUsers(userFilename)

	articlesFilename = os.path.join(sim_files_folder, "articles_"+str(n_articles)+"context_"+str(context_dimension)+"latent_"+str(latent_dimension)+ "Agroups" + str(ArticleGroups)+".json")
	# Similarly, we can choose to simulate articles every time we run the program or simulate articles once, save it to 'sim_files_folder', and keep using it.
	AM = ArticleManager(context_dimension+latent_dimension, n_articles=n_articles, ArticleGroups = ArticleGroups,
			FeatureFunc=featureUniform,  argv={'l2_limit':1})
	# articles = AM.simulateArticlePool()
	# AM.saveArticles(articles, articlesFilename, force=False)
	articles = AM.loadArticles(articlesFilename)
	for i in range(len(articles)):
		articles[i].contextFeatureVector = articles[i].featureVector[:context_dimension]

	simExperiment = simulateOnlineData(context_dimension = context_dimension,
						latent_dimension = latent_dimension,
						training_iterations = training_iterations,
						testing_iterations = testing_iterations,
						testing_method = "online", # batch or online
						plot = True,
						articles=articles,
						users = users,		
						noise = lambda : np.random.normal(scale = NoiseScale),
Beispiel #4
0
    #UM.saveUsers(users, userFilename, force = False) # Don't overwrite if the file already exist

    # Load from the saved file
    users = UM.loadUsers(userFilename)
    articlesFilename = os.path.join(
        sim_files_folder, "articles_" + str(n_articles) + "context_" +
        str(context_dimension) + "latent_" + str(latent_dimension) +
        "Agroups" + str(ArticleGroups) + ".json")
    #-----------------------------------------------------------------------------------------------------------------------
    # Generate simulated articles dataset
    #-----------------------------------------------------------------------------------------------------------------------
    # Similarly, generate the possible articles and their context dimensions
    # Similarly, we can choose to simulate articles every time we run the program or simulate articles once, save it to 'sim_files_folder', and keep using it.
    AM = ArticleManager(context_dimension + latent_dimension,
                        n_articles=n_articles,
                        ArticleGroups=ArticleGroups,
                        FeatureFunc=featureUniform,
                        argv={'l2_limit': 1})

    articles = AM.simulateArticlePool()
    # AM.saveArticles(articles, articlesFilename, force=False)
    AM.saveArticles(articles, articlesFilename, force=True)  # Force overwrite
    articles = AM.loadArticles(articlesFilename)
    #-----------------------------------------------------------------------------------------------------------------------

    # PCA
    # Perform PCA on articles
    # and randomly assign articles to each feature vector
    # (e.g. The first article wouldn't be the principal feature vector with largest difference)
    pca_articles(articles, 'random')
Beispiel #5
0
		config["global_dim"] = config["context_dimension"]
	if args.reward_model:
		config["reward_model"] = args.reward_model
	else:
		config["reward_model"] = 'linear'
	config["NoiseScale"] = 0.1  # standard deviation of Gaussian noise
	config["n_articles"] = 1000
	poolArticleSize = 25

	## Set Up Simulation ##
	UM = UserManager(config["context_dimension"], config["n_users"], thetaFunc=gaussianFeature, argv={'l2_limit': 1})
	if config["global_dim"] == config["context_dimension"]:
		users = UM.simulateThetaForHomoUsers()
	else:
		users = UM.simulateThetaForHeteroUsers(global_dim=config["global_dim"])
	AM = ArticleManager(config["context_dimension"], n_articles=config["n_articles"], FeatureFunc=gaussianFeature, argv={'l2_limit': 1}, ArticleGroups=0)
	articles = AM.simulateArticlePool()

	simExperiment = simulateOnlineData(	context_dimension=config["context_dimension"],
										testing_iterations=config["testing_iterations"],
										plot=True,
										articles=articles,
										users = users,
										noise=lambda: np.random.normal(scale=config["NoiseScale"]),
										reward_model=config["reward_model"],
										signature=AM.signature,
										NoiseScale=config["NoiseScale"],
										poolArticleSize=poolArticleSize)

	## Initiate Bandit Algorithms ##
	algorithms = {}
Beispiel #6
0
    UM = UserManager(context_dimension,
                     n_users,
                     UserGroups=UserGroups,
                     thetaFunc=gaussianFeature,
                     argv={'l2_limit': 1})
    users = UM.simulateThetafromUsers()
    # UM.saveUsers(users, userFilename, force = False)
    # users = UM.loadUsers(userFilename)

    articlesFilename = os.path.join(
        sim_files_folder, "articles_" + str(n_articles) + "context_" +
        str(context_dimension) + "Agroups" + str(ArticleGroups) + ".json")
    # Similarly, we can choose to simulate articles every time we run the program or simulate articles once, save it to 'sim_files_folder', and keep using it.
    AM = ArticleManager(context_dimension,
                        n_articles=n_articles,
                        ArticleGroups=ArticleGroups,
                        FeatureFunc=gaussianFeature,
                        argv={'l2_limit': 1})
    articles = AM.simulateArticlePool()
    AM.saveArticles(articles, articlesFilename, force=False)
    articles = AM.loadArticles(articlesFilename)

    for i in range(len(articles)):
        articles[i].contextFeatureVector = articles[
            i].featureVector[:context_dimension]

    simExperiment = simulateOnlineData(
        namelabel=namelabel,
        context_dimension=context_dimension,
        testing_iterations=testing_iterations,
        change_schedule=change_schedule,