Skip to content

Commit

Permalink
Completed ctx code example
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-hansen committed Aug 2, 2023
1 parent e3e121f commit 8aa8d2b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
resolver = "2"
members = [
"deep_causality/examples/csm",
# "deep_causality/examples/ctx",
"deep_causality/examples/ctx",
"deep_causality/examples/smoking",
"dcl_data_structures",
"deep_causality",
Expand Down
2 changes: 1 addition & 1 deletion deep_causality/examples/ctx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false

[dependencies]
#deep_causality = "0.2.8"
deep_causality = { git = "https://github.com/deepcausality-rs/deep_causality.git", rev = "c2c316246b840ed4c9f279fb5ff95c437c8a84b1"}
deep_causality = { git = "https://github.com/deepcausality-rs/deep_causality.git", rev = "e3e121f99e177c25de18ffd2e3ab319bae9faa01"}

# chrono default-features = false mitigates "RUSTSEC-2020-0071".
# See https://rustsec.org/advisories/RUSTSEC-2020-0071.html
Expand Down
1 change: 1 addition & 0 deletions deep_causality/examples/ctx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod workflow;
mod io;
mod config;
mod model;
mod utils;

use deep_causality::prelude::time_execution;

Expand Down
3 changes: 2 additions & 1 deletion deep_causality/examples/ctx/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ fn build_causaloid<'l>(

let _ = g.add_edge(root_index, month_index);

// Here we wrap the causal graph into a causaloid
Causaloid::from_causal_graph_with_context(
0,
&g,
g,
Option::from(context),
"Causaloid main graph"
)
Expand Down
15 changes: 5 additions & 10 deletions deep_causality/examples/ctx/src/run.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) "2023" . Marvin Hansen <[email protected]> All rights reserved.

use std::time::{Duration, Instant};
use std::time::Instant;
use deep_causality::prelude::{Contextuable, Identifiable, TimeScale};
use crate::model::get_main_causaloid;
use crate::utils;
use crate::workflow::{build_time_data_context, load_data};
use crate::workflow::build_model::build_model;

Expand Down Expand Up @@ -34,7 +35,7 @@ pub fn run()

// Reading parquet files is at least 10x faster than reading CSV files.
let elapsed = &lap.elapsed();
print_duration("Load Data", elapsed);
utils::print_duration("Load Data", elapsed);

// This context hypergraph is low resolution (Day), relatively small (<1k nodes),
// and thus takes only a few milliseconds to generate. In practice,
Expand All @@ -50,7 +51,7 @@ pub fn run()
};

let elapsed = &lap.elapsed();
print_duration("Build Context HyperGraph", elapsed);
utils::print_duration("Build Context HyperGraph", elapsed);

// Print out some key metrics of the context graph.
println!("Context HyperGraph Metrics:");
Expand All @@ -67,16 +68,10 @@ pub fn run()
Err(e) => panic!("{}", e),
};
let elapsed = &lap.elapsed();
print_duration("Build Causal Model", elapsed);
utils::print_duration("Build Causal Model", elapsed);

println!("Causal Model:");
println!("Model ID: {}", model.id());
println!("Model Description: {}", model.description());
println!();
}

fn print_duration(msg: &str, elapsed: &Duration)
{
println!("{} took: {:?} ", msg, elapsed);
println!();
}
3 changes: 0 additions & 3 deletions deep_causality/examples/ctx/src/types/date_time_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ impl DateTimeBar
pub fn high(&self) -> Decimal {
self.high
}
pub fn low(&self) -> Decimal {
self.low
}
pub fn close(&self) -> Decimal {
self.close
}
Expand Down
9 changes: 9 additions & 0 deletions deep_causality/examples/ctx/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) "2023" . Marvin Hansen <[email protected]> All rights reserved.

use std::time::Duration;

pub fn print_duration(msg: &str, elapsed: &Duration)
{
println!("{} took: {:?} ", msg, elapsed);
println!();
}

0 comments on commit 8aa8d2b

Please sign in to comment.