Declaring inferenced output as a variable

Quick question -
I’ve been working with the Anomaly detection on K-means clustering and trying to declare the output value of the Anomaly score ( based on input of three sensor axis features) as a variable,


            ei_printf("anomaly:\t%.3f\n", result.anomaly);

But, the Anomaly value is not in decimal format, rather in Vector(most probably). How can we go ahead declaring the Anomaly score as a variable, converting the vectorial format to a numerical format. If it’s left unconverted, the output for printing the value is - 0 -

float value1;

// generated code

value1 = (float)result.anomaly;

Output - 0

Also, how is the Anomaly being calculated. Do negative values mean that it isn’t an Anomaly?
On the live classification page, Anomaly clusters are being printed on a plane (2D Axis), with any two of sensor data processed features being the axis. So, when it is deployed on the MCU, is it calculated based on three axis clusters ( 3D vectors ) or two axis ( 2D Vectors ).

Thank you!


When you generate the anomaly model:

  1. All data is grouped in clusters (default 32).
  2. For each of these clusters the center and the radius is recorded.
  3. When new data comes in we calculate the distance to the edge of the closest cluster.

So a value <0 means that the data is in a known cluster. A value slightly above 0 means it’s very close to a cluster. And a high value means it’s far from a cluster.

So what you get out of here is already a number (not a vector), the visualization is just there so you have an idea of where the clusters are (and that works better in 2D).

1 Like

Thanks for clearing it out!
Also, although it is a numerical data, somehow I’m not able to record the value in the form of a variable. When I print the data, I get an output of 0

Where am I wrong here?

Which project ID is this for?

ID: 16818
It’s regarding this - Generating Raw features for static_buffer script
So, what I’m doing is declaring the Anomaly score as a variable and trying to send that data over to another device. The snippet attached here is a small part of the code.

Edit: Here’s the file if you wish to take a look.
It’s the continued part of the earlier topic, except that I’m trying to send the Anomaly score to particle Argon through serial comms. Rest everything is functional, data is sent over, but the Anomaly score gives an output - 0

@dhruvsheth Interesting… I don’t see the 0 on my Nano 33 BLE Sense… Could you enable debugging via:

EI_IMPULSE_ERROR res = run_classifier(&signal, &result, true);
1 Like

Thanks for the help.
I tried changing the false in the script to true, but didn’t change the result. Looks like this doesn’t solve the problem. I’m declaring a variable as the anomaly result i,e,
anomalydata is a variable declared, and -
anomalydata = (float)result.anomaly
Later when I print the variable it gives me 0.
Normally getting the anomaly score as in the default script gives perfect result. Am I declaring the variable wrong? You could have a look at the script for which the link is added above. I’m declaring the variable to merely send the anomaly score over to another board via serial comms.


Sorry for the late reply @dhruvsheth, missed the notification. Do you actually see the variable being printed with the true there? I see 1000 come by (the max. score) probably because one of my sensors returns 0…

I see the anomaly score from the defult ei_printf come up as expected. However, I do not see the true being printed, when I print the variable. The variable declared in the void WeatherData continuously returns 0 even after few syntax changes. Is there a possibility that the result.anomaly is a const char format, which cannot be directly declared as a float variable?

@dhruvsheth No, it’s a float. Here’s the struct:

typedef struct {
    ei_impulse_result_classification_t classification[EI_CLASSIFIER_LABEL_COUNT];
    float anomaly;
    ei_impulse_result_timing_t timing;
} ei_impulse_result_t;

Maybe marking your variable as volatile float anomaly ? I have no clue actually at the moment.

Thanks for the info
I feel that the sensor output is a bit more unstable. I left it for a few minutes and now, it gives an output - 1000. Changes back to 0 when it is plugged in again. I will check out what can be done to stabilize the readings.
Thanks, Dhruv

My bad, understood the issue.
It’s the delay that’s affecting the whole thing.
Delay for printing the variable is 5000ms
Delay for getting the value of the anomaly = 2000ms
In this, the anomaly doesn’t follow definite time interval until both arrive at a common multiple. I’ll change and then it should work

Thanks a ton

1 Like