Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
File size: 1,591 Bytes
ac7f7cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <math.h>
#include <stdint.h>
#include <string.h>

/* Read the dtype/strides verified by forest.py; never assume an sklearn C struct layout.
   The table contains pointers to non-owning array views pinned by the Python plan.
   f32 inputs, f64 comparisons and tree-order f64 sums match sklearn's serial path. */
static intptr_t read_index(uintptr_t p) {
    intptr_t out;
    memcpy(&out, (const void *)p, sizeof out);
    return out;
}
static double read_double(uintptr_t p) {
    double out;
    memcpy(&out, (const void *)p, sizeof out);
    return out;
}
#ifdef _WIN32
__declspec(dllexport)
#endif
void wisp_forest(const float *x, intptr_t n, intptr_t d,
                 const uintptr_t *specs, intptr_t nt, intptr_t k, double *out) {
    for (intptr_t t = 0; t < nt; ++t) {
        const uintptr_t *tree = specs + 8 * t;
        const uintptr_t stride = tree[6];
        for (intptr_t i = 0; i < n; ++i) {
            intptr_t node = 0, left;
            uintptr_t off = 0;
            while ((left = read_index(tree[0] + off)) != -1) {
                const float val = x[i*d + read_index(tree[2]+off)];
                const int go_left = isnan(val) ? *(const uint8_t *)(tree[5]+off)
                                               : (double)val <= read_double(tree[3]+off);
                node = go_left ? left : read_index(tree[1]+off);
                off = (uintptr_t)node * stride;
            }
            const double *leaf = (const double *)(tree[4] + (uintptr_t)node * tree[7]);
            for (intptr_t j = 0; j < k; ++j) out[i*k+j] += leaf[j];
        }
    }
}