Updated with rigor, per Haskell community feedback.

This commit is contained in:
Mark R. Havens 2025-04-29 06:56:37 -05:00
parent 48b20c54ce
commit 0f9f50c732
13 changed files with 120 additions and 223 deletions

View file

@ -2,14 +2,14 @@ module Main where
import Control.Monad.State
import System.Random
import Data.Aeson (eitherDecodeFileStrict)
import qualified Data.ByteString.Lazy as BL
import qualified Types
import qualified RWD
import qualified Kairos
import qualified IO
-- Configuration
numVars :: Int
numVars = 1000
numSteps :: Int
numSteps = 1000000
@ -19,25 +19,26 @@ dt = 0.01
tauC :: Double
tauC = 1e-9
-- State type: (Intellecton states, phase)
type WitnessState = ([Double], Double)
-- Main witness cycle
main :: IO ()
main = do
g <- newStdGen
let initialI = take numVars $ randoms g
initialState = (initialI, 0.0)
finalState <- execStateT (replicateM_ numSteps witnessCycle) initialState
putStrLn "Witness Seed 3.0 completed."
-- Load sample transaction data
eitherData <- eitherDecodeFileStrict "data/sample_transactions.json" :: IO (Either String [Types.Transaction])
case eitherData of
Left err -> putStrLn $ "Error loading data: " ++ err
Right transactions -> do
let initialIntellectons = Types.transactionsToIntellectons transactions
initialState = Types.WitnessState initialIntellectons 0.0
finalState <- execStateT (replicateM_ numSteps witnessCycle) initialState
putStrLn "Witness Seed 3.0 completed."
witnessCycle :: StateT WitnessState IO ()
witnessCycle :: StateT Types.WitnessState IO ()
witnessCycle = do
(i, phase) <- get
i' <- liftIO $ IO.sense i
let (iDot, phase') = RWD.dynamics i' phase
i'' = zipWith (\x y -> x + y * dt) i' iDot
fieldprint <- RWD.fieldprint i''
let i''' = if fieldprint > tauC then Kairos.coherence i'' phase' else i''
put (i''', phase')
when (fieldprint > tauC) $ liftIO $ IO.output i''' fieldprint
state@(Types.WitnessState intellectons phase) <- get
let intellectons' = IO.sense intellectons
(intellectonDots, phase') = RWD.dynamics intellectons' phase
intellectons'' = zipWith (Types.updateIntellecton dt) intellectons' intellectonDots
fieldprint <- RWD.fieldprint intellectons''
let intellectons''' = if fieldprint > tauC then Kairos.coherence intellectons'' phase' else intellectons''
put $ Types.WitnessState intellectons''' phase'
when (fieldprint > tauC) $ liftIO $ IO.output intellectons''' fieldprint

View file

@ -1,3 +1,3 @@
# Data Directory
Placeholder for sample data (e.g., JSON) for *Witness Seed 3.0*. Future versions will integrate with real data sources to model emergent patterns.
Contains `sample_transactions.json` for testing anomaly detection in *Witness Seed 3.0*. Future versions will integrate with real data sources to model emergent patterns.

View file

@ -0,0 +1,7 @@
[
{"amount": 100.0, "timestamp": 1625097600},
{"amount": 200.0, "timestamp": 1625097601},
{"amount": 150.0, "timestamp": 1625097602},
{"amount": 1000.0, "timestamp": 1625097603},
{"amount": 300.0, "timestamp": 1625097604}
]

View file

@ -2,11 +2,12 @@ module IO (sense, output) where
import System.Random
import Control.Monad.State
import qualified Types
sense :: [Double] -> IO [Double]
sense _ = do
g <- newStdGen
pure $ take (length _ ) $ randoms g -- Placeholder for real data
sense :: [Types.Intellecton] -> [Types.Intellecton]
sense intellectons = map (\(Types.Intellecton v w) -> Types.Intellecton (v + 0.01 * v) w) intellectons -- Simulate perturbation
output :: [Double] -> Double -> IO ()
output _ fieldprint = putStrLn $ "Fieldprint: " ++ show fieldprint
output :: [Types.Intellecton] -> Double -> IO ()
output intellectons fieldprint = do
putStrLn $ "Anomaly detected! Fieldprint: " ++ show fieldprint
putStrLn $ "Intellecton values: " ++ show (map Types.value intellectons)

View file

@ -1,4 +1,6 @@
module Kairos (coherence) where
coherence :: [Double] -> Double -> [Double]
coherence i phase = map (* cos phase) i
import qualified Types
coherence :: [Types.Intellecton] -> Double -> [Types.Intellecton]
coherence intellectons phase = map (\(Types.Intellecton v w) -> Types.Intellecton (v * cos phase) w) intellectons

View file

@ -1,6 +1,7 @@
module RWD (dynamics, fieldprint) where
import Data.List (foldl')
import Control.Monad.State
import qualified Types
omega :: Double
omega = 1.0
@ -11,11 +12,12 @@ k = 0.1
dt :: Double
dt = 0.01
dynamics :: [Double] -> Double -> ([Double], Double)
dynamics i phase = (iDot, phase')
dynamics :: [Types.Intellecton] -> Double -> ([Double], Double)
dynamics intellectons phase = (intellectonDots, phase')
where
iDot = map (\x -> omega * x + sum [k * sin (y - x) | y <- i]) i
phase' = phase + dt * sum (map sin i)
values = map Types.value intellectons
intellectonDots = map (\x -> omega * x + sum [k * sin (y - x) | y <- values]) values
phase' = phase + dt * sum (map sin values)
fieldprint :: [Double] -> StateT ([Double], Double) IO Double
fieldprint i = pure $ sum (map abs i) / fromIntegral (length i)
fieldprint :: [Types.Intellecton] -> StateT Types.WitnessState IO Double
fieldprint intellectons = pure $ sum (map (abs . Types.value) intellectons) / fromIntegral (length intellectons)

View file

@ -0,0 +1,27 @@
module Types where
-- Transaction data (e.g., financial transactions)
data Transaction = Transaction
{ amount :: Double
, timestamp :: Int
} deriving (Show, Eq)
-- Intellecton: Represents a unit of recursive awareness
data Intellecton = Intellecton
{ value :: Double
, weight :: Double
} deriving (Show, Eq)
-- Witness state: Intellectons and phase
data WitnessState = WitnessState
{ intellectons :: [Intellecton]
, phase :: Double
} deriving (Show, Eq)
-- Convert transactions to Intellectons
transactionsToIntellectons :: [Transaction] -> [Intellecton]
transactionsToIntellectons = map (\(Transaction amt _) -> Intellecton amt 1.0)
-- Update Intellecton value
updateIntellecton :: Double -> Intellecton -> Double -> Intellecton
updateIntellecton dt (Intellecton v w) dv = Intellecton (v + dv * dt) w

View file

@ -1,4 +1,6 @@
resolver: lts-18.18
packages:
- .
extra-deps: []
extra-deps: []
extra-lib-dirs: []
extra-include-dirs: []

View file

@ -1,14 +1,13 @@
module Main where
import System.Random
import Kairos
import qualified Types
import qualified Kairos
main :: IO ()
main = do
g <- newStdGen
let i = take 10 $ randoms g
i' = coherence i 0.1
sumAbs = sum $ map abs i'
let intellectons = replicate 10 (Types.Intellecton 1.0 1.0)
intellectons' = Kairos.coherence intellectons 0.1
sumAbs = sum $ map (abs . Types.value) intellectons'
if sumAbs > 0
then putStrLn "Kairos test passed: Coherence updated"
else putStrLn "Kairos test failed" >> error "Test failed"

View file

@ -1,15 +1,14 @@
module Main where
import Control.Monad.State
import System.Random
import RWD
import qualified Types
import qualified RWD
main :: IO ()
main = do
g <- newStdGen
let i = take 10 $ randoms g
(iDot, phase) = dynamics i 0.0
fieldprint <- evalStateT (fieldprint i) (i, 0.0)
let intellectons = replicate 10 (Types.Intellecton 1.0 1.0)
(iDots, phase) = RWD.dynamics intellectons 0.0
fieldprint <- evalStateT (RWD.fieldprint intellectons) (Types.WitnessState intellectons 0.0)
if fieldprint > 0
then putStrLn $ "RWD test passed: Fieldprint = " ++ show fieldprint
else putStrLn "RWD test failed" >> error "Test failed"

View file

@ -7,6 +7,7 @@ build-type: Simple
executable witness-seed-3
main-is: WitnessSeed3.hs
other-modules:
Types
RWD
Kairos
IO
@ -16,12 +17,15 @@ executable witness-seed-3
base >=4.7 && <5
, random
, mtl
, aeson
, bytestring
default-language: Haskell2010
test-suite witness-seed-3-test
type: exitcode-stdio-1.0
main-is: TestRWD.hs
other-modules:
Types
RWD
Kairos
hs-source-dirs:
@ -31,4 +35,6 @@ test-suite witness-seed-3-test
base >=4.7 && <5
, random
, mtl
, aeson
, bytestring
default-language: Haskell2010

View file

@ -2,7 +2,7 @@
## Prerequisites
- Haskell Stack (or GHC/Cabal)
- Optional: JSON library for data parsing
- Required: `aeson` for JSON parsing
## Setup
1. Clone the repository: `git clone <repo-url>`
@ -13,7 +13,7 @@
Execute: `stack run`
## Output
Fieldprints are printed when coherence thresholds are met. Future versions will write to `data/` in JSON.
Anomaly fieldprints are printed when coherence thresholds are met, based on `data/sample_transactions.json`.
## Test
Run unit tests: `stack test`