Skip to content

Commit fc3b294

Browse files
committed
update docstr
Signed-off-by: reiase <[email protected]>
1 parent e0c1e83 commit fc3b294

File tree

4 files changed

+49
-117
lines changed

4 files changed

+49
-117
lines changed

README.md

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,59 @@
1-
This project now is part of machine learning framework [towhee](https://github.com/towhee-io/towhee), and this repo is no longer maintained.
2-
31
**H**_yper_**P**_arameter_
42
===========================
53

64
A hyper-parameter library for researchers, data scientists and machine learning engineers.
75

8-
- [**H**_yper_**P**_arameter_](#hyperparameter)
9-
- [Quick Start](#quick-start)
10-
- [Object-Style API:](#object-style-api)
11-
- [Scoped Parameter](#scoped-parameter)
12-
- [Predefined Parameter](#predefined-parameter)
13-
- [Examples](#examples)
14-
- [parameter tunning for researchers](#parameter-tunning-for-researchers)
15-
- [experiment tracing for data scientists](#experiment-tracing-for-data-scientists)
16-
- [design-pattern for system engineers](#design-pattern-for-system-engineers)
17-
186
Quick Start
197
============
208

219
## Object-Style API:
2210

2311
```python
24-
from hyperparameter import HyperParameter
12+
>>> from hyperparameter import HyperParameter
13+
14+
>>> hp = HyperParameter(a=1, b={'c': 2})
15+
>>> hp.a == 1
16+
True
17+
>>> hp.b.c == 2 # (nested parameter)
18+
True
2519

26-
params = HyperParameter(a=1, b={'c': 2})
27-
params.a == 1 # True
28-
params.b.c == 2 # True (nested parameter)
2920
```
3021

31-
or becomes powerful with `params()`:
22+
or becomes powerful with `hp()`:
3223

3324
```python
34-
params().a.b.c.getOrElse(3) # 3 (default value)
35-
params().a.b.c(3) # 3 (shortcut for default value)
25+
>>> hp = HyperParameter()
26+
>>> hp().a.b.c.get_or_else(3) # (default value for undefined parameter)
27+
3
28+
>>> hp().a.b.c(3) # (shortcut for `get_or_else`)
29+
3
30+
31+
>>> hp().a.b.c = 4 # set value to param `a.b.c`
32+
>>> hp().a.b.c(3) # (default value is ignored)
33+
4
3634

37-
params().a.b.c = 4 # set value to param `a.b.c`
38-
params().a.b.c(3) # 4 (default value is ignored)
3935
```
4036

4137
## Scoped Parameter
4238

4339
```python
44-
from hyperparameter import param_scope
40+
>>> from hyperparameter import param_scope
4541

4642
# scoped parameter
47-
with param_scope(a=1) as hp:
48-
hp.a == 1 # True
43+
>>> with param_scope(a=1) as ps:
44+
... ps.a == 1
45+
True
46+
4947
```
5048
or becomes powerful with `nested scope`:
5149
``` python
52-
with param_scope(a=1) as hp:
53-
with param_scope(a=2) as hp:
54-
hp.a == 2 # True, a=2 for inner scope
55-
hp.a == 1 # True, a=1 for outer scope
50+
>>> with param_scope(a=1) as ps:
51+
... with param_scope(a=2) as ps2:
52+
... ps2.a == 2 # True, a=2 for inner scope
53+
... ps.a == 1 # True, a=1 for outer scope
54+
True
55+
True
56+
5657
```
5758

5859
even more powerful when using `param_scope` in function:
@@ -61,8 +62,8 @@ even more powerful when using `param_scope` in function:
6162
#change function behavior with scoped parameter:
6263
def foo(arg):
6364
# receive parameter using param_scope
64-
with param_scope() as hp:
65-
if (hp().param1.getOrElse(1) == 1):
65+
with param_scope() as ps:
66+
if (ps().param1(1) == 1):
6667
return 1
6768
else:
6869
return 2

docs/index.md

Lines changed: 0 additions & 75 deletions
This file was deleted.

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

hyperparameter/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
"auto_param",
1414
"set_auto_param_callback",
1515
]
16+
17+
VERSION = "0.3.0"

hyperparameter/hyperparameter.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,25 +433,28 @@ class param_scope(HyperParameter):
433433
Examples
434434
--------
435435
create a scoped HyperParameter
436-
>>> with param_scope(**{'a': 1, 'b': 2}) as cfg:
437-
... print(cfg.a)
436+
>>> with param_scope(**{'a': 1, 'b': 2}) as ps:
437+
... print(ps.a)
438438
1
439439
440440
read parameter in a function
441441
>>> def foo():
442-
... with param_scope() as cfg:
443-
... return cfg.a
444-
>>> with param_scope(**{'a': 1, 'b': 2}) as cfg:
445-
... foo() # foo should get cfg using a with statement
442+
... with param_scope() as ps:
443+
... return ps.a
444+
>>> with param_scope(**{'a': 1, 'b': 2}) as ps:
445+
... foo() # foo should get param_scope using a with statement
446446
1
447447
448448
update some config only in new scope
449-
>>> with param_scope(**{'a': 1, 'b': 2}) as cfg:
450-
... cfg.b
451-
... with param_scope(**{'b': 3}) as cfg2:
452-
... cfg2.b
453-
2
454-
3
449+
>>> with param_scope(**{'a': 1, 'b': 2}) as ps:
450+
... ps
451+
... with param_scope(**{'b': 3}) as ps:
452+
... ps
453+
... with param_scope() as ps:
454+
... ps
455+
{'a': 1, 'b': 2}
456+
{'a': 1, 'b': 3}
457+
{'a': 1, 'b': 2}
455458
"""
456459

457460
tls = threading.local()

0 commit comments

Comments
 (0)