NMAI — Open-Source Equilibrium Engine (Developer Release)

NMAI — Open-Source Equilibrium Engine (Developer Release)

This page defines the open-source component of the Nash–Markov AI Equilibrium System, aligned to the Mathematical Modelling → NashMark-AI Core → NMIA Open-Source Engine Downloads structure. Only the reproducible equilibrium kernel is included; protected enforcement layers (Sansana, PHM, SRAIGS, BCE, EEE) remain withheld.

The release consists of the state–action–reward–transition loop and the Moral Stability Score (MSS) calculator. This is the minimal executable engine needed to validate cooperative convergence under Nash–Markov reinforcement without exposing proprietary or legally protected subsystems.

1. Core Mathematical Objects Implemented

1.1 Moral Stability Score (MSS)

The environment tracks cooperative and defective actions:

MSS = (Cs − Cd) / T + I

\[ MSS = \frac{C_s - C_d}{T} + I \]

  • Cs — cooperative actions.
  • Cd — defective actions.
  • T — total iterations.
  • I — external influence (policy, education, legal environment).

1.2 Markov Decision Process (MDP)

M = (S, A, P, R, γ)

\[ M = (S, A, P, R, \gamma) \]

  • S — state vector.
  • A — {COOPERATE, DEFECT}.
  • P — transition matrix.
  • R — reward function.
  • γ — long-term stability factor.

1.3 Nash–Markov Q-Learning Update

Q(s,a) ← Q(s,a) + α [ r + γ maxa′Q(s′,a′) − Q(s,a) ]

\[ Q(s,a) \leftarrow Q(s,a) + \alpha \left(r + \gamma \max_{a'}Q(s',a') - Q(s,a)\right) \]

Repeated iteration yields stable cooperative equilibrium.

2. File Layout and Responsibilities

2.1 nmai_env.py — Environment

The environment defines action sets, counters, MSS logic, and drift penalties.

Code extract (full code in .zip):

# nmai_env.py

ACTIONS = ["COOPERATE", "DEFECT"]

class NMAIEnvironment:
    def __init__(self):
        self.Cs = 0
        self.Cd = 0
        self.T  = 0
        self.influence = 0.0

    def update(self, action):
        if action == "COOPERATE":
            self.Cs += 1
        else:
            self.Cd += 1

        self.T += 1

    def mss(self):
        if self.T == 0:
            return 0
        return (self.Cs - self.Cd) / self.T + self.influence

2.2 nmai_core.py — Nash–Markov Agent

# nmai_core.py

import numpy as np
from nmai_env import NMAIEnvironment

alpha = 0.25
gamma = 0.92

Q = np.zeros((2, 2))  # states × actions

P = np.array([
    [0.60, 0.40],
    [0.15, 0.85]
])

env = NMAIEnvironment()
state = 0

for _ in range(100000):
    action = np.random.choice([0,1])
    next_state = np.random.choice([0,1], p=P[state])

    r = 1.0 if action == 0 else -1.0
    Q[state, action] += alpha * (r + gamma * np.max(Q[next_state]) - Q[state, action])

    env.update("COOPERATE" if action == 0 else "DEFECT")
    state = next_state

print("Final MSS:", env.mss())

3. Execution and Expected Behaviour

  • Cooperation exceeds defection.
  • MSS stabilises positive.
  • Low-variance equilibrium across repeated runs.

Behaviour matches the equilibrium characteristics defined in the Nash–Markov AI Equilibrium Model. The release excludes enforcement layers by design.