當前位置: 首頁>>代碼示例>>Java>>正文


Java Accumulable類代碼示例

本文整理匯總了Java中org.apache.spark.Accumulable的典型用法代碼示例。如果您正苦於以下問題:Java Accumulable類的具體用法?Java Accumulable怎麽用?Java Accumulable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Accumulable類屬於org.apache.spark包,在下文中一共展示了Accumulable類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.spark.Accumulable; //導入依賴的package包/類
public static void main( String[] args )
{
    if (args.length == 0) {
    	
    }
    if (args.length == 0) {
		System.out.println("UniqueSeqGenerator {master} {inputPath} {outputFolder}");
	}
	
	String master = args[0];
	String inputPath = args[1];
	String outputPath = args[2];
	
	JavaSparkContext jsc = new JavaSparkContext(master, "UniqueSeqGenerator", null, "SeqGenerator.jar");
	
	SeqMapCounter seqMapCounter = new SeqMapCounter();
	Accumulable<SeqMapCounter, String> accumulable = jsc.accumulable(seqMapCounter, new SeqMapCounterAccumulableParam());
	
	JavaRDD<String> javaRdd = jsc.textFile(inputPath);
	javaRdd.foreach(new ForEachMapperPartitionCounter(accumulable));
	
	seqMapCounter = accumulable.value();
	
	System.out.println("--------");
	System.out.println(seqMapCounter.getSummery());
	System.out.println("--------");
	
	Broadcast<SeqMapCounter> broadcast = jsc.broadcast(seqMapCounter);
	
	JavaRDD<String> seqRdd = javaRdd.map(new MapAssignSequence(broadcast));
	seqRdd.saveAsTextFile(outputPath);
}
 
開發者ID:tmalaska,項目名稱:Spark..Unique.Seq.Generator,代碼行數:33,代碼來源:UniqueSeqGenerator.java

示例2: main

import org.apache.spark.Accumulable; //導入依賴的package包/類
public static void main(String[] args) {
	if (args.length == 0) {

	}
	if (args.length == 0) {
		System.out.println("ValidateSeqGeneration {master} {inputPath}");
	}

	String master = args[0];
	String inputPath = args[1];

	
	JavaSparkContext jsc = new JavaSparkContext(master,
			"ValidateSeqGeneration", null, "SeqGenerator.jar");

	MinMaxAccumulator minMaxAccumulator = new MinMaxAccumulator();
	Accumulable<MinMaxAccumulator, Long> accumulable = jsc.accumulable(
			minMaxAccumulator, new MinMaxAccumulatorParam());

	JavaRDD<String> javaRdd = jsc.textFile(inputPath);
	javaRdd.foreach(new ForEachMapperPartitionCounter(accumulable));

	minMaxAccumulator = accumulable.value();
	
	TreeMap<Long, Long> treeMap = new TreeMap<Long, Long>();
	
	for (Tuple2<Counter, Counter> minMax: minMaxAccumulator.minMaxRanges) {
		treeMap.put(minMax._1.val, minMax._2.val);
	}
	
	
	System.out.println("------");
	for (Entry<Long, Long> entry: treeMap.entrySet()) {
		System.out.println(entry.getKey() + "," + entry.getValue());
	}
	System.out.println("------");

}
 
開發者ID:tmalaska,項目名稱:Spark..Unique.Seq.Generator,代碼行數:39,代碼來源:ValidateSeqGeneration.java

示例3: updateDistributionMatrix

