代码拉取完成,页面将自动刷新
同步操作将从 anolis/keentune_brain 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# Copyright (c) 2021-2023 Alibaba Cloud Computing Ltd.
# SPDX-License-Identifier: MulanPSL-2.0
import os
import signal
import random
import numpy as np
TEST_KNOBS = [
{
"name" :"knobs_a",
"domain" :"sysctl",
"range" :[0, 100],
"dtype" :"int",
"step" :1,
"base" :50
},
{
"name" :"knobs_b",
"domain" :"sysctl",
"options" :["0", "1","2"],
"dtype" :"string",
"base" :"0"
},
{
"name" :"knobs_c",
"domain" :"sysctl",
"sequence" :["0", "1","2"],
"dtype" :"string",
"base" :"0"
},
]
TEST_BASELINE = {
"total":{
"base" :[126.5,126,127],
"negative" :True,
"weight" :100,
"strict" :False
}
}
TEST_FEEDBACK = {"total":[127.0, 127.5, 127.9]}
TEST_RULELIST = []
TEST_EPOCH = 50
TEST_TOPN = 10
TEST_THRESHOLD = 0.8
def testTuning(name, algorithm, iteration, parameters, baseline, rule_list):
if algorithm == "hord":
from brain.algorithm.tuning.hord import HORD
optimizer = HORD(name, iteration, parameters, baseline,rule_list)
if algorithm == "random":
from brain.algorithm.tuning.random import Random
optimizer = Random(name, iteration, parameters, baseline,rule_list)
if algorithm == "lamcts":
from brain.algorithm.tuning.lamcts import LamctsOptim
optimizer = LamctsOptim(name, iteration, parameters, baseline,rule_list)
if algorithm == "bgcs":
from brain.algorithm.tuning.lamcts import LamctsOptim
optimizer = LamctsOptim(name, iteration, parameters, baseline,rule_list)
optimizer.getDataHead()
for i in range(iteration):
_FEEDBACK = {}
_FEEDBACK['total'] = np.array(TEST_FEEDBACK['total'] ) * (1 + random.random())
optimizer.acquire()
optimizer.feedback(iteration = i, bench_score = _FEEDBACK)
optimizer.msg()
optimizer.best()
def testTuningProc(name, iteration, parameters, baseline, rule_list):
from brain.controller.process import TuningProcess
p = TuningProcess(name, "random", iteration, parameters, baseline, rule_list)
p.start()
p.out_q[1].recv()
for i in range(iteration):
p.cmd_q[0].send("acquire")
_ = p.out_q[1].recv()
p.input_q[0].send((i, TEST_FEEDBACK))
p.cmd_q[0].send("feedback")
_ = p.out_q[1].recv()
p.cmd_q[0].send("best")
_ = p.out_q[1].recv()
p.teardown()
os.kill(p.pid, signal.SIGKILL)
def testSensi(trials, explainer):
from brain.algorithm.sensitize.sensitize import sensitize
_ = sensitize(
data_name = "test_sensi",
trials = trials,
explainer = explainer,
epoch = TEST_EPOCH,
topN = TEST_TOPN,
threshold = TEST_THRESHOLD
)
def testSensiProc():
from brain.controller.process import SensitizeProcess
p = SensitizeProcess(
trials = 1,
data_name = "test_sensi",
explainer = "LASSO",
response_ip = "127.0.0.1",
response_port = "8888"
)
p.start()
p.join()
def testOther():
from brain.common.dataset import listData, deleteFile
testTuning("test_other", "random", 10, TEST_KNOBS, TEST_BASELINE, TEST_RULELIST)
print(listData())
deleteFile("test_other")
if __name__ == "__main__":
# test tuning
testTuning("test_random", "random", 30, TEST_KNOBS, TEST_BASELINE, TEST_RULELIST)
testTuning("test_hord", "hord", 30, TEST_KNOBS, TEST_BASELINE, TEST_RULELIST)
testTuning("test_lamcts", "lamcts", 30, TEST_KNOBS, TEST_BASELINE, TEST_RULELIST)
testTuning("test_bgcs", "bgcs", 30, TEST_KNOBS, TEST_BASELINE, TEST_RULELIST)
# test tuning process
testTuningProc("test_random", 10, TEST_KNOBS, TEST_BASELINE, TEST_RULELIST)
# ready test data
testTuning("test_sensi", "random", 10, TEST_KNOBS, TEST_BASELINE, TEST_RULELIST)
# test sensi
testSensi(3, "Xsen")
testSensi(3, "SHAPKernel")
testSensi(3, "XGBTotalGain")
testSensi(3, "LASSO")
testSensi(3, "MI")
testSensi(3, "GP")
# test sensi process
testSensiProc()
# test other function
testOther()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。