Edge AI Add-on API 2.2.0
Loading...
Searching...
No Matches
nrf_obsv_dist_binning.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef NRF_OBSV_DIST_BINNIG_H_
8#define NRF_OBSV_DIST_BINNIG_H_
9
10#include <stdint.h>
11
12/*
13 * Shared histogram-binning helpers for distribution-style metrics.
14 *
15 * Two binning paths are provided:
16 *
17 * - Custom edges: a metric that needs arbitrary (non-uniform) bin boundaries
18 * stores bin_num - 1 ascending inner edges and bins values with
19 * _dist_find_bin(). The per-class probability distribution metric uses this.
20 *
21 * - Uniform [0, 1] fast path: a metric whose bins are always uniform over
22 * [0, 1] needs no stored edges and bins values in O(1) with
23 * _dist_uniform_bin(). The entropy/margin/mel descriptor metrics use this.
24 */
25
26/* Fill the bin_num - 1 inner edges of bin_num uniform bins spanning [0, 1]. */
27void _dist_uniform_edges(float *edges, uint8_t bin_num);
28
29/*
30 * Return the bin index in [0, bin_num - 1] that @val falls into, given the
31 * bin_num - 1 ascending inner edges. A value below edges[b] lands in bin b;
32 * a value at or above the last edge lands in the top bin.
33 */
34uint8_t _dist_find_bin(const float *edges, uint8_t bin_num, float val);
35
36/*
37 * Return the bin index in [0, bin_num - 1] for @val over bin_num uniform bins
38 * spanning [0, 1], without any stored edges or search. @val <= 0 lands in bin 0;
39 * @val >= 1 lands in the top bin. Equivalent to _dist_find_bin() against uniform
40 * edges, but O(1).
41 */
42uint8_t _dist_uniform_bin(uint8_t bin_num, float val);
43
44/*
45 * Clip @v to [0, 1]. Used by the mel descriptor metrics to clamp their
46 * scale-invariant statistics to [0, 1] before binning.
47 */
48static inline float _clip01(float v)
49{
50 return (v < 0.0f) ? 0.0f : ((v > 1.0f) ? 1.0f : v);
51}
52
53#endif /* NRF_OBSV_DIST_BINNIG_H_ */