// Path: src/main/java/it/unipi/di/acube/smaph/learn/featurePacks/FeaturePack.java
// public abstract class FeaturePack <T extends Object> implements Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 	private double[] featuresArray;
// 
// 	public FeaturePack(HashMap<String, Double> features){
// 		if (features == null)
// 			return;
// 		checkFeatures(features);
// 		featuresArray = new double[this.getFeatureCount()];
// 		
// 		for (String ftrName : getFeatureNames())
// 			featuresArray[ftrNameToArrayPosition(ftrName)] = features
// 					.containsKey(ftrName) ? features.get(ftrName) : Double.NaN;
// 	}
// 	
// 	public abstract void checkFeatures(HashMap<String, Double> features);
// 	
// 	/**
// 	 * @return the array of feature names, ordered by their ID. In name of the
// 	 *         feature with ID=i+1 is in position i.
// 	 */
// 	public abstract String[] getFeatureNames();
// 
// 	/**
// 	 * @param ftrName
// 	 *            the feature name
// 	 * @return the feature index (an integer >=1) of a feature, or -1 if such a
// 	 *         feature does not exist.
// 	 */
// 	public int ftrNameToId(String ftrName) {
// 		int idx = Arrays.asList(getFeatureNames()).indexOf(ftrName);
// 		if (idx == -1)
// 			return -1;
// 		return idx + 1;
// 	}
// 
// 	public int ftrNameToArrayPosition(String ftrName) {
// 		return ftrNameToId(ftrName) -1;
// 	}
// 
// 	public double getFeature(String ftrName) {
// 		return featuresArray[ftrNameToArrayPosition(ftrName)];
// 	}
// 
// 	public String ftrIdToName(int featureId) {
// 		return getFeatureNames()[featureId - 1];
// 	}
// 	public int getFeatureCount() {
// 		return getFeatureNames().length;
// 	}
// 
// 	public boolean featureIsSet(String ftrName) {
// 		return !Double.isNaN(featuresArray[ftrNameToArrayPosition(ftrName)]);
// 	}
// }
// 
// Path: src/main/java/it/unipi/di/acube/smaph/learn/models/LibLinearModel.java
// public abstract class LibLinearModel<T> {
// 	private Model model;
// 
// 	public LibLinearModel(String modelFile){
// 		try {
// 			model = Model.load(new File(modelFile));
// 		} catch (IOException e) {
// 			e.printStackTrace();
// 			throw new RuntimeException(e);
// 		}
// 	}
// 	public double predictScore(FeaturePack<T> fp, FeatureNormalizer fn) {
// 		return Linear.predict(model, featureMapToFeatures(fn.ftrToNormalizedFtrArray(fp)));
// 	}
// 
// 	public Feature[] featureMapToFeatures(double[] ftrArray) {
// 		Feature[] llFtrArray = new Feature[ftrArray.length];
// 		for (int i = 0; i < llFtrArray.length; i++)
// 			llFtrArray[i] = new FeatureNode(i + 1, ftrArray[i]);
// 		return llFtrArray;
// 	}
// 
// 	public static Feature[] featureMapToFeatures(double[] ftrArray, int[] ftrList) {
// 		Feature[] llFtrArray = new Feature[ftrList.length];
// 		int j = 0;
// 		for (int i = 0; i < ftrList.length; i++)
// 			llFtrArray[j++] = new FeatureNode(i + 1, ftrArray[ftrList[i] - 1]);
// 		return llFtrArray;
// 	}
// }
// 
// Path: src/main/java/it/unipi/di/acube/smaph/learn/normalizer/FeatureNormalizer.java
// public abstract class FeatureNormalizer {
// 
// 	/**
// 	 * @param fp
// 	 *            a feature pack
// 	 * @param ftrName
// 	 *            a feature name
// 	 * @return the normalized value for this feature.
// 	 */
// 	public abstract double normalizeFeature(FeaturePack<?> fp, String ftrName);
// 
// 	/**
// 	 * @param features
// 	 *            the hashmap of non-normalized features.
// 	 * @return a feature vector of the given features (normalized), 0.0 in case
// 	 *         a feature is not provided.
// 	 */
// 	public double[] ftrToNormalizedFtrArray(FeaturePack<?> fp) {
// 		double[] res = new double[fp.getFeatureCount()];
// 		for (String featureName : fp.getFeatureNames()) {
// 			int ftrPos = fp.ftrNameToArrayPosition(featureName);
// 			res[ftrPos] = normalizeFeature(fp, featureName);
// 		}
// 		return res;
// 	}
// }


import java.util.HashSet;
import java.util.List;
import it.unipi.di.acube.batframework.data.Annotation;
import it.unipi.di.acube.smaph.learn.featurePacks.FeaturePack;
import it.unipi.di.acube.smaph.learn.models.LibLinearModel;
import it.unipi.di.acube.smaph.learn.normalizer.FeatureNormalizer;
package it.unipi.di.acube.smaph.learn.models.linkback.bindingRegressor;



public class LibLinearBindingRegressor extends LibLinearModel<HashSet<Annotation>> implements BindingRegressor {

	public LibLinearBindingRegressor(String modelFile) {
		super(modelFile);
	}

