mirror of
https://github.com/c-sooyoung/bo-ptycho.git
synced 2026-09-17 19:29:07 +09:00
also refactored BO to class/methods
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
from .bo_base import BOEngine
|
||||||
|
from .random import RandomBOEngine
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class BOEngine(ABC):
|
||||||
|
name = None
|
||||||
|
|
||||||
|
def __init__(self, config):
|
||||||
|
self.config = config
|
||||||
|
self.state = None
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def initialize(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def ask(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def tell(self, job_config, y_value):
|
||||||
|
pass
|
||||||
+17
-7
@@ -1,9 +1,17 @@
|
|||||||
import os
|
import os
|
||||||
import copy
|
import copy
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from bo.bo_base import BOEngine
|
||||||
|
|
||||||
|
|
||||||
def initialize(config):
|
class RandomBOEngine(BOEngine):
|
||||||
|
|
||||||
|
def __init__(self, config):
|
||||||
|
super().__init__(config)
|
||||||
|
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
config = self.config
|
||||||
|
|
||||||
bo_params = [
|
bo_params = [
|
||||||
key
|
key
|
||||||
@@ -35,10 +43,12 @@ def initialize(config):
|
|||||||
bo_state['train_x'] = train_x
|
bo_state['train_x'] = train_x
|
||||||
bo_state['train_y'] = train_y
|
bo_state['train_y'] = train_y
|
||||||
|
|
||||||
return bo_state
|
self.state = bo_state
|
||||||
|
|
||||||
|
|
||||||
def ask(config, bo_state):
|
def ask(self):
|
||||||
|
config = self.config
|
||||||
|
bo_state = self.state
|
||||||
next_config = copy.deepcopy(config)
|
next_config = copy.deepcopy(config)
|
||||||
|
|
||||||
for param in bo_state['params']:
|
for param in bo_state['params']:
|
||||||
@@ -51,7 +61,10 @@ def ask(config, bo_state):
|
|||||||
return next_config
|
return next_config
|
||||||
|
|
||||||
|
|
||||||
def tell(config, job_config, bo_state, y_value):
|
def tell(self, job_config, y_value):
|
||||||
|
config = self.config
|
||||||
|
bo_state = self.state
|
||||||
|
|
||||||
x_value = []
|
x_value = []
|
||||||
|
|
||||||
for param in bo_state['params']:
|
for param in bo_state['params']:
|
||||||
@@ -73,6 +86,3 @@ def tell(config, job_config, bo_state, y_value):
|
|||||||
result_dir = config['io']['result_dir']
|
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_x.npy'), bo_state['train_x'])
|
||||||
np.save(os.path.join(result_dir, 'train_y.npy'), bo_state['train_y'])
|
np.save(os.path.join(result_dir, 'train_y.npy'), bo_state['train_y'])
|
||||||
|
|
||||||
|
|
||||||
return bo_state
|
|
||||||
Reference in New Issue
Block a user