Random Seed to Control Experiment¶
In [1]:
Copied!
from abses import MainModel, Experiment
class RandomAddingMod(MainModel):
"""测试类"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.test_var = 0
def random_step(self):
"""测试步骤"""
return self.random.randint(0, 10)
def step(self):
"""测试步骤"""
self.test_var += self.random_step()
cfg = {
"reports": {"final": {"test_var": "test_var"}},
"time": {"end": 10},
}
exp = Experiment.new(RandomAddingMod, cfg=cfg, seed=42)
exp.batch_run()
exp.summary()
from abses import MainModel, Experiment
class RandomAddingMod(MainModel):
"""测试类"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.test_var = 0
def random_step(self):
"""测试步骤"""
return self.random.randint(0, 10)
def step(self):
"""测试步骤"""
self.test_var += self.random_step()
cfg = {
"reports": {"final": {"test_var": "test_var"}},
"time": {"end": 10},
}
exp = Experiment.new(RandomAddingMod, cfg=cfg, seed=42)
exp.batch_run()
exp.summary()
Job 0 repeats 1 times, with 1 processes.: 0%| | 0/1 [00:00<?, ?it/s]
Out[1]:
| job_id | repeat_id | seed | test_var | |
|---|---|---|---|---|
| 0 | 0 | 1 | 165578901 | 58 |
In [2]:
Copied!
exp2 = Experiment(RandomAddingMod, cfg=cfg, seed=42)
exp2._job_id = 1
exp2.batch_run()
exp2.summary()
exp2 = Experiment(RandomAddingMod, cfg=cfg, seed=42)
exp2._job_id = 1
exp2.batch_run()
exp2.summary()
Job 1 repeats 1 times, with 1 processes.: 0%| | 0/1 [00:00<?, ?it/s]
Out[2]:
| job_id | repeat_id | seed | test_var | |
|---|---|---|---|---|
| 0 | 0 | 1 | 165578901 | 58 |
| 1 | 1 | 1 | 1561874393 | 57 |
We include another experiment with the same model and config, but different seed. exp3 = Experiment(RandomAddingMod, cfg=cfg, seed=43)
In [3]:
Copied!
exp3 = Experiment(RandomAddingMod, cfg=cfg, seed=43)
exp3.batch_run()
exp3.summary()
exp3 = Experiment(RandomAddingMod, cfg=cfg, seed=43)
exp3.batch_run()
exp3.summary()
Job 0 repeats 1 times, with 1 processes.: 0%| | 0/1 [00:00<?, ?it/s]
Out[3]:
| job_id | repeat_id | seed | test_var | |
|---|---|---|---|---|
| 0 | 0 | 1 | 3702419103 | 35 |
| 1 | 1 | 1 | 1561874393 | 57 |