def test_gp(constrained_search: bool, normalization: str): logging.basicConfig(level=logging.INFO) num_evaluations = 8 Xy_train, X_test, y_test = artificial_task1() blackbox = Blackbox( input_dim=2, output_dim=1, eval_fun=lambda x: x.sum(axis=-1, keepdims=True), ) optimizer = GP( input_dim=blackbox.input_dim, output_dim=blackbox.output_dim, normalization=normalization, ) candidates = X_test for i in range(num_evaluations): x = optimizer.sample( candidates) if constrained_search else optimizer.sample() y = blackbox(x) logging.info(f"criterion {y} for arguments {x}") optimizer.observe(x=x, y=y)
def test_smoke_optimizers(optimizer_cls, constrained_search: bool): logging.basicConfig(level=logging.INFO) num_evaluations = 10 blackbox = Blackbox( input_dim=2, output_dim=1, eval_fun=lambda x: x.sum(axis=-1, keepdims=True), ) optimizer = optimizer_cls( input_dim=blackbox.input_dim, output_dim=blackbox.output_dim, evaluations_other_tasks=Xy_train, ) candidates = X_test for i in range(num_evaluations): if constrained_search: x = optimizer.sample(candidates) else: x = optimizer.sample() y = blackbox(x) logging.info(f"criterion {y} for arguments {x}") optimizer.observe(x=x, y=y)
def __init__(self,length=5,speed=0,location=0, current_time=0,road=None,number=-1): self.number = number self.length = length self.speed = speed self.location = location self.next_car = 0 self.max_speed = (100/3) #meters/second self.distance_from_car_ahead = 0 self.blackbox = Blackbox(-1,self.location,self.speed) self.road = road self.road_length = len(self.road.road)
class BlackboxSmsBackend(BaseSmsBackend): api_key = settings.BLACKBOX_API_KEY api_signature = settings.BLACKBOX_API_SIGNATURE shortcode = settings.BLACKBOX_SHORT_CODE keyword = settings.BLACKBOX_KEYWORD blackbox = Blackbox(api_key, api_signature) def send_messages(self, messages): for message in messages: for to in message.to: try: self.blackbox.queue_sms(to, message.body, self.shortcode, self.keyword) self.blackbox.send_sms() except: if not self.fail_silently: raise
import sys import os sys.path.append("ML/") from blackbox import Blackbox from annoy1 import save_to_annoy from time import time model = Blackbox(1) def test_detection(): assert model.send_picture('tests/1_test.jpg')[0] == [7] assert model.send_picture('tests/2_test.jpg') is None def test_annoy_save(): save_to_annoy(10, ann_path='tests/stars_embeddings.ann') assert time() - os.stat('tests/stars_embeddings.ann')[8] < 10
dur_time = round(time.time() - start, 4) add_log(time.asctime(), event.user_id, event.message, resp, dur_time) if __name__ == '__main__': token = "01e71dc0db9523a795691bcdc5f346b834b2138deb7d6591b14af99e78ffe3119001c950623abb1edae46" vk = vk_api.VkApi(token=token) longpoll = VkLongPoll(vk) keyboard = VkKeyboard(one_time=True) keyboard.add_button(u'Ты ошибся...', color=VkKeyboardColor.NEGATIVE) keyboard.add_button(u'Да это я! Похож!', color=VkKeyboardColor.POSITIVE) box = Blackbox(1) for event in longpoll.listen(): if event.type == VkEventType.MESSAGE_NEW and event.to_me: start = time.time() attach_data = event.attachments if attach_data: if len(attach_data) == 2: if attach_data["attach1_type"] == "photo": write_msg(event.user_id, u"Фото принято, обрабатываю...") upload_photo(event.message_id) indxs = box.send_picture("test.jpg") if indxs is None: resp = u"На фото я не вижу лиц." write_msg(event.user_id, resp)
return candidate[0] else: # (N,) ei = acq(torch.Tensor(candidates).unsqueeze(dim=-2)) return torch.Tensor(candidates[ei.argmax()]) if __name__ == '__main__': logging.basicConfig(level=logging.INFO) num_evaluations = 10 Xy_train, X_test, y_test = artificial_task1() blackbox = Blackbox( input_dim=2, output_dim=1, eval_fun=lambda x: x.sum(axis=-1, keepdims=True), ) optimizer = G3P( input_dim=blackbox.input_dim, output_dim=blackbox.output_dim, evaluations_other_tasks=Xy_train, num_gradient_updates=2, ) candidates = X_test for i in range(num_evaluations): x = optimizer.sample(candidates) #x = optimizer.sample()
import psycopg2 import xmltodict from blackbox import Blackbox # Loop which will retrieve all subscribers which haven't # acknowledged message receipt for the day, then send a # message through the shortcode they're associated with. # Setup API credentials api_key = "af23046bff4abfc22ffb21fa57c7a9ee" # Check under Settings->API Keys in Blackbox api_signature = "QeWgu7HTnlE+3nOy4mSvZcyumvC1CFTp53OF7/a0o9jDAkbNwxEyyRQHJCUl3+xqsCF6Og/38fnR+cyugaCaBZoeKQZsSKXYfVJ3lQPNhNBcs7QNUWaHb+z7umdlA/OiwVzFWKtY7pwbOAwErkAXkq3Z+74ZWzFYOCfFxiyKKLk=" # Check under Settings->API Keys in Blackbox # Make API request blackbox = Blackbox(api_key, api_signature) # Instantiate API library print('Establishing database connection...') conn = psycopg2.connect(database="blackbox", user="******", password="******", host="blackbox.c5oicakkxsxn.us-west-2.rds.amazonaws.com", port="5432") print("Database connection established.") conn.set_session(autocommit=True) cur = conn.cursor() # Select subscriber number, shortcode, and keyword from blackbox.subscribers sql = "SELECT DISTINCT subscriber, shortcode, keyword from subscribers where active_subscriber = 'true' and sent_today = 'false';" cur.execute(sql)