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

Last change on this file since 1641 was 1641, checked in by sherbold, 10 years ago
  • added method getLogSum to the interface IStochasticProcess and implemented it in the TrieBasedModel?
  • Property svn:mime-type set to text/plain
File size: 7.0 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     * @return randomly generated sequence
104     *
105     */
106    public List<Event> randomSequence(int maxLength, boolean validEnd);
107
108    /**
109     * <p>
110     * Generates all sequences of a given length are possible, i.e., have a positive probability.<br>
111     * All states are used as possible starting states.
112     * </p>
113     *
114     * @param length
115     *            length of the generated sequences
116     * @return generated sequences
117     * @see #generateSequences(int, boolean)
118     * @throws IllegalArgumentException
119     *             thrown if length is less than or equal to 0
120     */
121    public Collection<List<Event>> generateSequences(int length);
122
123    /**
124     * <p>
125     * Generates all sequences of given length that can are possible, i.e., have positive
126     * probability.<br>
127     * If {@code fromStart==true}, all generated sequences start in {@link Event#STARTEVENT}.
128     * Otherwise this method is the same as {@link #generateSequences(int)}.
129     * </p>
130     *
131     * @param length
132     *            length of the generated sequences
133     * @param fromStart
134     *            if true, all generated sequences start with {@link Event#STARTEVENT}
135     * @return generated sequences
136     * @throws IllegalArgumentException
137     *             thrown if length is less than or equal to 0
138     */
139    public Collection<List<Event>> generateSequences(int length, boolean fromStart);
140
141    /**
142     * <p>
143     * Generates all sequences starting with {@link Event#STARTEVENT} and finishing with
144     * {@link Event#ENDEVENT} of a given length. It is possible that no such sequence exists with
145     * the defined length and the returned set is empty. If {@code length} is less than 2 the
146     * returned set is always empty.
147     * </p>
148     *
149     * @param length
150     * @return generated sequences
151     * @throws IllegalArgumentException
152     *             thrown if length is less than or equal to 0
153     */
154    public Collection<List<Event>> generateValidSequences(int length);
155
156    /**
157     * <p>
158     * Returns the number of states known by the stochastic process, i.e., the size of its alphabet.
159     * </p>
160     *
161     * @return number of states
162     */
163    public int getNumSymbols();
164
165    /**
166     * <p>
167     * Returns a string representation of all known states.
168     * </p>
169     *
170     * @return string representation for all known states
171     */
172    public String[] getSymbolStrings();
173
174    /**
175     * <p>
176     * Returns the number of states the process would have if it would be flattened through
177     * state-splitting to a first-order Markov model.
178     * </p>
179     * <p>
180     * If it is not possible to flatten the model, -1 is returned.
181     * </p>
182     *
183     * @return number of states an equivalent FOM would have; -1 if not available
184     */
185    public int getNumFOMStates();
186
187    /**
188     * <p>
189     * Returns the number of transitions the process would have if it would be flattened through
190     * state-splitting to a first-order Markov model.
191     * </p>
192     *
193     * @return number of transitions an equivalent FOM would have; -1 if not available
194     */
195    public int getNumTransitions();
196
197    /**
198     * <p>
199     * Returns all states known by the stochastic process, i.e., its {@link Event}s.
200     * </p>
201     *
202     * @return events known by the process
203     */
204    public Collection<Event> getEvents();
205
206}
Note: See TracBrowser for help on using the repository browser.