{"id":23459553,"url":"https://github.com/d-led/elixir_ne","last_synced_at":"2025-04-11T21:37:49.431Z","repository":{"id":146619726,"uuid":"167078447","full_name":"d-led/elixir_ne","owner":"d-led","description":"a neural voting experiment","archived":false,"fork":false,"pushed_at":"2024-12-11T20:47:20.000Z","size":1079,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T23:44:23.645Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d-led.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-01-22T22:40:08.000Z","updated_at":"2025-01-05T07:15:38.000Z","dependencies_parsed_at":"2024-12-04T23:29:03.090Z","dependency_job_id":null,"html_url":"https://github.com/d-led/elixir_ne","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-led%2Felixir_ne","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-led%2Felixir_ne/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-led%2Felixir_ne/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-led%2Felixir_ne/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d-led","download_url":"https://codeload.github.com/d-led/elixir_ne/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248484942,"owners_count":21111751,"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":[],"created_at":"2024-12-24T06:15:40.718Z","updated_at":"2025-04-11T21:37:49.407Z","avatar_url":"https://github.com/d-led.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elixir_ne\n\n## structure\n\n```mermaid\nsequenceDiagram\n    %% create participant TargetNeuron\n    participant Demo\n    participant TargetNeuron as Neuron(pid=target_neuron)\n    Note right of Demo: this is synchronous\n    Demo-\u003e\u003e+TargetNeuron: starts \u003cbr\u003e new_neuron_connected_to(self())\n    loop N times\n        create participant VotingNeuron as Neuron(pid=voting_neuron)\n        Demo-\u003e\u003e+VotingNeuron: start \u003cbr\u003e new_neuron_connected_to(target_neuron)\n        Note right of Demo: this is an async but causal message\n        Demo--\u003e\u003e+TargetNeuron: connect_input_from(voting_neuron)\n    end\n    Demo--\u003e\u003e+TargetNeuron: please_predict\n    note right of TargetNeuron: these boxes happen in parallel\n    par on TargetNeuron\n        TargetNeuron--\u003e\u003e+VotingNeuron: please_predict\n        TargetNeuron-\u003e\u003eTargetNeuron: predict \u0026 sleep\n    and on VotingNeuron\n        VotingNeuron-\u003e\u003e+VotingNeuron: receive please_predict\n        VotingNeuron-\u003e\u003e+VotingNeuron: predict \u0026 sleep\n        VotingNeuron--\u003e\u003e+TargetNeuron: prediction\n    end\n    TargetNeuron-\u003e\u003e+TargetNeuron: wait_for_predictions \u003cbr\u003e (with a deadline)\n    TargetNeuron--\u003e\u003e+Demo: aggregate results \u0026 send prediction\n    Demo-\u003e\u003e+Demo: wait_for_reply exits\n```\n\n- Demo structure: [lib/demo.ex](lib/demo.ex)\n  - a single \"demo\" neuron is instantiated\n  - a `n==1000` neurons are started, knowing their target neuron\n  - these are connected to the \"demo\" neuron\n  - a prediction is requested (artificially), by sending the \"demo\" neuron a message\n  - this in turn requests predictions from its connections\n- Simulated voting neuron: [lib/neuron.ex](lib/neuron.ex)\n  - if there are no connections, the neuron just returns a random number and sleeps a bit (`delay`)\n  - if there are connections, the neuron tries to receive all the predictions, but within a deadline (\"metabolic constraint\"): `deadline_ms`\n  - returns the maximal value received so far or `-1` if none were received within a timeout\n  - *TODO*: return the best prediction if it's above a numeric threshold\n  - deadline example: `{:prediction, %{delay: 142, input_count: 1000, prediction: [value: 65.30085608551246, reason: :deadline, inputs_used: 496]}}`\n  - all received: `{:prediction, %{delay: 117, input_count: 1000, prediction: [value: 61.81215141710118, reason: :all_received, inputs_used: 1000]}`\n  - none received within time limits: `{:prediction, %{delay: 101, input_count: 1000, prediction: [value: -1, reason: :deadline, inputs_used: 0]}}`\n- written deliberately without [GenServer](https://hexdocs.pm/elixir/GenServer.html)s to demonstrate actual message passing that could be mapped onto neuron signalling\n- see the build [output](https://github.com/d-led/elixir_ne/actions)\n- run with: `mix run --no-halt`. Stop with `Ctrl+C` twice\n  - requires [Elixir](https://elixir-lang.org/install.html) being installed\n  - to run with more than 1000 neurons:\n\n```shell\n# increase maximum allowed processes\nexport ELIXIR_ERL_OPTIONS=\"+P 5000000\"\ntime N_NEURONS=1000000 mix run\n```\n\n## distributed neurons\n\n- start one shell with `iex --name a@127.0.0.1 -S mix`\n- and another one with `iex --name b@127.0.0.1 -S mix`\n  - ignore the initial unconnected run\n- connect the nodes e.g. on `a`: `Node.connect(:'b@127.0.0.1')`\n- make sure, the nodes are connected: `Node.list()`\n- run the distributed demo: `Demo.start(:demo, [])`\n- observe the result:\n\n```shell\nNeurons started on nodes: %{\"a@127.0.0.1\": 517, \"b@127.0.0.1\": 483}\nreceived: {:prediction, %{delay: 149, input_count: 1000, prediction: [value: 63.243549425083664, reason: :deadline, inputs_used: 596]}}\n```\n\n- change the code if necessary and hot-code reload in the cluster before running again:\n  `r [Demo, Neuron]; nl Demo; nl Neuron`\n\n## ideas behind it\n\n- brain has metabolic constraints: [Theriault et. al.: The sense of should: A biologically-based model of social pressure 10.31234/osf.io/x5rbs](https://psyarxiv.com/x5rbs/)\n- neurons have thousands of synapses: [Hawkins \u0026 Ahmad: Why Neurons Have Thousands of Synapses, a Theory of Sequence Memory in Neocortex doi:10.3389/fncir.2016.00023](https://www.frontiersin.org/articles/10.3389/fncir.2016.00023/full)\n- neurons might be voting on predictions [Hawkins et. al.: A Framework for Intelligence and Cortical Function Based on Grid Cells in the Neocortex doi:10.3389/FNCIR.2018.00121](https://numenta.com/neuroscience-research/research-publications/papers/thousand-brains-theory-of-intelligence-companion-paper/)\n- neurons are physically parallel\n- each neuron (or an aggregation of neurons for efficiency reason) can be represented by an [Erlang process](https://en.wikipedia.org/wiki/Erlang_(programming_language)#Erlang_Worldview)\n- in a rythmic fashion, attention seems to be interrupted: [A rhythmic theory of attention by Ian C. Fiebelkorn, Sabine Kastner](https://pmc.ncbi.nlm.nih.gov/articles/PMC6343831/#S1): \"We propose that the presently attended location is periodically re-assessed (**every ~250 ms**) to confirm that it is still the most important location\", \"These periodic disruptions in attention-related sampling may have provided our ancestors with an evolutionary advantage, e.g., allowing them to detect and therefore avoid predators while foraging.\"\n\n## disclaimer\n\n- I'm not a professional researcher\n- this is a spare time project to play around with ideas\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-led%2Felixir_ne","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd-led%2Felixir_ne","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-led%2Felixir_ne/lists"}