Search in sources :

Example 1 with ComparatorRecommendedMovie

use of com.util.ComparatorRecommendedMovie in project Movie by batsqd.

the class ImproveSlopeOne method getPredictMovies.

//返回的map<Movie_Id,Score>
public List<RecommendedMovie> getPredictMovies(int userid, int mums) {
    double[][] primitiveRatingData = ReadRatingData.readRatingFile(Configs.rating_file_path, Configs.countUsers, Configs.countItems);
    Node[][] MovieFansDataset = getMovieFansDataset(Configs.user_file_path, Configs.countUsers, Configs.num_of_feature, primitiveRatingData);
    HashMap<String, double[][]> getDev_avg = getDev_avg(MovieFansDataset);
    double[][] dev_avg = getDev_avg.get("dev_avg");
    List<RecommendedMovie> list = new ArrayList<RecommendedMovie>();
    for (int movie_id = 0; movie_id < Configs.countItems; movie_id++) {
        //应该注意的是在评价矩阵中user_id 0开始,数据库user_id 1开始
        double recommend_value = getPredictUseriToItemj(userid - 1, movie_id, primitiveRatingData, dev_avg);
        if (recommend_value >= 3) {
            //电影预测值大于3,随机选择list中5部电影推送给用户;
            RecommendedMovie recommendedMovie = new RecommendedMovie();
            recommendedMovie.setMovie_id(movie_id);
            recommendedMovie.setRecommend_vale(recommend_value);
            list.add(recommendedMovie);
        }
    //System.out.println(list.size());
    //在这里使用二叉堆选择排名较高的电影,可能要考虑多线程
    }
    List<RecommendedMovie> selectMoviesByRandomToUser = new ArrayList<RecommendedMovie>();
    //randomCommon(0, list.size(), 5) 产生【0 list.size()-1】中的任何随机数5个
    List<Integer> indexs = RandomNumsGenerator.randomCommon(0, list.size(), 5);
    for (int i = 0; i < indexs.size(); i++) {
        selectMoviesByRandomToUser.add(list.get(indexs.get(i)));
    }
    return selectMoviesByRandomToUser;
//打印所有推荐的电影
/*
	    for(int i=0;i<list.size();i++){
	    	System.out.println(list.get(i));
	    }*/
/*
	    ComparatorRecommendedMovie comparator=new ComparatorRecommendedMovie();
	    Collections.sort(list, comparator);
	    
	   List<RecommendedMovie> top_nums_movies=new ArrayList<RecommendedMovie>();
	   for(int i=0;i<mums;i++){
		   //推荐值<2.6不向用户推荐
		   if(list.get(i).getRecommend_vale()>2.6){
			   top_nums_movies.add(list.get(i));
		   }
		   
	   }
	   for(int i=0;i<top_nums_movies.size();i++){
	    	System.out.println(top_nums_movies.get(i).getRecommend_vale());
	    }		
		return top_nums_movies;
		*/
}
Also used : RecommendedMovie(com.po.RecommendedMovie) ComparatorRecommendedMovie(com.util.ComparatorRecommendedMovie) ArrayList(java.util.ArrayList)

Aggregations

RecommendedMovie (com.po.RecommendedMovie)1 ComparatorRecommendedMovie (com.util.ComparatorRecommendedMovie)1 ArrayList (java.util.ArrayList)1