pub struct CompiledInstinct {
pub name: String,
pub decision_type: String,
pub options: Vec<String>,
pub weights: HashMap<String, [f32; 384]>,
pub biases: HashMap<String, f32>,
pub temperature: f32,
/* private fields */
}Expand description
Portable, self-contained compiled decision model evaluating in <10us.
Fields§
§name: String§decision_type: String§options: Vec<String>§weights: HashMap<String, [f32; 384]>§biases: HashMap<String, f32>§temperature: f32Implementations§
Source§impl CompiledInstinct
impl CompiledInstinct
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, String>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, String>
Loads and verifies a .reflex binary model from a byte buffer.
Sourcepub fn from_file(path: &str) -> Result<Self, String>
pub fn from_file(path: &str) -> Result<Self, String>
Loads a .reflex file from the filesystem.
Examples found in repository?
examples/compiled_parity.rs (line 11)
4fn main() {
5 let args: Vec<String> = env::args().collect();
6 if args.len() < 2 {
7 eprintln!("Usage: compiled_parity <model_path> [query1] [query2] ...");
8 std::process::exit(1);
9 }
10 let model_path = &args[1];
11 let model = match CompiledInstinct::from_file(model_path) {
12 Ok(m) => m,
13 Err(e) => {
14 eprintln!("Error loading model: {}", e);
15 std::process::exit(1);
16 }
17 };
18
19 let queries = if args.len() > 2 {
20 args[2..].to_vec()
21 } else {
22 Vec::new()
23 };
24
25 print!("[");
26 for (i, q) in queries.iter().enumerate() {
27 let res = model.predict(q);
28 print!("{{\"query\":");
29 print!("\"{}\",", q.replace('\\', "\\\\").replace('"', "\\\""));
30 print!("\"selected\":\"{}\",", res.selected);
31 print!("\"distribution\":{{");
32 for (j, (opt, prob)) in res.distribution.iter().enumerate() {
33 print!("\"{}\":{:.6}", opt, prob);
34 if j + 1 < res.distribution.len() {
35 print!(",");
36 }
37 }
38 print!("}}}}");
39 if i + 1 < queries.len() {
40 print!(",");
41 }
42 }
43 println!("]");
44}Sourcepub fn predict(&self, state: &str) -> CompiledResult
pub fn predict(&self, state: &str) -> CompiledResult
Executes sub-10 microsecond inference on state input.
Examples found in repository?
examples/compiled_parity.rs (line 27)
4fn main() {
5 let args: Vec<String> = env::args().collect();
6 if args.len() < 2 {
7 eprintln!("Usage: compiled_parity <model_path> [query1] [query2] ...");
8 std::process::exit(1);
9 }
10 let model_path = &args[1];
11 let model = match CompiledInstinct::from_file(model_path) {
12 Ok(m) => m,
13 Err(e) => {
14 eprintln!("Error loading model: {}", e);
15 std::process::exit(1);
16 }
17 };
18
19 let queries = if args.len() > 2 {
20 args[2..].to_vec()
21 } else {
22 Vec::new()
23 };
24
25 print!("[");
26 for (i, q) in queries.iter().enumerate() {
27 let res = model.predict(q);
28 print!("{{\"query\":");
29 print!("\"{}\",", q.replace('\\', "\\\\").replace('"', "\\\""));
30 print!("\"selected\":\"{}\",", res.selected);
31 print!("\"distribution\":{{");
32 for (j, (opt, prob)) in res.distribution.iter().enumerate() {
33 print!("\"{}\":{:.6}", opt, prob);
34 if j + 1 < res.distribution.len() {
35 print!(",");
36 }
37 }
38 print!("}}}}");
39 if i + 1 < queries.len() {
40 print!(",");
41 }
42 }
43 println!("]");
44}Trait Implementations§
Source§impl Clone for CompiledInstinct
impl Clone for CompiledInstinct
Auto Trait Implementations§
impl Freeze for CompiledInstinct
impl RefUnwindSafe for CompiledInstinct
impl Send for CompiledInstinct
impl Sync for CompiledInstinct
impl Unpin for CompiledInstinct
impl UnsafeUnpin for CompiledInstinct
impl UnwindSafe for CompiledInstinct
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more