dabble.statistics
Description
Calculates the cumulative average, minimum, and maximum of a single variable of interest over time.
- class Node(config=None, **kwargs)[source]
Calculates the cumulative average, minimum, and maximum of a single variable of interest (defined as
current result
here) over time. The configurations for this node offer several functions to reduce the incoming data type into a singlecurrent result
of typeint
orfloat
, which is valid for the current video frame.current result
is then used to recalculate the values of the cumulative average, minimum, and maximum for PeekingDuck’s running duration thus far.The configuration for this node is described below using a combination of the Extended BNF and Augmented BNF metasyntax. Concrete examples are provided later for illustration.
pkd_data_type = ? PeekingDuck built-in data types ? e.g. count, large_groups, obj_attrs user_data_type = ? user data types produced by custom nodes ? e.g. my_var, my_attrs dict_key = ? Python dictionary keys, with optional nesting ? e.g. ["ids"], ["details"]["age"] data_type = pkd_data_type | user_data_type target_attr = data_type | data_type "[" dict_key "]" unary_function = "identity" | "length" | "maximum" | "minimum" unary_expr = unary_function ":" target_attr num_operator = "==" | ">=" | "<=" | ">" | "<" num_operand = ? Python integers or floats ? num_comparison = num_operator num_operand str_operator = "==" str_operand = ? Python strings enclosed by single or double quotes ? str_comparison = str_operator str_operand cond_function = "cond_count" cond_expr = cond_function ":" target_attr ( num_comparison | str_comparison ) configuration = unary_expr | cond_expr
Points to note:
Square brackets (
[]
) are used to define<dict_key>
, and should not be used elsewhere in the configuration.Operands are processed differently depending on whether they are enclosed by single/double quotes, or not. If enclosed, the operand is assumed to be of type
str
and classified as<str_operand>
. If not, the operand is classified as<num_operand>
and converted intofloat
for further processing.
The table below illustrates how configuration choices reduce the incoming data type into the
<current result>
.<pkd_data_type>
: valueor
<user_data_type>
: value<target_attr>
<unary_expr>
or
<cond_expr>
<current result>
count: 8
count
identity:
count
8
obj_attrs: {
ids: [1,2,4],
details: {
gender: [“male”,”male”,”female”],
age: [52,17,48] }}
obj_attrs[“ids”]
length:
obj_attrs[“ids”]
3
obj_attrs [“details”] [“age”]
maximum:
obj_attrs [“details”] [“age”]
52
obj_attrs [“details”] [“gender”]
cond_count:
obj_attrs [“details”] [“gender”]
== “male”
2
obj_attrs [“details”] [“age”]
cond_count:
obj_attrs [“details”] [“age”]
< 60
3
- Inputs
all
(Any
): This data type contains all the outputs from preceding nodes, granting a large degree of flexibility to nodes that receive it. Examples of such nodes includedraw.legend
,dabble.statistics
, andoutput.csv_writer
.- Outputs
cum_avg
(float
): Cumulative average of an attribute over time.Note that cum_avg will not be updated if there are no detections. For example, if cum_avg = 10 for video frame 1, and there are no detections in the following 500 frames, cum_avg is still 10 for video frame 501.
cum_max
(float | int
): Cumulative maximum of an attribute over time.cum_min
(float | int
): Cumulative minimum of an attribute over time.- Configs
identity (
str
) – default=null
Accepts<target_attr>
of typesint
orfloat
, and returns the same value.length (
str
) – default=null
Accepts<target_attr>
of typesList[Any]
orDict[str, Any]
, and returns its length.minimum (
str
) – default=null
Accepts<target_attr>
of typesList[float | int]
orDict[str, float | int]
, and returns the minimum element within for the current frame. Not to be confused with the cum_min output data type, which represents the cumulative minimum over time.maximum (
str
) – default=null
Accepts<target_attr>
of typesList[float | int]
orDict[str, float | int]
, and returns the maximum element within for the current frame. Not to be confused with the cum_max output data type, which represents the cumulative maximum over time.cond_count (
str
) – default=null
Accepts<target_attr>
of typesList[float | int | str]
, and checks if each element in the list fulfils the condition described by<num_comparison>
or<str_comparison>
. The number of elements that fulfil the condition are counted towards<current result>
.