// Path: rival-core/src/main/java/net/recommenders/rival/core/DataModelIF.java
// public interface DataModelIF<U, I> {
// 
//     /**
//      * Method that returns the preference between a user and an item.
//      *
//      * @param u the user.
//      * @param i the item.
//      * @return the preference between a user and an item.
//      */
//     public Double getUserItemPreference(U u, I i);
// 
//     /**
//      * Method that returns the items of a user.
//      *
//      * @param u the user.
//      * @return the items of a user.
//      */
//     public Iterable<I> getUserItems(U u);
// 
//     /**
//      * Method that adds a preference to the model between a user and an item.
//      *
//      * @param u the user.
//      * @param i the item.
//      * @param d the preference.
//      */
//     public void addPreference(final U u, final I i, final Double d);
// 
//     /**
//      * Method that returns the items in the model.
//      *
//      * @return the items in the model.
//      */
//     public Iterable<I> getItems();
// 
//     /**
//      * Method that returns the users in the model.
//      *
//      * @return the users in the model.
//      */
//     public Iterable<U> getUsers();
// 
//     /**
//      * Method that returns the number of items in the model.
//      *
//      * @return the number of items in the model.
//      */
//     public int getNumItems();
// 
//     /**
//      * Method that returns the number of users in the model.
//      *
//      * @return the number of users in the model.
//      */
//     public int getNumUsers();
// 
//     /**
//      * Method that clears all the maps contained in the model.
//      */
//     public void clear();
// }
// 
// Path: rival-evaluate/src/main/java/net/recommenders/rival/evaluation/metric/EvaluationMetric.java
// public interface EvaluationMetric<V> {
// 
//     /**
//      * Get the overall value of the metric.
//      *
//      * @return The overall value of the metric.
//      */
//     double getValue();
// 
//     /**
//      * Get the value of the metric on a per-user basis.
//      *
//      * @return Map containing the values per user.
//      */
//     Map<V, Double> getValuePerUser();
// 
//     /**
//      * Get the value of the metric for a specific user.
//      *
//      * @param u user whose metric value will be computed
//      *
//      * @return a value for user u.
//      */
//     double getValue(V u);
// 
//     /**
//      * Computes the evaluation metric. This method should be called
//      * <b>before</b> asking for the values of the metric.
//      */
//     void compute();
// }
// 
// Path: rival-evaluate/src/main/java/net/recommenders/rival/evaluation/Pair.java
// public class Pair<A, B> {
// 
//     /**
//      * First element.
//      */
//     private A first;
//     /**
//      * Second element.
//      */
//     private B second;
// 
//     /**
//      * Default constructor.
//      *
//      * @param firstElement first element to store
//      * @param secondElement second element to store
//      */
//     public Pair(final A firstElement, final B secondElement) {
//         this.first = firstElement;
//         this.second = secondElement;
//     }
// 
//     /**
//      * Gets the first element of the pair.
//      *
//      * @return the first element of the pair
//      */
//     public A getFirst() {
//         return first;
//     }
// 
//     /**
//      * Gets the second element of the pair.
//      *
//      * @return the second element of the pair
//      */
//     public B getSecond() {
//         return second;
//     }
// }


import net.recommenders.rival.core.DataModelIF;
import net.recommenders.rival.evaluation.metric.EvaluationMetric;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.recommenders.rival.evaluation.Pair;
/*
 * Copyright 2015 recommenders.net.
 *
 * Licensed 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 net.recommenders.rival.evaluation.metric.ranking;



/**
 * Recall of a ranked list of items.
 *
 * @author <a href="http://github.com/abellogin">Alejandro</a>.
 *
 * @param <U> - type associated to users' ids
 * @param <I> - type associated to items' ids
 */
public class Recall<U, I> extends AbstractRankingMetric<U, I> implements EvaluationMetric<U> {

    /**
     * Recall values per user at each cutoff level.
     */
    private Map<Integer, Map<U, Double>> userRecallAtCutoff;

    /**
     * Default constructor with predictions and groundtruth information.
     *
     * @param predictions predicted scores for users and items
     * @param test groundtruth information for users and items
     */
    public Recall(final DataModelIF<U, I> predictions, final DataModelIF<U, I> test) {
        this(predictions, test, 1.0);
    }

