File size: 3,465 Bytes
be99550
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
use rand::Rng;

/// 🌍 BioPhys 6.0: ν–‰μ„± μƒνƒœκ³„ μ§„ν™” μ—”μ§„ (The Living Planet)

// ---------------------------------------------------------
// 1. πŸ› λŒμ—°λ³€μ΄ λ°œμƒκΈ° (Mutation Injector)
// ---------------------------------------------------------
pub struct MutationInjector;

impl MutationInjector {
    /// 방사선 레벨(ν™•λ₯ )에 따라 μ˜λ„μ μœΌλ‘œ λΉ„νŠΈλ₯Ό λ’€μ§‘μ–΄ λŒμ—°λ³€μ΄(μƒˆλ‘œμš΄ μ°½μ˜μ„±)λ₯Ό μ°½μ‘°ν•©λ‹ˆλ‹€.
    pub fn inject_radiation(weights: &mut [u32], radiation_level: f64) {
        let mut rng = rand::thread_rng();
        let mutation_chance = (radiation_level * 1000000.0) as u32; // λ°±λ§ŒλΆ„μœ¨

        for w in weights.iter_mut() {
            if rng.gen_ratio(mutation_chance, 1_000_000) {
                // μž„μ˜μ˜ 1λΉ„νŠΈλ₯Ό λ’€μ§‘μŒ (Bit Flip)
                let flip_mask = 1 << rng.gen_range(0..32);
                *w ^= flip_mask;
            }
        }
    }
}

// ---------------------------------------------------------
// 2. 🧠 λ¬΄μ˜μ‹μ  영감 λˆ„μˆ˜ (Subconscious Bleed)
// ---------------------------------------------------------
pub struct SubconsciousMemory {
    pub kv_cache_pool: Vec<f32>, // 이전 μ„Έμ…˜λ“€μ˜ λ¬Έλ§₯ 찌꺼기
}

impl SubconsciousMemory {
    pub fn new(size: usize) -> Self {
        Self { kv_cache_pool: vec![0.0; size] }
    }

    /// 이전 λŒ€ν™”μ˜ λ¬Έλ§₯을 μ™„μ „νžˆ μ§€μš°μ§€ μ•Šκ³  1~5% ν™•λ₯ λ‘œ ν˜„μž¬ μž‘μ—…μ— λˆ„μˆ˜μ‹œν‚΅λ‹ˆλ‹€.
    pub fn bleed_into_current(&self, current_context: &mut [f32], bleed_rate: f32) {
        for (curr, prev) in current_context.iter_mut().zip(self.kv_cache_pool.iter()) {
            if rand::thread_rng().gen_bool(bleed_rate as f64) {
                *curr = (*curr * 0.5) + (*prev * 0.5); // λ¬Έλ§₯ ν˜Όν•© (λ¬΄μ˜μ‹μ˜ μœ΅ν•©)
            }
        }
    }

    pub fn save_to_subconscious(&mut self, current_context: &[f32]) {
        self.kv_cache_pool.copy_from_slice(current_context);
    }
}

// ---------------------------------------------------------
// 3. 🌱 μ—΄μ„± μœ μ „μž 포자 μ••μΆ•κΈ° (Spore Archiver)
// ---------------------------------------------------------
pub struct SporeArchiver;

impl SporeArchiver {
    /// μ„±λŠ₯이 λ–¨μ–΄μ§€λŠ” κ°€μ€‘μΉ˜λ₯Ό 죽이지 μ•Šκ³ , 1-Bit '씨앗(포자)' ν˜•νƒœλ‘œ κ·Ήν•œ μ••μΆ•ν•˜μ—¬ νœ΄λ©΄μ‹œν‚΅λ‹ˆλ‹€.
    pub fn hibernate_to_spore(weak_weights: &[u32]) -> Vec<u8> {
        let mut spores = Vec::with_capacity(weak_weights.len() / 8);
        let mut current_byte = 0u8;
        
        for (i, &w) in weak_weights.iter().enumerate() {
            // μ§ˆλŸ‰ 쀑심이 0보닀 큰지 μ—¬λΆ€λ§Œ 1-Bit둜 남김
            if w.count_ones() > 16 {
                current_byte |= 1 << (i % 8);
            }
            if i % 8 == 7 {
                spores.push(current_byte);
                current_byte = 0;
            }
        }
        spores
    }

    /// ν™˜κ²½μ΄ κΈ‰λ³€ν–ˆμ„ λ•Œ, μž λ“€μ–΄ 있던 포자λ₯Ό λ‹€μ‹œ ν™œμ„± κ°€μ€‘μΉ˜λ‘œ λ°œμ•„μ‹œν‚΅λ‹ˆλ‹€.
    pub fn germinate_spore(spores: &[u8]) -> Vec<u32> {
        let mut reactivated = Vec::with_capacity(spores.len() * 8);
        for &byte in spores {
            for bit in 0..8 {
                if (byte & (1 << bit)) != 0 {
                    reactivated.push(0xFFFFFFFF); // μ—΄μ„± μœ μ „μžμ˜ λΆ€ν™œ (거친 ν˜•νƒœ)
                } else {
                    reactivated.push(0x00000000);
                }
            }
        }
        reactivated
    }
}