mirror of
https://github.com/c-sooyoung/bo-ptycho.git
synced 2026-09-17 21:29:07 +09:00
completed abstract BO loop
This commit is contained in:
+33
-11
@@ -1,23 +1,40 @@
|
||||
import numpy as np
|
||||
import os
|
||||
import copy
|
||||
import numpy as np
|
||||
|
||||
|
||||
def initialize(config):
|
||||
bo_params = []
|
||||
|
||||
for key, value in config['bo']['params'].items():
|
||||
if value is not None:
|
||||
bo_params.append(key)
|
||||
|
||||
train_x = np.empty((0, len(bo_params)))
|
||||
train_y = np.empty((0,))
|
||||
bo_params = [
|
||||
key
|
||||
for key, value in config['bo']['params'].items()
|
||||
if value is not None
|
||||
]
|
||||
|
||||
bo_state = {
|
||||
'algorithm': 'random',
|
||||
'params': bo_params,
|
||||
'train_x': train_x,
|
||||
'train_y': train_y,
|
||||
'train_x': np.empty((0, len(bo_params))),
|
||||
'train_y': np.empty((0,)),
|
||||
}
|
||||
|
||||
train_x_path = config['bo'].get('train_x')
|
||||
train_y_path = config['bo'].get('train_y')
|
||||
|
||||
if train_x_path is not None and train_y_path is not None:
|
||||
if os.path.exists(train_x_path) and os.path.exists(train_y_path):
|
||||
train_x = np.load(train_x_path)
|
||||
train_y = np.load(train_y_path)
|
||||
|
||||
if (
|
||||
train_x.ndim == 2
|
||||
and train_x.shape[1] == len(bo_params)
|
||||
and train_y.ndim == 1
|
||||
and train_y.shape[0] == train_x.shape[0]
|
||||
):
|
||||
bo_state['train_x'] = train_x
|
||||
bo_state['train_y'] = train_y
|
||||
|
||||
return bo_state
|
||||
|
||||
|
||||
@@ -34,7 +51,7 @@ def ask(config, bo_state):
|
||||
return next_config
|
||||
|
||||
|
||||
def tell(job_config, bo_state, y_value):
|
||||
def tell(config, job_config, bo_state, y_value):
|
||||
x_value = []
|
||||
|
||||
for param in bo_state['params']:
|
||||
@@ -53,4 +70,9 @@ def tell(job_config, bo_state, y_value):
|
||||
y_value,
|
||||
])
|
||||
|
||||
result_dir = config['io']['result_dir']
|
||||
np.save(os.path.join(result_dir, 'train_x.npy'), bo_state['train_x'])
|
||||
np.save(os.path.join(result_dir, 'train_y.npy'), bo_state['train_y'])
|
||||
|
||||
|
||||
return bo_state
|
||||
Reference in New Issue
Block a user