[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.usageprofiles;
|
---|
[518] | 16 |
|
---|
| 17 | import java.io.Serializable;
|
---|
| 18 | import java.util.Collection;
|
---|
| 19 | import java.util.List;
|
---|
| 20 |
|
---|
[922] | 21 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
[518] | 22 |
|
---|
| 23 | /**
|
---|
| 24 | * <p>
|
---|
| 25 | * This interface defines the functionalities provided by stochastic processes.
|
---|
| 26 | * </p>
|
---|
| 27 | *
|
---|
| 28 | * @author Steffen Herbold
|
---|
| 29 | * @version 1.0
|
---|
| 30 | */
|
---|
| 31 | public interface IStochasticProcess extends Serializable {
|
---|
| 32 |
|
---|
[559] | 33 | /**
|
---|
| 34 | * <p>
|
---|
| 35 | * Returns the probability, that the next event is {@code symbol} given the last events are
|
---|
| 36 | * {@code context}. The last element of {@code context} is the most recent in the history, the
|
---|
| 37 | * first element is the oldest.
|
---|
| 38 | * </p>
|
---|
| 39 | *
|
---|
| 40 | * @param context
|
---|
| 41 | * recently observed symbols
|
---|
| 42 | * @param symbol
|
---|
| 43 | * event for which the probability is calculated
|
---|
| 44 | * @return probabilty the {@code symbol} is the next event, given the last events
|
---|
| 45 | * {@code context}
|
---|
[766] | 46 | * @throws IllegalArgumentException
|
---|
[559] | 47 | * thrown if context or symbol is null
|
---|
| 48 | */
|
---|
| 49 | double getProbability(List<Event> context, Event symbol);
|
---|
[518] | 50 |
|
---|
[559] | 51 | /**
|
---|
| 52 | * <p>
|
---|
[1641] | 53 | * Returns the probability that a given sequence is generated by the stochastic process.
|
---|
[559] | 54 | * </p>
|
---|
| 55 | *
|
---|
| 56 | * @param sequence
|
---|
| 57 | * sequences of which the probability is calculated
|
---|
[1641] | 58 | * @return probability of the sequences; 1.0 if sequence is empty
|
---|
[766] | 59 | * @throws IllegalArgumentException
|
---|
[559] | 60 | * thrown if sequence is null
|
---|
| 61 | */
|
---|
| 62 | double getProbability(List<Event> sequence);
|
---|
[2026] | 63 |
|
---|
[1641] | 64 | /**
|
---|
| 65 | * <p>
|
---|
[2026] | 66 | * Returns the sum of the negative logarithm of the probabilities.
|
---|
[1641] | 67 | * </p>
|
---|
[2026] | 68 | *
|
---|
[1641] | 69 | * @param sequence
|
---|
| 70 | * sequences of which the logsum is calculated
|
---|
| 71 | * @return logsum of the sequences; 0.0 if sequence is empty
|
---|
| 72 | * @throws IllegalArgumentException
|
---|
| 73 | * thrown if sequence is null
|
---|
| 74 | */
|
---|
| 75 | public double getLogSum(List<Event> sequence);
|
---|
[518] | 76 |
|
---|
[559] | 77 | /**
|
---|
| 78 | * <p>
|
---|
| 79 | * Generates a random sequence of events. The sequence starts with {@link Event#STARTEVENT} and
|
---|
| 80 | * finishes with {@link Event#ENDEVENT}.
|
---|
| 81 | * </p>
|
---|
| 82 | *
|
---|
| 83 | * @return randomly generated sequence
|
---|
| 84 | */
|
---|
| 85 | public List<Event> randomSequence();
|
---|
[518] | 86 |
|
---|
[559] | 87 | /**
|
---|
| 88 | * <p>
|
---|
| 89 | * Generates a random sequence of events. The sequence starts with {@link Event#STARTEVENT} and
|
---|
| 90 | * finishes with
|
---|
[2218] | 91 | * </p>
|
---|
[559] | 92 | * <ul>
|
---|
| 93 | * <li>{@link Event#ENDEVENT} if validEnd==true.</li>
|
---|
| 94 | * <li>b) if a generated sequences reaches {@link Event#ENDEVENT} before maxLength, the sequence
|
---|
| 95 | * finishes and is shorter than maxLenght. Otherwise, the sequence finishes as soon as maxLength
|
---|
| 96 | * is reached and the final event of the sequence must not be {@link Event#ENDEVENT}.</li>
|
---|
| 97 | * </ul>
|
---|
| 98 | *
|
---|
| 99 | * @param maxLength
|
---|
| 100 | * maximum length of the generated sequence
|
---|
| 101 | * @param validEnd
|
---|
| 102 | * if true, only sequences that finish with {@link Event#ENDEVENT} are generated
|
---|
[2026] | 103 | * @param maxIter
|
---|
| 104 | * maximum number of attempts for the generation of the sequence; in case of failure
|
---|
| 105 | * and empty sequence is returned
|
---|
[559] | 106 | * @return randomly generated sequence
|
---|
| 107 | *
|
---|
| 108 | */
|
---|
[2026] | 109 | public List<Event> randomSequence(int maxLength, boolean validEnd, long maxIter);
|
---|
[518] | 110 |
|
---|
[559] | 111 | /**
|
---|
| 112 | * <p>
|
---|
| 113 | * Generates all sequences of a given length are possible, i.e., have a positive probability.<br>
|
---|
| 114 | * All states are used as possible starting states.
|
---|
| 115 | * </p>
|
---|
| 116 | *
|
---|
| 117 | * @param length
|
---|
| 118 | * length of the generated sequences
|
---|
| 119 | * @return generated sequences
|
---|
| 120 | * @see #generateSequences(int, boolean)
|
---|
[766] | 121 | * @throws IllegalArgumentException
|
---|
[559] | 122 | * thrown if length is less than or equal to 0
|
---|
| 123 | */
|
---|
| 124 | public Collection<List<Event>> generateSequences(int length);
|
---|
[518] | 125 |
|
---|
[559] | 126 | /**
|
---|
| 127 | * <p>
|
---|
| 128 | * Generates all sequences of given length that can are possible, i.e., have positive
|
---|
| 129 | * probability.<br>
|
---|
| 130 | * If {@code fromStart==true}, all generated sequences start in {@link Event#STARTEVENT}.
|
---|
| 131 | * Otherwise this method is the same as {@link #generateSequences(int)}.
|
---|
| 132 | * </p>
|
---|
| 133 | *
|
---|
| 134 | * @param length
|
---|
| 135 | * length of the generated sequences
|
---|
| 136 | * @param fromStart
|
---|
| 137 | * if true, all generated sequences start with {@link Event#STARTEVENT}
|
---|
| 138 | * @return generated sequences
|
---|
[766] | 139 | * @throws IllegalArgumentException
|
---|
[559] | 140 | * thrown if length is less than or equal to 0
|
---|
| 141 | */
|
---|
| 142 | public Collection<List<Event>> generateSequences(int length, boolean fromStart);
|
---|
[518] | 143 |
|
---|
[559] | 144 | /**
|
---|
| 145 | * <p>
|
---|
| 146 | * Generates all sequences starting with {@link Event#STARTEVENT} and finishing with
|
---|
| 147 | * {@link Event#ENDEVENT} of a given length. It is possible that no such sequence exists with
|
---|
| 148 | * the defined length and the returned set is empty. If {@code length} is less than 2 the
|
---|
| 149 | * returned set is always empty.
|
---|
| 150 | * </p>
|
---|
| 151 | *
|
---|
| 152 | * @param length
|
---|
| 153 | * @return generated sequences
|
---|
[766] | 154 | * @throws IllegalArgumentException
|
---|
[559] | 155 | * thrown if length is less than or equal to 0
|
---|
| 156 | */
|
---|
| 157 | public Collection<List<Event>> generateValidSequences(int length);
|
---|
[518] | 158 |
|
---|
[559] | 159 | /**
|
---|
| 160 | * <p>
|
---|
| 161 | * Returns the number of states known by the stochastic process, i.e., the size of its alphabet.
|
---|
| 162 | * </p>
|
---|
| 163 | *
|
---|
| 164 | * @return number of states
|
---|
| 165 | */
|
---|
| 166 | public int getNumSymbols();
|
---|
[518] | 167 |
|
---|
[559] | 168 | /**
|
---|
| 169 | * <p>
|
---|
| 170 | * Returns a string representation of all known states.
|
---|
| 171 | * </p>
|
---|
| 172 | *
|
---|
| 173 | * @return string representation for all known states
|
---|
| 174 | */
|
---|
| 175 | public String[] getSymbolStrings();
|
---|
[518] | 176 |
|
---|
[559] | 177 | /**
|
---|
| 178 | * <p>
|
---|
| 179 | * Returns the number of states the process would have if it would be flattened through
|
---|
| 180 | * state-splitting to a first-order Markov model.
|
---|
| 181 | * </p>
|
---|
| 182 | * <p>
|
---|
| 183 | * If it is not possible to flatten the model, -1 is returned.
|
---|
| 184 | * </p>
|
---|
| 185 | *
|
---|
| 186 | * @return number of states an equivalent FOM would have; -1 if not available
|
---|
| 187 | */
|
---|
| 188 | public int getNumFOMStates();
|
---|
[518] | 189 |
|
---|
[559] | 190 | /**
|
---|
| 191 | * <p>
|
---|
| 192 | * Returns the number of transitions the process would have if it would be flattened through
|
---|
| 193 | * state-splitting to a first-order Markov model.
|
---|
| 194 | * </p>
|
---|
| 195 | *
|
---|
| 196 | * @return number of transitions an equivalent FOM would have; -1 if not available
|
---|
| 197 | */
|
---|
| 198 | public int getNumTransitions();
|
---|
[518] | 199 |
|
---|
[559] | 200 | /**
|
---|
| 201 | * <p>
|
---|
| 202 | * Returns all states known by the stochastic process, i.e., its {@link Event}s.
|
---|
| 203 | * </p>
|
---|
| 204 | *
|
---|
| 205 | * @return events known by the process
|
---|
| 206 | */
|
---|
| 207 | public Collection<Event> getEvents();
|
---|
[518] | 208 |
|
---|
[559] | 209 | }
|
---|