From 4892aaf69b9e78fe0d3985a5efa1f0abc2d36e35 Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 10 Jan 2024 00:10:39 -0500 Subject: [PATCH] Checking bayes-star v0.1.0 (/Users/greg/Code/bayes-star/rust) error: expected expression, found `let` statement --> src/common/run.rs:65:5 | 65 | let train_result = do_training(&mut storage); | ^^^ error: expected expression, found statement (`let`) --> src/common/run.rs:65:5 | 65 | let train_result = do_training(&mut storage); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: variable declaration using `let` is a statement error[E0425]: cannot find function `train_on_example` in this scope --> src/common/run.rs:30:15 | 30 | match train_on_example(storage, &proposition, &backlinks) { | ^^^^^^^^^^^^^^^^ not found in this scope | help: consider importing this function | 1 | use crate::model::maxent::train_on_example; | error[E0658]: `let` expressions in this position are unstable --> src/common/run.rs:65:5 | 65 | let train_result = do_training(&mut storage); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #53667 for more information warning: unused import: `super::choose::compute_backlinks` --> src/model/maxent.rs:8:5 | 8 | use super::choose::compute_backlinks; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `initialize_weights` --> src/model/maxent.rs:11:58 | 11 | use super::weights::{negative_feature, positive_feature, initialize_weights}; | ^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> src/common/run.rs:27:43 | 27 | let backlinks = compute_backlinks(storage, &proposition)?; | ----------------- ^^^^^^^ types differ in mutability | | | arguments to this function are incorrect | = note: expected mutable reference `&mut Storage` found reference `&Storage` note: function defined here --> src/model/choose.rs:74:8 | 74 | pub fn compute_backlinks( | ^^^^^^^^^^^^^^^^^ 75 | storage: &mut Storage, | --------------------- error[E0061]: this function takes 2 arguments but 1 argument was supplied --> src/common/run.rs:65:24 | 65 | let train_result = do_training(&mut storage); | ^^^^^^^^^^^ ------------ an argument of type `Box<(dyn LogicalModel + 'static)>` is missing | note: function defined here --> src/common/run.rs:12:8 | 12 | pub fn do_training(model:Box, storage: &Storage) -> Result<(), Box> { | ^^^^^^^^^^^ --------------------------- ----------------- help: provide the argument | 65 | let train_result = do_training(/* Box<(dyn LogicalModel + 'static)> */, &mut storage); --- rust/src/common/interface.rs | 4 +++- rust/src/common/run.rs | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/rust/src/common/interface.rs b/rust/src/common/interface.rs index 961f316..877a15a 100644 --- a/rust/src/common/interface.rs +++ b/rust/src/common/interface.rs @@ -17,13 +17,15 @@ pub trait PropositionProbability { } pub trait LogicalModel { - fn initialize_weight(implication:&Implication) -> Result<(), Box>; + fn initialize_connection(&mut self, implication:&Implication) -> Result<(), Box>; fn train( + &mut self, storage: &mut Storage, proposition: &Proposition, ) -> Result>; fn predict( + &self, storage: &mut Storage, evidence: &dyn PropositionProbability, proposition: &Proposition, diff --git a/rust/src/common/run.rs b/rust/src/common/run.rs index b66dec0..f7cd072 100644 --- a/rust/src/common/run.rs +++ b/rust/src/common/run.rs @@ -4,15 +4,17 @@ use redis::Client; use crate::model::{storage::Storage, inference::marginalized_inference_probability}; use crate::model::choose::compute_backlinks; -use super::interface::ScenarioMaker; +use super::interface::{ScenarioMaker, LogicalModel}; - -pub fn do_training(storage: &mut Storage) -> Result<(), Box> { +fn create_model(model_name:&String) -> Result, Box> { + todo!() +} +pub fn do_training(model:Box, storage: &Storage) -> Result<(), Box> { trace!("do_training - Getting all implications"); let implications = storage.get_all_implications()?; for implication in implications { trace!("do_training - Processing implication: {:?}", implication); - initialize_weights(storage.get_redis_connection(), &implication)?; + model.initialize_connection( &implication)?; } trace!("do_training - Getting all propositions"); @@ -58,6 +60,8 @@ pub fn train_and_test(scenario_maker:&dyn ScenarioMaker) -> Result<(), Box