ndlib

Network Diffusion Library - (for NetworkX and iGraph)

View the Project on GitHub GiulioRossetti/ndlib

Visual Model Builder Extension Guide

This document describes how to extend the current dashboard visual model builder so it can express epidemic models that also carry opinion variables, both continuous and discrete.

The goal is not to implement the feature now. This is a design and execution guide for a future iteration.

1. Scope

The current builder already supports a graph-based composition workflow for custom models. The next step is to make it capable of building models where each node may carry:

The builder should stay usable for simple models. Users creating a standard epidemic model should not be forced to configure opinion-specific blocks unless they need them.

2. Target Model Families

The extended builder should support at least these model patterns:

This should cover the common use cases behind models such as:

3. NDQL Language Extensions

The current NDQL representation is centered on statuses, compartments, rules, and initialization. To support opinion variables, NDQL needs a typed state section and a richer initialization syntax.

3.1 Variable Declarations

Add explicit declarations for node state variables:

MODEL MyModel

STATUS Susceptible
STATUS Infected

VARIABLE opinion TYPE continuous RANGE [0,1]
VARIABLE label TYPE discrete VALUES [A,B,C]

Suggested semantics:

3.2 Initialization

Initialization should be able to assign either scalar values or distributions.

Examples:

INITIALIZE
SET Susceptible 0.95
SET Infected 0.05
SET opinion UNIFORM 0.0 1.0
SET label SAMPLE [A,B,C] WEIGHTS [0.5,0.3,0.2]

Recommended additions:

3.3 Update Rules

Current RULE blocks are sufficient for status transitions, but opinion variables need variable-aware updates.

Extend the syntax to support:

RULE
FROM Susceptible
TO Infected
USING threshold_rule
WHEN opinion > 0.7

UPDATE opinion = opinion + 0.1
UPDATE label = "B"

The new rule layer should support:

3.4 Parameter Typing

NDQL parameters should carry type metadata so the runtime can validate values:

This matters because the builder needs to distinguish:

3.5 Backward Compatibility

The extended NDQL must remain valid for existing models.

Compatibility rules:

4. Builder Blocks to Add

The interface should remain block-based, but the block palette needs a second layer for state variables and opinion dynamics.

4.1 Variable Blocks

Add blocks for node-level variables:

Suggested configuration fields:

4.2 Opinion Update Blocks

Add blocks for dynamics on those variables:

Suggested configuration fields:

4.3 Coupling Blocks

Add blocks that connect epidemic and opinion dynamics:

These blocks are needed because many useful models are not pure epidemic or pure opinion systems. They are coupled systems.

4.4 Initialization Blocks

The builder should support explicit initialization blocks for:

5. Interface Extensions

The interface should be extended in a way that keeps the current visual model builder recognizable.

5.1 Separate Tabs or Modes

Introduce a clear split between:

A single canvas can still be used, but the left palette and the right inspector should change with the active mode.

5.2 Typed Node Appearance

The canvas should visually distinguish block types:

Recommended cues:

5.3 Typed Properties Panel

The properties editor should adapt to the selected block.

Examples:

5.4 Validation Feedback

The builder should validate before save:

Validation errors should be shown inline on the canvas and in the save dialog.

5.5 NDQL Preview

The NDQL preview should highlight typed sections:

This makes the language understandable even when the model becomes more expressive.

6. Data Model Extensions

The JSON payload produced by the builder will need new fields beyond the current statuses, compartments, rules, and initial_status.

Recommended additions:

Example shape:

{
  "name": "CoupledOpinionEpidemic",
  "statuses": [],
  "variables": [
    { "name": "opinion", "type": "continuous", "range": [0, 1] },
    { "name": "label", "type": "discrete", "values": ["A", "B", "C"] }
  ],
  "updates": [],
  "couplings": [],
  "initial_status": [],
  "initial_variables": []
}

The version field is important so the backend can evolve without breaking older saved models.

7. Phased Implementation Plan

Implement this incrementally. Each phase should deliver a usable improvement on its own.

Phase 1: Typed State Foundation

Goal:

Success criteria:

Phase 2: Initialization and Validation

Goal:

Success criteria:

Phase 3: Opinion Update Blocks

Goal:

Success criteria:

Phase 4: Coupled Epidemic-Opinion Dynamics

Goal:

Success criteria:

Phase 5: UX Hardening

Goal:

Success criteria:

Before the feature is considered complete, the following should be true:

9. Notes on Usability

This feature will be easier to adopt if the UI avoids exposing too many advanced options at once.

Practical design rules:

10. Suggested Deliverable Order

If this work is split among multiple contributors, a practical order is:

  1. extend the model schema and NDQL parser/serializer
  2. add opinion variable blocks and validation
  3. add update and coupling blocks
  4. refine the UI and preview
  5. add tests and migration coverage

That ordering minimizes the risk of building a UI that cannot be serialized or executed.

11. Current Shipped Behavior

The dashboard implementation already includes a first, bounded version of this design:

Future work should extend this foundation without reintroducing epidemic-only assumptions into opinion workflows.