2014-12-09 19:46:25 +00:00
|
|
|
/** Histogram functions.
|
|
|
|
*
|
2015-06-02 22:29:15 +02:00
|
|
|
* @file
|
2014-12-09 19:46:25 +00:00
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
2017-04-27 12:56:43 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-06-02 21:53:04 +02:00
|
|
|
*********************************************************************************/
|
2014-12-09 19:46:25 +00:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-12-09 19:46:25 +00:00
|
|
|
|
2015-01-20 13:52:32 +00:00
|
|
|
#include <stdio.h>
|
2016-11-08 00:36:04 -05:00
|
|
|
#include <stdint.h>
|
2015-01-20 13:52:32 +00:00
|
|
|
|
2017-03-13 23:51:38 -03:00
|
|
|
#include <jansson.h>
|
2015-09-21 17:12:02 +02:00
|
|
|
|
|
|
|
#define HIST_HEIGHT (LOG_WIDTH - 55)
|
2014-12-09 19:46:25 +00:00
|
|
|
#define HIST_SEQ 17
|
|
|
|
|
2016-10-30 22:54:20 -04:00
|
|
|
typedef uintmax_t hist_cnt_t;
|
2014-12-09 22:51:02 +00:00
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Histogram structure used to collect statistics. */
|
2014-12-09 19:46:25 +00:00
|
|
|
struct hist {
|
2015-10-11 13:22:58 +02:00
|
|
|
double resolution; /**< The distance between two adjacent buckets. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2015-10-11 13:22:58 +02:00
|
|
|
double high; /**< The value of the highest bucket. */
|
|
|
|
double low; /**< The value of the lowest bucket. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2015-10-11 13:22:58 +02:00
|
|
|
double highest; /**< The highest value observed (may be higher than #high). */
|
|
|
|
double lowest; /**< The lowest value observed (may be lower than #low). */
|
|
|
|
double last; /**< The last value which has been put into the buckets */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2015-10-11 13:22:58 +02:00
|
|
|
int length; /**< The number of buckets in #data. */
|
|
|
|
|
|
|
|
hist_cnt_t total; /**< Total number of counted values. */
|
2017-05-05 22:26:34 +00:00
|
|
|
hist_cnt_t warmup; /**< Number of values which are used during warmup phase. */
|
|
|
|
|
2017-05-05 19:24:16 +00:00
|
|
|
hist_cnt_t higher; /**< The number of values which are higher than #high. */
|
2015-10-11 13:22:58 +02:00
|
|
|
hist_cnt_t lower; /**< The number of values which are lower than #low. */
|
|
|
|
|
|
|
|
hist_cnt_t *data; /**< Pointer to dynamically allocated array of size length. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2015-10-11 13:22:58 +02:00
|
|
|
double _m[2], _s[2]; /**< Private variables for online variance calculation */
|
2014-12-09 19:46:25 +00:00
|
|
|
};
|
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Initialize struct hist with supplied values and allocate memory for buckets. */
|
2017-05-05 22:26:34 +00:00
|
|
|
int hist_init(struct hist *h, int buckets, hist_cnt_t warmup);
|
2014-12-09 19:46:25 +00:00
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Free the dynamically allocated memory. */
|
2017-02-18 10:43:01 -05:00
|
|
|
int hist_destroy(struct hist *h);
|
2014-12-09 19:46:25 +00:00
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Reset all counters and values back to zero. */
|
2014-12-09 19:46:25 +00:00
|
|
|
void hist_reset(struct hist *h);
|
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Count a value within its corresponding bucket. */
|
2014-12-09 19:46:25 +00:00
|
|
|
void hist_put(struct hist *h, double value);
|
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Calcluate the variance of all counted values. */
|
2014-12-09 22:51:02 +00:00
|
|
|
double hist_var(struct hist *h);
|
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Calculate the mean average of all counted values. */
|
2014-12-09 22:51:02 +00:00
|
|
|
double hist_mean(struct hist *h);
|
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Calculate the standard derivation of all counted values. */
|
2014-12-09 22:51:02 +00:00
|
|
|
double hist_stddev(struct hist *h);
|
|
|
|
|
2014-12-09 22:51:04 +00:00
|
|
|
/** Print all statistical properties of distribution including a graphilcal plot of the histogram. */
|
2016-10-30 22:55:56 -04:00
|
|
|
void hist_print(struct hist *h, int details);
|
2014-12-09 22:51:02 +00:00
|
|
|
|
2014-12-09 19:46:25 +00:00
|
|
|
/** Print ASCII style plot of histogram */
|
|
|
|
void hist_plot(struct hist *h);
|
|
|
|
|
2015-09-22 12:58:37 +02:00
|
|
|
/** Dump histogram data in Matlab format.
|
|
|
|
*
|
|
|
|
* @return The string containing the dump. The caller is responsible to free() the buffer.
|
|
|
|
*/
|
|
|
|
char * hist_dump(struct hist *h);
|
2015-01-20 13:52:32 +00:00
|
|
|
|
|
|
|
/** Prints Matlab struct containing all infos to file. */
|
2016-10-22 20:38:31 -04:00
|
|
|
int hist_dump_matlab(struct hist *h, FILE *f);
|
|
|
|
|
|
|
|
int hist_dump_json(struct hist *h, FILE *f);
|
|
|
|
|
|
|
|
json_t * hist_json(struct hist *h);
|