|
|
|
@ -1,6 +1,11 @@ |
|
|
|
|
use reCTBN; |
|
|
|
|
|
|
|
|
|
use json::*; |
|
|
|
|
use std::collections::BTreeSet; |
|
|
|
|
use std::fs; |
|
|
|
|
use std::fs::File; |
|
|
|
|
use std::io::prelude::*; |
|
|
|
|
|
|
|
|
|
use reCTBN::params; |
|
|
|
|
use reCTBN::params::Params::DiscreteStatesContinousTime; |
|
|
|
|
use reCTBN::params::ParamsTrait; |
|
|
|
@ -12,12 +17,20 @@ use reCTBN::tools::RandomGraphGenerator; |
|
|
|
|
use reCTBN::tools::RandomParametersGenerator; |
|
|
|
|
use reCTBN::tools::UniformGraphGenerator; |
|
|
|
|
use reCTBN::tools::UniformParametersGenerator; |
|
|
|
|
use std::collections::BTreeSet; |
|
|
|
|
|
|
|
|
|
fn uniform_parameters_generator_right_densities_ctmp() -> (CtbnNetwork, Dataset) { |
|
|
|
|
fn uniform_parameters_generator_right_densities_ctmp( |
|
|
|
|
nodes_cardinality: usize, |
|
|
|
|
domain_cardinality: usize, |
|
|
|
|
density: f64, |
|
|
|
|
interval_s: f64, |
|
|
|
|
interval_f: f64, |
|
|
|
|
n_trajectories: u64, |
|
|
|
|
t_end: f64, |
|
|
|
|
sg_seed: Option<u64>, |
|
|
|
|
cg_seed: Option<u64>, |
|
|
|
|
tg_seed: Option<u64>, |
|
|
|
|
) -> (CtbnNetwork, Dataset) { |
|
|
|
|
let mut net = CtbnNetwork::new(); |
|
|
|
|
let nodes_cardinality = 5; |
|
|
|
|
let domain_cardinality = 3; |
|
|
|
|
for node in 0..nodes_cardinality { |
|
|
|
|
// Create the domain for a discrete node
|
|
|
|
|
let mut domain = BTreeSet::new(); |
|
|
|
@ -34,30 +47,29 @@ fn uniform_parameters_generator_right_densities_ctmp() -> (CtbnNetwork, Dataset) |
|
|
|
|
|
|
|
|
|
// Initialize the Graph Generator using the one with an
|
|
|
|
|
// uniform distribution
|
|
|
|
|
let mut structure_generator = UniformGraphGenerator::new(1.0 / 3.0, Some(7641630759785120)); |
|
|
|
|
let mut structure_generator = UniformGraphGenerator::new(density, sg_seed); |
|
|
|
|
|
|
|
|
|
// Generate the graph directly on the network
|
|
|
|
|
structure_generator.generate_graph(&mut net); |
|
|
|
|
|
|
|
|
|
// Initialize the parameters generator with uniform distributin
|
|
|
|
|
let mut cim_generator = UniformParametersGenerator::new(3.0..7.0, Some(7641630759785120)); |
|
|
|
|
let mut cim_generator = UniformParametersGenerator::new(interval_s..interval_f, cg_seed); |
|
|
|
|
|
|
|
|
|
// Generate CIMs with uniformly distributed parameters.
|
|
|
|
|
cim_generator.generate_parameters(&mut net); |
|
|
|
|
|
|
|
|
|
let dataset = trajectory_generator(&net, 300, 200.0, Some(30230423)); |
|
|
|
|
let dataset = trajectory_generator(&net, n_trajectories, t_end, tg_seed); |
|
|
|
|
|
|
|
|
|
return (net, dataset); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
|
fn json_gen(net: CtbnNetwork, dataset: Dataset) -> String { |
|
|
|
|
let mut data = json::JsonValue::new_array(); |
|
|
|
|
data.push(json::JsonValue::new_object()).unwrap(); |
|
|
|
|
data[0]["dyn.str"] = json::JsonValue::new_array(); |
|
|
|
|
data[0]["variables"] = json::JsonValue::new_array(); |
|
|
|
|
data[0]["dyn.cims"] = object! {}; |
|
|
|
|
data[0]["samples"] = json::JsonValue::new_array(); |
|
|
|
|
let (net, dataset) = uniform_parameters_generator_right_densities_ctmp(); |
|
|
|
|
|
|
|
|
|
for node_idx in net.get_node_indices() { |
|
|
|
|
let mut variable = json::JsonValue::new_object(); |
|
|
|
@ -91,5 +103,50 @@ fn main() { |
|
|
|
|
} |
|
|
|
|
data[0]["samples"].push(trajectory).unwrap(); |
|
|
|
|
} |
|
|
|
|
println!("{}", data.dump()); |
|
|
|
|
data.dump() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn create_dir(path: String) -> std::io::Result<()> { |
|
|
|
|
fs::create_dir_all(path)?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn write_file(file_name: String, file_content: &[u8]) -> std::io::Result<()> { |
|
|
|
|
let mut file = File::create(file_name)?; |
|
|
|
|
file.write_all(file_content)?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
|
let file_path = "./networks-settings.json"; |
|
|
|
|
eprintln!("Opening file {}...", file_path); |
|
|
|
|
let file_content = |
|
|
|
|
fs::read_to_string(file_path).expect("File not found! Check the README for instructions!"); |
|
|
|
|
let parsed_json = json::parse(&file_content).unwrap(); |
|
|
|
|
|
|
|
|
|
let networks_dir = "./networks.d/"; |
|
|
|
|
create_dir(networks_dir.to_string()).unwrap(); |
|
|
|
|
|
|
|
|
|
for idx in 0..parsed_json.len() { |
|
|
|
|
let (net, dataset) = uniform_parameters_generator_right_densities_ctmp( |
|
|
|
|
parsed_json[idx]["nodes_cardinality"].as_usize().unwrap(), |
|
|
|
|
parsed_json[idx]["domain_cardinality"].as_usize().unwrap(), |
|
|
|
|
parsed_json[idx]["density"].as_f64().unwrap(), |
|
|
|
|
parsed_json[idx]["interval_s"].as_f64().unwrap(), |
|
|
|
|
parsed_json[idx]["interval_f"].as_f64().unwrap(), |
|
|
|
|
parsed_json[idx]["n_trajectories"].as_u64().unwrap(), |
|
|
|
|
parsed_json[idx]["t_end"].as_f64().unwrap(), |
|
|
|
|
parsed_json[idx]["sg_seed"].as_u64(), |
|
|
|
|
parsed_json[idx]["cg_seed"].as_u64(), |
|
|
|
|
parsed_json[idx]["tg_seed"].as_u64(), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
let data = json_gen(net, dataset); |
|
|
|
|
let file_content = data.as_bytes(); |
|
|
|
|
let file_name = format!("{}{}{}", idx, "network", ".json"); |
|
|
|
|
let file_name = format!("{}{}", networks_dir, file_name); |
|
|
|
|
write_file(file_name.to_owned(), &file_content).unwrap(); |
|
|
|
|
|
|
|
|
|
eprintln!("Networks generation complete!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|