{"id":37062880,"url":"https://github.com/leonard-gleyzer/connex","last_synced_at":"2026-01-14T07:01:00.913Z","repository":{"id":37021500,"uuid":"503117844","full_name":"leonard-gleyzer/connex","owner":"leonard-gleyzer","description":"Fine-grained, dynamic control of neural network topology in JAX.","archived":false,"fork":false,"pushed_at":"2023-07-23T05:24:32.000Z","size":807,"stargazers_count":21,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-06T14:03:55.501Z","etag":null,"topics":["deep-learning","jax","neural-networks"],"latest_commit_sha":null,"homepage":"https://leonard-gleyzer.github.io/connex/","language":"Python","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/leonard-gleyzer.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":"2022-06-13T21:17:35.000Z","updated_at":"2025-06-24T06:37:40.000Z","dependencies_parsed_at":"2023-02-10T07:01:46.046Z","dependency_job_id":null,"html_url":"https://github.com/leonard-gleyzer/connex","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/leonard-gleyzer/connex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonard-gleyzer%2Fconnex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonard-gleyzer%2Fconnex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonard-gleyzer%2Fconnex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonard-gleyzer%2Fconnex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leonard-gleyzer","download_url":"https://codeload.github.com/leonard-gleyzer/connex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonard-gleyzer%2Fconnex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28412478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T05:26:33.345Z","status":"ssl_error","status_checked_at":"2026-01-14T05:21:57.251Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["deep-learning","jax","neural-networks"],"created_at":"2026-01-14T07:00:40.150Z","updated_at":"2026-01-14T07:01:00.875Z","avatar_url":"https://github.com/leonard-gleyzer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align='center'\u003eConnex\u003c/h1\u003e\n\nConnex is a [JAX](https://github.com/google/jax) library built on [Equinox](https://github.com/patrick-kidger/equinox) that allows for fine-grained, dynamic control of neural network topology. With Connex, you can\n\n- Turn any directed acyclic graph (DAG) into a trainable neural network.\n- Add and remove both connections and neurons at the individual level.\n- Set and modify dropout probabilities for all neurons individually.\n- Easily toggle techniques such as normalization, adaptive activations, and self-attention.\n- Export a trained network to a NetworkX weighted digraph for network analysis.\n\n## Installation\n\n```bash\npip install connex\n```\n\n## Usage\n\nAs a tiny pedagogical example, let's create a trainable neural network from the following DAG\n\n![dag](docs/imgs/dag.png)\n\nwith input neuron 0 and output neurons 3 and 11 (in that order) and ReLU activation for the hidden neurons:\n\n```python\nimport connex as cnx\nimport jax.nn as jnn\n\n\n# Create the graph data\nadjacency_dict = {\n    0: [1, 2, 3],\n    1: [4],\n    2: [4, 5],\n    4: [6],\n    5: [7],\n    6: [8, 9],\n    7: [10],\n    8: [11],\n    9: [11],\n    10: [11]\n}\n\n# Specify the input and output neurons\ninput_neurons = [0]\noutput_neurons = [3, 11]\n\n# Create the network\nnetwork = cnx.NeuralNetwork(\n    adjacency_dict,\n    input_neurons, \n    output_neurons,\n    jnn.relu\n)\n```\n\nThat's it! A `connex.NeuralNetwork` is a subclass of `equinox.Module`, so it can be trained as such:\n\n```python\nimport equinox as eqx\nimport jax\nimport jax.numpy as jnp\nimport optax\n\n# Initialize the optimizer\noptim = optax.adam(1e-3)\nopt_state = optim.init(eqx.filter(network, eqx.is_array))\n\n# Define the loss function\n@eqx.filter_value_and_grad\ndef loss_fn(model, x, y):\n    preds = jax.vmap(model)(x)\n    return jnp.mean((preds - y) ** 2)\n\n# Define a single training step\n@eqx.filter_jit\ndef step(model, opt_state, x, y):\n    loss, grads = loss_fn(model, x, y)\n    updates, opt_state = optim.update(grads, opt_state, model)\n    model = eqx.apply_updates(model, updates)\n    return model, opt_state, loss\n\n# Toy data\nx = jnp.expand_dims(jnp.linspace(0, 2 * jnp.pi, 250), 1)\ny = jnp.hstack((jnp.cos(x), jnp.sin(x)))\n\n# Training loop\nn_epochs = 500\nfor epoch in range(n_epochs):\n    network, opt_state, loss = step(network, opt_state, x, y)\n    print(f\"Epoch: {epoch}   Loss: {loss}\")\n```\n\nNow suppose we wish to add connections 1 \u0026rarr; 6 and 2 \u0026rarr; 11, remove neuron 9, and set the dropout probability of all hidden neurons to 0.1:\n\n```python\n# Add connections\nnetwork = cnx.add_connections(network, [(1, 6), (2, 11)])\n\n# Remove neuron\nnetwork = cnx.remove_neurons(network, [9])\n\n# Set dropout probability\nnetwork = cnx.set_dropout_p(network, 0.1)\n```\n\nThat's all there is to it.  The new connections have been initialized with untrained parameters, and the neurons in the original network that have not been removed (along with their respective incoming and outgoing connections) have retained their trained parameters.\n\nFor more information about manipulating connectivity structure and the `NeuralNetwork` base class, please see the API section of the documentation. For examples of subclassing `NeuralNetwork`, please see `connex.nn`.\n\n## Citation\n\n```bibtex\n@software{gleyzer2023connex,\n  author = {Leonard Gleyzer},\n  title = {{C}onnex: Fine-grained Control over Neural Network Topology in {JAX}},\n  url = {http://github.com/leonard-gleyzer/connex},\n  year = {2023},\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonard-gleyzer%2Fconnex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleonard-gleyzer%2Fconnex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonard-gleyzer%2Fconnex/lists"}