/** * Creates a new, empty {@code DefaultPair} with both values being null. * * @param <FirstType> * Type of the first object in the pair. * @param <SecondType> * Type of the second object in the pair. * @return * A new, empty {@code DefaultPair}. */ public static <FirstType, SecondType> DefaultPair<FirstType, SecondType> create() { return new DefaultPair<FirstType, SecondType>(); }
/** * Creates a new, empty {@code DefaultPair} with both values being null. * * @param <FirstType> * Type of the first object in the pair. * @param <SecondType> * Type of the second object in the pair. * @return * A new, empty {@code DefaultPair}. */ public static <FirstType, SecondType> DefaultPair<FirstType, SecondType> create() { return new DefaultPair<FirstType, SecondType>(); }
/** * Creates a new, empty {@code DefaultPair} with both values being null. * * @param <FirstType> * Type of the first object in the pair. * @param <SecondType> * Type of the second object in the pair. * @return * A new, empty {@code DefaultPair}. */ public static <FirstType, SecondType> DefaultPair<FirstType, SecondType> create() { return new DefaultPair<FirstType, SecondType>(); }
/** * Creates a new {@code DefaultPair} from the given values. * * @param <FirstType> * Type of the first object in the pair. * @param <SecondType> * Type of the second object in the pair. * @param first * The first value. * @param second * The second value. * @return * A new DefaultPair containing the two values. */ public static <FirstType, SecondType> DefaultPair<FirstType, SecondType> create( final FirstType first, final SecondType second) { return new DefaultPair<FirstType, SecondType>(first, second); }
/** * Creates a new {@code DefaultPair} from the given values. * * @param <FirstType> * Type of the first object in the pair. * @param <SecondType> * Type of the second object in the pair. * @param first * The first value. * @param second * The second value. * @return * A new DefaultPair containing the two values. */ public static <FirstType, SecondType> DefaultPair<FirstType, SecondType> create( final FirstType first, final SecondType second) { return new DefaultPair<FirstType, SecondType>(first, second); }
/** * Creates a new {@code DefaultPair} from the given values. * * @param <FirstType> * Type of the first object in the pair. * @param <SecondType> * Type of the second object in the pair. * @param first * The first value. * @param second * The second value. * @return * A new DefaultPair containing the two values. */ public static <FirstType, SecondType> DefaultPair<FirstType, SecondType> create( final FirstType first, final SecondType second) { return new DefaultPair<FirstType, SecondType>(first, second); }
/** * Converts from the editable edge map to the dense-memory edge list */ public void convert() { listEdgeMap = new ArrayList<>(editableEdgeMap.size()); for (Map.Entry<UniqueEdge, List<EdgeIndex>> e : editableEdgeMap.entrySet()) { listEdgeMap.add(new DefaultPair<>(e.getKey(), e.getValue())); } editableEdgeMap.clear(); editableEdgeMap = null; }
/** * Evaluates the two batch learners using the given data on the same set of * validation folds and returns the resulting information including the * confidence statistic that the two are different along with the summary * of their performance. * * @param learner1 The first learner. * @param learner2 The second learner. * @param data The data to use. * @return The experimental results. */ public Result<SummaryType> evaluate( final BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType> learner1, final BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType> learner2, final Collection<? extends InputDataType> data) { return this.evaluate( new DefaultPair<BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType>, BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType>>( learner1, learner2), data); }
/** * Evaluates the two batch learners using the given data on the same set of * validation folds and returns the resulting information including the * confidence statistic that the two are different along with the summary * of their performance. * * @param learner1 The first learner. * @param learner2 The second learner. * @param data The data to use. * @return The experimental results. */ public Result<SummaryType> evaluate( final BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType> learner1, final BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType> learner2, final Collection<? extends InputDataType> data) { return this.evaluate( new DefaultPair<BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType>, BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType>>( learner1, learner2), data); }
/** * Evaluates the two batch learners using the given data on the same set of * validation folds and returns the resulting information including the * confidence statistic that the two are different along with the summary * of their performance. * * @param learner1 The first learner. * @param learner2 The second learner. * @param data The data to use. * @return The experimental results. */ public Result<SummaryType> evaluate( final BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType> learner1, final BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType> learner2, final Collection<? extends InputDataType> data) { return this.evaluate( new DefaultPair<BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType>, BatchLearner<? super Collection<? extends FoldDataType>, ? extends LearnedType>>( learner1, learner2), data); }
for (FirstType d1 : firsts) result.add(new DefaultPair<FirstType, SecondType>(d1, i2.next()));
for (FirstType d1 : firsts) result.add(new DefaultPair<FirstType, SecondType>(d1, i2.next()));
for (FirstType d1 : firsts) result.add(new DefaultPair<FirstType, SecondType>(d1, i2.next()));
@Override public ROCResult<CLASS> analyse(Map<OBJECT, ClassificationResult<CLASS>> predicted, Map<OBJECT, Set<CLASS>> actual) { //get all the classes Set<CLASS> allClasses = new HashSet<CLASS>(); for (OBJECT o : predicted.keySet()) { allClasses.addAll(actual.get(o)); } //for each class compute a ROC curve Map<CLASS, ReceiverOperatingCharacteristic> output = new HashMap<CLASS, ReceiverOperatingCharacteristic>(); for (CLASS clz : allClasses) { List<Pair<Boolean, Double>> data = new ArrayList<Pair<Boolean, Double>>(); for (OBJECT o : predicted.keySet()) { if (predicted.get(o) != null) { double score = predicted.get(o).getConfidence(clz); boolean objIsClass = actual.get(o).contains(clz); data.add(new DefaultPair<Boolean, Double>(objIsClass, score)); } else { data.add(new DefaultPair<Boolean, Double>(false, 1.0)); } } output.put(clz, ReceiverOperatingCharacteristic.createFromTargetEstimatePairs(data)); } return new ROCResult<CLASS>(output); }
@Override public ROCResult<CLASS> analyse(Map<OBJECT, ClassificationResult<CLASS>> predicted, Map<OBJECT, Set<CLASS>> actual) { //get all the classes Set<CLASS> allClasses = new HashSet<CLASS>(); for (OBJECT o : predicted.keySet()) { allClasses.addAll(actual.get(o)); } //for each class compute a ROC curve Map<CLASS, ReceiverOperatingCharacteristic> output = new HashMap<CLASS, ReceiverOperatingCharacteristic>(); for (CLASS clz : allClasses) { List<Pair<Boolean, Double>> data = new ArrayList<Pair<Boolean, Double>>(); for (OBJECT o : predicted.keySet()) { if (predicted.get(o) != null) { double score = predicted.get(o).getConfidence(clz); boolean objIsClass = actual.get(o).contains(clz); data.add(new DefaultPair<Boolean, Double>(objIsClass, score)); } else { data.add(new DefaultPair<Boolean, Double>(false, 1.0)); } } output.put(clz, ReceiverOperatingCharacteristic.createFromTargetEstimatePairs(data)); } return new ROCResult<CLASS>(output); }
/** * Returns the source/dest pair for the edge stored at index i * * @param i The edge index * @return the source/dest pair for the edge stored at index i */ public Pair<Integer, Integer> getEdgePair(int i) { UniqueEdge e = getEdge(i).getFirst(); return new DefaultPair<>(e.idxi, e.idxj); }
/** * Computes the transfer entropy value and returns a map of the states with their corresponding partial sums. * Used to identify which states contribute the most or least to the transfer entropy. * @return A pair, where the first element is the transfer entropy value between the two vectors, and the second * element is a map from states to their corresponding partial sums. */ public Pair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>> computeWithPartialSums() { double solution = 0.0; HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject> mapSolution = new HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>(); ConditionalProbability<TransferEntropyDistributionObject> instance = new ConditionalProbability<TransferEntropyDistributionObject>(); for (TransferEntropyDistributionObject state : twoTermPosteriorDistribution.getDomain()) { TransferEntropyPartialSumObject answerWithWrapper = partialSumWithWrapper(state, instance); solution += answerWithWrapper.partialSum; mapSolution.put(state, answerWithWrapper); } Pair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>> finalAnswer = new DefaultPair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>>(solution, mapSolution); return finalAnswer; }
/** * Computes the transfer entropy value and returns a map of the states with their corresponding partial sums. * Used to identify which states contribute the most or least to the transfer entropy. * @return A pair, where the first element is the transfer entropy value between the two vectors, and the second * element is a map from states to their corresponding partial sums. */ public Pair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>> computeWithPartialSums() { double solution = 0.0; HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject> mapSolution = new HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>(); ConditionalProbability<TransferEntropyDistributionObject> instance = new ConditionalProbability<TransferEntropyDistributionObject>(); for (TransferEntropyDistributionObject state : twoTermPosteriorDistribution.getDomain()) { TransferEntropyPartialSumObject answerWithWrapper = partialSumWithWrapper(state, instance); solution += answerWithWrapper.partialSum; mapSolution.put(state, answerWithWrapper); } Pair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>> finalAnswer = new DefaultPair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>>(solution, mapSolution); return finalAnswer; }
/** * Computes the transfer entropy value and returns a map of the states with their corresponding partial sums. * Used to identify which states contribute the most or least to the transfer entropy. * @return A pair, where the first element is the transfer entropy value between the two vectors, and the second * element is a map from states to their corresponding partial sums. */ public Pair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>> computeWithPartialSums() { double solution = 0.0; HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject> mapSolution = new HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>(); ConditionalProbability<TransferEntropyDistributionObject> instance = new ConditionalProbability<TransferEntropyDistributionObject>(); for (TransferEntropyDistributionObject state : twoTermPosteriorDistribution.getDomain()) { TransferEntropyPartialSumObject answerWithWrapper = partialSumWithWrapper(state, instance); solution += answerWithWrapper.partialSum; mapSolution.put(state, answerWithWrapper); } Pair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>> finalAnswer = new DefaultPair<Double, HashMap<TransferEntropyDistributionObject, TransferEntropyPartialSumObject>>(solution, mapSolution); return finalAnswer; }
new DefaultPair<ArrayList<StatisticType>, ArrayList<StatisticType>>( new ArrayList<StatisticType>(folds.size()), new ArrayList<StatisticType>(folds.size()))); new DefaultPair<SummaryType, SummaryType>(summary1, summary2));