Package ca.uwo.csd.ai.nlp.common

Examples of ca.uwo.csd.ai.nlp.common.SparseVector


    @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);
    }   
View Full Code Here


    public double evaluate(svm_node x, svm_node y) {                       
        if (!(x.data instanceof SparseVector) || !(y.data instanceof SparseVector)) {
            throw new RuntimeException("svm_nodes should contain sparse vectors.");
        }
       
        SparseVector v1 = (SparseVector) x.data;
        SparseVector v2 = (SparseVector) y.data;
        double result = 0.0;
        int i = 0;
        int j = 0;       
       
        while (i < v1.size() && j < v2.size()) {
            Element e1 = v1.get(i);
            Element e2 = v2.get(j);
           
            if (e1.index == e2.index) {
                double d = e1.value - e2.value;
                result += d * d;
                i++;
                j++;
            } else if (e1.index < e2.index) {
                result += e1.value * e1.value;
                i++;
            } else {
                result += e2.value * e2.value;
                j++;
            }           
        }
       
        while (i < v1.size()) {
            Element e1 = v1.get(i);
            result += e1.value * e1.value;
            i++;
        }
       
        while (j < v2.size()) {
            Element e2 = v2.get(j);
            result += e2.value * e2.value;
            j++;
        }
       
        //System.out.println("score: " + result);
View Full Code Here

                System.err.println("Error in line " + lineCount);
                System.exit(-1);
            }
           
            labels.add(Double.parseDouble(tokens[0]));           
            SparseVector vector = new SparseVector(tokens.length - 1);
           
            for (int i = 1; i < tokens.length; i++) {
                String[] fields = tokens[i].split(":");
                if (fields.length < 2) {
                    System.err.println("Inappropriate file format: " + fileName);
                    System.err.println("Error in line " + lineCount);
                    System.exit(-1);
                }
                int index = Integer.parseInt(fields[0]);
                double value = Double.parseDouble(fields[1]);
                vector.add(index, value);
            }
           
            vectors.add(vector);
        }               
       
View Full Code Here

TOP

Related Classes of ca.uwo.csd.ai.nlp.common.SparseVector

Copyright © 2018 www.massapicom. 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.