import org.apache.spark.Accumulable; //導入依賴的package包/類
protected void updateDistributionMatrix(JavaSparkContext sc, JavaRDD<MultilabelPoint> docs, double[][] localDM, WeakHypothesis localWH) {
    Broadcast<WeakHypothesis> distWH = sc.broadcast(localWH);
    Broadcast<double[][]> distDM = sc.broadcast(localDM);

    Accumulable<ArrayList<SingleDMUpdate>, DMPartialResult> partialResults = sc.accumulable(new ArrayList<SingleDMUpdate>(),
            new DMPartialResultAccumulableParam());

    Double[] normArray = new Double[localDM.length];
    for (int i = 0; i < normArray.length; i++)
        normArray[i] = 0.0;
    Accumulable<ArrayList<Double>, DMPartialResult> normalizations = sc.accumulable(new ArrayList<Double>(Arrays.asList(normArray)), new DMNormalizationAccumulableParam());

    docs.map(doc -> {
        int[] validFeatures = doc.getFeatures().indices();
        HashMap<Integer, Integer> dictFeatures = new HashMap<>();
        for (int featID : validFeatures)
            dictFeatures.put(featID, featID);
        HashMap<Integer, Integer> dictLabels = new HashMap<>();
        for (int idx = 0; idx < doc.getLabels().length; idx++)
            dictLabels.put(doc.getLabels()[idx], doc.getLabels()[idx]);

        double[][] dm = distDM.getValue();
        WeakHypothesis wh = distWH.getValue();
        double[] labelsRes = new double[dm.length];
        for (int labelID = 0; labelID < dm.length; labelID++) {
            float catValue = 1;
            if (dictLabels.containsKey(labelID)) {
                catValue = -1;
            }

            // Compute the weak hypothesis value.
            double value = 0;
            WeakHypothesis.WeakHypothesisData v = wh.getLabelData(labelID);
            int pivot = v.getFeatureID();
            if (dictFeatures.containsKey(pivot))
                value = v.getC1();
            else
                value = v.getC0();


            double partialRes = dm[labelID][doc.getPointID()] * Math.exp(catValue * value);
            labelsRes[labelID] = partialRes;
        }

        return new DMPartialResult(doc.getPointID(), labelsRes);
    }).foreach(r -> {
        partialResults.add(r);
        normalizations.add(r);
    });

    // Update distribution matrix.
    ArrayList<SingleDMUpdate> updates = partialResults.value();
    ArrayList<Double> normalizationValues = normalizations.value();
    for (int i = 0; i < updates.size(); i++) {
        SingleDMUpdate update = updates.get(i);
        localDM[update.getLabelID()][update.getDocID()] = update.getResult() / normalizationValues.get(update.getLabelID());
    }

}
 
開發者ID:tizfa,項目名稱:sparkboost,代碼行數:60,代碼來源:MpBoostLearner.java

示例4: ForEachMapperPartitionCounter

import org.apache.spark.Accumulable; //導入依賴的package包/類
public ForEachMapperPartitionCounter(Accumulable<SeqMapCounter, String> accumulable) {
	this.accumulable = accumulable;
}
 
開發者ID:tmalaska,項目名稱:Spark..Unique.Seq.Generator,代碼行數:4,代碼來源:UniqueSeqGenerator.java

示例5: ForEachMapperPartitionCounter

import org.apache.spark.Accumulable; //導入依賴的package包/類
public ForEachMapperPartitionCounter(Accumulable<MinMaxAccumulator, Long> accumulable) {
	this.accumulable = accumulable;
}
 
開發者ID:tmalaska,項目名稱:Spark..Unique.Seq.Generator,代碼行數:4,代碼來源:ValidateSeqGeneration.java

示例6: readExternal

import org.apache.spark.Accumulable; //導入依賴的package包/類
@Override
public void readExternal(ObjectInput in)
        throws IOException, ClassNotFoundException{
    Credentials credentials = null;
    if (in.readBoolean()) {
        // we've got credentials to apply
        Broadcast<SerializableWritable<Credentials>> bcast = (Broadcast<SerializableWritable<Credentials>>) in.readObject();
        credentials = bcast.getValue().value();
    }
    badRecordsSeen = in.readLong();
    badRecordThreshold = in.readLong();
    permissive=in.readBoolean();
    SpliceSpark.setupSpliceStaticComponents(credentials);
    boolean isOp=in.readBoolean();
    if(isOp){
        broadcastedActivation = (BroadcastedActivation)in.readObject();
        op=(Op)broadcastedActivation.getActivationHolder().getOperationsMap().get(in.readInt());
        activation=broadcastedActivation.getActivationHolder().getActivation();
    }
    rowsRead=(LongAccumulator)in.readObject();
    rowsFiltered=(LongAccumulator)in.readObject();
    rowsWritten=(LongAccumulator)in.readObject();
    retryAttempts =(LongAccumulator)in.readObject();
    regionTooBusyExceptions =(LongAccumulator)in.readObject();
    rowsJoinedLeft=(LongAccumulator)in.readObject();
    rowsJoinedRight=(LongAccumulator)in.readObject();
    rowsProduced=(LongAccumulator)in.readObject();
    badRecordsAccumulator = (Accumulable<BadRecordsRecorder,String>) in.readObject();

    thrownErrorsRows=(LongAccumulator)in.readObject();
    retriedRows=(LongAccumulator)in.readObject();
    partialRows=(LongAccumulator)in.readObject();
    partialThrownErrorRows=(LongAccumulator)in.readObject();
    partialRetriedRows=(LongAccumulator)in.readObject();
    partialIgnoredRows=(LongAccumulator)in.readObject();
    partialWrite=(LongAccumulator)in.readObject();
    ignoredRows=(LongAccumulator)in.readObject();
    catchThrownRows=(LongAccumulator)in.readObject();
    catchRetriedRows=(LongAccumulator)in.readObject();
    pipelineRowsWritten=(LongAccumulator)in.readObject();
}
 
開發者ID:splicemachine,項目名稱:spliceengine,代碼行數:42,代碼來源:SparkOperationContext.java


注:本文中的org.apache.spark.Accumulable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。