Package ca.uwo.csd.ai.nlp.kernel

Source Code of ca.uwo.csd.ai.nlp.kernel.LinearKernel

package ca.uwo.csd.ai.nlp.kernel;

import ca.uwo.csd.ai.nlp.common.SparseVector;
import ca.uwo.csd.ai.nlp.libsvm.svm_node;
import java.io.Serializable;

/**
<code>LinearKernel</code> implements a linear kernel function.
* @author Syeed Ibn Faiz
*/
public class LinearKernel implements CustomKernel, Serializable {

    @Override
    public double evaluate(svm_node x, svm_node y) {                       
        if (!(x.data instanceof SparseVector) || !(y.data instanceof SparseVector)) {
            throw new RuntimeException("Could not find sparse vectors in svm_nodes");
        }       
        SparseVector v1 = (SparseVector) x.data;
        SparseVector v2 = (SparseVector) y.data;
                       
        return v1.dot(v2);
    }   
}
TOP

Related Classes of ca.uwo.csd.ai.nlp.kernel.LinearKernel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.