Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spatial anomaly #587

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Spatial anomaly #587

wants to merge 6 commits into from

Conversation

breznak
Copy link
Member

@breznak breznak commented Jul 24, 2019

  • implements spatial anomaly, as is currenly used in NAB
    • use as SP.anomaly&
    • later find better approach, but not part of this PR
  • test & doc
  • bindings - I'm waiting with bindings for consulting with you,
    • I don't like extending SP.compute(..., Real spatialValue) with the optional argument for spatial anomaly (it designates the original input value)
    • my proposal: Extend SDR to have const Real& SDR.origValue
      • which the encoder, user on input sets
      • other layers copy to higher SDRs (enc->SP->TM) still carries the same value.
      • used by: Predictor, Classifier, spatial_anomaly
      • can be unknown (default) (merging in higher layers, ...)

spatial anomaly ported from NAB
had to exptend SP.compute(..., value=Real) with an optional argument
@breznak breznak added question Further information is requested ready anomaly SP labels Jul 24, 2019
@breznak breznak self-assigned this Jul 24, 2019
<< "Deterministic output of Anomaly failed! " << an << "should be: " << goldAn;
NTA_CHECK(static_cast<UInt>(avgAnom10.getCurrentAvg() * 10000.0f) == static_cast<UInt>(goldAnAvg * 10000.0f))
<< "Deterministic average anom score failed:" << avgAnom10.getCurrentAvg() << " should be: " << goldAnAvg;
if(useSPglobal) { NTA_CHECK(0.0f == spGlobal.anomaly) << "Deterministic spatial anomaly mismatch!" << spGlobal.anomaly; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hotgym checks the new spatial anomaly

virtual void compute(const SDR &input,
const bool learn,
SDR &active,
const Real spatialAnomalyInputValue = std::numeric_limits<Real>::min());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to extend SP.compute() with the extra, optional field. It works ok, but I don't like it too much, maybe better is the proposal with "SP carrying orig input value"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the anomaly code could be built into the encoder, since the encoder already has access to the original input value?

Alternatively, this piece of code (spatial anomaly detection) could live in its own class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anomaly code could be built into the encoder, since the encoder already has access to the original input value?

makes sense! This is really more a function of an encoder (input). As I was saying, I don't really like the current implementation, but it is what's used in NAB.

spatial anomaly detection) could live in its own class?

later I'm going to implement SP's anomaly detection based on synapses of SP, so

  • a part of this PR was preparation of the "infrastructure" for the SP.anomaly, later I'd just change the actual method
  • you're right this belongs more to the BaseEncoder than to SP

Which way would you suggest, I don't really have a preference now

*
* @return either 0.0f (no anomaly), or exactly 0.9995947141f (spatial anomaly). This specific value can be recognized in results.
*/
const Real& anomaly = spAnomaly.anomalyScore_;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spAnomaly implementation,

val = 100.0f; //(12-0) * 0.2 == ~2.2 -> <-2.2, +14.2> is not anomalous, but 100 is!
enc.encode(val, inputs);
sp.compute(inputs, true, columns, val);
EXPECT_EQ(0.9995947141f, sp.anomaly) << "This should be an anomaly!";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing SP.anomaly correctness

return self.anomaly;
});
py_SpatialPooler.def("anomalyThreshold", [](const SpatialPooler& self) {
return &self.spAnomaly.SPATIAL_TOLERANCE;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the py bindings. Will this work so that I'll be able to set through the variable, or is it just a getter?

@breznak
Copy link
Member Author

breznak commented Jul 25, 2019

@dkeeney a chance this has to do with the recent x64 changes?

Undefined symbols for architecture x86_64:
"htm::SpatialPooler::spatial_anomaly::NO_ANOMALY", referenced from:
testing::SpatialPoolerTest_spatialAnomaly_Test::TestBody() in SpatialPoolerTest.cpp.o
"htm::SpatialPooler::spatial_anomaly::SPATIAL_ANOMALY", referenced from:
testing::SpatialPoolerTest_spatialAnomaly_Test::TestBody() in SpatialPoolerTest.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I cannot reproduce it locally on x86_64 Linux, also other CI pass.

@breznak breznak added the on_hold label Aug 1, 2019
@breznak
Copy link
Member Author

breznak commented Aug 1, 2019

Putting this on hold until htm-community/NAB#15 is resolved.
Ie the API for spatial anomaly is good, the implementation is not (valid)

@breznak breznak removed the ready label Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
anomaly on_hold question Further information is requested SP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants