├── hprs ├── __init__.py ├── common │ ├── __init__.py │ ├── info │ │ ├── __init__.py │ │ └── HPRSJobInfo.py │ ├── Common.py │ └── Constants.py ├── recommender │ ├── __init__.py │ └── RandomRecommender.py ├── manager │ ├── __init__.py │ └── HPRSManager.py └── HyperParameterRecommender.py ├── .gitignore ├── requirements.txt ├── README.md ├── hprs.sh ├── .editorconfig ├── pyproject.toml ├── Dockerfile ├── conf └── hprs-conf.xml ├── setup.py └── LICENSE /hprs/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hprs/common/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | /data -------------------------------------------------------------------------------- /hprs/common/info/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests == 2.27.1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoAPE-hprs 2 | AutoAPE(Advanced Perceptron Engine) - HPRS(Hyper Parameter Recommend Server) 3 | -------------------------------------------------------------------------------- /hprs/recommender/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author : Jin Kim 3 | # e-mail : jin.kim@seculayer.com 4 | # Powered by Seculayer © 2021 AI Service Model Team, R&D Center. 5 | -------------------------------------------------------------------------------- /hprs/manager/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author : Jin Kim 3 | # e-mail : jin.kim@seculayer.com 4 | # Powered by Seculayer © 2021 Service Model Team, R&D Center. 5 | 6 | # class : class_name 7 | -------------------------------------------------------------------------------- /hprs/common/info/HPRSJobInfo.py: -------------------------------------------------------------------------------- 1 | class HPRSJobInfo(object): 2 | def __init__(self, filename): 3 | self.filename = filename 4 | 5 | 6 | if __name__ == '__main__': 7 | _cls = HPRSJobInfo("filename") 8 | -------------------------------------------------------------------------------- /hprs/common/Common.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author : Jin Kim 3 | # e-mail : jin.kim@seculayer.com 4 | # Powered by Seculayer © 2021 Service Model Team, R&D Center. 5 | 6 | # ---- automl packages 7 | from pycmmn.Singleton import Singleton 8 | from pycmmn.logger.MPLogger import MPLogger 9 | from pycmmn.utils.FileUtils import FileUtils 10 | from hprs.common.Constants import Constants 11 | 12 | 13 | # class : class_name 14 | class Common(metaclass=Singleton): 15 | # make directories 16 | FileUtils.mkdir(Constants.DIR_DATA_ROOT) 17 | FileUtils.mkdir(Constants.DIR_LOG) 18 | 19 | # LOGGER 20 | LOGGER: MPLogger = MPLogger(log_dir=Constants.DIR_LOG, log_level=Constants.LOG_LEVEL, 21 | log_name=Constants.LOG_NAME) 22 | -------------------------------------------------------------------------------- /hprs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ###################################################################################### 3 | # eyeCloudAI 3.1 MLPS Run Script 4 | # Author : Jin Kim 5 | # e-mail : jinkim@seculayer.com 6 | # Powered by Seculayer © 2021 Service Model Team, R&D Center. 7 | ###################################################################################### 8 | 9 | APP_PATH=/eyeCloudAI/app/ape 10 | 11 | if [ -x "${APP_PATH}/hprs/.venv/bin/python3" ]; then 12 | PYTHON_BIN="${APP_PATH}/hprs/.venv/bin/python3" 13 | else 14 | PYTHON_BIN="$(command -v python3.7)" 15 | export PYTHONPATH=$APP_PATH/hprs/lib:$APP_PATH/hprs 16 | export PYTHONPATH=$PYTHONPATH:$APP_PATH/pycmmn/lib:$APP_PATH/pycmmn 17 | fi 18 | 19 | KEY=${1} 20 | WORKER_IDX=${2} 21 | 22 | $PYTHON_BIN -m hprs.HyperParameterRecommender ${KEY} ${WORKER_IDX} 23 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | end_of_line = lf 9 | 10 | [*.py] 11 | charset = utf-8 12 | end_of_line = lf 13 | indent_style = space 14 | indent_size = 4 15 | trim_trailing_whitespace = true 16 | insert_final_newline = true 17 | 18 | [{Dockerfile,*.dockerfile,Dockerfile.*}] 19 | charset = utf-8 20 | end_of_line = lf 21 | indent_style = space 22 | indent_size = 4 23 | trim_trailing_whitespace = true 24 | insert_final_newline = true 25 | 26 | [pom.xml] 27 | charset = utf-8 28 | end_of_line = lf 29 | indent_style = space 30 | indent_size = 2 31 | trim_trailing_whitespace = true 32 | insert_final_newline = true 33 | 34 | [{*.yml,*.yaml}] 35 | charset = utf-8 36 | end_of_line = lf 37 | indent_style = space 38 | indent_size = 2 39 | trim_trailing_whitespace = true 40 | insert_final_newline = true 41 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "hprs" 3 | version = "1.0.0" 4 | description = "AutoAPE : HPRS(Hyper Parameter Recommend Server)" 5 | authors = ["Jin Kim "] 6 | include = ["conf"] 7 | 8 | [tool.poetry.dependencies] 9 | python = "^3.7, <3.11" 10 | requests = "^2.27.1" 11 | pycmmn = { git = "https://ssdlc-bitbucket.seculayer.com:8443/scm/slaism/autoape-pycmmn.git", rev = "main" } 12 | 13 | [tool.poetry.dev-dependencies] 14 | black = "^22" 15 | isort = "^5.10.1" 16 | pytest = "^7.1.1" 17 | mypy = "^0.942" 18 | hypothesis = "^6.43.3" 19 | pytest-xdist = { extras = ["psutil"], version = "^2.5.0" } 20 | pytest-cov = "^3.0.0" 21 | prospector = { extras = [ 22 | "with_mypy", 23 | "with_vulture", 24 | "with_bandit", 25 | ], version = "^1.7.7" } 26 | coverage = "^6.3.3" 27 | 28 | [build-system] 29 | requires = ["poetry-core>=1.0.0"] 30 | build-backend = "poetry.core.masonry.api" 31 | 32 | [tool.pytest.ini_options] 33 | minversion = "7.0" 34 | addopts = "-ra -q --failed-first -n auto" 35 | testpaths = ["tests"] 36 | 37 | [tool.black] 38 | line-length = 120 39 | 40 | [tool.isort] 41 | multi_line_output = 3 42 | include_trailing_comma = true 43 | force_grid_wrap = 0 44 | use_parentheses = true 45 | line_length = 120 46 | 47 | [tool.pylint.format] 48 | max-line-length = "120" 49 | -------------------------------------------------------------------------------- /hprs/HyperParameterRecommender.py: -------------------------------------------------------------------------------- 1 | import time 2 | from pycmmn.Singleton import Singleton 3 | from pycmmn.KubePodSafetyTermThread import KubePodSafetyTermThread 4 | from hprs.common.Common import Common 5 | from hprs.common.Constants import Constants 6 | from hprs.manager.HPRSManager import HPRSManager 7 | 8 | 9 | class HyperParameterRecommender(KubePodSafetyTermThread, metaclass=Singleton): 10 | def __init__(self, job_id: str, job_idx: str): 11 | KubePodSafetyTermThread.__init__(self) 12 | self.logger = Common.LOGGER.getLogger() 13 | 14 | self.hprs_manager = HPRSManager(job_id, job_idx) 15 | try: 16 | self.hprs_manager.initialize() 17 | self.logger.info("HyperParameterRecommender Initialized!") 18 | except Exception as e: 19 | self.logger.error(e, exc_info=True) 20 | 21 | def run(self) -> None: 22 | while not self.hprs_manager.get_terminate(): 23 | try: 24 | self.hprs_manager.recommend() 25 | except Exception as e: 26 | self.logger.error(e, exc_info=True) 27 | self.hprs_manager.update_project_status(Constants.STATUS_PROJECT_ERROR) 28 | finally: 29 | time.sleep(10) 30 | 31 | self.logger.info("HyperParameterRecommender terminate!") 32 | self.hprs_manager.terminate() 33 | 34 | 35 | if __name__ == '__main__': 36 | import sys 37 | 38 | j_id = sys.argv[1] 39 | j_idx = sys.argv[2] 40 | hprs = HyperParameterRecommender(j_id, j_idx) 41 | hprs.start() 42 | hprs.join() 43 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.3 2 | FROM seculayer/python:3.7 AS builder 3 | LABEL maintainer="jinkim jinkim@seculayer.com" 4 | 5 | ARG APP_DIR="/opt/app" 6 | ARG POETRY_VERSION=1.1.13 7 | 8 | ENV POETRY_VIRTUALENVS_IN_PROJECT=1 \ 9 | PATH="/root/.local/bin:$PATH" 10 | 11 | RUN --mount=type=cache,target=/root/.cache/pip \ 12 | pip install install pipx 13 | RUN pipx ensurepath 14 | RUN pipx install "poetry==$POETRY_VERSION" 15 | 16 | WORKDIR ${APP_DIR} 17 | 18 | COPY pyproject.toml poetry.lock ${APP_DIR} 19 | 20 | RUN --mount=type=secret,id=gitconfig,target=/root/.gitconfig,required=true \ 21 | --mount=type=secret,id=cert,required=true \ 22 | # --mount=type=cache,target=/root/.cache/pypoetry/cache \ 23 | # --mount=type=cache,target=/root/.cache/pypoetry/artifacts \ 24 | poetry install --no-dev --no-root --no-interaction --no-ansi 25 | 26 | 27 | FROM seculayer/python:3.7 AS app 28 | ARG APP_DIR="/opt/app" 29 | ARG CLOUD_AI_DIR="/eyeCloudAI/app/ape/hprs/" 30 | ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 31 | 32 | RUN mkdir -p ${CLOUD_AI_DIR} 33 | WORKDIR ${CLOUD_AI_DIR} 34 | 35 | RUN groupadd -g 1000 aiuser 36 | RUN useradd -r -u 1000 -g aiuser aiuser 37 | RUN chown -R aiuser:aiuser /eyeCloudAI 38 | USER aiuser 39 | 40 | COPY --chown=aiuser:aiuser --from=builder ${APP_DIR}/.venv ${CLOUD_AI_DIR}/.venv 41 | COPY --chown=aiuser:aiuser hprs ${CLOUD_AI_DIR}/hprs 42 | COPY --chown=aiuser:aiuser hprs.sh ${CLOUD_AI_DIR} 43 | RUN chmod +x ${CLOUD_AI_DIR}/hprs.sh 44 | 45 | ENV PATH="${CLOUD_AI_DIR}/.venv/bin:${PATH}" 46 | 47 | CMD ["${CLOUD_AI_DIR}/hprs.sh"] 48 | -------------------------------------------------------------------------------- /conf/hprs-conf.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | dir_data_root 5 | /eyeCloudAI/data 6 | Data root directory 7 | 8 | 9 | 10 | dir_log 11 | /eyeCloudAI/logs 12 | None 13 | 14 | 15 | log_name 16 | HyperParameterRecommender 17 | None 18 | 19 | 20 | log_level 21 | INFO 22 | [INFO, DEBUG, WARN, ERROR, CRITICAL] 23 | 24 | 25 | 26 | mrms_svc 27 | mrms-svc 28 | 29 | 30 | mrms_sftp_port 31 | 10022 32 | 33 | 34 | mrms_rest_port 35 | 9200 36 | 37 | 38 | mrms_username 39 | HE12RmzKHQtH3bL7tTRqCg== 40 | 41 | 42 | mrms_password 43 | jTf6XrqcYX1SAhv9JUPq+w== 44 | 45 | 46 | 47 | rcmd_min_count 48 | 1 49 | 50 | 51 | rcmd_max_count 52 | 2 53 | 54 | 55 | -------------------------------------------------------------------------------- /hprs/common/Constants.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author : Jin Kim 3 | # e-mail : jin.kim@seculayer.com 4 | # Powered by Seculayer © 2021 Service Model Team, R&D Center. 5 | 6 | from pycmmn.Singleton import Singleton 7 | from pycmmn.utils.ConfUtils import ConfUtils 8 | from pycmmn.utils.FileUtils import FileUtils 9 | 10 | import os 11 | os.chdir(FileUtils.get_realpath(__file__) + "/../../") 12 | 13 | 14 | # class : Constants 15 | class Constants(metaclass=Singleton): 16 | # load config xml file 17 | _CONFIG = ConfUtils.load(filename=os.getcwd() + "/conf/hprs-conf.xml") 18 | 19 | # Directories 20 | DIR_DATA_ROOT = _CONFIG.get("dir_data_root", "/eyeCloudAI/data") 21 | DIR_DIVISION_PATH = DIR_DATA_ROOT + "/processing/ape/division" 22 | DIR_JOB_PATH = DIR_DATA_ROOT + "/processing/ape/jobs" 23 | 24 | # Logs 25 | DIR_LOG = _CONFIG.get("dir_log", "./logs") 26 | LOG_LEVEL = _CONFIG.get("log_level", "INFO") 27 | LOG_NAME = _CONFIG.get("log_name", "HyperParameterRecommender") 28 | 29 | # Hosts 30 | MRMS_SVC = _CONFIG.get("mrms_svc", "mrms-svc") 31 | MRMS_USER = _CONFIG.get("mrms_username", "HE12RmzKHQtH3bL7tTRqCg==") 32 | MRMS_PASSWD = _CONFIG.get("mrms_password", "jTf6XrqcYX1SAhv9JUPq+w==") 33 | MRMS_SFTP_PORT = int(_CONFIG.get("mrms_sftp_port", "10022")) 34 | MRMS_REST_PORT = int(_CONFIG.get("mrms_rest_port", "9200")) 35 | 36 | # STATUS 37 | STATUS_PROJECT_COMPLETE = "8" 38 | STATUS_PROJECT_ERROR = "9" 39 | 40 | RCMD_MIN_COUNT = int(_CONFIG.get("rcmd_min_count", "1")) 41 | RCMD_MAX_COUNT = int(_CONFIG.get("rcmd_max_count", "2")) 42 | 43 | 44 | if __name__ == '__main__': 45 | print(Constants.DIR_DATA_ROOT) 46 | 47 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author : Jin Kim 3 | # e-mail : jin.kim@seculayer.com 4 | # Powered by Seculayer © 2021 AI Service Model Team, R&D Center. 5 | 6 | # ---------------------------------------------------------------------------------------------- 7 | # AutoML - HPRS(Hyper Parameter Recommend Server) Setup Script 8 | # ---------------------------------------------------------------------------------------------- 9 | 10 | from typing import List 11 | 12 | from setuptools import setup, find_packages 13 | 14 | 15 | class APEPythonSetup(object): 16 | def __init__(self): 17 | self.module_nm = "hprs" 18 | self.version = "1.0.0" 19 | 20 | @staticmethod 21 | def get_require_packages() -> List[str]: 22 | f = open("./requirements.txt", "r") 23 | require_packages = f.readlines() 24 | f.close() 25 | return require_packages 26 | 27 | @staticmethod 28 | def get_packages() -> List[str]: 29 | return find_packages( 30 | exclude=[ 31 | "build", "tests", "scripts", "dists" 32 | ], 33 | ) 34 | 35 | def setup(self) -> None: 36 | setup( 37 | name=self.module_nm, 38 | version=self.version, 39 | description="SecuLayer Inc. AutoML Project \n" 40 | "Module : HPRS(Hyper Parameter Recommend Server)", 41 | author="Jin Kim", 42 | author_email="jin.kim@seculayer.com", 43 | packages=self.get_packages(), 44 | package_dir={ 45 | "conf": "conf", 46 | "resources": "resources" 47 | }, 48 | python_requires='>3.7', 49 | package_data={ 50 | # self.module_nm: FILE_LIST 51 | }, 52 | install_requires=self.get_require_packages(), 53 | zip_safe=False, 54 | ) 55 | 56 | 57 | if __name__ == '__main__': 58 | print(" __ ______ ____ _____") 59 | print(" / / / / __ \/ __ \/ ___/") 60 | print(" / /_/ / /_/ / /_/ /\__ \ ") 61 | print(" / __ / ____/ _, _/___/ / ") 62 | print("/_/ /_/_/ /_/ |_|/____/ ") 63 | print(" ") 64 | APEPythonSetup().setup() 65 | 66 | 67 | -------------------------------------------------------------------------------- /hprs/manager/HPRSManager.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author : Jin Kim 3 | # e-mail : jin.kim@seculayer.com 4 | # Powered by Seculayer © 2021 AI Service Model Team, R&D Center. 5 | 6 | import requests as rq 7 | import json 8 | from typing import List, Dict 9 | 10 | from pycmmn.utils.Utils import Utils 11 | from hprs.common.Common import Common 12 | from hprs.common.Constants import Constants 13 | from pycmmn.sftp.SFTPClientManager import SFTPClientManager 14 | from hprs.recommender.RandomRecommender import RandomRecommender 15 | 16 | 17 | class HPRSManager(object): 18 | # class : DataAnalyzerManager 19 | def __init__(self, job_id, job_idx): 20 | self.logger = Common.LOGGER.getLogger() 21 | 22 | self.mrms_sftp_manager = None 23 | self.rest_root_url = f"http://{Constants.MRMS_SVC}:{Constants.MRMS_REST_PORT}" 24 | 25 | self.job_id = job_id 26 | self.current = 0 27 | self.logger.info("HPRSManager initialized.") 28 | 29 | def initialize(self): 30 | self.mrms_sftp_manager: SFTPClientManager = SFTPClientManager( 31 | "{}:{}".format(Constants.MRMS_SVC, Constants.MRMS_SFTP_PORT), 32 | Constants.MRMS_USER, Constants.MRMS_PASSWD, self.logger 33 | ) 34 | 35 | def load_job_info(self, filename): 36 | return self.mrms_sftp_manager.load_json_data(filename) 37 | 38 | def recommend(self): 39 | filename = f"{Constants.DIR_JOB_PATH}/{self.job_id}/MARS_{self.job_id}_{self.current}.info" 40 | if self.mrms_sftp_manager.is_exist(filename): 41 | job_info = self.load_job_info(filename) 42 | results = RandomRecommender().recommend(job_info, self.job_id) 43 | self.logger.info(f"Recommended {len(results)} elements") 44 | self.logger.debug(f"project_id: {self.job_id}, Recommended: {results}") 45 | 46 | response = rq.post(f"{self.rest_root_url}/mrms/insert_ml_param_info", json=results) 47 | self.logger.info(f"insert ml param info: {response.status_code} {response.reason} {response.text}") 48 | 49 | learn_hist_list = self.make_learn_hist(results) 50 | for learn_hist in learn_hist_list: 51 | response = rq.post(f"{self.rest_root_url}/mrms/insert_learn_hist", json=learn_hist) 52 | self.logger.info(f"insert learn hist: {response.status_code} {response.reason} {response.text}") 53 | 54 | file_nm = f"{Constants.DIR_JOB_PATH}/{self.job_id}/HPRS_{self.job_id}_{self.current}" 55 | f = self.mrms_sftp_manager.get_client().open( 56 | f"{file_nm}.tmp", 57 | "w" 58 | ) 59 | f.write(json.dumps(results, indent=2)) 60 | 61 | status = {"status": "6", "project_id": self.job_id} 62 | response = rq.post(f"{self.rest_root_url}/mrms/update_projects_status", json=status) 63 | self.logger.info(f"update project status: {response.status_code} {response.reason} {response.text}") 64 | f.close() 65 | self.mrms_sftp_manager.rename(f"{file_nm}.tmp", f"{file_nm}.info") 66 | self.current += 1 67 | 68 | def update_project_status(self, status): 69 | status_json = {"status": status, "project_id": self.job_id} 70 | response = rq.post(f"{self.rest_root_url}/mrms/update_projects_status", json=status_json) 71 | self.logger.info(f"update project status: {response.status_code} {response.reason} {response.text}") 72 | 73 | def get_terminate(self) -> bool: 74 | response = rq.get(f"{self.rest_root_url}/mrms/get_proj_sttus_cd?project_id={self.job_id}") 75 | status = response.text.replace("\n", "") 76 | if status == Constants.STATUS_PROJECT_COMPLETE or status == Constants.STATUS_PROJECT_ERROR: 77 | return True 78 | return False 79 | 80 | def terminate(self): 81 | if self.mrms_sftp_manager is not None: 82 | self.mrms_sftp_manager.close() 83 | 84 | def make_learn_hist(self, ml_param_dict_list: List[Dict]): 85 | for ml_param_dict in ml_param_dict_list: 86 | ml_param_dict["learn_hist_no"] = self.get_uuid() 87 | ml_param_dict["learn_sttus_cd"] = "1" 88 | ml_param_dict["start_time"] = Utils.get_current_time() 89 | 90 | return ml_param_dict_list 91 | 92 | def get_uuid(self): 93 | response = rq.get(f"{self.rest_root_url}/mrms/get_uuid") 94 | self.logger.info(f"get uuid: {response.status_code} {response.reason} {response.text}") 95 | return response.text.replace("\n", "") 96 | 97 | 98 | if __name__ == '__main__': 99 | dam = HPRSManager("ID", "0") 100 | -------------------------------------------------------------------------------- /hprs/recommender/RandomRecommender.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author : Jin Kim 3 | # e-mail : jin.kim@seculayer.com 4 | # Powered by Seculayer © 2021 AI Service Model Team, R&D Center. 5 | 6 | import requests as rq 7 | import json 8 | import random 9 | 10 | from hprs.common.Constants import Constants 11 | 12 | 13 | class RandomRecommender(object): 14 | def __init__(self): 15 | self.rest_root_url = f"http://{Constants.MRMS_SVC}:{Constants.MRMS_REST_PORT}" 16 | 17 | def get_algorithm_params(self, algorithm_id): 18 | response = rq.get(f"{self.rest_root_url}/mrms/get_param_info?alg_id={algorithm_id}") 19 | str_data = response.text 20 | data = json.loads(str_data) 21 | response.close() 22 | return data 23 | 24 | def get_uuid(self): 25 | response = rq.get(f"{self.rest_root_url}/mrms/get_uuid") 26 | return response.text.replace("\n", "") 27 | 28 | def recommend(self, mars_list, job_id): 29 | result = list() 30 | is_first = True 31 | 32 | for idx, mars_data in enumerate(mars_list): 33 | params_list = self.get_algorithm_params(mars_data.get("alg_id")) 34 | for i in range(random.randint(Constants.RCMD_MIN_COUNT, Constants.RCMD_MAX_COUNT)): 35 | res = dict() 36 | param_dict = dict() 37 | fixed_size = 0 38 | for param in params_list: 39 | param_nm = param.get("param_code") 40 | if param.get("param_type") == "1" and param.get("param_type_value") == "list": 41 | if param_nm == "filter_sizes" or param_nm == "pool_sizes": 42 | fixed_size = random.randint(1, 3) if fixed_size == 0 else fixed_size 43 | param_dict[param_nm] = ",".join([str(random.randint(2, 8)) for i in range(random.randint(fixed_size, fixed_size))]) 44 | else: 45 | param_dict[param_nm] = ",".join([str(random.randint(3, 1024)) for i in range(random.randint(1, 3))]) 46 | elif param.get("param_type") == "1": 47 | if param_nm == "n_neighbors": 48 | param_dict[param_nm] = random.randint(2, 3) 49 | elif param_nm == "seq_term": 50 | param_dict[param_nm] = 60 51 | elif param_nm == "n_estimators": 52 | if is_first: 53 | param_dict[param_nm] = 20 54 | else: 55 | param_dict[param_nm] = random.randint(1000, 1500) 56 | elif param_nm == "num_leaves": 57 | if is_first: 58 | param_dict[param_nm] = 41 59 | else: 60 | param_dict[param_nm] = random.randint(15, 80) 61 | elif param_nm == "max_depth": 62 | if is_first: 63 | param_dict[param_nm] = 21 64 | else: 65 | param_dict[param_nm] = random.randint(1, 16) 66 | else: 67 | param_dict[param_nm] = random.randint(1, 16) 68 | elif param.get("param_type") == "2": 69 | if param_nm == "dropout_prob": 70 | param_dict[param_nm] = random.uniform(0, 0.5) 71 | elif param_nm == "contamination": 72 | if is_first: 73 | param_dict[param_nm] = 0.1 74 | else: 75 | param_dict[param_nm] = random.uniform(0, 0.3) 76 | elif param_nm == "learning_rate": 77 | param_dict[param_nm] = random.uniform(0, 0.8) 78 | else: 79 | param_dict[param_nm] = random.random() 80 | elif param.get("param_type") == "3": 81 | if int(mars_data.get("dataset_format")) == 2: # case image dataset 82 | if param_nm == "conv_fn": 83 | param_dict[param_nm] = "Conv2D" 84 | elif param_nm == "pooling_fn": 85 | param_dict[param_nm] = random.choice(["Max2D", "Average2D"]) 86 | else: 87 | param_dict[param_nm] = random.choice(param.get("param_type_value").split(",")) 88 | else: 89 | if param_nm == "conv_fn": 90 | param_dict[param_nm] = "Conv1D" 91 | elif param_nm == "pooling_fn": 92 | param_dict[param_nm] = random.choice(["Max1D", "Average1D"]) 93 | else: 94 | param_dict[param_nm] = random.choice(param.get("param_type_value").split(",")) 95 | 96 | res["project_id"] = job_id 97 | res["alg_anal_id"] = mars_data.get("alg_anal_id") 98 | res["dp_analysis_id"] = mars_data.get("dp_analysis_id") 99 | res["param_id"] = self.get_uuid() 100 | res["alg_id"] = mars_data.get("alg_id") 101 | res["param_json"] = param_dict 102 | result.append(res) 103 | 104 | is_first = False 105 | return result 106 | 107 | 108 | if __name__ == '__main__': 109 | RandomRecommender() 110 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------