DAAL.SVDStep3Mapper.java Source code

Java tutorial

Introduction

Here is the source code for DAAL.SVDStep3Mapper.java

Source

/* file: SVDStep3Mapper.java */
/*
 //  Copyright(C) 2014-2015 Intel Corporation. All Rights Reserved.
 //
 //  The source code, information  and  material ("Material") contained herein is
 //  owned  by Intel Corporation or its suppliers or licensors, and title to such
 //  Material remains  with Intel Corporation  or its suppliers or licensors. The
 //  Material  contains proprietary information  of  Intel or  its  suppliers and
 //  licensors. The  Material is protected by worldwide copyright laws and treaty
 //  provisions. No  part  of  the  Material  may  be  used,  copied, reproduced,
 //  modified, published, uploaded, posted, transmitted, distributed or disclosed
 //  in any way  without Intel's  prior  express written  permission. No  license
 //  under  any patent, copyright  or  other intellectual property rights  in the
 //  Material  is  granted  to  or  conferred  upon  you,  either  expressly,  by
 //  implication, inducement,  estoppel or  otherwise.  Any  license  under  such
 //  intellectual  property  rights must  be express  and  approved  by  Intel in
 //  writing.
 //
 //  *Third Party trademarks are the property of their respective owners.
 //
 //  Unless otherwise  agreed  by Intel  in writing, you may not remove  or alter
 //  this  notice or  any other notice embedded  in Materials by Intel or Intel's
 //  suppliers or licensors in any way.
 */

package DAAL;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;
import org.apache.hadoop.conf.Configuration;

import com.intel.daal.data_management.data.HomogenNumericTable;
import com.intel.daal.algorithms.svd.*;
import com.intel.daal.data_management.data.*;
import com.intel.daal.services.*;

public class SVDStep3Mapper extends Mapper<IntWritable, WriteableData, IntWritable, WriteableData> {

    private static Configuration conf;

    @Override
    public void setup(Context context) {
        conf = context.getConfiguration();
    }

    @Override
    public void map(IntWritable step2key, WriteableData step2value, Context context)
            throws IOException, InterruptedException {

        DaalContext daalContext = new DaalContext();

        SequenceFile.Reader reader = new SequenceFile.Reader(new Configuration(),
                SequenceFile.Reader.file(new Path("/Hadoop/SVD/step1/step1x" + step2value.getId())));
        IntWritable step1key = new IntWritable();
        WriteableData step1value = new WriteableData();
        reader.next(step1key, step1value);
        reader.close();

        DataCollection s1 = (DataCollection) step1value.getObject(daalContext);
        DataCollection s2 = (DataCollection) step2value.getObject(daalContext);

        /* Create an algorithm to compute SVD on the master node */
        DistributedStep3Local svdStep3Local = new DistributedStep3Local(daalContext, Double.class,
                Method.defaultDense);
        svdStep3Local.input.set(DistributedStep3LocalInputId.inputOfStep3FromStep1, s1);
        svdStep3Local.input.set(DistributedStep3LocalInputId.inputOfStep3FromStep2, s2);

        /* Compute SVD in step 3 */
        svdStep3Local.compute();
        Result result = svdStep3Local.finalizeCompute();
        HomogenNumericTable Ui = (HomogenNumericTable) result.get(ResultId.leftSingularMatrix);

        SequenceFile.Writer writer = SequenceFile.createWriter(new Configuration(),
                SequenceFile.Writer.file(new Path("/Hadoop/SVD/Output/Ux" + step2value.getId())),
                SequenceFile.Writer.keyClass(IntWritable.class),
                SequenceFile.Writer.valueClass(WriteableData.class));
        writer.append(new IntWritable(0), new WriteableData(step2value.getId(), Ui));
        writer.close();

        daalContext.dispose();
    }
}