You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
use std::{thread,time};
|
|
extern crate rand;
|
|
use std::sync::{Arc,Mutex};
|
|
#[macro_use] extern crate lazy_static;
|
|
|
|
lazy_static! {
|
|
static ref NEURAL_NET_WEIGHTS: Vec<Arc<Mutex<Vec<f64>>>> = {
|
|
let mut nn = Vec::with_capacity(10000);
|
|
for _ in 0..10000 {
|
|
let mut mm = Vec::with_capacity(100);
|
|
for _ in 0..100 {
|
|
mm.push(rand::random::<f64>());
|
|
}
|
|
let mm = Arc::new(Mutex::new(mm));
|
|
nn.push(mm);
|
|
}
|
|
nn
|
|
};
|
|
}
|
|
|
|
fn train() {
|
|
let t = time::Duration::from_millis(100);
|
|
loop {
|
|
for _ in 0..100 {
|
|
let update_position = rand::random::<u64>() % 1000000;
|
|
let update_column = update_position / 10000;
|
|
let update_row = update_position % 100;
|
|
let update_value = rand::random::<f64>();
|
|
let mut update_column = NEURAL_NET_WEIGHTS[update_column as usize].lock().unwrap();
|
|
update_column[update_row as usize] = update_value;
|
|
}
|
|
thread::sleep(t);
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let t = time::Duration::from_millis(1000);
|
|
|
|
for _ in 0..500 {
|
|
thread::spawn(train);
|
|
}
|
|
|
|
loop {
|
|
thread::sleep(t);
|
|
}
|
|
}
|