def main(): parser = arguments.parser( 'Feed Unbound zone information via the control interface') factory = arguments.Arguments(parser) try: factory.read_env() factory.read_argv() factory.read_stdin() except Exception as err: print(err) sys.exit(1) registry = prometheus_client.core.REGISTRY control = factory.control_client() provider = factory.provider() spoon = feeder.Feeder(control, provider) log_level = logging.INFO if factory.quiet: log_level = logging.WARNING elif factory.verbose: log_level = logging.DEBUG logging.basicConfig(format='%(message)s', level=log_level) provider.enable_logger() spoon.enable_logger() if factory.metrics: spoon.enable_metrics(registry) prometheus_client.start_http_server(factory.metrics_port, factory.metrics_bind, registry) schedule_job(spoon, factory.zone_type, factory.day, factory.time, factory.instant)
import numpy as np import random import arguments # arguments args = arguments.parser() lr = args.lr # learning rate y = args.y # discount factor e = args.e # e-greedy factor n_episodes = args.r # episode number (round) n_steps = args.s # step number print("> Setting:", args) class Agent: def __init__(self, n_actions, world_size): self.n_actions = n_actions self.Q_table = np.zeros([world_size, self.n_actions]) self.size = int(np.sqrt(world_size)) self.lr = lr self.y = y self._e0 = e self.e = self._e0 self._noise = 1.0 self.noise = self._noise def _flatten(self, cord): return cord[0] * self.size + cord[1]
matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib import style style.use('ggplot') from gym import spaces import sys import os from arguments import parser, print_args import pdb from functions import OUNoise, NormalizedEnv, Memory, Critic, Actor, DDPGagent, make_env, graph_reward, penalties, velocity, shape_rew, step_jor, reward_first, get_observation, shape_reward_s, step_s from functions import MyProstheticsEnv import time cuda = True if torch.cuda.is_available() else False args = parser() print_args(args) #env = make_env(test=args.mode_test,render=args.render_environment) env = MyProstheticsEnv(integrator_accuracy=1e-4) env.seed() #env = NormalizedEnv(env) obs_size = np.asarray(env.observation_space.shape).prod() #action_size = np.asarray(action_space.shape).prod() agent = DDPGagent(env) noise = OUNoise(env.action_space) batch_size = args.minibatch_size rewards = [] avg_rewards = [] best_reward = -10000
from sklearn.metrics import roc_auc_score from sklearn.metrics import mean_squared_error from scipy import stats import torch import torch.nn as nn from torch.utils.data import DataLoader import arguments import utils from dataset import MolDataset from dataset import DTISampler from dataset import tensor_collate_fn import model random.seed(0) args = arguments.parser(sys.argv) print(args) # Read labels with open(args.filename) as f: lines = f.readlines() lines = [l.split() for l in lines] id_to_y = {l[0]: float(l[1]) for l in lines} with open(args.key_dir + "/test_keys.pkl", "rb") as f: test_keys = pickle.load(f) # Model cmd = utils.set_cuda_visible_device(args.ngpu) os.environ["CUDA_VISIBLE_DEVICES"] = cmd[:-1] if args.potential == "morse":
def test_no_dir(capsys): with pytest.raises(SystemExit): arguments.parser([]) out, err = capsys.readouterr() assert "error: the following arguments are required: -d/--directory" in err
def test_bitrate_string(capsys): with pytest.raises(SystemExit): arguments.parser(["-d", "~/Videos/", "-b", "notanint"]) out, err = capsys.readouterr() assert "error: argument -b/--bitrate: invalid int value: 'notanint'" in err
def test_bitrate_set(): args = arguments.parser(["-d", "~/Videos/", "-b", "{}".format(int(DEFAULT_BITRATE / 2))]) assert args.bitrate == int(DEFAULT_BITRATE / 2)
def test_bitrate_default(): args = arguments.parser(["-d", "~/Videos/"]) assert args.bitrate == DEFAULT_BITRATE
def test_codec_wrong_choice(capsys): with pytest.raises(SystemExit): arguments.parser(["-d", "~/Videos/", "-c", "notacodec"]) out, err = capsys.readouterr() assert "error: argument -c/--codec: invalid choice: 'notacodec' (choose from" in err
def test_codec_h264(): args = arguments.parser(["-d", "~/Videos/", "-c", "h264"]) assert args.videocodec == "h264"
def test_codec_default(): args = arguments.parser(["-d", "~/Videos/"]) assert args.videocodec == "hevc"
def test_single_dir(): args = arguments.parser(["-d", "~/Videos/"]) assert args.paths == ["~/Videos/"]
def main(): args = parser() print("=" * 20) print("Experiment parameters:") for arg in vars(args): print(arg, getattr(args, arg)) print("=" * 20) src_repr_path = os.path.join(args.output_path, f"{args.src_repr_model}_{args.src_name}.csv") dst_repr_path = os.path.join(args.output_path, f"{args.dst_repr_model}_{args.dst_name}.csv") if args.src_repr_model == args.dst_repr_model: if args.src_repr_model == "BOW": print("Generating BOW representations for source and destination") BOW.generate_BOW_vectors_two_taxonomies(args.src_problems_path, args.dst_problems_path, src_repr_path, dst_repr_path) results = evaluate.evaluate(src_repr_path, dst_repr_path, args.labels_path, args.recall_at_5, args.mrr) elif args.src_repr_model == "TFIDF": print( "Generating TFIDF representations for source and destination") TFIDF.generate_TFIDF_vectors_two_taxonomies( args.src_problems_path, args.dst_problems_path, src_repr_path, dst_repr_path) results = evaluate.evaluate(src_repr_path, dst_repr_path, args.labels_path, args.recall_at_5, args.mrr) elif args.src_repr_model == "content2vec": print( "Generating content2vec representations for source and destination" ) content2vec.generate_content2vec_vectors_two_taxonomies( args.src_problems_path, args.dst_problems_path, src_repr_path, dst_repr_path, args.content2vec_size, args.content2vec_window, args.content2vec_min_count) results = evaluate.evaluate(src_repr_path, dst_repr_path, args.labels_path, args.recall_at_5, args.mrr) elif args.src_repr_model == "skill2vec": print( "Generating skill2vec representations for source and destination" ) skill2vec.generate_skill2vec_vectors_two_taxonomies( args.src_sequences_path, args.src_skill2id_path, src_repr_path, args.src_skill2vec_size, args.src_skill2vec_window, args.dst_sequences_path, args.dst_skill2id_path, dst_repr_path, args.dst_skill2vec_size, args.dst_skill2vec_window) print("Learning skill translation") training_labels_path, test_labels_path = translate.split_labels( args.labels_path) src_translated_path = translate.generate_translated_source_vectors( src_repr_path, dst_repr_path, training_labels_path, args.device, args.num_epochs, args.val_ratio, args.max_val_non_decreasing_epochs, args.verbose) results = evaluate.evaluate(src_translated_path, dst_repr_path, test_labels_path, args.recall_at_5, args.mrr) elif args.src_repr_model == "content2vec_skill2vec": src_content2vec_path = os.path.join( args.output_path, f"content2vec_{args.src_name}.csv") src_skill2vec_path = os.path.join( args.output_path, f"skill2vec_{args.src_name}.csv") dst_content2vec_path = os.path.join( args.output_path, f"content2vec_{args.dst_name}.csv") dst_skill2vec_path = os.path.join( args.output_path, f"skill2vec_{args.dst_name}.csv") print( "Generating content2vec representations for source and destination" ) content2vec.generate_content2vec_vectors_two_taxonomies( args.src_problems_path, args.dst_problems_path, src_content2vec_path, dst_content2vec_path, args.content2vec_size, args.content2vec_window, args.content2vec_min_count) print( "Generating skill2vec representations for source and destination" ) skill2vec.generate_skill2vec_vectors_two_taxonomies( args.src_sequences_path, args.src_skill2id_path, src_skill2vec_path, args.src_skill2vec_size, args.src_skill2vec_window, args.dst_sequences_path, args.dst_skill2id_path, dst_skill2vec_path, args.dst_skill2vec_size, args.dst_skill2vec_window) print("Learning skill translation") training_labels_path, test_labels_path = translate.split_labels( args.labels_path) src_translated_path = translate.generate_translated_source_vectors( src_skill2vec_path, dst_skill2vec_path, training_labels_path, args.device, args.num_epochs, args.val_ratio, args.max_val_non_decreasing_epochs, args.verbose) print( "Combining content2vec and skill2vec representations for source and destination" ) content2vec_skill2vec.combine_content2vec_and_skill2vec_two_taxonomies( src_content2vec_path, src_translated_path, src_repr_path, dst_content2vec_path, dst_skill2vec_path, dst_repr_path) results = evaluate.evaluate(src_repr_path, dst_repr_path, test_labels_path, args.recall_at_5, args.mrr) elif args.src_repr_model == "TAMF": src_content2vec_path = os.path.join( args.output_path, f"content2vec_{args.src_name}.csv") dst_content2vec_path = os.path.join( args.output_path, f"content2vec_{args.dst_name}.csv") print( "Generating content2vec representations for source and destination" ) content2vec.generate_content2vec_vectors_two_taxonomies( args.src_problems_path, args.dst_problems_path, src_content2vec_path, dst_content2vec_path, args.content2vec_size, args.content2vec_window, args.content2vec_min_count) print("Generating TAMF representations for source and destination") TAMF.generate_TAMF_vectors_two_taxonomies( args.src_sequences_path, args.src_skill2id_path, src_content2vec_path, src_repr_path, args.src_TAMF_k, args.src_TAMF_lambda, args.dst_sequences_path, args.dst_skill2id_path, dst_content2vec_path, dst_repr_path, args.dst_TAMF_k, args.dst_TAMF_lambda) print("Learning skill translation") training_labels_path, test_labels_path = translate.split_labels( args.labels_path) src_translated_path = translate.generate_translated_source_vectors( src_repr_path, dst_repr_path, training_labels_path, args.device, args.num_epochs, args.val_ratio, args.max_val_non_decreasing_epochs, args.verbose) results = evaluate.evaluate(src_translated_path, dst_repr_path, test_labels_path, args.recall_at_5, args.mrr) elif args.src_repr_model != args.dst_repr_model: ## Source if args.src_repr_model == "BOW": print("Generating BOW representations for source") BOW.generate_BOW_vectors_one_taxonomy(args.src_problems_path, src_repr_path) elif args.src_repr_model == "TFIDF": print("Generating TFIDF representations for source") TFIDF.generate_TFIDF_vectors_one_taxonomy(args.src_problems_path, src_repr_path) elif args.src_repr_model == "content2vec": print("Generating content2vec representations for source") content2vec.generate_content2vec_vectors_one_taxonomy( args.src_problems_path, src_repr_path, args.src_content2vec_size, args.src_content2vec_window, args.src_content2vec_min_count) elif args.src_repr_model == "skill2vec": print("Generating skill2vec representations for source") skill2vec.generate_skill2vec_vectors_one_taxonomy( args.src_sequences_path, args.src_skill2id_path, src_repr_path, args.src_skill2vec_size, args.src_skill2vec_window) elif args.src_repr_model == "content2vec_skill2vec": src_content2vec_path = os.path.join( args.output_path, f"content2vec_{args.src_name}.csv") src_skill2vec_path = os.path.join( args.output_path, f"skill2vec_{args.src_name}.csv") print("Generating content2vec representations for source") content2vec.generate_content2vec_vectors_one_taxonomy( args.src_problems_path, src_content2vec_path, args.src_content2vec_size, args.src_content2vec_window, args.src_content2vec_min_count) print("Generating skill2vec representations for source") skill2vec.generate_skill2vec_vectors_one_taxonomy( args.src_sequences_path, args.src_skill2id_path, src_skill2vec_path, args.src_skill2vec_size, args.src_skill2vec_window) print( "Combining content2vec and skill2vec representations for source" ) content2vec_skill2vec.combine_content2vec_and_skill2vec_one_taxonomy( src_content2vec_path, src_skill2vec_path, src_repr_path) elif args.src_repr_model == "TAMF": src_content2vec_path = os.path.join( args.output_path, f"content2vec_{args.src_name}.csv") print("Generating content2vec representations for source") content2vec.generate_content2vec_vectors_one_taxonomy( args.src_problems_path, src_content2vec_path, args.src_content2vec_size, args.src_content2vec_window, args.src_content2vec_min_count) print("Generating TAMF representations for source") TAMF.generate_TAMF_vectors_one_taxonomy(args.src_sequences_path, args.src_skill2id_path, src_content2vec_path, src_repr_path, args.src_TAMF_k, args.src_TAMF_lambda) ## Destination if args.dst_repr_model == "BOW": print("Generating BOW representations for destination") BOW.generate_BOW_vectors_one_taxonomy(args.dst_problems_path, dst_repr_path) elif args.dst_repr_model == "TFIDF": print("Generating TFIDF representations for destination") TFIDF.generate_TFIDF_vectors_one_taxonomy(args.dst_problems_path, dst_repr_path) elif args.dst_repr_model == "content2vec": print("Generating content2vec representations for destination") content2vec.generate_content2vec_vectors_one_taxonomy( args.dst_problems_path, dst_repr_path, args.dst_content2vec_size, args.dst_content2vec_window, args.dst_content2vec_min_count) elif args.dst_repr_model == "skill2vec": print("Generating skill2vec representations for destination") skill2vec.generate_skill2vec_vectors_one_taxonomy( args.dst_sequences_path, args.dst_skill2id_path, dst_repr_path, args.dst_skill2vec_size, args.dst_skill2vec_window) elif args.dst_repr_model == "content2vec_skill2vec": dst_content2vec_path = os.path.join( args.output_path, f"content2vec_{args.dst_name}.csv") dst_skill2vec_path = os.path.join( args.output_path, f"skill2vec_{args.dst_name}.csv") print("Generating content2vec representations for destination") content2vec.generate_content2vec_vectors_one_taxonomy( args.dst_problems_path, dst_content2vec_path, args.dst_content2vec_size, args.dst_content2vec_window, args.dst_content2vec_min_count) print("Generating skill2vec representations for destination") skill2vec.generate_skill2vec_vectors_one_taxonomy( args.dst_sequences_path, args.dst_skill2id_path, dst_skill2vec_path, args.dst_skill2vec_size, args.dst_skill2vec_window) print( "Combining content2vec and skill2vec representations for destination" ) content2vec_skill2vec.combine_content2vec_and_skill2vec_one_taxonomy( dst_content2vec_path, dst_skill2vec_path, dst_repr_path) elif args.dst_repr_model == "TAMF": dst_content2vec_path = os.path.join( args.output_path, f"content2vec_{args.dst_name}.csv") print("Generating content2vec representations for destination") content2vec.generate_content2vec_vectors_one_taxonomy( args.dst_problems_path, dst_content2vec_path, args.dst_content2vec_size, args.dst_content2vec_window, args.dst_content2vec_min_count) print("Generating TAMF representations for destination") TAMF.generate_TAMF_vectors_one_taxonomy(args.dst_sequences_path, args.dst_skill2id_path, dst_content2vec_path, dst_repr_path, args.dst_TAMF_k, args.dst_TAMF_lambda) print("Learning skill translation") training_labels_path, test_labels_path = translate.split_labels( args.labels_path) src_translated_path = translate.generate_translated_source_vectors( src_repr_path, dst_repr_path, training_labels_path, args.device, args.num_epochs, args.val_ratio, args.max_val_non_decreasing_epochs, args.verbose) results = evaluate.evaluate(src_translated_path, dst_repr_path, test_labels_path, args.recall_at_5, args.mrr) print("=" * 20) print(f"results {results}") json.dump(results, open(os.path.join(args.output_path, "results.json"), "w"))