(self)
| 217 | return [self] |
| 218 | |
| 219 | def getLog10Cardinality(self): |
| 220 | if "anyOf" in self.config or "oneOf" in self.config: |
| 221 | v = "anyOf" if "anyOf" in self.config else "oneOf" |
| 222 | data = self.config[v] |
| 223 | |
| 224 | log10_cardinality = Hyperparameter( |
| 225 | data[0], self, self.root + ".0" |
| 226 | ).getLog10Cardinality() |
| 227 | for index, subParam in enumerate(data[1:]): |
| 228 | # We used logarithm identities to create this reduction formula |
| 229 | other_log10_cardinality = Hyperparameter( |
| 230 | subParam, self, self.root + "." + str(index) |
| 231 | ).getLog10Cardinality() |
| 232 | |
| 233 | # Revert to linear at high and low values, for numerical stability. Check here: https://www.desmos.com/calculator/efkbbftd18 to observe |
| 234 | if (log10_cardinality - other_log10_cardinality) > 3: |
| 235 | log10_cardinality = log10_cardinality + 1 |
| 236 | elif (other_log10_cardinality - log10_cardinality) > 3: |
| 237 | log10_cardinality = other_log10_cardinality + 1 |
| 238 | else: |
| 239 | log10_cardinality = other_log10_cardinality + math.log10( |
| 240 | 1 + math.pow(10, log10_cardinality - other_log10_cardinality) |
| 241 | ) |
| 242 | return log10_cardinality + math.log10(len(data)) |
| 243 | elif "enum" in self.config: |
| 244 | return math.log10(len(self.config["enum"])) |
| 245 | elif "constant" in self.config: |
| 246 | return math.log10(1) |
| 247 | elif self.config["type"] == "object": |
| 248 | log10_cardinality = 0 |
| 249 | for index, subParam in enumerate(self.config["properties"].values()): |
| 250 | subParameter = Hyperparameter( |
| 251 | subParam, self, self.root + "." + str(index) |
| 252 | ) |
| 253 | log10_cardinality += subParameter.getLog10Cardinality() |
| 254 | return log10_cardinality |
| 255 | elif self.config["type"] == "number": |
| 256 | if "rounding" in self.config: |
| 257 | return math.log10( |
| 258 | min( |
| 259 | 20, |
| 260 | (self.config["max"] - self.config["min"]) |
| 261 | / self.config["rounding"] |
| 262 | + 1, |
| 263 | ) |
| 264 | ) |
| 265 | else: |
| 266 | # Default of 20 for fully uniform numbers. |
| 267 | return math.log10(20) |
| 268 | |
| 269 | def convertToFlatValues(self, params): |
| 270 | flatParams = {} |
no test coverage detected