the-aerospace-corporation / brainblocks

Practical Tool for Building ML Applications with HTM-Like Algorithms
GNU Affero General Public License v3.0
60 stars 13 forks source link

example for sequence learning? #14

Closed Thanh-Binh closed 2 years ago

Thanh-Binh commented 3 years ago

I am interested in sequence learning and try to learn it by running a C++ test example for sequence learning in the folder "test". For doing it I try to modify very slightly the data by adding 0.01 into the learn sequence, but it can not learn correctly. std::vector values = { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 0.01, 0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81, 0.91}; Here is scores: values, scores 0.0000, 1.0000 0.1000, 1.0000 0.2000, 1.0000 0.3000, 1.0000 0.4000, 1.0000 0.5000, 1.0000 0.6000, 1.0000 0.7000, 1.0000 0.8000, 1.0000 0.9000, 1.0000 0.0000, 1.0000 0.1000, 0.0000 0.2000, 0.0000 0.3000, 0.0000 0.4000, 0.0000 0.5000, 0.0000 0.6000, 0.0000 0.7000, 0.0000 0.8000, 0.0000 0.9000, 0.0000 0.0000, 0.0000 0.1000, 0.0000 0.2000, 0.0000 0.3000, 0.0000 0.4000, 0.0000 0.5000, 0.0000 0.6000, 0.0000 0.7000, 0.0000 0.8000, 0.0000 0.9000, 0.0000 0.0100, 0.6250 0.1100, 1.0000 0.2100, 1.0000 0.3100, 1.0000 0.4100, 1.0000 0.5100, 1.0000 0.6100, 1.0000 0.7100, 1.0000 0.8100, 1.0000 0.9100, 1.0000

Any explain? Thanks

jacobeverist commented 3 years ago

So the anomaly scores look right. Although the data you declared in std::vector values, is not the same as the output you printed.

At the data point of 0.01, it recognizes an irregular transition and rightfully scores a 0.625 for the anomaly score. Then, every step after of 0.11, 0.21, etc is an anomalous state and transition. So it is correct at flagging 1.0 as the score.

Now, if you repeated this sequence, you should be getting 0.0 for the scores since it is a sequence you've seen before. The sequence learner needs to see the sequence at least once before it will recognize it and give a 0.0 anomaly score.

Was there some other kind of behavior you wanted to achieve? If you wanted to make the small change of 0.01 irrelevant, you would need to reduce the sensitivity of the ScalarTransformer being used.

Try changing the block definitions from this:

// Setup blocks
ScalarTransformer st(0.0, 1.0, 512, 8, 2);
SequenceLearner sl(512, 10, 10, 12, 6, 20, 2, 1, 2);

to this:

// Setup blocks
ScalarTransformer st(0.0, 1.0, 256, 4, 2);
SequenceLearner sl(256, 10, 10, 12, 6, 20, 2, 1, 2);

or even smaller:

// Setup blocks
ScalarTransformer st(0.0, 1.0, 128, 2, 2);
SequenceLearner sl(128, 10, 10, 12, 6, 20, 2, 1, 2);

Alternatively, you can keep the same size of 512 statelets, but you could increase the scalar range and thus achieve the same effect of a less sensitive encoder:

// Setup blocks
ScalarTransformer st(-2.0, 3.0, 512, 8, 2);
SequenceLearner sl(512, 10, 10, 12, 6, 20, 2, 1, 2);
Thanh-Binh commented 3 years ago

@jacobeverist by changing the 1st parameter from 512 to 256 you reduce the value resolution by 2 so that it is less sensitive. In Praxis we do not have sequence which repeated exactly, but somehows like fuzzy or looks like the same, e.g. triangle vs triangle with rounded corners or signal with slightly changes of the middle value over time. Do you think that your algorithm can solve this problem?

jacobeverist commented 3 years ago

I reduced the sensitivity because I thought you were trying to keep the new data as normal. Is this correct?

For your own problem, you need to better define it and how you would define success. Yes it can recognize noisy trajectories and identify slight changes, but you need to better define what normal data looks like and what abnormal data looks like. If you give examples of the data, I can help you tune it to identify the abnormal sequences.

Thanh-Binh commented 3 years ago

@jacobeverist thanks. How can I send my data to you? Maybe you can send me an email using: Thanh-Binh.To@online.de After that I will send you my data per email.

jacobeverist commented 2 years ago

Added further examples in 7a40ff577cd031bcbe4708121768c596251cd2e5