Search in sources :

Example 1 with SequentialSparseDataSet

use of edu.neu.ccs.pyramid.dataset.SequentialSparseDataSet in project pyramid by cheng-li.

the class CMLCRFElasticNet method expandData.

private DataSet expandData(int l) {
    SequentialSparseDataSet newData = new SequentialSparseDataSet(numData, numParameters, false);
    MultiLabel label = supportedCombinations.get(l);
    List<Integer> labelPairForL = combinationToLabelPair.get(l);
    // TODO: parallelism
    for (int i = 0; i < numData; i++) {
        // add feature-label feature
        for (int y : label.getMatchedLabels()) {
            // set bias as 1
            newData.setFeatureValue(i, (numFeature + 1) * y, 1.0);
            for (Vector.Element element : dataSet.getRow(i).nonZeroes()) {
                int index = element.index();
                double value = element.get();
                newData.setFeatureValue(i, (numFeature + 1) * y + index + 1, value);
            }
        }
        for (int y : labelPairForL) {
            newData.setFeatureValue(i, (numWeightsForFeatures + y), 1.0);
        }
    }
    return newData;
}
Also used : MultiLabel(edu.neu.ccs.pyramid.dataset.MultiLabel) SequentialSparseDataSet(edu.neu.ccs.pyramid.dataset.SequentialSparseDataSet) DenseVector(org.apache.mahout.math.DenseVector) SequentialAccessSparseVector(org.apache.mahout.math.SequentialAccessSparseVector) Vector(org.apache.mahout.math.Vector)

Aggregations

MultiLabel (edu.neu.ccs.pyramid.dataset.MultiLabel)1 SequentialSparseDataSet (edu.neu.ccs.pyramid.dataset.SequentialSparseDataSet)1 DenseVector (org.apache.mahout.math.DenseVector)1 SequentialAccessSparseVector (org.apache.mahout.math.SequentialAccessSparseVector)1 Vector (org.apache.mahout.math.Vector)1