{"id":13831676,"url":"https://github.com/htm-community/htm","last_synced_at":"2026-02-19T21:58:22.000Z","repository":{"id":16221324,"uuid":"18968575","full_name":"htm-community/htm","owner":"htm-community","description":"Hierarchical Temporal Memory implementation in Golang","archived":false,"fork":false,"pushed_at":"2020-02-13T01:22:51.000Z","size":275,"stargazers_count":64,"open_issues_count":4,"forks_count":14,"subscribers_count":14,"default_branch":"master","last_synced_at":"2026-01-14T11:38:38.389Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/htm-community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-20T16:32:19.000Z","updated_at":"2025-10-31T07:19:37.000Z","dependencies_parsed_at":"2022-09-01T20:41:35.728Z","dependency_job_id":null,"html_url":"https://github.com/htm-community/htm","commit_stats":null,"previous_names":["zacg/htm","nupic-community/htm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/htm-community/htm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htm-community%2Fhtm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htm-community%2Fhtm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htm-community%2Fhtm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htm-community%2Fhtm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/htm-community","download_url":"https://codeload.github.com/htm-community/htm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htm-community%2Fhtm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29634567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T18:02:07.722Z","status":"ssl_error","status_checked_at":"2026-02-19T18:01:46.144Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T10:01:36.751Z","updated_at":"2026-02-19T21:58:21.985Z","avatar_url":"https://github.com/htm-community.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"htm\n===\n\nHierarchical Temporal Memory Implementation in Golang\n\n[![GoDoc](https://godoc.org/github.com/nupic-community/htm?status.png)](https://godoc.org/github.com/nupic-community/htm)\n[![Build Status](https://travis-ci.org/nupic-community/htm.svg?branch=master)](https://travis-ci.org/nupic-community/htm)\n\nThis is a direct port of the spatial \u0026 temporal poolers, temporal memory, and encoders as they currently exist in Numenta's Nupic Project. This project was done as a learning exercise, no effort has been made to optimize this implementation and it was not designed for production use.\n\nThe Nupic project basically demonstrates the CLA, a single stage of the cortical hierarchy. Eventually this same code can be extended to form a full HTM hierarchy. https://github.com/numenta/nupic\n\n##Changes From Numentas Implementation\n * Temporal pooler ephemeral state is stored in strongly typed struct rather than a hashmap. t-1 vars have \"last\" appended to their names.\n * Temporal pooler params stored in \"params\" sub struct\n * Binary data structures are used rather than ints\n * No C++ dependency everything is written in Go\n\n##Current State of Project\n * Temporal and Spatial poolers pass basic tests\n * Temporal memory passes basic unit tests\n * Basic scaler encoder implemented\n\n##Todo\n ~~* Finish temporal unit tests~~\n * Implement a better sparse binary matrix structure with versions optimized for col or row heavy access.\n * Implement better binary datastructure\n * Refactor to be more idiomatic Go. It is basically a line for line port of the python implementation, it could be refactored to make better use of Go's type system.\n * Implement some of the common encoders\n\n##Examples\n\n###Temporal Pooler\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/zacg/htm\"\n\t\"github.com/nupic-community/htmutils\"\n)\n\nfunc main() {\n\ttps := htm.NewTemporalPoolerParams()\n\ttps.Verbosity = 0\n\ttps.NumberOfCols = 50\n\ttps.CellsPerColumn = 2\n\ttps.ActivationThreshold = 8\n\ttps.MinThreshold = 10\n\ttps.InitialPerm = 0.5\n\ttps.ConnectedPerm = 0.5\n\ttps.NewSynapseCount = 10\n\ttps.PermanenceDec = 0.0\n\ttps.PermanenceInc = 0.1\n\ttps.GlobalDecay = 0\n\ttps.BurnIn = 1\n\ttps.PamLength = 10\n\ttps.CollectStats = true\n\ttp := htm.NewTemporalPooler(*tps)\n\n\t//Mock encoding of ABCDE\n\tinputs := make([][]bool, 5)\n\tinputs[0] = boolRange(0, 9, 50)   //bits 0-9 are \"on\"\n\tinputs[1] = boolRange(10, 19, 50) //bits 10-19 are \"on\"\n\tinputs[2] = boolRange(20, 29, 50) //bits 20-29 are \"on\"\n\tinputs[3] = boolRange(30, 39, 50) //bits 30-39 are \"on\"\n\tinputs[4] = boolRange(40, 49, 50) //bits 40-49 are \"on\"\n\n\t//Learn 5 sequences above\n\tfor i := 0; i \u003c 10; i++ {\n\t\tfor p := 0; p \u003c 5; p++ {\n\t\t\ttp.Compute(inputs[p], true, false)\n\t\t}\n\t\ttp.Reset()\n\t}\n\n\t//Predict sequences\n\tfor i := 0; i \u003c 4; i++ {\n\t\ttp.Compute(inputs[i], false, true)\n\t\tp := tp.DynamicState.InfPredictedState\n\n\t\tfmt.Printf(\"Predicted: %v From input: %v \\n\", p.NonZeroRows(), utils.OnIndices(inputs[i]))\n\n\t}\n\n}\n\n//helper method for creating boolean sequences\nfunc boolRange(start int, end int, length int) []bool {\n\tresult := make([]bool, length)\n\tfor i := start; i \u003c= end; i++ {\n\t\tresult[i] = true\n\t}\n\treturn result\n}\n\n\n```\n\n###Spatial Pooler\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/davecheney/profile\"\n\t\"github.com/zacg/htm\"\n\t\"github.com/nupic-community/htmutils\"\n\t\"math/rand\"\n)\n\nfunc main() {\n\t\n\tssp := htm.NewSpParams()\n\tssp.ColumnDimensions = []int{64, 64}\n\tssp.InputDimensions = []int{32, 32}\n\tssp.PotentialRadius = ssp.NumInputs()\n\tssp.NumActiveColumnsPerInhArea = int(0.02 * float64(ssp.NumColumns()))\n\tssp.GlobalInhibition = true\n\tssp.SynPermActiveInc = 0.01\n\tssp.SpVerbosity = 10\n\tsp := htm.NewSpatialPooler(ssp)\n\t\n\n\tactiveArray := make([]bool, sp.NumColumns())\n\tinputVector := make([]bool, sp.NumInputs())\n\n\tfor idx, _ := range inputVector {\n\t\tinputVector[idx] = rand.Intn(5) \u003e= 2\n\t}\n\n\tsp.Compute(inputVector, true, activeArray, sp.InhibitColumns)\n\n\tfmt.Println(\"Active Indices:\", utils.OnIndices(activeArray))\n\n}\n\n```\n\n###Temporal Memory\n```go\n\n\ttmp := NewTemporalMemoryParams()\n\ttmp.MaxNewSynapseCount = 1000\n\n\ttm := NewTemporalMemory(tmp)\n\n```\n\n###Encoding\n```go\n\n\t//Create new scaler encoder\n\tp := NewScalerEncoderParams(3, 1, 8)\n\tp.Radius = 1.5\n\tp.Periodic = true\n\tp.Verbosity = 5\n\te := NewScalerEncoder(p)\n\n\t//Encode \"1\"\n\tencoded := e.Encode(1, false)\n\n\t//Print results\n\tfmt.Printfn(\"1 Encoded as: %v\", utils.Bool2Int(encoded))\n\n```\n\n```go\n\n\t//Create new date encoder\n\tp := NewDateEncoderParams()\n\tp.SeasonWidth = 3\n\tp.DayOfWeekWidth = 1\n\tp.WeekendWidth = 3\n\tp.TimeOfDayWidth = 5\n\tp.Verbosity = 5\n\tde := NewDateEncoder(p)\n\t\n\td := time.Date(2010, 11, 4, 14, 55, 0, 0, time.UTC)\n\tencoded := de.Encode(d)\n\n\t//Print results\n\tfmt.Printfn(\"%v Encoded as: %v\", d, utils.Bool2Int(encoded))\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhtm-community%2Fhtm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhtm-community%2Fhtm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhtm-community%2Fhtm/lists"}