Skip to content

An interactive web UI for exploring Neural Cellular Automata (NCA). Visualize NCA evolution, design custom neural network architectures with various activation functions, and inspect cell behavior in real-time. Features include randomization tools, colormap options, and direct weight editing to observe the immediate impact on the NCA's behaviour.

License

Notifications You must be signed in to change notification settings

semvdn/NCA_Playground

Repository files navigation

Neural Cellular Automata Web UI

This project provides an interactive web-based interface for exploring Neural Cellular Automata (NCA). It allows users to visualize the evolution of a cellular automaton driven by a small neural network, experiment with different network architectures, activation functions, and weights, and observe their impact on the grid's behavior.

screenshot

What are Neural Cellular Automata?

Neural Cellular Automata are a fascinating class of systems where each cell in a grid updates its state based on the states of its immediate neighbors, using a neural network as the update rule. This project implements a basic NCA where each cell's value (a float between 0 and 1) is determined by a Multi-Layer Perceptron (MLP) that takes the 3x3 neighborhood of the cell as input.

Features

  • Interactive Simulation: Start, stop, step forward, and step backward through the NCA evolution.
  • Customizable Architecture:
    • Select from predefined MLP presets (Linear, Shallow ReLU, Deep Tanh, Wide Sigmoid, Custom).
    • Dynamically add/remove hidden layers and adjust node counts within constraints.
    • Choose activation functions (ReLU, Sigmoid, Tanh).
    • Adjust initial weight scale and bias for the neural network.
  • Randomization Tools:
    • Randomize the grid state.
    • Randomize network weights based on current architecture.
    • Randomize the entire network architecture (layers, nodes, activation, weights).
  • Visualization Options:
    • Select from various colormaps to visualize cell states.
    • Adjust simulation speed.
  • Inspection Tools:
    • Click on any cell to inspect its 3x3 neighborhood input and the activations of each layer in the neural network for that specific cell.
    • Visualize the neural network architecture with color-coded weights (green for positive, red for negative).
  • Manual Weight Editor: Directly modify the incoming weights for individual neurons or apply preset patterns to all neurons in a selected layer.
  • Capture Tools:
    • Capture screenshots of the NCA grid.
    • Record video of the simulation.

Visual Showcase

Here are videos demonstrating the Neural Cellular Automata Web UI in action:

Canvas Simulations

canvas_video_1.mp4
canvas_video_4.mp4
canvas_video_3.mp4
canvas_video_2.mp4

Web UI Walkthrough

https://youtu.be/euN4uQ0BBNc

Project Structure

  • app.py: The main Flask application file. It handles web routes, manages the NCA simulation, processes user requests, and serves the frontend.
  • config.py: Contains configuration settings for the Flask application and NCA parameters.
  • nca_core.py: Contains the core logic for the Neural Cellular Automaton and the Flexible Multi-Layer Perceptron (MLP). This file defines how the NCA steps and how the neural network processes inputs.
  • services/:
    • nca_service.py: Provides a service layer for NCA-related operations, abstracting core logic from the Flask app.
  • utils/:
    • validation.py: Contains utility functions for data validation.
    • visualization.py: Contains utility functions for visualization-related tasks, such as colormap generation.
  • templates/:
    • index.html: The main HTML template for the web user interface.
  • static/:
    • css/style.css: Contains the CSS styles for the web interface.
    • js/app.js: The main entry point for the frontend JavaScript, responsible for initializing all modules and setting up the application.
    • js/modules/: Contains modularized JavaScript files, each encapsulating specific functionalities:
  • requirements.txt: Lists the Python dependencies required to run the application.

Setup and Running

To set up and run this project locally, follow these steps:

  1. Clone the repository (if you haven't already):

    git clone <repository_url>
    cd <repository_directory>
  2. Create a virtual environment (recommended):

    python -m venv venv
  3. Activate the virtual environment:

    • On Windows:
      .\venv\Scripts\activate
    • On macOS/Linux:
      source venv/bin/activate
  4. Install the required Python dependencies:

    pip install -r requirements.txt

    The dependencies include:

    • Flask: Web framework for the backend.
    • numpy: For numerical operations, especially array manipulations in NCA and MLP.
    • matplotlib: Used for colormap generation on the backend.
  5. Run the Flask application:

    python app.py

    The application will typically run on http://127.0.0.1:5000/ (or localhost:5000).

  6. Open in your browser: Navigate to http://127.0.0.1:5000/ in your web browser to access the Neural Cellular Automata Playground.

Usage

Once the application is running and you've opened it in your browser, you can:

  • Use the Simulation Controls to start/stop the simulation, step through it, or restart.
  • Adjust the Speed slider to control the animation rate.
  • Select different Colormaps to change the visual representation of the cell states.
  • Utilize the Randomizer buttons to generate new grids, randomize network weights, or create entirely new network architectures.
  • In the NCA Architecture section, choose Presets or configure a Custom network by adjusting hidden layer sizes, activation functions, weight scale, and bias. Changes are applied immediately.
  • Explore the Manual Neuron Weight Editor to fine-tune individual neuron weights or apply predefined patterns.
  • Click on any cell in the main grid to view its Neighborhood input and the Layer Activations within the neural network in the "Under the Hood" panel.
  • Observe the Network Visualization to see the MLP structure and how weights are distributed.
  • Use the Capture Tools to save screenshots or record videos of your simulations.

About

An interactive web UI for exploring Neural Cellular Automata (NCA). Visualize NCA evolution, design custom neural network architectures with various activation functions, and inspect cell behavior in real-time. Features include randomization tools, colormap options, and direct weight editing to observe the immediate impact on the NCA's behaviour.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published