1 /*
2 * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 /**
26 ** This file contains a few classes that represent number sequence,
27 ** x1, x2, x3, ..., xN, and can calculate their avg, max, and sd.
28 **
29 ** Here's a quick description of the classes:
30 **
31 ** AbsSeq: abstract superclass
32 ** NumberSeq: the sequence is assumed to be very long and the
33 ** maximum, avg, sd, davg, and dsd are calculated over all its elements
34 ** TruncatedSeq: this class keeps track of the last L elements
35 ** of the sequence and calculates avg, max, and sd only over them
36 **/
37
38 #define DEFAULT_ALPHA_VALUE 0.7
39
40 class AbsSeq {
41 private:
42 void init(double alpha);
43
44 protected:
108 void init();
109 protected:
110 double *_sequence; // buffers the last L elements in the sequence
111 int _length; // this is L
112 int _next; // oldest slot in the array, i.e. next to be overwritten
113
114 public:
115 // accepts a value for L
116 TruncatedSeq(int length = DefaultSeqLength,
117 double alpha = DEFAULT_ALPHA_VALUE);
118 virtual void add(double val);
119 virtual double maximum() const;
120 virtual double last() const; // the last value added to the sequence
121
122 double oldest() const; // the oldest valid value in the sequence
123 double predict_next() const; // prediction based on linear regression
124
125 // Debugging/Printing
126 virtual void dump_on(outputStream* s);
127 };
|
1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_UTILITIES_NUMBERSEQ_HPP
26 #define SHARE_VM_UTILITIES_NUMBERSEQ_HPP
27
28 /**
29 ** This file contains a few classes that represent number sequence,
30 ** x1, x2, x3, ..., xN, and can calculate their avg, max, and sd.
31 **
32 ** Here's a quick description of the classes:
33 **
34 ** AbsSeq: abstract superclass
35 ** NumberSeq: the sequence is assumed to be very long and the
36 ** maximum, avg, sd, davg, and dsd are calculated over all its elements
37 ** TruncatedSeq: this class keeps track of the last L elements
38 ** of the sequence and calculates avg, max, and sd only over them
39 **/
40
41 #define DEFAULT_ALPHA_VALUE 0.7
42
43 class AbsSeq {
44 private:
45 void init(double alpha);
46
47 protected:
111 void init();
112 protected:
113 double *_sequence; // buffers the last L elements in the sequence
114 int _length; // this is L
115 int _next; // oldest slot in the array, i.e. next to be overwritten
116
117 public:
118 // accepts a value for L
119 TruncatedSeq(int length = DefaultSeqLength,
120 double alpha = DEFAULT_ALPHA_VALUE);
121 virtual void add(double val);
122 virtual double maximum() const;
123 virtual double last() const; // the last value added to the sequence
124
125 double oldest() const; // the oldest valid value in the sequence
126 double predict_next() const; // prediction based on linear regression
127
128 // Debugging/Printing
129 virtual void dump_on(outputStream* s);
130 };
131
132 #endif // SHARE_VM_UTILITIES_NUMBERSEQ_HPP
|