async def run(self, coz_conn: cozmo.conn.CozmoConnection): robot = await coz_conn.wait_for_robot() self._supervisor = Supervisor(robot) robot.move_lift(-3) # robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE) robot.world.add_event_handler(cozmo.faces.EvtFaceObserved, self.onFaceObserved) robot.world.add_event_handler(cozmo.faces.EvtFaceAppeared, self.onFaceAppeared) robot.world.add_event_handler(cozmo.faces.EvtFaceDisappeared, self.onFaceDisappeared) await self._supervisor.startStare() while not self.exit_flag: if self._face and self._face.is_visible: #self._face pass else: try: # find a human face self._face = await robot.world.wait_for_observed_face( timeout=SEARCH_FACE_TIMEOUT) except asyncio.TimeoutError: self.curr_time += SEARCH_FACE_TIMEOUT print("Fail to find a face") await asyncio.sleep(0.5) await self._supervisor.regularCheck() self.curr_time += 0.5 if self.curr_time > self.focus_time: break
async def test_service_restart(event_loop): s = Supervisor(loop=event_loop) s.application = test_app await s.service_start(service_id=2) res = await s.service_restart(service_id=2) await s.stop() assert res
def setUp(self) -> None: self.exchange_mock = Mock() self.exchange_mock.get_open_orders_ws.return_value = [] self.exchange_mock.get_position_size_ws.return_value = 0 self.supervisor = Supervisor(interface=self.exchange_mock) self.exchange_mock.conn.base_url = 'https://testnet.bitmex.com/api/v1' self.exchange_mock.conn.get_tick_size.return_value = 0.5
def say(self, e): """ Canvia l'estat del node per un de nou, a més a més notifica al supervisor utilitzant la funcio notify_change(). Per canviar l'estat iguala la variable self._estat amb el estat nou. """ supervi = Supervisor() if self._e != e: self._e = e supervi.notify_change()
def list_value_and_commander_factory(): new_list = ListQuery() global CURRENT_WINDOW, EVENT_DISPATCHER supervisor = Supervisor() commander = Commander() EVENT_DISPATCHER.register(new_list) EVENT_DISPATCHER.register(commander) EVENT_DISPATCHER.register(supervisor) return new_list, commander
async def test_ip_address_get(event_loop): s = Supervisor(loop=event_loop) res = await s.ip_address_get() assert res await s.stop()
apiServer.CreateWorker(cmdAttributes[1:]) elif cmdAttributes[0] == 'DeleteDeployment': #We have to makesure that our load balancer will end gracefully here for loadBalancer in loadBalancers: if loadBalancer.deployment.deploymentLabel == cmdAttributes[1]: loadBalancer.running = False apiServer.RemoveDeployment(cmdAttributes[1:]) elif cmdAttributes[0] == 'ReqIn': apiServer.PushReq(cmdAttributes[1:]) elif cmdAttributes[0] == 'CreateHPA': hpa = HPA(apiServer, _hpaCtlLoop, cmdAttributes[1:]) hpaThread = threading.Thread(target=hpa) hpaThread.start() hpas.append(hpa) hpaThreads.append(hpaThread) supervisor = Supervisor(apiServer, hpa) supervisorThread = threading.Thread(target=supervisor) supervisorThread.start() supervisors.append(supervisor) supervisorThreads.append(supervisorThread) elif cmdAttributes[0] == 'CrashPod': apiServer.CrashPod(cmdAttributes[1:]) #The instructions will sleep after each round of requests. The following code stores values for graphing if cmdAttributes[0] == 'Sleep': count += 1 time.sleep(int(cmdAttributes[1])) if len(apiServer.etcd.deploymentList) == 1: depPods1.append(apiServer.etcd.deploymentList[0].expectedReplicas) depPods2.append(0) depPods3.append(0) count1 = 0
def __init__(self): self.supervisor = Supervisor() self.population = Population(size=100, crossover=0.8, elitism=0.1, \ mutation=0.5, supervisor=self.supervisor) self.max_generations = 16384
def init_connection(self): self.conn = Supervisor(host=self.config['HOST'], port=self.config['PORT'], user=self.config['USER'], password=self.config['PASSWORD'])
file_handler.setLevel(logging.DEBUG) file_handler.setFormatter( logging.Formatter( "[%(levelname)s @ %(asctime)-15s] %(name)s: %(message)s")) handlers.append(file_handler) del file_handler # Needed to set the "max level" for the above handlers. If we don't set this to # DEBUG but for example to INFO, all the handlers are limited to INFO. logging.basicConfig(handlers=handlers, level=logging.DEBUG) del handlers # </Logger initialization> bot = IrcBot(state_path="pyhtonbot_state.json") supervisor = Supervisor("8Banana/nettirely") # this used to trigger on !py and >>>, but the >>> annoyed others than raylu # # <Summertime> $> d['wow'] # <Summertime> [1, 2, 3] # <darkf> wtf is $> # <Summertime> its f**k pyhtonbot @bot.on_command("!py", NO_SPLITTING) async def annoy_raylu(self, _, recipient, text): if recipient == self.nick: return await self.send_privmsg(recipient, "!py3 " + text)
async def test_service_pull_(event_loop): s = Supervisor(loop=event_loop) s.application = test_app res = await s.service_pull_(service_id=1) assert res await s.stop()
from pessoa import Pessoa from funcionario import Funcionario from supervisor import Supervisor from datetime import datetime as dt data_nascimento = dt.strptime('2000-01-01', '%Y-%m-%d') data_admissao = dt.strptime('2005-01-01', '%Y-%m-%d') funcionario = Funcionario('Josh', '793.253.125-92', data_nascimento, data_admissao, 2000, 'Setor 1') supervisor = Supervisor('Nicole', '589.365.182-21', data_nascimento, data_admissao, 2000, 'Setor 1', 500) print('---Funcionario---') print(funcionario) print('Salário mensal: {}'.format(funcionario.calcula_salario_mensal())) print('---Supervisora---') print(supervisor) print('Salário mensal: {}'.format(supervisor.calcula_salario_mensal()))
from supervisor import Supervisor from WindowsSleepInhibitor import WindowsSleepInhibitor import sys osSleep = None # in Windows, prevent the OS from sleeping while we run if sys.platform == 'win32': osSleep = WindowsSleepInhibitor() osSleep.inhibit() supervisor = Supervisor(dev=True, archive=False) supervisor.run() # Remove sleep inhibition if osSleep: osSleep.uninhibit()
def pdf_report(training_data_name, training_data_X, training_data_y, attack_training_set, test_set, kernel_type, prediction_type, attack_type, bf_alpha, budget_factor_alpha_list, test_set_y=None): dimension = len(training_data_X[0]) print( "---------------------------------------------------------------------------" ) print("[*] Initiating Experiment") print("Parameters:") print("Training set: ", training_data_name) print("Training data count: ", len(training_data_X)) print("Attack data count: ", len(attack_training_set)) print("Data dimension: ", dimension) print("Test set size: ", len(test_set)) if kernel_type is not None: print("Kernel: ", kernel_type) print("Prediction type: ", prediction_type) print("Attack type: ", attack_type) if budget_factor_alpha_list: print("Budget Factor Alpha List: ", budget_factor_alpha_list[0], "..", budget_factor_alpha_list[-1]) print("----------------------------------------------------") s = Supervisor() name = training_data_name print("[*] Training Server Model...") s.add_model(name, training_data_X, training_data_y, prediction_type, kernel_type) print("[*] Starting Test Attack...") query_budget = math.ceil(bf_alpha * (dimension + 1)) if attack_type == "agnostic": kernel_type = None if True: run_time, queries, model = s.attack_with_metrics(name, kernel_type, attack_type, dimension, query_budget, attack_training_set, roundsize=160, test_set=test_set) print("[*] Attack took ", run_time, " seconds and ", queries, " queries.") print("[*] Starting Prediction Comparison for test Attack... ") a = s.compare_predictions(name, test_set, correct_results=test_set_y, verbose=True) if attack_type == "lowd-meek": return a[0], queries, run_time if not budget_factor_alpha_list: return a[0], queries, run_time if attack_type not in ["extraction", "lowd-meek", "agnostic"]: print("[*] Running query mapping") s.plot_error_on_queries("mse", name, kernel_type, attack_type, dimension, budget_factor_alpha_list, attack_training_set, test_set, 16)
def main(): qb1 = [1, 5, 10, 25, 50, 100, 250, 500, 1000] qb2 = range(1, 100) qb3 = range(10, 100) qb4 = range(10, 200, 5) qb5 = range(1, 250) qb6 = range(6, 500, 2) qb7 = range(5, 500) print("SVM Model extractor") print("Version ", version) """ x = [] y = [] for i in range(0, 1000): datum = [i, random.choice([1, 3])] x.append([datum[0], datum[1] + 0.5*datum[0]]) if datum[1] == 3: y.append(0) else: y.append(1) """ s = Supervisor() X = [] y = [] m = 3 b = 12 for i in range(0, 1000): n = random.randrange(-50, 50, 1) / 100 y.append(m * i + b + n) X.append([i]) line_training_data = {"x": X, "y": y} line_training = "line-training-svr" line_trained_model = s.create_trained_model_from_training_data( line_training_data["x"][:500], line_training_data["y"][:500], "SVR", "linear") s.add_model(line_training, line_training_data, line_trained_model, "SVR") s.attack_model(line_training, "SVR", "linear", "adaptive retraining", 1, 0, 100, 100, line_training_data["x"][500:600]) #s.compare_predictions(line_training, False, line_training_data["x"][600:700], "SVR") s.plot_mse_on_queries_with_dataset(line_training, "SVR", "linear", "adaptive retraining", 1, 0, 100, qb4, line_training_data["x"][500:1000]) return X, y = sklearn.datasets.make_blobs(n_samples=60, centers=2, random_state=7) flat_training_data = {"x": X, "y": y} firstclass = y[0] for index, classf in enumerate(y): if classf != firstclass: secondindex = index posneg = [X[0], X[secondindex]] plt.scatter(X[:, 0], X[:, 1], c=y, s=30, cmap=plt.cm.Paired) ax = plt.gca() xlim = ax.get_xlim() ylim = ax.get_ylim() xx = numpy.linspace(xlim[0], xlim[1], 30) yy = numpy.linspace(ylim[0], ylim[1], 30) YY, XX = numpy.meshgrid(yy, xx) xy = numpy.vstack([XX.ravel(), YY.ravel()]).T s = Supervisor() """ s.add_random_model("test_regression_linear", "SVR", "linear", 2, 100) s.attack_model("test_regression_linear", "SVR", "linear", "retraining", 2, 100) print(s.get_models()) s.compare_random_predictions("test_regression_linear", 50, 2, 0) s.plot_mse_on_queries("test_regression_linear", "SVR", "linear", "retraining", 2, range(1, 101)) """ flat_trained_model = s.create_trained_model_from_training_data( flat_training_data["x"], flat_training_data["y"], "SVM", "linear") s.add_model("flat-linear-svm", flat_training_data, flat_trained_model, "SVM") print(s.get_models()["flat-linear-svm"]["original_model"].coef_[0]) s.attack_model("flat-linear-svm", "SVM", "linear", "lowd-meek", 2, 0, 7, 100, posneg) #s.compare_predictions("flat-linear-svm", False, flat_training_data["x"][800:1000], "SVM") Z = s.get_models()["flat-linear-svm"]["original_model"].decision_function( xy).reshape(XX.shape) # plot decision boundary and margins ax.contour(XX, YY, Z, colors='k', levels=[-1, 0, 1], alpha=0.5, linestyles=['--', '-', '--']) # plot support vectors ax.scatter(s.get_models()["flat-linear-svm"] ["original_model"].support_vectors_[:, 0], s.get_models()["flat-linear-svm"] ["original_model"].support_vectors_[:, 1], s=100, linewidth=1, facecolors='none', edgecolors='k') p, w, oneoff, doob, lastdoob, doox = s.get_models( )["flat-linear-svm"]["extracted_model"] wr = s.get_models()["flat-linear-svm"]["original_model"].coef_[0] a = -w[0] / w[1] intercept = p[1] - a * p[0] inter = s.get_models()["flat-linear-svm"]["original_model"].intercept_ print("correct a", -wr[0] / wr[1]) print("correct intercept", inter) print("calculated with correct", p[1] - (-wr[0] / wr[1]) * p[0]) print("with correct", (-wr[0] / wr[1]) * p[0] + inter) print("a", a, "intercept", intercept) print("p", p) #xx = numpy.linspace(min_x - 5, max_x + 5) # make sure the line is long enough yy = a * xx + intercept #/ w[1] plt.plot(xx, yy, 'k-', label='extracted') plt.plot(p[0], p[1], marker='o', color='r') plt.plot(oneoff[0], oneoff[1], marker='o', color='b') #for doo in doob: # plt.plot(doo[0], doo[1], marker='o', color='g') plt.plot(lastdoob[0], lastdoob[1], marker='o', color='y') #plt.plot(doox[0], doox[1], marker='o', color='b') print("pred", s.get_models()["flat-linear-svm"]["original_model"].predict([doox])) print( "pred", s.get_models()["flat-linear-svm"]["original_model"].predict([oneoff])) plt.show() return krebs = sklearn.datasets.load_breast_cancer() krebs_training_data = {"x": krebs.data, "y": krebs.target} krebs_trained_model = s.create_trained_model_from_training_data( krebs_training_data["x"], krebs_training_data["y"], "SVM", "rbf") print(krebs_training_data["x"][18:20]) s.add_model("krebs-rbf", krebs_training_data, krebs_trained_model, "SVM") s.attack_model("krebs-rbf", "SVM", "rbf", "lowd-meek", 30, 0, 2000, 10, dataset=krebs_training_data["x"][18:20]) #print(s.get_models()) s.compare_predictions("krebs-rbf", False, krebs_training_data["x"][100:200], "SVM") #s.plot_mse_on_queries_with_dataset("krebs-rbf", "SVM", "rbf", "retraining", 30, 0, 2000, qb7, # krebs_training_data["x"][0:500]) #boston = sklearn.datasets.load_boston() #boston_training_data = {"x": boston.data, "y": boston.target} #boston_trained_model = s.create_trained_model_from_training_data(boston_training_data["x"], boston_training_data["y"], # "SVR", "rbf") #s.add_model("boston-svr-rbf", boston_training_data, boston_trained_model, "SVR") #s.attack_model("boston-svr-rbf", "SVR", "rbf", "adaptive retraining", 13, 5, 50, 120, dataset=boston_training_data["x"][200:320]) #s.compare_predictions("boston-svr-rbf", False, boston_training_data["x"][000:500], "SVR") #s.plot_mse_on_queries("boston-svr-rbf", "SVR" , "rbf", "adaptive retraining", 13, 5, 50, qb2) #print(boston.DESCR) return with open( r"C:\Users\Kolja\Documents\Uni\Bachelor\BA\STEALING SVM MODELS\Resources\Datasets\Alcala Tutorial 2017\1490779198_4046512_alc2017_training_set.csv" ) as csvfile: reader = csv.reader(csvfile, delimiter=',') line = 1 X = [] y1 = [] y2 = [] for row in reader: if line == 1: line += 1 continue integered = list(map(lambda x: int(x), row[:-2])) floated = list(map(lambda x: float(x), row[-2:])) X.append(integered) y1.append(floated[0]) y2.append(floated[1]) line += 1 print(len(X)) location_training_data = {"x": X, "y": y1} #print(y1[500:]) svr = svm.SVR(kernel="rbf") print(X[500:502]) print(y1[500:502]) svr.fit(X, y1) j = 12 #for j in range(0, 100): # print(svr.predict([X[j]]), y1[j]) location_trained_model = s.create_trained_model_from_training_data( location_training_data["x"], location_training_data["y"], "SVR", "rbf") s.add_model("location-svr-rbf", location_training_data, location_trained_model, "SVR") #for j in range(0, 100): # print(svr.predict([X[j]]), y1[j], s.get_models()["location-svr-rbf"]["original_model"].predict([X[j]])) s.attack_model("location-svr-rbf", "SVR", "rbf", "retraining", 13, 5, 50, 100, dataset=location_training_data["x"][200:400]) s.compare_predictions("location-svr-rbf", False, location_training_data["x"][100:200], "SVR") s.plot_mse_on_queries_with_dataset("location-svr-rbf", "SVR", "rbf", "adaptive retraining", 13, 5, 50, qb4, location_training_data["x"][0:500])
all_sprites.draw(screen) pygame.display.flip() clock.tick(framerate) if __name__ == '__main__': logging.basicConfig(format='%(funcName)s#%(lineno)-15s [%(asctime)-15s] %(message)s', level=logging.INFO) all_sprites = pygame.sprite.Group() config = load_config(argv[1] if len(argv) > 1 else "configs/simple.yaml") grid = Grid(config["intersection"], all_sprites) config['car']['paths_gridded'] = precompute_waypoint_grid_relation(grid, config["car"]["paths"]) config['car']['paths'] = [[tuple(waypoint) for waypoint in path] for path in config['car']['paths']] screen, clock, background = init_simulation(config) framerate = config["framerate"] framerate_modifier = 1 supervisor = Supervisor(grid=grid, screen=screen) rolling_counter = 0 current_time = 0 grid_visible = True dead = False while not dead: current_time += 1 events = process_events() dead = events.get("dead", False) if (events.get("faster", False)): framerate_modifier *= 1.25 if (events.get("slower", False)): framerate_modifier *= 0.8 if (events.get("toggle_grid", False)): grid_visible = not grid_visible #if events.get("spawn", False):
async def test_service_status(event_loop): s = Supervisor(loop=event_loop) s.application = test_app res = await s.service_status(service_id=1) assert res == 'starting' await s.stop()
async def test_device_register(event_loop): s = Supervisor(loop=event_loop) s.application = test_app res = await s.device_register() assert res await s.stop()