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 |
|
---|
15 | package de.ugoe.cs.autoquest.usageprofiles;
|
---|
16 |
|
---|
17 | import java.io.Serializable;
|
---|
18 | import java.util.Collection;
|
---|
19 | import java.util.List;
|
---|
20 |
|
---|
21 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
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 |
|
---|
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}
|
---|
46 | * @throws IllegalArgumentException
|
---|
47 | * thrown if context or symbol is null
|
---|
48 | */
|
---|
49 | double getProbability(List<Event> context, Event symbol);
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * <p>
|
---|
53 | * Returns the probabilitiy that a given sequence is generated by the stochastic process.
|
---|
54 | * </p>
|
---|
55 | *
|
---|
56 | * @param sequence
|
---|
57 | * sequences of which the probability is calculated
|
---|
58 | * @return probability of the sequences; 1.0 if sequence is empty or null
|
---|
59 | * @throws IllegalArgumentException
|
---|
60 | * thrown if sequence is null
|
---|
61 | */
|
---|
62 | double getProbability(List<Event> sequence);
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * <p>
|
---|
66 | * Generates a random sequence of events. The sequence starts with {@link Event#STARTEVENT} and
|
---|
67 | * finishes with {@link Event#ENDEVENT}.
|
---|
68 | * </p>
|
---|
69 | *
|
---|
70 | * @return randomly generated sequence
|
---|
71 | */
|
---|
72 | public List<Event> randomSequence();
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * <p>
|
---|
76 | * Generates a random sequence of events. The sequence starts with {@link Event#STARTEVENT} and
|
---|
77 | * finishes with
|
---|
78 | * <ul>
|
---|
79 | * <li>{@link Event#ENDEVENT} if validEnd==true.</li>
|
---|
80 | * <li>b) if a generated sequences reaches {@link Event#ENDEVENT} before maxLength, the sequence
|
---|
81 | * finishes and is shorter than maxLenght. Otherwise, the sequence finishes as soon as maxLength
|
---|
82 | * is reached and the final event of the sequence must not be {@link Event#ENDEVENT}.</li>
|
---|
83 | * </ul>
|
---|
84 | * </p>
|
---|
85 | *
|
---|
86 | * @param maxLength
|
---|
87 | * maximum length of the generated sequence
|
---|
88 | * @param validEnd
|
---|
89 | * if true, only sequences that finish with {@link Event#ENDEVENT} are generated
|
---|
90 | * @return randomly generated sequence
|
---|
91 | *
|
---|
92 | */
|
---|
93 | public List<Event> randomSequence(int maxLength, boolean validEnd);
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * <p>
|
---|
97 | * Generates all sequences of a given length are possible, i.e., have a positive probability.<br>
|
---|
98 | * All states are used as possible starting states.
|
---|
99 | * </p>
|
---|
100 | *
|
---|
101 | * @param length
|
---|
102 | * length of the generated sequences
|
---|
103 | * @return generated sequences
|
---|
104 | * @see #generateSequences(int, boolean)
|
---|
105 | * @throws IllegalArgumentException
|
---|
106 | * thrown if length is less than or equal to 0
|
---|
107 | */
|
---|
108 | public Collection<List<Event>> generateSequences(int length);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * <p>
|
---|
112 | * Generates all sequences of given length that can are possible, i.e., have positive
|
---|
113 | * probability.<br>
|
---|
114 | * If {@code fromStart==true}, all generated sequences start in {@link Event#STARTEVENT}.
|
---|
115 | * Otherwise this method is the same as {@link #generateSequences(int)}.
|
---|
116 | * </p>
|
---|
117 | *
|
---|
118 | * @param length
|
---|
119 | * length of the generated sequences
|
---|
120 | * @param fromStart
|
---|
121 | * if true, all generated sequences start with {@link Event#STARTEVENT}
|
---|
122 | * @return generated sequences
|
---|
123 | * @throws IllegalArgumentException
|
---|
124 | * thrown if length is less than or equal to 0
|
---|
125 | */
|
---|
126 | public Collection<List<Event>> generateSequences(int length, boolean fromStart);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * <p>
|
---|
130 | * Generates all sequences starting with {@link Event#STARTEVENT} and finishing with
|
---|
131 | * {@link Event#ENDEVENT} of a given length. It is possible that no such sequence exists with
|
---|
132 | * the defined length and the returned set is empty. If {@code length} is less than 2 the
|
---|
133 | * returned set is always empty.
|
---|
134 | * </p>
|
---|
135 | *
|
---|
136 | * @param length
|
---|
137 | * @return generated sequences
|
---|
138 | * @throws IllegalArgumentException
|
---|
139 | * thrown if length is less than or equal to 0
|
---|
140 | */
|
---|
141 | public Collection<List<Event>> generateValidSequences(int length);
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * <p>
|
---|
145 | * Returns the number of states known by the stochastic process, i.e., the size of its alphabet.
|
---|
146 | * </p>
|
---|
147 | *
|
---|
148 | * @return number of states
|
---|
149 | */
|
---|
150 | public int getNumSymbols();
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * <p>
|
---|
154 | * Returns a string representation of all known states.
|
---|
155 | * </p>
|
---|
156 | *
|
---|
157 | * @return string representation for all known states
|
---|
158 | */
|
---|
159 | public String[] getSymbolStrings();
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * <p>
|
---|
163 | * Returns the number of states the process would have if it would be flattened through
|
---|
164 | * state-splitting to a first-order Markov model.
|
---|
165 | * </p>
|
---|
166 | * <p>
|
---|
167 | * If it is not possible to flatten the model, -1 is returned.
|
---|
168 | * </p>
|
---|
169 | *
|
---|
170 | * @return number of states an equivalent FOM would have; -1 if not available
|
---|
171 | */
|
---|
172 | public int getNumFOMStates();
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * <p>
|
---|
176 | * Returns the number of transitions the process would have if it would be flattened through
|
---|
177 | * state-splitting to a first-order Markov model.
|
---|
178 | * </p>
|
---|
179 | *
|
---|
180 | * @return number of transitions an equivalent FOM would have; -1 if not available
|
---|
181 | */
|
---|
182 | public int getNumTransitions();
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * <p>
|
---|
186 | * Returns all states known by the stochastic process, i.e., its {@link Event}s.
|
---|
187 | * </p>
|
---|
188 | *
|
---|
189 | * @return events known by the process
|
---|
190 | */
|
---|
191 | public Collection<Event> getEvents();
|
---|
192 |
|
---|
193 | }
|
---|