package de.ugoe.cs.eventbench.coverage; import java.security.InvalidParameterException; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import de.ugoe.cs.eventbench.data.Event; import de.ugoe.cs.eventbench.models.IStochasticProcess; /** *
* This class gathers some helper functions to work with sequences. *
* * @author Steffen Herbold * @version 1.0 */ public class SequenceTools { /** ** Private constructor to prevent initializing of the class. *
*/ private SequenceTools() { } /** ** Calculates the weights for all sequences passed to this function as * defined by the stochastic process and stores them in a {@link Map}. The * weights are normalized, i.e., the sum of all weights contained in this * map is 1. *
* * @param process * process used for weight calculation * @param sequences * sequences for which the weights are calculated * @return {@link Map} of weights */ public static Map* Calculates the number of all existing sequences of a given length, * regardless whether they are possible or not. *
* * @param process * stochastic process whose symbols are the basis for this * calculation * @param length * lenght of the sequences * @return numStates^length * @throws InvalidParameterException * thrown if length less or equal to 0 */ public static long numSequences(IStochasticProcess process, int length) { if (length <= 0) { throw new InvalidParameterException( "length must be a positive integer"); } long result = 0; if (process != null) { result = (long) Math.pow(process.getNumSymbols(), length); } return result; } /** ** Creates a {@link Set} of all subsequences of a given length that are * contained in a sequence collection. *
* * @param sequences * sequences from which the subsequences are extracted * @param length * length of the subsequences * @return {@link Set} of all subsequences * @throws InvalidParameterException * thrown if length less or equal to 0 */ public static Set