# gianpgunawan/neural_network architecture

> Architecture diagram of the GitHub repository gianpgunawan/neural_network, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gianpgunawan/neural_network
- Repository: https://github.com/gianpgunawan/neural_network

## Overview

This is a small C neural-network implementation with an example executable: it loads a predefined model, accepts two command-line inputs, runs inference, prints activations, and dumps model code. The library also contains backpropagation, matrix operations, arena allocation, and several activation functions. The example’s training loop is commented out. Relationships below follow shown calls and source-index references; bitmap.h’s role is unclear from the available evidence.

Main entry points: [`main.c`](https://github.com/gianpgunawan/neural_network/blob/main/main.c) (Example entry point), [`includes/nn.c`](https://github.com/gianpgunawan/neural_network/blob/main/includes/nn.c) (Network and training), [`includes/activations/softmax.c`](https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/softmax.c) (Softmax), [`includes/matrices/matrix_dyn.c`](https://github.com/gianpgunawan/neural_network/blob/main/includes/matrices/matrix_dyn.c) (Arena-backed matrices)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Example application"]
  node_main["Example entry point<br/>[main.c]"]
  node_model["Predefined model<br/>[model.h]"]
  node_bitmap["Bitmap header<br/>[bitmap.h]"]
end

subgraph group_network["Network runtime"]
  node_nn["Network and training<br/>[nn.c]"]
end

subgraph group_math["Matrix operations"]
  node_matrix["Matrix operations<br/>[matrix.c]"]
  node_matrix_dyn["Arena-backed matrices<br/>[matrix_dyn.c]"]
end

subgraph group_memory["Memory and utilities"]
  node_arena["Arena allocator<br/>[arena.c]"]
  node_dynamic_array["Dynamic array<br/>[dynamic_array.h]"]
  node_container_of["Container helper<br/>[container_of.h]"]
  node_assert["Assertions<br/>[nn_assert.h]"]
end

subgraph group_activation["Activations"]
  node_activation_api["Activation interface<br/>[activation.h]"]
  node_relu["ReLU<br/>[relu.c]"]
  node_sigmoid["Sigmoid<br/>[sigmoid.c]"]
  node_softmax["Softmax<br/>[softmax.c]"]
end

node_user(("CLI user"))

node_user -->|"provides inputs"| node_main
node_main -->|"loads model"| node_model
node_main -->|"initializes arena"| node_arena
node_main -->|"runs inference"| node_nn
node_main -->|"prints matrices"| node_matrix
node_main -->|"initializes activation"| node_sigmoid
node_main -->|"initializes activation"| node_relu
node_main -->|"initializes activation"| node_softmax
node_main -->|"allocates dataset"| node_matrix_dyn
node_model -->|"adds layers"| node_nn
node_model -->|"creates matrices"| node_matrix_dyn
node_nn -->|"computes operations"| node_matrix
node_nn -->|"creates temporaries"| node_matrix_dyn
node_nn -->|"dispatches functions"| node_activation_api
node_nn -->|"stores layers"| node_dynamic_array
node_matrix_dyn -->|"allocates buffers"| node_arena
node_matrix_dyn -->|"performs operations"| node_matrix
node_matrix -->|"checks dimensions"| node_assert
node_relu -->|"implements interface"| node_activation_api
node_sigmoid -->|"implements interface"| node_activation_api
node_softmax -->|"implements interface"| node_activation_api
node_softmax -->|"reads final layer"| node_dynamic_array
node_softmax -->|"reads logits"| node_matrix
node_softmax -->|"reads model layers"| node_nn

click node_main "https://github.com/gianpgunawan/neural_network/blob/main/main.c"
click node_model "https://github.com/gianpgunawan/neural_network/blob/main/model.h"
click node_bitmap "https://github.com/gianpgunawan/neural_network/blob/main/bitmap.h"
click node_nn "https://github.com/gianpgunawan/neural_network/blob/main/includes/nn.c"
click node_activation_api "https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/activation.h"
click node_relu "https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/relu.c"
click node_sigmoid "https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/sigmoid.c"
click node_softmax "https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/softmax.c"
click node_matrix "https://github.com/gianpgunawan/neural_network/blob/main/includes/matrices/matrix.c"
click node_matrix_dyn "https://github.com/gianpgunawan/neural_network/blob/main/includes/matrices/matrix_dyn.c"
click node_arena "https://github.com/gianpgunawan/neural_network/blob/main/includes/arena.c"
click node_dynamic_array "https://github.com/gianpgunawan/neural_network/blob/main/includes/utils/dynamic_array.h"
click node_container_of "https://github.com/gianpgunawan/neural_network/blob/main/includes/utils/container_of.h"
click node_assert "https://github.com/gianpgunawan/neural_network/blob/main/includes/utils/nn_assert.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_model,node_bitmap,node_user toneBlue
class node_nn toneAmber
class node_matrix,node_matrix_dyn toneMint
class node_arena,node_dynamic_array,node_container_of,node_assert toneRose
class node_activation_api,node_relu,node_sigmoid,node_softmax toneIndigo
```

## Components

### Example application

- [Example entry point](https://github.com/gianpgunawan/neural_network/blob/main/main.c): `main.c`
- [Predefined model](https://github.com/gianpgunawan/neural_network/blob/main/model.h): `model.h`
- [Bitmap header](https://github.com/gianpgunawan/neural_network/blob/main/bitmap.h): `bitmap.h`

### Network runtime

- [Network and training](https://github.com/gianpgunawan/neural_network/blob/main/includes/nn.c): `includes/nn.c`

### Matrix operations

- [Matrix operations](https://github.com/gianpgunawan/neural_network/blob/main/includes/matrices/matrix.c): `includes/matrices/matrix.c`
- [Arena-backed matrices](https://github.com/gianpgunawan/neural_network/blob/main/includes/matrices/matrix_dyn.c): `includes/matrices/matrix_dyn.c`

### Memory and utilities

- [Arena allocator](https://github.com/gianpgunawan/neural_network/blob/main/includes/arena.c): `includes/arena.c`
- [Dynamic array](https://github.com/gianpgunawan/neural_network/blob/main/includes/utils/dynamic_array.h): `includes/utils/dynamic_array.h`
- [Container helper](https://github.com/gianpgunawan/neural_network/blob/main/includes/utils/container_of.h): `includes/utils/container_of.h`
- [Assertions](https://github.com/gianpgunawan/neural_network/blob/main/includes/utils/nn_assert.h): `includes/utils/nn_assert.h`

### Activations

- [Activation interface](https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/activation.h): `includes/activations/activation.h`
- [ReLU](https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/relu.c): `includes/activations/relu.c`
- [Sigmoid](https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/sigmoid.c): `includes/activations/sigmoid.c`
- [Softmax](https://github.com/gianpgunawan/neural_network/blob/main/includes/activations/softmax.c): `includes/activations/softmax.c`

### Other components

- **CLI user**

## Connections

- CLI user → Example entry point: provides inputs (evidence: `main.c`)
- Example entry point → Predefined model: loads model (evidence: `main.c`)
- Example entry point → Arena allocator: initializes arena (evidence: `main.c`)
- Example entry point → Network and training: runs inference (evidence: `main.c`)
- Example entry point → Matrix operations: prints matrices (evidence: `main.c`)
- Example entry point → Sigmoid: initializes activation (evidence: `main.c`)
- Example entry point → ReLU: initializes activation (evidence: `main.c`)
- Example entry point → Softmax: initializes activation (evidence: `main.c`)
- Example entry point → Arena-backed matrices: allocates dataset (evidence: `main.c`)
- Predefined model → Network and training: adds layers (evidence: `model.h`)
- Predefined model → Arena-backed matrices: creates matrices (evidence: `model.h`)
- Network and training → Matrix operations: computes operations (evidence: `includes/nn.c`)
- Network and training → Arena-backed matrices: creates temporaries (evidence: `includes/nn.c`)
- Network and training → Activation interface: dispatches functions (evidence: `includes/nn.c`)
- Network and training → Dynamic array: stores layers (evidence: `includes/nn.c`)
- Arena-backed matrices → Arena allocator: allocates buffers (evidence: `includes/matrices/matrix_dyn.c`)
- Arena-backed matrices → Matrix operations: performs operations (evidence: `includes/matrices/matrix_dyn.c`)
- Matrix operations → Assertions: checks dimensions (evidence: `includes/matrices/matrix.c`)
- ReLU → Activation interface: implements interface (evidence: `includes/activations/relu.c`)
- Sigmoid → Activation interface: implements interface (evidence: `includes/activations/sigmoid.c`)
- Softmax → Activation interface: implements interface (evidence: `includes/activations/softmax.c`)
- Softmax → Dynamic array: reads final layer (evidence: `includes/activations/softmax.c`)
- Softmax → Matrix operations: reads logits (evidence: `includes/activations/softmax.c`)
- Softmax → Network and training: reads model layers (evidence: `includes/activations/softmax.c`)
