Skip to content

Latest commit

 

History

History
403 lines (309 loc) · 9.05 KB

File metadata and controls

403 lines (309 loc) · 9.05 KB

Fibonacci-based Chaos Weighting System

Overview

The Fibonacci-based chaos weighting system provides exponential priority weighting for system components, enabling precise resource allocation and impact assessment using mathematical principles from the Fibonacci sequence and golden ratio.

Mathematical Foundation

Fibonacci Sequence

F(n) = F(n-1) + F(n-2)
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89...

Golden Ratio Convergence

φ = (1 + √5) / 2 ≈ 1.618
F(n+1) / F(n) → φ as n → ∞

Exponential Impact

Higher Fibonacci weights create exponential differences in impact:

  • Safety (F(10) = 55): 10% degradation = 5.5 impact
  • Branding (F(4) = 3): 10% degradation = 0.3 impact
  • 18.3x difference in impact sensitivity

Core API

FibonacciWeightingEngine

import { FibonacciWeightingEngine } from './src/fibonacci/weighting.js';

const engine = new FibonacciWeightingEngine();

assignWeight(componentName: string, importance: number)

Assigns Fibonacci weight to a component based on importance (0-100).

const safety = engine.assignWeight('Safety Systems', 95);
// {
//   name: 'Safety Systems',
//   fibonacciWeight: 10,        // Position in sequence
//   impactMultiplier: 55,       // F(10) = 55
//   priority: 'critical'        // Auto-assigned priority
// }

Priority Mapping:

  • 85-100: critical
  • 65-84: high
  • 40-64: medium
  • 0-39: low

calculateImpact(component, degradation)

Calculates impact of component failure with exponential sensitivity.

const impact = engine.calculateImpact(safety, 0.1);  // 10% degradation
// Returns: 5.5 (55 × 0.1)

optimizeAllocation(components, budget)

Allocates resources proportionally to Fibonacci weights.

const components = [
  engine.assignWeight('Safety', 95),
  engine.assignWeight('Traffic', 85),
  engine.assignWeight('Cost', 70)
];

const plan = engine.optimizeAllocation(components, 100);
// {
//   allocations: [
//     { component: 'Safety', allocation: 48.67, percentage: 48.7 },
//     { component: 'Traffic', allocation: 30.09, percentage: 30.1 },
//     { component: 'Cost', allocation: 11.50, percentage: 11.5 }
//   ],
//   totalAllocated: 99.99,
//   efficiency: 99.99
// }

findCriticalPaths(components)

Groups components by risk level with weight analysis.

const paths = engine.findCriticalPaths(components);
// [
//   {
//     components: ['Safety', 'Auth'],
//     totalWeight: 89,
//     riskLevel: 'extreme',
//     description: 'Critical path with 2 components (total weight: 89)'
//   }
// ]

refineThresholdWithGoldenRatio(baseThreshold)

Applies golden ratio refinement for optimal thresholds.

const refined = engine.refineThresholdWithGoldenRatio(60);
// Returns: 97.08 (60 × φ)

CLI Commands

fibonacci assign

Assign Fibonacci weight to a component.

coherence-mcp fibonacci assign "Safety Systems" 95

# Output:
# === Fibonacci Weight Assignment ===
# Component: Safety Systems
# Importance: 95/100
# Fibonacci Position: F(10)
# Impact Multiplier: 55
# Priority: CRITICAL
# ===================================

fibonacci optimize

Optimize resource allocation using Fibonacci weights.

coherence-mcp fibonacci optimize --components components.json --budget 100

# Output:
# === Resource Optimization Plan ===
# Total Budget: 100
# Total Allocated: 99.99
# Efficiency: 99.99%
#
# Allocations:
#   Safety Systems               48.67 (48.7%)
#   Traffic Coherence            30.09 (30.1%)
#   Cost Optimization            11.50 (11.5%)
# ===================================

components.json format:

{
  "components": [
    {"name": "Safety Systems", "importance": 95},
    {"name": "Traffic Coherence", "importance": 85}
  ]
}

fibonacci visualize

Generate ASCII priority heatmap.

coherence-mcp fibonacci visualize --input weights.json [--output heatmap.txt]

# Output:
# === Priority Distribution (Fibonacci Weighted) ===
#
# Safety Systems            [████████████████████████████████████████] (55) 48.7%
# Traffic Coherence         [█████████████████████████               ] (34) 30.1%
# Cost Optimization         [█████████                               ] (13) 11.5%
# ===================================================

fibonacci refine

Refine threshold using golden ratio.

coherence-mcp fibonacci refine --threshold 60 --method golden-ratio

# Output:
# === Threshold Refinement ===
# Method: Golden Ratio (φ = 1.618)
# Base Threshold: 60
# Refined Threshold: 97.08
# Multiplier: 1.618x
# ============================