    /**
     * Constructor where the relevance threshold can be initialized.
     *
     * @param predictions predicted ratings
     * @param test groundtruth ratings
     * @param relThreshold relevance threshold
     */
// Path: rival-core/src/main/java/net/recommenders/rival/core/DataModelIF.java
// public interface DataModelIF<U, I> {
// 
//     /**
//      * Method that returns the preference between a user and an item.
//      *
//      * @param u the user.
//      * @param i the item.
//      * @return the preference between a user and an item.
//      */
//     public Double getUserItemPreference(U u, I i);
// 
//     /**
//      * Method that returns the items of a user.
//      *
//      * @param u the user.
//      * @return the items of a user.
//      */
//     public Iterable<I> getUserItems(U u);
// 
//     /**
//      * Method that adds a preference to the model between a user and an item.
//      *
//      * @param u the user.
//      * @param i the item.
//      * @param d the preference.
//      */
//     public void addPreference(final U u, final I i, final Double d);
// 
//     /**
//      * Method that returns the items in the model.
//      *
//      * @return the items in the model.
//      */
//     public Iterable<I> getItems();
// 
//     /**
//      * Method that returns the users in the model.
//      *
//      * @return the users in the model.
//      */
//     public Iterable<U> getUsers();
// 
//     /**
//      * Method that returns the number of items in the model.
//      *
//      * @return the number of items in the model.
//      */
//     public int getNumItems();
// 
//     /**
//      * Method that returns the number of users in the model.
//      *
//      * @return the number of users in the model.
//      */
//     public int getNumUsers();
// 
//     /**
//      * Method that clears all the maps contained in the model.
//      */
//     public void clear();
// }
// 
// Path: rival-evaluate/src/main/java/net/recommenders/rival/evaluation/metric/EvaluationMetric.java
// public interface EvaluationMetric<V> {
// 
//     /**
//      * Get the overall value of the metric.
//      *
//      * @return The overall value of the metric.
//      */
//     double getValue();
// 
//     /**
//      * Get the value of the metric on a per-user basis.
//      *
//      * @return Map containing the values per user.
//      */
//     Map<V, Double> getValuePerUser();
// 
//     /**
//      * Get the value of the metric for a specific user.
//      *
//      * @param u user whose metric value will be computed
//      *
//      * @return a value for user u.
//      */
//     double getValue(V u);
// 
//     /**
//      * Computes the evaluation metric. This method should be called
//      * <b>before</b> asking for the values of the metric.
//      */
//     void compute();
// }
// 
// Path: rival-evaluate/src/main/java/net/recommenders/rival/evaluation/Pair.java
// public class Pair<A, B> {
// 
//     /**
//      * First element.
//      */
//     private A first;
//     /**
//      * Second element.
//      */
//     private B second;
// 
//     /**
//      * Default constructor.
//      *
//      * @param firstElement first element to store
//      * @param secondElement second element to store
//      */
//     public Pair(final A firstElement, final B secondElement) {
//         this.first = firstElement;
//         this.second = secondElement;
//     }
// 
//     /**
//      * Gets the first element of the pair.
//      *
//      * @return the first element of the pair
//      */
//     public A getFirst() {
//         return first;
//     }
// 
//     /**
//      * Gets the second element of the pair.
//      *
//      * @return the second element of the pair
//      */
//     public B getSecond() {
//         return second;
//     }
// }


// Path: rival-evaluate/src/main/java/net/recommenders/rival/evaluation/metric/ranking/Recall.java
import net.recommenders.rival.core.DataModelIF;
import net.recommenders.rival.evaluation.metric.EvaluationMetric;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.recommenders.rival.evaluation.Pair;

/*
 * Copyright 2015 recommenders.net.
 *
 * Licensed 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 net.recommenders.rival.evaluation.metric.ranking;



/**
 * Recall of a ranked list of items.
 *
 * @author <a href="http://github.com/abellogin">Alejandro</a>.
 *
 * @param <U> - type associated to users' ids
 * @param <I> - type associated to items' ids
 */
public class Recall<U, I> extends AbstractRankingMetric<U, I> implements EvaluationMetric<U> {

    /**
     * Recall values per user at each cutoff level.
     */
    private Map<Integer, Map<U, Double>> userRecallAtCutoff;

    /**
     * Default constructor with predictions and groundtruth information.
     *
     * @param predictions predicted scores for users and items
     * @param test groundtruth information for users and items
     */
    public Recall(final DataModelIF<U, I> predictions, final DataModelIF<U, I> test) {
        this(predictions, test, 1.0);
    }

    /**
     * Constructor where the relevance threshold can be initialized.
     *
     * @param predictions predicted ratings
     * @param test groundtruth ratings
     * @param relThreshold relevance threshold
     */
    public Recall(final DataModelIF<U, I> predictions, final DataModelIF<U, I> test, final double relThreshold) {