Skip to main content

CompiledInstinct

Struct CompiledInstinct 

Source
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: f32

Implementations§

Source§

impl CompiledInstinct

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, String>

Loads and verifies a .reflex binary model from a byte buffer.

Source

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}
Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompiledInstinct

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.