htm-algorithms
Direct NuPIC legacy HTM encoders, SpatialPooler, TemporalMemory, SDRClassifier, anomaly score, and anomaly likelihood workflows.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- htm-algorithms
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Direct NuPIC legacy HTM encoders, SpatialPooler, TemporalMemory, SDRClassifier, anomaly score, and anomaly likelihood workflows.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md9.9 KB
- 参考文档references/troubleshooting.md10.8 KB
- 参考文档references/workflows.md9.3 KB
- 脚本scripts/algorithm_smoke.py13.0 KB
03 SKILL.md 正文
HTM Algorithms
Use this sub-skill when a task asks for direct NuPIC legacy HTM algorithm APIs: encoders, SpatialPooler, TemporalMemory, SDRClassifier, raw anomaly score, or anomaly likelihood for a small streaming scalar/temporal example.
NuPIC legacy is a Python 2.7 package. Direct algorithm workflows normally require installed nupic, nupic.bindings, numpy in the legacy-compatible range, and pycapnp/Cap'n Proto only when serialization is needed.
Route first
- Stay here for:
ScalarEncoder,RandomDistributedScalarEncoder,DateEncoder,CategoryEncoder,MultiEncoder,SpatialPooler.compute,TemporalMemory.compute,SDRClassifier.compute,computeRawAnomalyScore, andAnomalyLikelihood.anomalyProbability. - Read references/api-reference.md when you need constructor signatures, input/output shapes, classifier result keys, or anomaly helper semantics.
- Read references/workflows.md when you need a direct encoders -> SP -> TM -> classifier/anomaly recipe or a debugging checklist for algorithm pipelines.
- Read references/troubleshooting.md when an algorithm example fails with encoder parameter, active-array shape, TM state/reset, classifier dict, Python 2, bindings, or serialization errors.
- Run scripts/algorithm_smoke.py when you need a deterministic installed-package smoke check for tiny encoders, SP/TM, classifier, and anomaly helpers.
- Route CSV stream headers, field metadata, OPF model parameter files, and config validation to ../data-and-configuration/.
- Route high-level
ModelFactory, OPF inference dictionaries, checkpoints, and experiment workflows to ../opf-prediction/. - For package-wide install/import failures before algorithm code runs, start with the root troubleshooting guide at
../../references/troubleshooting.md; local reference files also cross-link to that guide from their own relative paths.
Direct API checklist
- Confirm the runtime is Python 2.7 and can import
nupic,nupic.bindings, andnumpy. - Encode every raw value into a one-dimensional binary SDR. Allocate one zero-filled NumPy array per encoder with
encoder.getWidth()and callencoder.encodeIntoArray(value, bits). - Concatenate encoder outputs. Set
SpatialPooler(inputDimensions=(encodingWidth,), columnDimensions=(columnCount,), ...)soencodingWidth == len(concatenatedEncoding). - Allocate
activeArray = numpy.zeros(columnCount, dtype="uint32"), callsp.compute(encoding, learn, activeArray), then passnumpy.nonzero(activeArray)[0]toTemporalMemory.compute. - Set
TemporalMemory(columnDimensions=(columnCount,), ...)to the same column count used by the SP. Usetm.getActiveCells()for classifierpatternNZ; usetm.getPredictiveCells()plustm.columnForCell(cell)to build next-step predicted columns for anomaly score. - For scalar predictions, call
classifier.compute(recordNum, patternNZ, {"bucketIdx": bucketIdx, "actValue": rawValue}, learn=True, infer=True). Look for integer step keys such as1plus the"actualValues"key in the result. - For anomaly checks, compare current active columns with previous-step predicted columns using
computeRawAnomalyScore(activeColumns, prevPredictedColumns), then optionally updateAnomalyLikelihoodwith the raw value, anomaly score, and timestamp.
Minimal validation command
From this sub-skill directory in a prepared NuPIC legacy environment:
python scripts/algorithm_smoke.py --mode all --records 20 --encoder scalar
Expected success signal: the script prints PASS, encoder/SP/TM dimensions, a final one-step prediction summary, and bounded anomaly likelihood values. If it fails before imports, use root install/import troubleshooting; if it fails after imports, use the local troubleshooting reference.
Evidence provenance
This sub-skill distills NuPIC legacy algorithm evidence from source/doc paths such as src/nupic/algorithms/, src/nupic/encoders/, docs/source/quick-start/algorithms.rst, docs/examples/algo/complete-algo-example.py, examples/sp/hello_sp.py, examples/tm/hello_tm.py, and unit tests under tests/unit/nupic/algorithms/ and tests/unit/nupic/encoders/. Runtime guidance here is self-contained; future agents should not need to open the original checkout examples to use it.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).