com.github.TKnudsen.ComplexDataObject.data.uncertainty.string.LabelUncertaintyTools Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of complex-data-object Show documentation
Show all versions of complex-data-object Show documentation
A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.
The newest version!
package com.github.TKnudsen.ComplexDataObject.data.uncertainty.string;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.TKnudsen.ComplexDataObject.model.tools.MathFunctions;
/**
*
* Title: LabelUncertaintyTools
*
*
*
* Description:
*
*
*
* Copyright: Copyright (c) 2015-2017
*
*
* @author Juergen Bernard
* @version 1.01
*/
public class LabelUncertaintyTools {
/**
* merges a series of LabelUncertaintys.
*
* @param labelUncertainties
* @return
*/
public static LabelUncertainty mergeLabelUncertainties(Collection labelUncertainties) {
if (labelUncertainties == null)
return null;
Map> valueDistributions = new LinkedHashMap<>();
for (LabelUncertainty labelUncertainty : labelUncertainties) {
if (labelUncertainty == null)
continue;
for (String label : labelUncertainty.getLabelSet()) {
if (valueDistributions.get(label) == null)
valueDistributions.put(label, new ArrayList<>());
valueDistributions.get(label).add(labelUncertainty.getValueDistribution().get(label));
}
}
Map valueDistribution = new LinkedHashMap<>();
for (String label : valueDistributions.keySet())
valueDistribution.put(label, MathFunctions.getMean(valueDistributions.get(label)));
return new LabelUncertainty(valueDistribution);
}
}