/rnn-model-with-c

model rnn with c

Primary LanguageC

๐Ÿง  RNN in C

This is a simple implementation of a Recurrent Neural Network (RNN) in pure C.
It demonstrates the concept of forward propagation over a sequence of time-series inputs without using any external libraries.


๐Ÿ“ Project Structure

rnn-c/
โ”œโ”€โ”€ include/             # Header files
โ”‚   โ”œโ”€โ”€ rnn.h            # RNN structure and declarations
โ”‚   โ””โ”€โ”€ utils.h          # Utility functions (e.g., matrix multiplication)
โ”œโ”€โ”€ src/                 # Source code
โ”‚   โ”œโ”€โ”€ rnn.c            # RNN logic (init, forward, print)
โ”‚   โ””โ”€โ”€ utils.c          # Math utility implementation
โ”œโ”€โ”€ data/                # Example input data (optional)
โ”‚   โ””โ”€โ”€ sample_input.txt
โ”œโ”€โ”€ main.c               # Program entry point
โ”œโ”€โ”€ Makefile             # Build configuration
โ””โ”€โ”€ README.md            # This file

๐Ÿงช Requirements

  • GCC or compatible C compiler (e.g. gcc, clang)
  • make (for building the project)

โš™๏ธ Build Instructions

1. Clone or download the project:

git clone https://github.com/nomadsdev/rnn-model-with-c.git
cd rnn-c

2. Build the project using make:

make

This compiles all .c files and generates an executable named rnn.


๐Ÿš€ Running the Program

./rnn

Expected Output:

Time step 0: Output: 0.4938
Time step 1: Output: 0.4962
Time step 2: Output: 0.4975

The program performs forward propagation across 3 time steps using a hardcoded input sequence (0.1, 0.5, 0.9) and prints the output of the RNN at each step.


๐Ÿงฐ How to Modify Inputs

To change the input sequence:

  1. Open main.c
  2. Modify the inputs[] array:
float inputs[] = {0.2f, 0.4f, 0.6f, 0.8f};
  1. Rebuild the project:
make clean && make
./rnn

๐Ÿ› ๏ธ How to Extend This Project

Here are some ideas for improving this base project:

  • โœ… Add Backpropagation Through Time (BPTT)
  • ๐Ÿ“‰ Loss function and training loop
  • ๐Ÿ“ Load input from file (sample_input.txt)
  • ๐Ÿง  Increase model complexity (e.g., stacked RNN layers)
  • ๐Ÿ’พ Save and load weights to/from file