forked from wagenaartje/neataptic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterfaces.ts
More file actions
228 lines (211 loc) · 6.71 KB
/
Copy pathinterfaces.ts
File metadata and controls
228 lines (211 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
* Shared ASCII Maze contracts plus compatibility re-exports for the Step 5 type split.
*
* The ownership of run/configuration contracts now lives in `evolutionEngine/`
* and fitness evaluation contracts now live in `fitness.types.ts`. This file
* intentionally keeps only the genuinely cross-cutting network, result, and
* terminal-oriented shapes while re-exporting the moved contracts to preserve
* the established public import surface.
*/
import type { NeatInstance } from './evolutionEngine/evolutionEngine.types';
export type {
DistanceMap,
EncodedMaze,
EncodedMazeData,
EvolutionHelpers,
EvolutionLoopHelpers,
EvolutionOptions,
FileSystem,
IAgentSimulationConfig,
IEvolutionAlgorithmConfig,
IMazeConfig,
IReportingConfig,
IRunMazeEvolutionOptions,
LogitsRingState,
LoopHelpers,
MazeDistanceMap,
MazePosition,
NeatInstance,
NetworkConnection,
NetworkInstance,
NetworkNode,
PathModule,
Position,
ProfilingAccumulators,
ScratchBundle,
SimulationResult,
SnapshotEntry,
TrainingConstants,
} from './evolutionEngine/evolutionEngine.types';
export type {
FitnessEvaluatorFn,
IFitnessEvaluationContext,
} from './fitness.types';
/**
* Interface for dashboard manager abstraction.
* Used for dependency inversion and testability.
*/
export interface IDashboardManager {
/**
* Update the dashboard with the latest simulation/evolution state.
*
* @param maze - The current maze layout represented as an array of ASCII strings.
* @param result - Result object produced by the agent run.
* @param network - The network instance used for the run.
* @param generation - The current generation number.
* @param neatInstance - Optional NEAT instance for advanced telemetry display.
*/
update(
maze: string[],
result: IMazeRunResult | undefined,
network: INetwork | null,
generation: number,
neatInstance?: NeatInstance,
): void;
/** Optional log function for dashboard messages. */
logFunction?: (msg: string) => void;
/** Allow additional properties for extensibility. */
[key: string]: unknown;
}
/**
* Result structure returned by the maze simulation and evolution helpers.
*/
export interface IMazeRunResult {
/** Whether the agent solved the maze during this run. */
success: boolean;
/** Number of steps executed before termination. */
steps: number;
/** Materialised path as [x, y] coordinates visited sequentially. */
path: Array<[number, number]>;
/** Scalar fitness assigned to the run. */
fitness: number;
/** Progress metric (usually 0-100) representing completion percentage. */
progress: number;
/** Optional saturation fraction of outputs during the run. */
saturationFraction?: number;
/** Optional action-entropy metric derived from movement distribution. */
actionEntropy?: number;
/** Optional exit reason string used by the evolution loop. */
exitReason?: string;
/** Additional diagnostics or telemetry fields supplied by callers. */
[key: string]: unknown;
}
/**
* Visualization node used by ASCII and graph renderers to present a network node.
*/
export interface IVisualizationNode {
uuid: string;
id: number;
type: string;
activation: number;
bias?: number;
isAverage?: boolean;
avgCount?: number;
label?: string;
}
/**
* Visualization connection used by ASCII and graph renderers to present an edge between two nodes.
*/
export interface IVisualizationConnection {
fromUUID: string;
toUUID: string;
gaterUUID?: string | null;
weight: number;
enabled: boolean;
}
/** Structural connection descriptor referencing resolved node structures. */
export interface IConnectionWithStructRefs {
from?: INodeStruct | null;
to?: INodeStruct | null;
gater?: INodeStruct | null;
weight?: number;
enabled?: boolean;
[key: string]: unknown;
}
/** Aggregates incoming and outgoing link arrays for a node snapshot. */
export interface INodeConnectionRegistry {
in?: IConnectionWithStructRefs[];
out?: IConnectionWithStructRefs[];
gated?: IConnectionWithStructRefs[];
self?: IConnectionWithStructRefs[];
[key: string]: unknown;
}
/** Type representing a node activation (squash) function with optional metadata. */
export type ActivationFunctionWithName = ((
input: number,
derivate?: boolean,
) => number) & {
name?: string;
originalName?: string;
};
/** Structure describing a single network node for visualization, serialization and tooling. */
export interface INodeStruct {
type: string;
bias?: number;
squash?: ActivationFunctionWithName;
activation?: number;
name?: string;
index?: number;
[key: string]: unknown;
}
/** Extended node snapshot including connection registries for visualisation utilities. */
export interface INodeWithConnectionInfo extends INodeStruct {
connections?: INodeConnectionRegistry;
}
/**
* Lightweight neural-network abstraction used across the ASCII Maze example.
*/
export interface IActivationSchedulingDiagnostics {
/** Requested scheduling mode for the current runtime topology contract. */
requestedMode?: 'acyclic' | 'recurrent';
/** Execution path used for the current activation traversal. */
executionPath?:
'compiled-schedule' | 'cycle-fallback-order' | 'raw-node-order';
/** Number of compiled schedule steps when scheduling is available. */
stepCount?: number;
/** Number of recurrent-component steps in the compiled schedule. */
recurrentComponentCount?: number;
/** High-level issue attached to the scheduling decision, when one exists. */
issue?: 'cycle-detected' | 'schedule-missing' | null;
/** Stable input-role ids associated with the runtime network. */
inputNodeIds?: number[];
/** Stable output-role ids associated with the runtime network. */
outputNodeIds?: number[];
}
/**
* Lightweight neural-network abstraction used across the ASCII Maze example.
*/
export interface INetwork {
activate: (inputs: number[]) => number[];
propagate?: (
rate: number,
momentum: number,
update: boolean,
target: number[],
) => void;
clear?: () => void;
clone?: () => INetwork;
getActivationSchedulingDiagnostics?: () => IActivationSchedulingDiagnostics;
nodes?: INodeStruct[];
connections?: {
from: INodeStruct;
to: INodeStruct;
weight: number;
gater?: INodeStruct | null;
enabled?: boolean;
[key: string]: unknown;
}[];
inputNodeIds?: number[];
input?: number | INodeStruct[];
outputNodeIds?: number[];
output?: number | INodeStruct[];
}
/** Represents the outcome of a single logical step or checkpoint in the evolution process. */
export interface IEvolutionStepResult {
success: boolean;
progress: number;
}
/** Represents the overall result of an evolution function call. */
export interface IEvolutionFunctionResult {
finalResult: IEvolutionStepResult;
}