{"id":13438296,"url":"https://github.com/yurytsoy/revonet","last_synced_at":"2025-03-19T18:32:39.370Z","repository":{"id":57660801,"uuid":"91160877","full_name":"yurytsoy/revonet","owner":"yurytsoy","description":"Rust implementation of real-coded GA for solving optimization problems and training of neural networks","archived":false,"fork":false,"pushed_at":"2017-08-20T14:10:04.000Z","size":186,"stargazers_count":20,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-27T23:25:30.974Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yurytsoy.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-13T08:37:07.000Z","updated_at":"2024-07-19T23:49:06.000Z","dependencies_parsed_at":"2022-09-26T21:40:42.087Z","dependency_job_id":null,"html_url":"https://github.com/yurytsoy/revonet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yurytsoy%2Frevonet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yurytsoy%2Frevonet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yurytsoy%2Frevonet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yurytsoy%2Frevonet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yurytsoy","download_url":"https://codeload.github.com/yurytsoy/revonet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244483648,"owners_count":20460156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:04.340Z","updated_at":"2025-03-19T18:32:39.352Z","avatar_url":"https://github.com/yurytsoy.png","language":"Rust","funding_links":[],"categories":["Libraries","库","库 Libraries","人工智能（Artificial Intelligence）"],"sub_categories":["Artificial Intelligence","人工智能","人工智能 Artificial Intelligence","遗传算法（Genetic Algorithms）"],"readme":"# revonet\n\nRust implementation of real-coded genetic algorithm for solving optimization problems and training of neural networks. The latter is also known as neuroevolution.\n\nFeatures:\n\n* real-coded Evolutionary Algorithm\n* NeuroEvolutionary tuning of weights of Neural Network with fixed structure\n* supports several feed-forward architectures\n\n![https://github.com/yurytsoy/revonet/blob/master/imgs/nn_arch.png](https://github.com/yurytsoy/revonet/blob/master/imgs/nn_arch.png)\n\u003c!-- \n![Supported NN architectures](file:/home/yury/code/revonet/imgs/nn_arch.png)\n --\u003e\n\n* automatically computes statistics for single and multiple runs for EA and NE\n* EA settings and results can be saved to json\n* allows defining user-specified objective functions for EA and NE (see examples below)\n\n# Examples\n\n### Real-coded genetic algorithm\n\n```rust\nlet pop_size = 20u32;       // population size.\nlet problem_dim = 10u32;    // number of optimization parameters.\n\nlet problem = RosenbrockProblem{};  // objective function.\nlet gen_count = 10u32;      // generations number.\nlet settings = GASettings::new(pop_size, gen_count, problem_dim);\nlet mut ga: GA\u003cRosenbrockProblem\u003e = GA::new(settings, \u0026problem);   // init GA.\nlet res = ga.run(settings).expect(\"Error during GA run\");  // run and fetch the results.\n\n// get and print results of the current run.\nprintln!(\"\\n\\nGA results: {:?}\", res);\n\n// make multiple runs and get combined results.\nlet res = ga.run_multiple(settings, 10 as u32).expect(\"Error during multiple GA runs\");\nprintln!(\"\\n\\nResults of multple GA runs: {:?}\", res);\n\n```\n\n### Run evolution of NN weights to solve regression problem\n\n```rust\nlet (pop_size, gen_count, param_count) = (20, 20, 100); // gene_count does not matter here as NN structure is defined by a problem.\nlet settings = EASettings::new(pop_size, gen_count, param_count);\nlet problem = SymbolicRegressionProblem::new_f();\n\nlet mut ne: NE\u003cSymbolicRegressionProblem\u003e = NE::new(\u0026problem);\nlet res = ne.run(settings).expect(\"Error: NE result is empty\");\nprintln!(\"result: {:?}\", res);\nprintln!(\"\\nbest individual: {:?}\", res.best);\n```\n\n### Creating multilayered neural network with 2 hidden layers with sigmoid activation and with linear output nodes.\n\n```rust\nconst INPUT_SIZE: usize = 20;\nconst OUTPUT_SIZE: usize = 2;\n\nlet mut rng = rand::thread_rng();   // needed for weights initialization when NN is built.\nlet mut net: MultilayeredNetwork = MultilayeredNetwork::new(INPUT_SIZE, OUTPUT_SIZE);\nnet.add_hidden_layer(30 as usize, ActivationFunctionType::Sigmoid)\n     .add_hidden_layer(20 as usize, ActivationFunctionType::Sigmoid)\n     .build(\u0026mut rng, NeuralArchitecture::Multilayered);       // `build` finishes creation of neural network.\n\nlet (ws, bs) = net.get_weights();   // `ws` and `bs` are `Vec` arrays containing weights and biases for each layer.\nassert!(ws.len() == 3);\t\t// number of elements equals to number of hidden layers + 1 output layer\nassert!(bs.len() == 3);\t\t// number of elements equals to number of hidden layers + 1 output layer\n\n```\n\n### Creating custom optimization problem for GA\n\n```rust\n// Dummy problem returning random fitness.\npub struct DummyProblem;\nimpl Problem for DummyProblem {\n    // Function to evaluate a specific individual.\n    fn compute\u003cT: Individual\u003e(\u0026self, ind: \u0026mut T) -\u003e f32 {\n        // use `to_vec` to get real-coded representation of an individual.\n        let v = ind.to_vec().unwrap();\n\n        let mut rng: StdRng = StdRng::from_seed(\u0026[0]);\n        rng.gen::\u003cf32\u003e()\n    }\n}\n```\n\n### Creating custom problem for NN evolution\n\n```rust\n// Dummy problem returning random fitness.\nstruct RandomNEProblem {}\nimpl RandomNEProblem {\n    fn new() -\u003e RandomNEProblem {\n        RandomNEProblem{}\n    }\n}\nimpl NeuroProblem for RandomNEProblem {\n    // return number of NN inputs.\n    fn get_inputs_num(\u0026self) -\u003e usize {1}\n    // return number of NN outputs.\n    fn get_outputs_num(\u0026self) -\u003e usize {1}\n    // return NN with random weights and a fixed structure. For now the structure should be the same all the time to make sure that crossover is possible. Likely to change in the future.\n    fn get_default_net(\u0026self) -\u003e MultilayeredNetwork {\n        let mut rng = rand::thread_rng();\n        let mut net: MultilayeredNetwork = MultilayeredNetwork::new(self.get_inputs_num(), self.get_outputs_num());\n        net.add_hidden_layer(5 as usize, ActivationFunctionType::Sigmoid)\n            .build(\u0026mut rng, NeuralArchitecture::Multilayered);\n        net\n    }\n    // Function to evaluate performance of a given NN.\n    fn compute_with_net\u003cT: NeuralNetwork\u003e(\u0026self, nn: \u0026mut T) -\u003e f32 {\n        let mut rng: StdRng = StdRng::from_seed(\u0026[0]);\n        let mut input = (0..self.get_inputs_num())\n                            .map(|_| rng.gen::\u003cf32\u003e())\n                            .collect::\u003cVec\u003cf32\u003e\u003e();\n        // compute NN output using random input.\n        let mut output = nn.compute(\u0026input);\n        output[0]\n    }\n}\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurytsoy%2Frevonet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyurytsoy%2Frevonet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurytsoy%2Frevonet/lists"}