Hypergrid enables concise declaration of parameter grids for hyperparameter optimization and batch jobs.
Project description
hypergrid
Hypergrid enables concise declaration and manipulation of parameter grid spaces, with an aim towards use cases such as hyperparameter tuning or defining large batch jobs.
Use the following features to lazily declare a parameter grid:
- Dimension and Grid direct instantiation
+and|for "sum" or "union" types (concatenation)*for "product" types&for coiteration (zip)selectto project dimensions by name
There are also a few transformations that can be lazily applied element-wise, which take a GridElement (a namedtuple of dimension<->value) as input.
filterto apply boolean predicatemapfor lambda transformationmap_tofor map + concat
Once a parameter grid is declared, there are two ways to "materialize" your grid, which return GridElements.
__iter__: a grid is directly iterablesample: allows you to sample from the grid according to a sampling strategy
Usage Examples
from hypergrid.dsl import *
from dataclasses import dataclass
# First, we need to create a Dimension, which is essentially a named, finite, 1-d collection
d = Dimension(custom_name=[1, 2, 3]) # any python Collection will work - set, dict, range(), etc.
assert d.name == "custom_name" # the argument name is used as the dimension's name.
d.with_name("ints") # which you can reset
Uniform(low=1, high=5).take(5)
ExponentialStep(start=1, step=1.1).take(6) # You can also take a dimension from a Distribution or HIterable
# You can `len(d)` or `[i for i in d]`, but grids are more interesting
g = d.to_grid()
i2d = Dimension(ints=[4, 5, 6])
cd = Dimension(chars=["a", "b", "c", "d"])
union_ints = g + i2d # result is length 6: Concatenate two grids that have the same underlying dimensions
product_g = g * cd # result is length 12: tuples (1, "a") - take the cartesian product of the underlying grids
zip_g = g & cd # result is length 3: tuples (1, "a") - zip two grids together, up to the shorter grid
ml = [i for i in zip_g] # You can iterate through a grid
tl = zip_g.take(5) # or you can just take up to a certain number of grid elements from it
print(tl[0].ints), print(tl[0].chars) # The iterator elements are python NamedTuples taken from the dimension names.
# These gridelements can be referenced and used in the grid higher-order functions
zip_g.filter(lambda ge: ge.chars in ["a", "b"]) # result is length 2: keep the tuples (1, "a") and (2, "b")
zip_g.map(doubled=lambda ge: ge.ints * 2) # result is length 3, with single attribute (drops `ints` and `chars`)
mt = zip_g.map_to(doubled=lambda ge: ge.ints * 2) # result is length 3, appends `doubled` and keeps `ints` and `chars`
print(mt.select("doubled", "ints").take(1)[0]) # resulting gridelement no longer has `chars`
# There are some other utility methods on a grid:
zip_g.sample() # Randomly samples a single grid element from a grid
zip_g.to_sklearn() # The Grid.to_* methods convert HyperGrids to other grid formats
# The general idea is to allow for fairly extensive grid construction routines
@dataclass
class FakeModel:
idx: int
param1: float
g = HyperGrid( # A grid with 4 x 10 combinations
ExponentialStep(start=1.0, step=1.5).take(4).with_name("param1"),
idx=range(10)
).instantiate(model=FakeModel).select("model") + \
HyperGrid( # A different grid with 15 combinations
Uniform(low=-1, high=1).take(5).with_name("param1"),
idx=[10, 20, 30]
).instantiate(model=FakeModel).select("model")
assert len(g) == 55
g.sample()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hypergrid-0.0.1.tar.gz.
File metadata
- Download URL: hypergrid-0.0.1.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b84548831f5f1c61967b9c535c198d15afe16fa6013ac7eb0b358a771a86694b
|
|
| MD5 |
2c741d02f6c83a1442625face163a8ee
|
|
| BLAKE2b-256 |
aecb8c139da45b76a9dfe55520ecd7e9ac9824ea5501185efe496f53c5255878
|
File details
Details for the file hypergrid-0.0.1-py3-none-any.whl.
File metadata
- Download URL: hypergrid-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7e972d89020a7ba70eb5bbaae6c39a33cfd4eec0df8a078694b8d2cd23270ba
|
|
| MD5 |
ebd0024cd7e1d6420c8033dc230dc209
|
|
| BLAKE2b-256 |
4ce75e083cc0a22a3befe859fc7bdda5e64e6b3745a471dd8eed8eedf16df14c
|