config file + first network layer
This commit is contained in:
parent
95f602b0a3
commit
be9af4c7b1
@ -4,3 +4,5 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
toml = "0.9.7"
|
||||||
|
|||||||
44
src/config.rs
Normal file
44
src/config.rs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone)]
|
||||||
|
pub struct BrainRegionConfig {
|
||||||
|
name: String,
|
||||||
|
input_size: usize,
|
||||||
|
connection_likeliness: i8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BrainRegionConfig {
|
||||||
|
pub fn set_name(&mut self, name: String) {
|
||||||
|
self.name = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BrainRegionConfig {
|
||||||
|
pub fn input_size(&self) -> usize {
|
||||||
|
self.input_size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone)]
|
||||||
|
pub struct BrainConfig {
|
||||||
|
region: HashMap<String, BrainRegionConfig>,
|
||||||
|
|
||||||
|
network_file: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BrainConfig {
|
||||||
|
pub fn from_string(path: &str) -> Self {
|
||||||
|
let toml_str = fs::read_to_string(path).unwrap();
|
||||||
|
toml::from_str(&toml_str).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn regions(self) -> HashMap<String, BrainRegionConfig> {
|
||||||
|
std::mem::take(&mut self.region.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn network_file(self) -> String {
|
||||||
|
self.network_file
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/main.rs
16
src/main.rs
@ -5,6 +5,20 @@
|
|||||||
mod structure;
|
mod structure;
|
||||||
mod sensors;
|
mod sensors;
|
||||||
|
|
||||||
|
mod config;
|
||||||
|
|
||||||
|
use crate::structure::network::Network;
|
||||||
|
use std::{path::Path};
|
||||||
|
use crate::config::BrainConfig;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
let config_file = "./config.toml";
|
||||||
|
|
||||||
|
let config = BrainConfig::from_string(config_file);
|
||||||
|
|
||||||
|
let network = if ! Path::exists(Path::new(&config_file)) {
|
||||||
|
Network::new(config.regions())
|
||||||
|
} else {
|
||||||
|
Network::from_file(config.network_file())
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,11 +12,14 @@ change rate of structures
|
|||||||
|
|
||||||
focus <= prediction
|
focus <= prediction
|
||||||
*/
|
*/
|
||||||
pub struct Sight;
|
pub enum Senses {
|
||||||
|
Sight,
|
||||||
|
Hearing,
|
||||||
|
}
|
||||||
|
|
||||||
const SIZE: usize = 1024;
|
const SIZE: usize = 1024;
|
||||||
|
|
||||||
impl Sensor<SIZE> for Sight {
|
impl Sensor<SIZE> for Senses {
|
||||||
|
|
||||||
fn input(&self, input: [f32; SIZE]) {
|
fn input(&self, input: [f32; SIZE]) {
|
||||||
todo!()
|
todo!()
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
pub mod neuron;
|
pub mod neuron;
|
||||||
pub mod sensoric;
|
pub mod sensoric;
|
||||||
|
pub mod network;
|
||||||
|
|||||||
36
src/structure/network.rs
Normal file
36
src/structure/network.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
use std::str;
|
||||||
|
use std::array;
|
||||||
|
use crate::structure::neuron::Neuron;
|
||||||
|
use crate::config::BrainRegionConfig;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
||||||
|
pub struct BrainRegion {
|
||||||
|
config: BrainRegionConfig,
|
||||||
|
nodes: Vec<Neuron>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BrainRegion {
|
||||||
|
fn new(mut config: BrainRegionConfig, name: String) -> Self {
|
||||||
|
config.set_name(name);
|
||||||
|
Self {
|
||||||
|
nodes: vec![Neuron::default(); config.input_size()],
|
||||||
|
config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Network {
|
||||||
|
parts: Vec<BrainRegion>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Network {
|
||||||
|
pub fn new(region_config: HashMap<String, BrainRegionConfig>) -> Self {
|
||||||
|
let parts = region_config.into_iter().map(|config| BrainRegion::new(config.1, config.0)).collect();
|
||||||
|
Self { parts }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_file(path: String) -> Self {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,4 +17,16 @@ systems
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct Connection {
|
||||||
|
weight: u8,
|
||||||
|
id: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Clone)]
|
||||||
|
pub struct Neuron {
|
||||||
|
id: usize,
|
||||||
|
connections: Vec<Connection>,
|
||||||
|
state: f32,
|
||||||
|
difference: f32
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user