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

add learnPattern ClassifierRegion #800

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/htm/algorithms/SDRClassifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ PDF Classifier::infer(const SDR & pattern) const {
PDF probabilities( numCategories_, 0.0f );
for( const auto bit : pattern.getSparse() ) {
for( size_t i = 0; i < numCategories_; i++ ) {
probabilities[i] += weights_[bit][i];
if (weights_.size() > bit) {
if (weights_[bit].size() > i) {
Lupino marked this conversation as resolved.
Show resolved Hide resolved
probabilities[i] += weights_[bit][i];
}
}
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/htm/regions/ClassifierRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ namespace htm {
},
inputs: {
bucket: { description: "The quantized value of the current sample, one from each encoder if more than one, for the learn step",
type: Real64, count: 0},
pattern: { description: "An SDR output bit pattern for a sample. Usually the output of the SP or TM. For example: activeCells from TM",
type: SDR, count: 0}
},
type: Real64, count: 0},
pattern: { description: "An SDR output bit pattern for a sample. Usually the output of the SP or TM. For example: activeCells from TM",
Lupino marked this conversation as resolved.
Show resolved Hide resolved
type: SDR, count: 0},
learnPattern: { description: "An SDR output bit pattern for a sample. Usually the output of the SP or TM. For example: activeCells from TM",
Copy link
Member

Choose a reason for hiding this comment

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

how would this learn/infer pattern input work with async data? I mean, Say you want to learn a single pattern, and then make inference on 10 samples. What would be on learnPattern input? And will this behave correctly?

We might need (already have) a separate learn & infer () const, and call it separately in the ClassRegion.

type: SDR, count: 0}
},
outputs: {
pdf: { description: "probability distribution function (pdf) for each category or bucket. Sorted by title. Warning, buffer length will grow.",
type: Real64, count: 0},
Expand Down Expand Up @@ -143,12 +145,13 @@ void ClassifierRegion::compute() {
// and SDRClassifier::infer() will throw an exception.

if (learn_) {
SDR &learnPattern = getInput("learnPattern")->getData().getSDR();
Array &b = getInput("bucket")->getData();
// 'bucket' is a list of quantized samples being processed for this iteration.
// There are one of these for each encoder (or value being encoded).
// The values might not be consecutive, or in different ranges, or different things entirely.
// We build a map and a corresponding vector containing the quantized samples actually used.
// This vector becomes the titles. The index into this list will be a consecutive list that
// This vector becomes the titles. The index into this list will be a consecutive list that
// we can presented to the Classifier which produces the pdf. Note that the indexes used
// by the classifier are not sorted by title but rather by the order in which an index is first seen.
std::vector<UInt> categoryIdxList;
Expand All @@ -166,7 +169,7 @@ void ClassifierRegion::compute() {
}
categoryIdxList.push_back(c);
}
classifier_->learn(pattern, categoryIdxList);
classifier_->learn(learnPattern, categoryIdxList);
}
PDF pdf = classifier_->infer(pattern);

Expand Down