-
Notifications
You must be signed in to change notification settings - Fork 42
Add option to select activation function for ChamberSphere #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7836a6f
06b9d32
ec94a39
11a4841
b51c81b
d7d77fb
1c9cf33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,14 +145,14 @@ std::unique_ptr<ActivationFunction> generate_activation_function( | |
| throw std::runtime_error( | ||
| "Missing 'activation_function' for chamber " + chamber_name + | ||
| ". Required with structure: {\"type\": \"half_cosine\", \"t_active\": " | ||
| "0.2, \"t_twitch\": 0.3} (or type piecewise_cosine / two_hill with " | ||
| "0.2, \"t_twitch\": 0.3} (or type piecewise_cosine / two_hill / double_tanh with " | ||
| "their parameters)."); | ||
| } | ||
| if (!j.contains("type") || !j["type"].is_string()) { | ||
| throw std::runtime_error( | ||
| "Missing or invalid 'type' in activation_function for chamber " + | ||
| chamber_name + | ||
| ". Must be one of: half_cosine, piecewise_cosine, two_hill"); | ||
| ". Must be one of: half_cosine, piecewise_cosine, two_hill, double_tanh"); | ||
| } | ||
|
|
||
| // Extract activation function type | ||
|
|
@@ -254,6 +254,19 @@ SimulationParameters load_simulation_params(const nlohmann::json& config) { | |
|
|
||
| void load_simulation_model(const nlohmann::json& config, Model& model) { | ||
| DEBUG_MSG("Loading model"); | ||
|
|
||
| // Set cardiac period from simulation_parameters so activation functions | ||
| // have it available while blocks are created below. May already be set by | ||
| // closed_loop_blocks. | ||
| if (model.cardiac_cycle_period < 0.0 && | ||
| config.contains("simulation_parameters") && | ||
| config["simulation_parameters"].contains("cardiac_period")) { | ||
| double period = config["simulation_parameters"]["cardiac_period"]; | ||
| if (period > 0.0) { | ||
| model.cardiac_cycle_period = period; | ||
| } | ||
| } | ||
|
|
||
| // Create list to store block connections while generating blocks | ||
| std::vector<std::tuple<std::string, std::string>> connections; | ||
|
|
||
|
|
@@ -337,10 +350,18 @@ void create_vessels( | |
| JsonWrapper(config, component, "vessel_name", i); | ||
| const auto& vessel_values = vessel_config["zero_d_element_values"]; | ||
| const std::string vessel_name = vessel_config["vessel_name"]; | ||
| const std::string vessel_type = vessel_config["zero_d_element_type"]; | ||
| vessel_id_map.insert({vessel_config["vessel_id"], vessel_name}); | ||
|
|
||
| generate_block(model, vessel_values, vessel_config["zero_d_element_type"], | ||
| vessel_name); | ||
| generate_block(model, vessel_values, vessel_type, vessel_name); | ||
|
|
||
| // Create and set activation_function for vessel types that use one | ||
| if (vessel_type == "ChamberSphere") { | ||
|
mrp089 marked this conversation as resolved.
|
||
| auto act_func = generate_activation_function( | ||
|
mrp089 marked this conversation as resolved.
|
||
| model, vessel_config["activation_function"], vessel_name); | ||
| model.get_block(vessel_name) | ||
| ->set_activation_function(std::move(act_func)); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this extra check necessary? There is already the function |
||
|
|
||
| // Read connected boundary conditions | ||
| if (vessel_config.contains("boundary_conditions")) { | ||
|
|
@@ -601,16 +622,6 @@ void create_chambers( | |
| Model& model, | ||
| std::vector<std::tuple<std::string, std::string>>& connections, | ||
| const nlohmann::json& config, const std::string& component) { | ||
| // Set cardiac period from simulation_parameters so activation functions have | ||
| // it. May already be set by closed_loop_blocks. | ||
| if (model.cardiac_cycle_period < 0.0 && | ||
| config.contains("simulation_parameters") && | ||
| config["simulation_parameters"].contains("cardiac_period")) { | ||
| double period = config["simulation_parameters"]["cardiac_period"]; | ||
| if (period > 0.0) { | ||
| model.cardiac_cycle_period = period; | ||
| } | ||
| } | ||
| for (size_t i = 0; i < config[component].size(); i++) { | ||
| const auto& chamber_config = JsonWrapper(config, component, "name", i); | ||
| std::string chamber_type = chamber_config["type"]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be moved? Maybe with the change to
create_chambersthat can stay where it is.