package de.ugoe.cs.eventbench.coverage; import java.security.InvalidParameterException; import java.util.Collection; import java.util.List; import java.util.Map; import de.ugoe.cs.eventbench.data.Event; import de.ugoe.cs.eventbench.models.IStochasticProcess; /** *
* This class calculates various types of sequence coverage in relation to a * stochastic process. *
* * @author Steffen Herbold * @version 1.0 */ public class CoverageCalculatorProcess { /** ** Stochastic process that is the foundation for probabilistic coverages and * coverages with reference to all possible sequences. *
*/ private final IStochasticProcess process; /** ** Sequences for which the coverage is calculated. *
*/ private Collection* Length of the subsequences in relation to which the coverage is * calculated. *
*/ private final int length; /** ** All subsequences of {@link #length} of {@link #sequences}. *
*/ private Collection* All subsequences of {@link #length} that can be generated by * {@link #process}. *
*/ private Collection* The probabilities of all subsequences of {@link #length} according to * {@link #process}. *
*/ private Map* Constructor. Creates a new CoverageCalculatorProcess for a given * stochastic process and generated sequences. *
* * @param process * stochastic process used for coverage calculations; must not be * null * @param sequences * sequences for which the coverage is calculated; must not be * null * @param length * length of the subsequences for which the coverage is analyzed; * must be >0 * @throws InvalidParameterException * thrown if process or sequences is null or length less than or equal to 0 */ public CoverageCalculatorProcess(IStochasticProcess process, Collection* Calculates the percentage of subsequences of length k that occur, * including those that cannot be generated by {@link #process}. *
* * @return coverage percentage */ public double getCoverageAllNoWeight() { if (containedSubSeqs == null) { containedSubSeqs = SequenceTools.containedSubSequences(sequences, length); } return ((double) containedSubSeqs.size()) / SequenceTools.numSequences(process, length); } /** ** Calculates the percentage of subsequences of length k that occur and can * generated by {@link #process}. *
* * @return coverage percentage */ public double getCoveragePossibleNoWeight() { if (containedSubSeqs == null) { containedSubSeqs = SequenceTools.containedSubSequences(sequences, length); } if (allPossibleSubSeqs == null) { allPossibleSubSeqs = process.generateSequences(length); } return ((double) containedSubSeqs.size()) / allPossibleSubSeqs.size(); } /** ** Calculates the weight of the subsequences that occur with relation to * {@link #process}, i.e., the mass of the subsequence probability covered * by the subsequences. *
* * @return coverage weight */ public double getCoveragePossibleWeight() { if (containedSubSeqs == null) { containedSubSeqs = SequenceTools.containedSubSequences(sequences, length); } if (allPossibleSubSeqs == null) { allPossibleSubSeqs = process.generateSequences(length); } if (subSeqWeights == null) { subSeqWeights = SequenceTools.generateWeights(process, allPossibleSubSeqs); } double weight = 0.0; for (List extends Event>> subSeq : containedSubSeqs) { weight += subSeqWeights.get(subSeq); } return weight; } /** ** Returns the number of covered subsequences of length k. *
* * @return number of covered subsequences */ public int getNumCovered() { if (containedSubSeqs == null) { containedSubSeqs = SequenceTools.containedSubSequences(sequences, length); } return containedSubSeqs.size(); } /** ** Returns the number of possible subsequences of length k according to the * stochastic process. *
* * @return number of possible subsequences */ public int getNumPossible() { if (allPossibleSubSeqs == null) { allPossibleSubSeqs = process.generateSequences(length); } return allPossibleSubSeqs.size(); } /** ** Sets a new collection of sequences for which the coverage is analyzed. *
* * @param newSequences * new collection of sequences * @throws InvalidParameterException * thrown is newSequences is null */ public void setSequences(Collection