{"id":15394264,"url":"https://github.com/xyproto/wann","last_synced_at":"2025-04-15T23:53:13.281Z","repository":{"id":136552070,"uuid":"215965772","full_name":"xyproto/wann","owner":"xyproto","description":":balance_scale: Weight Agnostic Neural Networks in Go","archived":false,"fork":false,"pushed_at":"2022-03-07T12:53:42.000Z","size":12706,"stargazers_count":27,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T03:03:18.714Z","etag":null,"topics":["go","neural-network","nn","svg-diagram","wann","weight-agnostic-neural-network"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xyproto.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-18T07:27:05.000Z","updated_at":"2023-06-25T12:47:07.000Z","dependencies_parsed_at":"2024-06-20T08:17:45.964Z","dependency_job_id":"cb1ede68-0104-4744-acbc-c6de1cd6752a","html_url":"https://github.com/xyproto/wann","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fwann","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fwann/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fwann/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fwann/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xyproto","download_url":"https://codeload.github.com/xyproto/wann/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249173061,"owners_count":21224481,"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","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","neural-network","nn","svg-diagram","wann","weight-agnostic-neural-network"],"created_at":"2024-10-01T15:22:52.371Z","updated_at":"2025-04-15T23:53:13.262Z","avatar_url":"https://github.com/xyproto.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg alt=Logo src=img/after.svg width=128 /\u003e\n\n# wann [![Go Report Card](https://goreportcard.com/badge/github.com/xyproto/wann)](https://goreportcard.com/report/github.com/xyproto/wann) [![GoDoc](https://godoc.org/github.com/xyproto/wann?status.svg)](https://godoc.org/github.com/xyproto/wann)\n\nWeight Agnostic Neural Networks is a new type of neural network, where the weights of all the neurons are shared and the structure of the network is what matters.\n\nThis package implements Weight Agnostic Neural Networks for Go, and is inspired by this paper from June 2019:\n\n*\"Weight Agnostic Neural Networks\" by Adam Gaier and David Ha*. ([PDF](https://arxiv.org/pdf/1906.04358.pdf) | [Interactive version](https://weightagnostic.github.io/) | [Google AI blog post](https://ai.googleblog.com/2019/08/exploring-weight-agnostic-neural.html))\n\n## Features and limitations\n\n* All activation functions are benchmarked at the start of the program and the results are taken into account when calculating the complexity of a network.\n* All networks can be translated to a Go statement, using the wonderful [jennifer](https://github.com/dave/jennifer) package (work in progress, there are a few kinks that needs to be ironed out).\n* Networks can be saved as `SVG` diagrams. This feature needs more testing.\n* Neural networks can be trained and used. See the `cmd` folder for examples.\n* A random weight is chosen when training, instead of looping over the range of the weight. The paper describes both methods.\n* After the network has been trained, the optimal weight is found by looping over all weights (with a step size of `0.0001`).\n* Increased complexity counts negatively when evolving networks. This optimizes not only for less complex networks, but also for execution speed.\n* The diagram drawing routine plots the activation functions directly onto the nodes, together with a label. This can be saved as an SVG file.\n\n## Example program\n\nThis is a simple example, for creating a network that can recognize one of four shapes:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"os\"\n\n    \"github.com/xyproto/wann\"\n)\n\nfunc main() {\n    // Here are four shapes, representing: up, down, left and right:\n\n    up := []float64{\n        0.0, 1.0, 0.0, //  o\n        1.0, 1.0, 1.0} // ooo\n\n    down := []float64{\n        1.0, 1.0, 1.0, // ooo\n        0.0, 1.0, 0.0} //  o\n\n    left := []float64{\n        1.0, 1.0, 1.0, // ooo\n        0.0, 0.0, 1.0} //   o\n\n    right := []float64{\n        1.0, 1.0, 1.0, // ooo\n        1.0, 0.0, 0.0} // o\n\n    // Prepare the input data as a 2D slice\n    inputData := [][]float64{\n        up,\n        down,\n        left,\n        right,\n    }\n\n    // Target scores for: up, down, left, right\n    correctResultsForUp := []float64{1.0, -1.0, -1.0, -1.0}\n\n    // Prepare a neural network configuration struct\n    config := \u0026wann.Config{\n        InitialConnectionRatio: 0.2,\n        Generations:            2000,\n        PopulationSize:         500,\n        Verbose:                true,\n    }\n\n    // Evolve a network, using the input data and the sought after results\n    trainedNetwork, err := config.Evolve(inputData, correctResultsForUp)\n    if err != nil {\n        fmt.Fprintf(os.Stderr, \"error: %s\\n\", err)\n        os.Exit(1)\n    }\n\n    // Now to test the trained network on 4 different inputs and see if it passes the test\n    upScore := trainedNetwork.Evaluate(up)\n    downScore := trainedNetwork.Evaluate(down)\n    leftScore := trainedNetwork.Evaluate(left)\n    rightScore := trainedNetwork.Evaluate(right)\n\n    if config.Verbose {\n        if upScore \u003e downScore \u0026\u0026 upScore \u003e leftScore \u0026\u0026 upScore \u003e rightScore {\n            fmt.Println(\"Network training complete, the results are good.\")\n        } else {\n            fmt.Println(\"Network training complete, but the results did not pass the test.\")\n        }\n    }\n\n    // Save the trained network as an SVG image\n    if config.Verbose {\n        fmt.Print(\"Writing network.svg...\")\n    }\n    if err := trainedNetwork.WriteSVG(\"network.svg\"); err != nil {\n        fmt.Fprintf(os.Stderr, \"error: %s\\n\", err)\n        os.Exit(1)\n    }\n    if config.Verbose {\n        fmt.Println(\"ok\")\n    }\n}\n```\n\nHere is the resulting network generated by the above program:\n\n\u003cimg alt=Network src=img/labels.svg width=256 /\u003e\n\nThis makes sense, since taking the third number in the input data (index 2), running it through a swish function and then inverting it should be a usable detector for the `up` pattern.\n\n* The generated networks may differ for each run.\n\n## Quick start\n\nThis requires Go 1.11 or later.\n\nClone the repository:\n\n    git clone https://github.com/xyproto/wann\n\nEnter the `cmd/evolve` directory:\n\n    cd wann/cmd/evolve\n\nBuild and run the example:\n\n    go build \u0026\u0026 ./evolve\n\nTake a look at the best network for judging if a set of numbers that are either 0 or 1 are of one category:\n\n    xdg-open network.svg\n\n(If needed, use your favorite SVG viewer instead of the `xdg-open` command).\n\n## Ideas\n\n* Adding convolution nodes might give interesting results.\n\n## Generating Go code from a trained network\n\nThis is an experimental feature and a work in progress!\n\nThe idea is to generate one large expression from all the expressions that each node in the network represents.\n\nRight now, this only works for networks that has a depth of 1.\n\nFor example, adding these two lines to `cmd/evolve/main.go`:\n\n```go\n// Output a Go function for this network\nfmt.Println(trainedNetwork.GoFunction())\n```\n\nProduces this output:\n\n```go\nfunc f(x float64) float64 { return -x }\n```\n\nThe plan is to output a function that takes the input data instead, and refers to the input data by index. Support for deeper networks also needs to be added.\n\nThere is a complete example for outputting Go code in `cmd/gofunction`.\n\n## General info\n\n* Version: 0.3.2\n* License: BSD-3\n* Author: Alexander F. Rødseth \u0026lt;xyproto@archlinux.org\u0026gt;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fwann","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxyproto%2Fwann","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fwann/lists"}