BioDynaMo  v1.05.120-25dc9790
log_range_param.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_MULTI_SIMULATION_OPTIMIZATION_PARAM_TYPE_LOG_RANGE_PARAM_H_
16 #define CORE_MULTI_SIMULATION_OPTIMIZATION_PARAM_TYPE_LOG_RANGE_PARAM_H_
17 
18 #include <string>
19 
21 #include "core/util/log.h"
22 
23 namespace bdm {
24 
27  LogRangeParam() = default;
28  LogRangeParam(const std::string& n, real_t base, real_t min, real_t max,
29  real_t stride)
31  base(base),
32  lower_bound(min),
33  upper_bound(max),
34  stride(stride) {
35  Validate();
36  };
37 
38  void Validate() const override {
39  if (lower_bound > upper_bound) {
40  Log::Fatal("LogRangeParam", "Tried to initialize parameter '", param_name,
41  "' with a lower_bound value higher than upper_bound: ",
42  lower_bound, " > ", upper_bound);
43  }
44  }
45 
46  OptimizationParamType* GetCopy() const override {
47  return new LogRangeParam(*this);
48  }
49 
50  // Get the nth value
51  real_t GetValue(int n) const override {
52  real_t exp = lower_bound + n * stride;
53  return exp > upper_bound ? std::pow(base, upper_bound)
54  : std::pow(base, exp);
55  }
56 
57  // Returns the number of discrete values that this range contains (including
58  // the `lower_bound` and `upper_bound` values)
59  uint32_t GetNumElements() const override {
60  return std::round(((upper_bound - lower_bound) + stride) / stride);
61  }
62 
63  // The base value
64  real_t base = 10;
65  // The minimum value
67  // THe maximum value
69  // The stride
72 };
73 
74 } // namespace bdm
75 
76 #endif // CORE_MULTI_SIMULATION_OPTIMIZATION_PARAM_TYPE_LOG_RANGE_PARAM_H_
bdm::LogRangeParam::lower_bound
real_t lower_bound
Definition: log_range_param.h:66
optimization_param_type.h
bdm
Definition: agent.cc:39
bdm::LogRangeParam::GetCopy
OptimizationParamType * GetCopy() const override
Definition: log_range_param.h:46
bdm::LogRangeParam::base
real_t base
Definition: log_range_param.h:64
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::OptimizationParamType
An interface for creating different types of optimization parameters.
Definition: optimization_param_type.h:27
bdm::OptimizationParamType::param_name
std::string param_name
Definition: optimization_param_type.h:52
bdm::LogRangeParam::LogRangeParam
LogRangeParam()=default
bdm::LogRangeParam::BDM_CLASS_DEF_OVERRIDE
BDM_CLASS_DEF_OVERRIDE(LogRangeParam, 1)
bdm::LogRangeParam
A uniform range of logarithmically scaled values (e.g. 1, 10, 100, 1000)
Definition: log_range_param.h:26
bdm::LogRangeParam::stride
real_t stride
Definition: log_range_param.h:70
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
log.h
bdm::LogRangeParam::Validate
void Validate() const override
Definition: log_range_param.h:38
bdm::LogRangeParam::upper_bound
real_t upper_bound
Definition: log_range_param.h:68
bdm::LogRangeParam::LogRangeParam
LogRangeParam(const std::string &n, real_t base, real_t min, real_t max, real_t stride)
Definition: log_range_param.h:28
bdm::LogRangeParam::GetNumElements
uint32_t GetNumElements() const override
Definition: log_range_param.h:59
bdm::LogRangeParam::GetValue
real_t GetValue(int n) const override
Definition: log_range_param.h:51