	@Override
	public double[] getScores(List<FeaturePack<HashSet<Annotation>>> features,
			FeatureNormalizer fn) {
// Path: src/main/java/it/unipi/di/acube/smaph/learn/featurePacks/FeaturePack.java
// public abstract class FeaturePack <T extends Object> implements Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 	private double[] featuresArray;
// 
// 	public FeaturePack(HashMap<String, Double> features){
// 		if (features == null)
// 			return;
// 		checkFeatures(features);
// 		featuresArray = new double[this.getFeatureCount()];
// 		
// 		for (String ftrName : getFeatureNames())
// 			featuresArray[ftrNameToArrayPosition(ftrName)] = features
// 					.containsKey(ftrName) ? features.get(ftrName) : Double.NaN;
// 	}
// 	
// 	public abstract void checkFeatures(HashMap<String, Double> features);
// 	
// 	/**
// 	 * @return the array of feature names, ordered by their ID. In name of the
// 	 *         feature with ID=i+1 is in position i.
// 	 */
// 	public abstract String[] getFeatureNames();
// 
// 	/**
// 	 * @param ftrName
// 	 *            the feature name
// 	 * @return the feature index (an integer >=1) of a feature, or -1 if such a
// 	 *         feature does not exist.
// 	 */
// 	public int ftrNameToId(String ftrName) {
// 		int idx = Arrays.asList(getFeatureNames()).indexOf(ftrName);
// 		if (idx == -1)
// 			return -1;
// 		return idx + 1;
// 	}
// 
// 	public int ftrNameToArrayPosition(String ftrName) {
// 		return ftrNameToId(ftrName) -1;
// 	}
// 
// 	public double getFeature(String ftrName) {
// 		return featuresArray[ftrNameToArrayPosition(ftrName)];
// 	}
// 
// 	public String ftrIdToName(int featureId) {
// 		return getFeatureNames()[featureId - 1];
// 	}
// 	public int getFeatureCount() {
// 		return getFeatureNames().length;
// 	}
// 
// 	public boolean featureIsSet(String ftrName) {
// 		return !Double.isNaN(featuresArray[ftrNameToArrayPosition(ftrName)]);
// 	}
// }
// 
// Path: src/main/java/it/unipi/di/acube/smaph/learn/models/LibLinearModel.java
// public abstract class LibLinearModel<T> {
// 	private Model model;
// 
// 	public LibLinearModel(String modelFile){
// 		try {
// 			model = Model.load(new File(modelFile));
// 		} catch (IOException e) {
// 			e.printStackTrace();
// 			throw new RuntimeException(e);
// 		}
// 	}
// 	public double predictScore(FeaturePack<T> fp, FeatureNormalizer fn) {
// 		return Linear.predict(model, featureMapToFeatures(fn.ftrToNormalizedFtrArray(fp)));
// 	}
// 
// 	public Feature[] featureMapToFeatures(double[] ftrArray) {
// 		Feature[] llFtrArray = new Feature[ftrArray.length];
// 		for (int i = 0; i < llFtrArray.length; i++)
// 			llFtrArray[i] = new FeatureNode(i + 1, ftrArray[i]);
// 		return llFtrArray;
// 	}
// 
// 	public static Feature[] featureMapToFeatures(double[] ftrArray, int[] ftrList) {
// 		Feature[] llFtrArray = new Feature[ftrList.length];
// 		int j = 0;
// 		for (int i = 0; i < ftrList.length; i++)
// 			llFtrArray[j++] = new FeatureNode(i + 1, ftrArray[ftrList[i] - 1]);
// 		return llFtrArray;
// 	}
// }
// 
// Path: src/main/java/it/unipi/di/acube/smaph/learn/normalizer/FeatureNormalizer.java
// public abstract class FeatureNormalizer {
// 
// 	/**
// 	 * @param fp
// 	 *            a feature pack
// 	 * @param ftrName
// 	 *            a feature name
// 	 * @return the normalized value for this feature.
// 	 */
// 	public abstract double normalizeFeature(FeaturePack<?> fp, String ftrName);
// 
// 	/**
// 	 * @param features
// 	 *            the hashmap of non-normalized features.
// 	 * @return a feature vector of the given features (normalized), 0.0 in case
// 	 *         a feature is not provided.
// 	 */
// 	public double[] ftrToNormalizedFtrArray(FeaturePack<?> fp) {
// 		double[] res = new double[fp.getFeatureCount()];
// 		for (String featureName : fp.getFeatureNames()) {
// 			int ftrPos = fp.ftrNameToArrayPosition(featureName);
// 			res[ftrPos] = normalizeFeature(fp, featureName);
// 		}
// 		return res;
// 	}
// }


// Path: src/main/java/it/unipi/di/acube/smaph/learn/models/linkback/bindingRegressor/LibLinearBindingRegressor.java
import java.util.HashSet;
import java.util.List;
import it.unipi.di.acube.batframework.data.Annotation;
import it.unipi.di.acube.smaph.learn.featurePacks.FeaturePack;
import it.unipi.di.acube.smaph.learn.models.LibLinearModel;
import it.unipi.di.acube.smaph.learn.normalizer.FeatureNormalizer;

package it.unipi.di.acube.smaph.learn.models.linkback.bindingRegressor;



public class LibLinearBindingRegressor extends LibLinearModel<HashSet<Annotation>> implements BindingRegressor {

	public LibLinearBindingRegressor(String modelFile) {
		super(modelFile);
	}

	@Override
	public double[] getScores(List<FeaturePack<HashSet<Annotation>>> features,
			FeatureNormalizer fn) {
		double[] scores = new double[features.size()];