132 std::string model_path;
133 std::string cell_indices_file;
134 std::vector<int> cell_indices;
135 std::size_t n_cells = 0;
136 std::vector<double> apply_times;
137 std::vector<std::pair<std::string, FeatureSpec>> input_features;
138 std::vector<std::pair<std::string, FeatureSpec>> output_features;
151 model_path =
model_config.get<std::string>(
"model_path",
"");
152 if (model_path.empty())
153 throw std::runtime_error(
"Missing 'model_path' in HybridNewton config");
155 cell_indices_file =
model_config.get<std::string>(
"cell_indices_file",
"");
156 if (cell_indices_file.empty())
157 throw std::runtime_error(
"Missing 'cell_indices_file' in HybridNewton config");
160 cell_indices = loadCellIndicesFromFile(cell_indices_file);
161 n_cells = cell_indices.size();
166 throw std::runtime_error(
"Missing 'apply_times' in HybridNewton config");
169 apply_times.push_back(
applyTimesOpt->get_child(key).get<
double>(
""));
171 if (apply_times.empty())
172 throw std::runtime_error(
"'apply_times' must contain at least one value");
175 parseFeatures(
model_config,
"features.inputs", input_features);
176 parseFeatures(
model_config,
"features.outputs", output_features);
179 bool hasInputFeature(
const std::string& name)
const {
180 return std::any_of(input_features.begin(), input_features.end(),
181 [&](
const auto&
p) { return p.first == name; });
184 bool hasOutputFeature(
const std::string& name)
const {
185 return std::any_of(output_features.begin(), output_features.end(),
186 [&](
const auto&
p) { return p.first == name; });
198 hasOutputFeature(
"RS") ||
199 hasOutputFeature(
"DELTA_RS");
202 hasOutputFeature(
"RV") ||
203 hasOutputFeature(
"DELTA_RV");
207 "HybridNewton: RS or RV features detected but composition support is disabled. "
208 "CompositionSwitch must be enabled for RS/RV features."
220 std::vector<int> loadCellIndicesFromFile(
const std::string&
filename)
const {
221 std::vector<int> indices;
224 throw std::runtime_error(
"Cannot open cell indices file: " +
filename);
230 if (
line.empty() ||
line[0] ==
'#')
continue;
231 try { indices.push_back(std::stoi(
line)); }
233 throw std::runtime_error(
"Invalid cell index at line " + std::to_string(
lineNumber) +
239 throw std::runtime_error(
"No valid cell indices found in file: " +
filename);
254 void parseFeatures(
const PropertyTree&
pt,
const std::string&
path,
255 std::vector<std::pair<std::string, FeatureSpec>>&
features) {
259 for (
const auto& name :
subtreeOpt->get_child_keys()) {
262 spec.transform = Transform(
ft.get<std::string>(
"feature_engineering",
"none"));
264 if (
auto sOpt =
ft.get_child_optional(
"scaling_params")) {
265 const PropertyTree& s = *
sOpt;
266 if (s.get_child_optional(
"mean") && s.get_child_optional(
"std")) {
267 spec.scaler.type = Scaler::Type::Standard;
268 spec.scaler.mean = s.get<
double>(
"mean", 0.0);
269 spec.scaler.std = s.get<
double>(
"std", 1.0);
270 }
else if (s.get_child_optional(
"min") && s.get_child_optional(
"max")) {
271 spec.scaler.type = Scaler::Type::MinMax;
272 spec.scaler.min = s.get<
double>(
"min", 0.0);
273 spec.scaler.max = s.get<
double>(
"max", 1.0);
275 spec.scaler.type = Scaler::Type::None;
278 spec.scaler.type = Scaler::Type::None;
281 spec.is_delta = name.compare(0, 6,
"DELTA_") == 0;
282 spec.actual_name =
spec.is_delta ? name.substr(6) : name;
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240