All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ciir.umass.edu.features.Normalizer Maven / Gradle / Ivy

There is a newer version: 2.10.1
Show newest version
/*===============================================================================
 * Copyright (c) 2010-2012 University of Massachusetts.  All Rights Reserved.
 *
 * Use of the RankLib package is subject to the terms of the software license set
 * forth in the LICENSE file included with this software, and also available at
 * http://people.cs.umass.edu/~vdang/ranklib_license.html
 *===============================================================================
 */

package ciir.umass.edu.features;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import ciir.umass.edu.learning.RankList;

/**
 * @author vdang
 *
 * Abstract class for feature normalization
 */
public abstract class Normalizer {
    public abstract void normalize(final RankList rl);

    public void normalize(final List samples) {
        for (int i = 0; i < samples.size(); i++) {
            normalize(samples.get(i));
        }
    }

    public abstract void normalize(final RankList rl, final int[] fids);

    public void normalize(final List samples, final int[] fids) {
        for (int i = 0; i < samples.size(); i++) {
            normalize(samples.get(i), fids);
        }
    }

    public int[] removeDuplicateFeatures(int[] fids) {
        final Set uniqueSet = new HashSet<>();
        for (int i = 0; i < fids.length; i++) {
            if (!uniqueSet.contains(fids[i])) {
                uniqueSet.add(fids[i]);
            }
        }
        fids = new int[uniqueSet.size()];
        int fi = 0;
        for (final Integer i : uniqueSet) {
            fids[fi++] = i.intValue();
        }
        return fids;
    }

    public abstract String name();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy