{"id":17531130,"url":"https://github.com/milosgajdos/gopfield","last_synced_at":"2025-09-12T00:12:32.269Z","repository":{"id":39660538,"uuid":"76576395","full_name":"milosgajdos/gopfield","owner":"milosgajdos","description":"Hopfield neural networks in Go","archived":false,"fork":false,"pushed_at":"2022-05-28T17:48:26.000Z","size":58,"stargazers_count":57,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T13:54:06.753Z","etag":null,"topics":["go","golang","hopfield-network","machine-learning","memory-network","neural-network","neural-networks"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/milosgajdos.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":"2016-12-15T16:26:56.000Z","updated_at":"2025-02-18T05:12:02.000Z","dependencies_parsed_at":"2022-09-18T04:50:18.655Z","dependency_job_id":null,"html_url":"https://github.com/milosgajdos/gopfield","commit_stats":null,"previous_names":["milosgajdos83/gopfield"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/milosgajdos/gopfield","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosgajdos%2Fgopfield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosgajdos%2Fgopfield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosgajdos%2Fgopfield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosgajdos%2Fgopfield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milosgajdos","download_url":"https://codeload.github.com/milosgajdos/gopfield/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosgajdos%2Fgopfield/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274728935,"owners_count":25338572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","golang","hopfield-network","machine-learning","memory-network","neural-network","neural-networks"],"created_at":"2024-10-20T17:22:57.723Z","updated_at":"2025-09-12T00:12:32.221Z","avatar_url":"https://github.com/milosgajdos.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gopfield: Hopfield neural networks in Go\n\n[![Build Status](https://github.com/milosgajdos/gopfield/workflows/CI/badge.svg)](https://github.com/milosgajdos/gopfield/actions?query=workflow%3ACI)\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/milosgajdos/gopfield)\n[![GoDoc](https://godoc.org/github.com/milosgajdos/gopfield?status.svg)](https://godoc.org/github.com/milosgajdos/gopfield)\n[![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Go Report Card](https://goreportcard.com/badge/github.com/milosgajdos/gopfield)](https://goreportcard.com/report/github.com/milosgajdos/gopfield)\n\nThis project provides an implementation of [Hopfield network](https://en.wikipedia.org/wiki/Hopfield_network) in Go. It implements both [Hebbian](https://en.wikipedia.org/wiki/Hopfield_network#Hebbian_learning_rule_for_Hopfield_networks) and [Storkey](https://en.wikipedia.org/wiki/Hopfield_network#The_Storkey_learning_rule) training algorithms. The goal is to provide a simple API to build Hopfield networks in `Go`.\n\n# Get started\n\nGet the source code:\n\n```\n$ go get -u github.com/milosgajdos/gopfield\n```\n\nGet dependencies:\n\n```\n$ make dep\n```\n\nRun the tests:\n\n```\n$ make test\n```\n\n# Example\n\nYou can see an example program below. It first creates a Hopfield network pattern based on arbitrary data. The data is encoded into binary values of +1/-1 (see the documentation) using `Encode` function. It is then stored in the network and then restored.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/milosgajdos/gopfield/hopfield\"\n)\n\nfunc main() {\n\tpattern := hopfield.Encode([]float64{0.2, -12.4, 0.0, 3.4})\n\t// Create new Hopfield Network and set its size to the length of pattern\n\tn, err := hopfield.NewNetwork(pattern.Len(), \"hebbian\")\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"\\nERROR: %s\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(\"Storing: \\n%v\\n\\n\", pattern)\n\t// store patterns in Hopfield network\n\tif err := n.Store([]*hopfield.Pattern{pattern}); err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"\\nERROR: %s\\n\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// restore image from Hopfield network\n\tres, err := n.Restore(pattern, \"async\", 10)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"\\nERROR: %s\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(\"Restored: \\n%v\\n\", res)\n}\n```\n\nIf you run this program, you will see the pattern being reconstructed correctly:\n\n```\n$ go run main.go\nStoring:\n⎡ 1⎤\n⎢-1⎥\n⎢-1⎥\n⎣ 1⎦\n\nRestored:\n⎡ 1⎤\n⎢-1⎥\n⎢-1⎥\n⎣ 1⎦\n```\n\nYou can find a more elaborate example in the `examples` directory of the project. There is a mnist example which tries to reconstruct a corrupted image loaded from the `patterns` subdirectory which contains two [MNIST](http://yann.lecun.com/exdb/mnist/) images: 0 and 4. These are stored in the Hopfield neural network. The mnist program then picks image `4` and adds some random noise to it. Finallys, it tries to reconstruct the original image from the network. See below how to use the example program:\n\nFirst you need to build it:\n\n```\n$ make examples\n```\n\nIf the build succeeds, you will find the built binary in `_build` directory of the project root. You can find out the cli options it provides:\n\n```\n$  _build/mnist -h\n```\n\nExample run:\n\n```\n$ _build/mnist -mode \"async\" -iters 1 -datadir ./examples/mnist/patterns/ -output out.png -training \"storkey\"\n```\n\nThis will generate two files in directory: `noisy.png` and `out.png`.\n\n`noisy.png` image displays the file that was attempted to be reconstructed from the network:\n\n\u003cimg src=\"./examples/mnist/noisy.png\" alt=\"Corrupted image 4\" width=\"200\"\u003e\n\n\n`out.png` image shows the reconstucted image:\n\n\u003cimg src=\"./examples/mnist/out.png\" alt=\"Reconstructed image 4\" width=\"200\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilosgajdos%2Fgopfield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilosgajdos%2Fgopfield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilosgajdos%2Fgopfield/lists"}