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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//! # Kizzasi (兆候)
//!
//! **Autoregressive General-Purpose Signal Predictor (AGSP)**
//!
//! *"Predicting the flux of the world with the precision of logic."*
//!
//! Kizzasi is a Rust-native AGSP designed for continuous signal streams—audio,
//! sensor data, robotics control signals, and video frames. Unlike traditional
//! LLMs that operate on discrete text tokens, Kizzasi is built for the
//! continuous domain.
//!
//! ## Core Innovation: Neuro-Symbolic Architecture
//!
//! Kizzasi combines the learning capability of State Space Models (Mamba/RWKV)
//! with the strict reliability of TensorLogic. This ensures that predicted
//! signals not only follow statistical likelihoods but also adhere to defined
//! physical laws, safety constraints, and logical rules.
//!
//! ## COOLJAPAN Ecosystem
//!
//! This crate is part of the COOLJAPAN scientific computing ecosystem and
//! follows the KIZZASI_POLICY.md for dependency management, using:
//! - `scirs2-core` for array and numerical operations
//! - `tensorlogic` for constraint logic
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use kizzasi::prelude::*;
//!
//! fn main() -> Result<()> {
//! // Initialize predictor with Mamba2 backend
//! let config = KizzasiConfig::new()
//! .model_type(ModelType::Mamba2)
//! .context_window(8192);
//!
//! let mut predictor = Kizzasi::new(config)?;
//!
//! // Single step prediction
//! let input = array![0.1, 0.2, 0.3];
//! let output = predictor.step(&input)?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Common Use Cases
//!
//! ### Audio Processing
//! ```rust,ignore
//! let mut predictor = KizzasiBuilder::audio_preset().build()?;
//! let sample = array![0.5]; // Single sample
//! let next = predictor.step(&sample)?;
//! ```
//!
//! ### Robotics Control
//! ```rust,ignore
//! let mut predictor = KizzasiBuilder::robotics_preset(6).build()?; // 6-DOF
//! let joint_angles = array![0.1, 0.2, 0.3, 0.4, 0.5, 0.6];
//! let predicted = predictor.step(&joint_angles)?;
//! ```
//!
//! ### Sensor Monitoring
//! ```rust,ignore
//! let mut predictor = KizzasiBuilder::sensor_preset(10).build()?;
//! let readings = array![/* 10 sensor values */];
//! let forecast = predictor.predict_n(&readings, 5)?; // 5 steps ahead
//! ```
//!
//! ### With Safety Constraints
//! ```rust,ignore
//! # #[cfg(feature = "logic")]
//! # {
//! use kizzasi::{ConstraintBuilder, Guardrail, GuardrailSet};
//!
//! let mut predictor = KizzasiBuilder::robotics_preset(3).build()?;
//!
//! // Add safety bounds
//! let mut guardrails = GuardrailSet::new();
//! let constraint = ConstraintBuilder::new()
//! .name("joint_limits")
//! .greater_eq(-3.14)
//! .less_eq(3.14)
//! .build()?;
//! guardrails.add_global(Guardrail::new(constraint, false));
//! predictor.set_guardrails(guardrails);
//! # }
//! ```
//!
//! ## Features
//!
//! - `std` (default): Standard library support
//! - `full` (default): Enable all features (io, logic, async, config-files, macros)
//! - `io`: Physical world connectors (MQTT, Audio)
//! - `logic`: TensorLogic constraint enforcement
//! - `async`: Async/streaming APIs, connection pooling with tokio
//! - `config-files`: TOML/YAML configuration file support
//! - `macros`: Derive macros for custom configurations
//!
//! ## Performance
//!
//! Kizzasi is optimized for real-time inference:
//! - Zero-copy operations where possible
//! - Efficient state management
//! - SIMD-optimized computations via scirs2-core
//! - Batch processing support
//!
//! Run benchmarks with: `cargo bench --bench predictor_benchmarks`
//!
//! ## Thread Safety
//!
//! `Kizzasi` predictors are `Send` but not `Sync`. For concurrent predictions:
//! - Use `fork()` to create independent predictors per thread
//! - Or wrap in `Arc<Mutex<Kizzasi>>` for shared access
//! - Async APIs are available with the `async` feature
//!
//! ## Advanced Features
//!
//! ### Model Versioning and A/B Testing
//! Manage multiple model versions with deployment strategies:
//! ```rust,ignore
//! use kizzasi::versioning::{ModelRegistry, DeploymentStrategy};
//!
//! let mut registry = ModelRegistry::new();
//! registry.deploy("2.0.0", DeploymentStrategy::Canary { traffic_percent: 10 })?;
//! let model = registry.select_for_request(request_id)?;
//! ```
//!
//! ### Telemetry and Metrics
//! Production-grade metrics collection and monitoring:
//! ```rust,ignore
//! use kizzasi::telemetry::{MetricsCollector, MetricEvent};
//!
//! let metrics = MetricsCollector::new("my_service");
//! metrics.record(MetricEvent::Prediction { latency_us: 1500, input_dim: 64, output_dim: 64 });
//! let stats = metrics.snapshot();
//! println!("P99 latency: {:.2}ms", stats.p99_latency_ms);
//! ```
//!
//! ### Connection Pooling
//! Efficient resource management for I/O operations (requires `async` feature):
//! ```rust,ignore
//! use kizzasi::pool::{ConnectionPool, PoolConfig};
//!
//! let config = PoolConfig::default().with_max_connections(10);
//! let pool = ConnectionPool::new(factory, config).await?;
//! let conn = pool.acquire().await?;
//! ```
//!
//! ## Examples
//!
//! See the `examples/` directory for comprehensive examples:
//! - `basic_prediction` - Core API usage
//! - `with_guardrails` - Constraint enforcement
//! - `audio_processing` - Audio signal prediction
//! - `robotics_control` - Robot control systems
//! - `streaming` - Async streaming APIs
//! - `anomaly_detection` - Real-time anomaly detection
//! - `model_checkpointing` - Save/load predictor configuration
//! - `custom_model` - Advanced configuration patterns
//! - `production_deployment` - Full production setup with versioning, metrics, and pooling
//! - `metrics_monitoring` - Comprehensive metrics and monitoring
pub use ;
pub use ;
pub use ;
pub use ;
pub use LazyKizzasi;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// Re-export core types
pub use ;
// Re-export logic types when feature is enabled
pub use ;
// Re-export io types when feature is enabled
pub use ;
pub use ;
pub use ;
// Re-export scirs2-core array types
pub use ;