(self, lockedValues=None)
| 56 | self.hyperoptVariableName = config["name"] |
| 57 | |
| 58 | def createHyperoptSpace(self, lockedValues=None): |
| 59 | name = self.root |
| 60 | |
| 61 | if lockedValues is None: |
| 62 | lockedValues = {} |
| 63 | |
| 64 | if "anyOf" in self.config or "oneOf" in self.config: |
| 65 | v = "anyOf" if "anyOf" in self.config else "oneOf" |
| 66 | data = self.config[v] |
| 67 | |
| 68 | subSpaces = [ |
| 69 | Hyperparameter( |
| 70 | param, self, name + "." + str(index) |
| 71 | ).createHyperoptSpace(lockedValues) |
| 72 | for index, param in enumerate(data) |
| 73 | ] |
| 74 | for index, space in enumerate(subSpaces): |
| 75 | space["$index"] = index |
| 76 | |
| 77 | choices = hp.choice(self.hyperoptVariableName, subSpaces) |
| 78 | |
| 79 | return choices |
| 80 | elif "enum" in self.config: |
| 81 | if self.name in lockedValues: |
| 82 | return lockedValues[self.name] |
| 83 | |
| 84 | choices = hp.choice(self.hyperoptVariableName, self.config["enum"]) |
| 85 | return choices |
| 86 | elif "constant" in self.config: |
| 87 | if self.name in lockedValues: |
| 88 | return lockedValues[self.name] |
| 89 | |
| 90 | return self.config["constant"] |
| 91 | elif self.config["type"] == "object": |
| 92 | space = {} |
| 93 | for key in self.config["properties"].keys(): |
| 94 | config = self.config["properties"][key] |
| 95 | space[key] = Hyperparameter( |
| 96 | config, self, name + "." + key |
| 97 | ).createHyperoptSpace(lockedValues) |
| 98 | return space |
| 99 | elif self.config["type"] == "number": |
| 100 | if self.name in lockedValues: |
| 101 | return lockedValues[self.name] |
| 102 | |
| 103 | mode = self.config.get("mode", "uniform") |
| 104 | scaling = self.config.get("scaling", "linear") |
| 105 | |
| 106 | if mode == "uniform": |
| 107 | min = self.config.get("min", 0) |
| 108 | max = self.config.get("max", 1) |
| 109 | rounding = self.config.get("rounding", None) |
| 110 | |
| 111 | if scaling == "linear": |
| 112 | if rounding is not None: |
| 113 | return hp.quniform( |
| 114 | self.hyperoptVariableName, min, max, rounding |
| 115 | ) |
no test coverage detected