コード例 #1
0
ファイル: Simulation.py プロジェクト: ZeroWeight/BanditLib
    else:
        use_coUsers = 'collaborative' in user and user['collaborative']
        reward_type = reco['type'] if 'type' in reco else 'linear'

    #if user.has_key('collaborative') and user['collaborative']:
    if use_coUsers:
        UM = CoUserManager(context_dimension + latent_dimension,
                           user,
                           argv={
                               'l2_limit': 1,
                               'sparseLevel': n_users,
                               'matrixNoise': rewardManagerDict['matrixNoise']
                           })
    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})
コード例 #2
0
	# Matrix parameters
	matrixNoise = 0.01
	sparseLevel = n_users  # if smaller or equal to 0 or larger or enqual to usernum, matrix is fully connected


	# Parameters for GOBLin
	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)
	
	#PCA
	pca_articles(articles, 'random')