initialize
Initializes the neural network engine with optional state restoration.
This method performs complete engine initialization including neural network weight initialization, state restoration from previous sessions, and coroutine scope configuration for asynchronous operations.
Initialization Process:
Atomicity Check: Ensures single initialization using AtomicBoolean.compareAndSet
Scope Assignment: Stores provided CoroutineScope for async training operations
State Restoration: Attempts to restore neural network from saved KarlContainerState
Fallback Initialization: Creates new model if restoration fails or no state provided
Validation: Confirms successful initialization with comprehensive logging
State Restoration Strategy:
Primary Path: Deserialize neural network weights from state.data
Fallback Path: Initialize new Xavier-distributed weights if restoration fails
Error Handling: Graceful degradation with detailed error logging
Validation: Verify restored state integrity before proceeding
Concurrency Considerations:
Thread Safety: Atomic initialization flag prevents concurrent initialization
Mutex Protection: Model state modifications protected by modelMutex
Coroutine Integration: All operations compatible with provided scope
Error Recovery:
State restoration errors trigger new model initialization
Comprehensive error logging for debugging and monitoring
Graceful fallback ensures engine always reaches operational state
Parameters
Optional KarlContainerState containing serialized neural network weights and training metadata from previous session. If null, initializes new model.
CoroutineScope for executing asynchronous training operations. Must remain active throughout engine lifetime.
See also
New model weight initialization
State deserialization and restoration
Persistent state data structure
Throws
If called multiple times on the same instance