source: trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/IStochasticProcess.java @ 2026

Last change on this file since 2026 was 2026, checked in by sherbold, 9 years ago
  • made generation of random sequences with an expected valid end and a predefined maximum length more robust. the generation now aborts after a user-defined number of attempts to create a valid sequence and returns an empty sequence instead.
  • Property svn:mime-type set to text/plain
File size: 7.2 KB
Line 
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
15package de.ugoe.cs.autoquest.usageprofiles;
16
17import java.io.Serializable;
18import java.util.Collection;
19import java.util.List;
20
21import 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 */
31public 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 probability 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
59     * @throws IllegalArgumentException
60     *             thrown if sequence is null
61     */
62    double getProbability(List<Event> sequence);
63
64    /**
65     * <p>
66     * Returns the sum of the negative logarithm of the probabilities.
67     * </p>
68     *
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);
76
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();
86
87    /**
88     * <p>
89     * Generates a random sequence of events. The sequence starts with {@link Event#STARTEVENT} and
90     * finishes with
91     * <ul>
92     * <li>{@link Event#ENDEVENT} if validEnd==true.</li>
93     * <li>b) if a generated sequences reaches {@link Event#ENDEVENT} before maxLength, the sequence
94     * finishes and is shorter than maxLenght. Otherwise, the sequence finishes as soon as maxLength
95     * is reached and the final event of the sequence must not be {@link Event#ENDEVENT}.</li>
96     * </ul>
97     * </p>
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
103     * @param maxIter
104     *            maximum number of attempts for the generation of the sequence; in case of failure
105     *            and empty sequence is returned
106     * @return randomly generated sequence
107     *
108     */
109    public List<Event> randomSequence(int maxLength, boolean validEnd, long maxIter);
110
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)
121     * @throws IllegalArgumentException
122     *             thrown if length is less than or equal to 0
123     */
124    public Collection<List<Event>> generateSequences(int length);
125
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
139     * @throws IllegalArgumentException
140     *             thrown if length is less than or equal to 0
141     */
142    public Collection<List<Event>> generateSequences(int length, boolean fromStart);
143
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
154     * @throws IllegalArgumentException
155     *             thrown if length is less than or equal to 0
156     */
157    public Collection<List<Event>> generateValidSequences(int length);
158
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();
167
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();
176
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();
189
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();
199
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();
208
209}
Note: See TracBrowser for help on using the repository browser.