fibonacci paths

Find critical paths in system.

coherence-mcp fibonacci paths --components components.json

# Output:
# === Critical Paths Analysis ===
#
# Path 1: EXTREME
# Total Weight: 89
# Components: Safety Systems, Traffic Coherence
# ================================

MCP Tools

The Fibonacci weighting system exposes 5 MCP tools:

fibonacci_assign_weight

{
  "name": "fibonacci_assign_weight",
  "arguments": {
    "componentName": "Safety Systems",
    "importance": 95
  }
}

fibonacci_calculate_impact

{
  "name": "fibonacci_calculate_impact",
  "arguments": {
    "component": {
      "name": "Safety",
      "fibonacciWeight": 10,
      "impactMultiplier": 55,
      "priority": "critical"
    },
    "degradation": 0.1
  }
}

fibonacci_optimize_allocation

{
  "name": "fibonacci_optimize_allocation",
  "arguments": {
    "components": [...],
    "budget": 100
  }
}

fibonacci_find_critical_paths

{
  "name": "fibonacci_find_critical_paths",
  "arguments": {
    "components": [...]
  }
}

fibonacci_refine_threshold

{
  "name": "fibonacci_refine_threshold",
  "arguments": {
    "baseThreshold": 60
  }
}

Integration with WAVE Validator

The WAVE coherence validator uses Fibonacci weighting for score components:

// Fibonacci weights in WAVE scoring:
// - Structural: 8 (F(6)) - Most critical
// - Semantic: 5 (F(5))  - Second most important
// - Temporal: 3 (F(4))  - Least important

const fibonacci_weighted = (
  structural * 8 +
  semantic * 5 +
  temporal * 3
) / 16;

Use Cases

1. Tunnel Boring Optimization

Prioritize safety over cosmetic features with exponential sensitivity:

const components = [
  { name: 'Safety Systems', weight: 34 },      // F(9)
  { name: 'Traffic Coherence', weight: 21 },   // F(8)
  { name: 'Cost Optimization', weight: 13 },   // F(7)
  { name: 'Environmental', weight: 8 },        // F(6)
  { name: 'Branding', weight: 3 }              // F(4)
];

// 10% safety degradation = 3.4 impact
// 10% branding degradation = 0.3 impact
// 11.3x difference in sensitivity

2. PR Prioritization

Weight PRs by criticality for merge order:

const prs = [
  { title: 'WAVE Validator', fibonacci: 21 },  // Foundation
  { title: 'ATOM Trail', fibonacci: 21 },      // Foundation
  { title: 'SPHINX Gates', fibonacci: 21 },    // Foundation
  { title: 'H&&S Protocol', fibonacci: 13 },   // Integration
  { title: 'Documentation', fibonacci: 5 }     // Enhancement
];

3. Coherence Threshold Calibration

Apply golden ratio for optimal thresholds:

const baseThreshold = 60;  // Minimum coherence
const optimalThreshold = baseThreshold * φ;  // ≈ 97%

// Creates natural gap between "passing" and "optimal"
// Encourages continuous improvement beyond minimums

Testing

Comprehensive test suite with 25 tests covering:

npm run test -- fibonacci-weighting

# Tests:
# ✓ Fibonacci sequence generation
# ✓ Golden ratio convergence
# ✓ Weight assignment for all priority levels
# ✓ Impact calculations with exponential scaling
# ✓ Resource optimization algorithms
# ✓ Critical path detection
# ✓ Visualization data generation
# ✓ Real-world use cases

Performance Characteristics

  • Time Complexity: O(1) for F(1)-F(20) (pre-calculated)
  • Space Complexity: O(1) constant memory
  • Scalability: Handles hundreds of components efficiently
  • Accuracy: IEEE 754 double precision for weights up to F(1476)

Mathematical Properties

Exponential Growth

F(5) = 5    → 1x baseline
F(7) = 13   → 2.6x
F(9) = 34   → 6.8x
F(11) = 89  → 17.8x

Golden Ratio Applications

  • Threshold Refinement: Creates natural quality gaps
  • Resource Allocation: Optimal proportions emerge naturally
  • Impact Assessment: Self-similar scaling at all levels

Convergence Properties

F(n+1) / F(n) approaches φ as n increases:
F(6)/F(5)   = 8/5   = 1.600
F(10)/F(9)  = 55/34 = 1.617
F(20)/F(19) = 6765/4181 = 1.618...

References

  • Fibonacci sequence: OEIS A000045
  • Golden ratio: φ = 1.6180339887...
  • WAVE protocol: docs/WAVE.md
  • SpiralSafe methodology: spiralsafe.org

Support

For issues or questions: