Code Examples
A repository of 155 code examples for BeepBeep
MaxMiningFunctionProcessor.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2017 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package mining.extraction;
19 
20 import java.util.Set;
21 
22 import ca.uqac.lif.cep.functions.CumulativeFunction;
23 import ca.uqac.lif.cep.functions.Cumulate;
24 import ca.uqac.lif.cep.functions.FunctionException;
25 import ca.uqac.lif.cep.peg.Sequence;
26 import ca.uqac.lif.cep.peg.ml.ProcessorMiningFunction;
27 import ca.uqac.lif.cep.util.Bags;
28 import ca.uqac.lif.cep.util.Numbers;
29 import mining.SequenceReader;
30 
31 /**
32  * Create a mining function from BeepBeep processors. This example is
33  * identical to {@link MaxMiningFunction}, except that it uses BeepBeep
34  * processors to perform the same mining task, instead of custom code.
35  * As a result, the solution here is about 3 times shorter (in absolute
36  * number of lines of code, roughly 5 vs. 15).
37  * <p>
38  * The function is parameterized as follows:
39  * <p>
40  * <table>
41  * <tr><th>Parameter</th><th>Value</th></tr>
42  * <tr>
43  * <td><img src="./doc-files/mining/trenddistance/BetaProcessor.png" alt="Processor graph"></td>
44  * <td><img src="./doc-files/mining/extraction/MaxProcessor.png" alt="Processor graph"></td>
45  * </tr>
46  * <tr>
47  * <td><img src="./doc-files/mining/extraction/AlphaProcessor.png" alt="Processor graph"></td>
48  * <td><img src="./doc-files/mining/extraction/MaxOnSet.png" alt="Processor graph"></td>
49  * </tr>
50  * </table>
51  * <p>
52  * As one can see, the trend processor computes the maximum value on a stream.
53  * The aggregation processor runs yet another instance of the max processor,
54  * by feeding the elements of the input set one by one and returning its
55  * last value.
56  *
57  * @see MaxMiningFunction
58  * @author Sylvain HallĂ©
59  */
61 {
62  public static void main(String[] args) throws FunctionException
63  {
64  /* First, we must get from somewhere a set of sequences. For the sake
65  * of this example, we just create a few dummy sequences of numbers
66  * from the contents of a file. */
67  Set<Sequence<Number>> sequences = SequenceReader.readNumericalSequences("numbers-1.csv");
68 
69  /* We then create an instance of our mining function. A mining function
70  * takes as input a set of sequences, and returns for its output some
71  * "pattern" extracted from this set of sequences. */
72  ProcessorMiningFunction<Number,Number> a_f = new ProcessorMiningFunction<Number,Number>(
73  new Cumulate(new CumulativeFunction<Number>(Numbers.maximum)),
74  new Bags.RunOn(new Cumulate(new CumulativeFunction<Number>(Numbers.maximum))));
75 
76  /* We then evaluate the function on our set of sequences. */
77  Number n = (Number) a_f.mine(sequences);
78 
79  /* In this case, the result of this function should be the maximum of
80  * all values in all the input sequences. */
81  System.out.println(n);
82  }
83 }
Extract patterns from input streams using data mining and statistical algorithms. ...
Utility class that creates a set of sequences from a file.
Create a mining function from BeepBeep processors.