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
64A 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-
186Quick 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```
5048or 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
5859even 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:
6263def 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
0 commit comments