Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codelibs.elasticsearch.taste.recommender;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.codelibs.elasticsearch.taste.common.FastByIDMap;
import org.codelibs.elasticsearch.taste.common.FastIDSet;
import org.codelibs.elasticsearch.taste.common.FullRunningAverage;
import org.codelibs.elasticsearch.taste.common.LongPrimitiveIterator;
import org.codelibs.elasticsearch.taste.common.RefreshHelper;
import org.codelibs.elasticsearch.taste.common.Refreshable;
import org.codelibs.elasticsearch.taste.common.RunningAverage;
import org.codelibs.elasticsearch.taste.exception.NoSuchUserException;
import org.codelibs.elasticsearch.taste.model.DataModel;
import org.codelibs.elasticsearch.taste.model.PreferenceArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
/**
*
* Like {@link ItemAverageRecommender}, except that estimated preferences are adjusted for the users' average
* preference value. For example, say user X has not rated item Y. Item Y's average preference value is 3.5.
* User X's average preference value is 4.2, and the average over all preference values is 4.0. User X prefers
* items 0.2 higher on average, so, the estimated preference for user X, item Y is 3.5 + 0.2 = 3.7.
*
*/
public final class ItemUserAverageRecommender extends AbstractRecommender {
private static final Logger log = LoggerFactory
.getLogger(ItemUserAverageRecommender.class);
private final FastByIDMap itemAverages;
private final FastByIDMap userAverages;
private final RunningAverage overallAveragePrefValue;
private final ReadWriteLock buildAveragesLock;
private final RefreshHelper refreshHelper;
public ItemUserAverageRecommender(final DataModel dataModel) {
super(dataModel);
itemAverages = new FastByIDMap();
userAverages = new FastByIDMap();
overallAveragePrefValue = new FullRunningAverage();
buildAveragesLock = new ReentrantReadWriteLock();
refreshHelper = new RefreshHelper(new Callable