def exp_draw():
    config = Config()
    dataloader = DataLoader()
    #read a
    with open(sys.path[0] + "/../a") as a_in:
        aid = a_in.read().split('\n')[0]

    #read
    with open(sys.path[0] + "/../n") as n_in:
        nids = n_in.read().split('\n')

    #nids.remove('None')
    if '' in nids:
        nids.remove('')

    cate_trees = generate_category_tree(dataloader)
    rlt_dist = {1.:[], 0.1:[], 0.01:[], 0.001:[], 0.0001:[]}
    x_axis = ['0%', '20%', '40%', '60%', '80%', '100%']

    fig, axs = plt.subplots(ncols=5)
    sigmas = [1., 0.1, 0.01, 0.001, 0.0001]
    for row, sigma in enumerate(sigmas):
        ax = axs[row]
        data = dataloader.load(vectorized_convertor, pivots = cate_trees, sigma=sigma, valid_uid=[aid] + nids)
        avec = data[0]
        nvecs = data[1:]
        for nv in nvecs:
            rlt_dist[sigma].append(vectorized_dist_calculator(np.array(avec), np.array(nv)))
        print rlt_dist[sigma]
        ax.bar(x_axis, rlt_dist[sigma] + [0.0], width = 0.4)
        for a, b in zip(x_axis, rlt_dist[sigma] + [0.0]):
            ax.text(a, b+0.000000001, '%f'%b, ha='center', va= 'bottom',fontsize=7)
        ax.set_title(str(sigma))
    plt.show()
示例#2
0
    def __init__(self, data_file_name=None, cate_file_name=None, business_file_name=None):
        '''
            load config and category information from processed data
        '''

        #load config
        config = Config().config
        self.data_file_name = config['data_file_name'] if data_file_name is None else data_file_name
        self.cate_file_name = config['cate_file_name'] if cate_file_name is None else cate_file_name
        self.business_file_name = config['business_file_name'] if business_file_name is None else business_file_name

        #load category
        self.cate_parent = {}
        with open(self.cate_file_name) as cate_csv:
            try:
                cate_rec = csv.reader(cate_csv)
                for row in cate_rec:
                    self.cate_parent[row[0]] = row[1]
            except Exception as e:
                raise e
        
        #load business's category info
        with open(self.business_file_name) as businss_cate_f:
            if 'line' in self.business_file_name:
                self.business_cate = {}
                line = businss_cate_f.readline()
                while line!='' and line!='\n':
                    item = json.loads(line)
                    self.business_cate[item['bid']] = item['category']
                    line = businss_cate_f.readline()
            else:
                self.business_cate = json.load(businss_cate_f)
示例#3
0
    def __init__(self, business_file, user_business_file, top_level):
        '''
            init function of LocDataLoader

            @business_file: str, name of business_file
            @user_business_file: str, name of user_business_file
            @top_level: int, state,0 => city,1 => neighborhood,2 => street,3
        '''

        self.config = Config().config
        self.business_file = self.config['processed_data_path'] + business_file
        self.user_business_file = self.config['processed_data_path'] + user_business_file
        self.top_level = top_level

        with open(self.business_file) as business_in:
            self.business = json.load(business_in)
示例#4
0
def merge_config(args_config):
    config_file_path = args_config.config_path
    config_dict = yaml.safe_load(open(config_file_path))
    config = Config(config_dict[args_config.config_name])
    config.update_args(args_config)
    LOGGING.info("=" * 10 + "... Model Configs ..." + "=" * 10)
    LOGGING.info("{}".format(config.to_json_string()))
    bert_config = Config.from_json_file(
        os.path.join(args_config.bert_model, "config.json"))
    LOGGING.info("=" * 10 + "... PRETRAINED Model Configs ..." + "=" * 10)
    LOGGING.info("{}".format(bert_config.to_json_string()))
    return config
    def __init__(self, data_file_name=None, cate_file_name=None, business_file_name=None):
        '''
            load config and category information from processed data
        '''

        #load config
        config = Config().config
        self.data_file_name = config['data_file_name'] if data_file_name is None else data_file_name
        self.cate_file_name = config['cate_file_name'] if cate_file_name is None else cate_file_name
        self.business_file_name = config['business_file_name'] if business_file_name is None else business_file_name

        #load category
        self.cate_parent = {}
        with open(self.cate_file_name) as cate_csv:
            try:
                cate_rec = csv.reader(cate_csv)
                for row in cate_rec:
                    self.cate_parent[row[0]] = row[1]
            except Exception, e:
                raise e
        @dist: float
    '''
    #parameter modified here#
    sigma = config['rbf_sigma']
    return np.exp(-(dist**2) / (2 * (10000**2)))


def latlon_to_3857(lat, lon):
    p1 = Proj(init='epsg:4326')
    p2 = Proj(init='epsg:3857')
    x1, y1 = p1(lon, lat)
    x2, y2 = transform(p1, p2, x1, y1, radians=True)
    return [x2, y2]


config = Config().config
# with open(config['processed_data_path'] + 'lasvegas_user_latlon.json') as latlon_in:
#     user_latlon = json.load(latlon_in)
# with open(config['processed_data_path'] + 'lasvegas_X.json', 'r') as X_in:
#     X = json.load(X_in)
# uids = X['uids']
# X_3857 = []
# for uid in uids:
#     tmp_loc = [ latlon_to_3857(loc[0], loc[1]) for loc in user_latlon[uid] ]
#     X_3857.append(tmp_loc)
# X['user_3857_all'] = X_3857
# with open(config['processed_data_path'] + 'lasvegas_X.json', 'w') as X_out:
#     json.dump(X,X_out)

#load data
with open(config['processed_data_path'] + 'lasvegas_X.json', 'r') as X_in:
 def setUp(self):
     self.data_loader = DataLoader()
     self.data = self.data_loader.load(bottomup_edit_dist_converter)
     config = Config().config
     self.data_file_name = config['data_file_name']
     self.cate_file_name = config['cate_file_name']
 def __init__(self):
     self.__config = Config().config
示例#9
0
def merge_config(args_config):
    config_file_path = args_config.config_path 
    config_dict = yaml.safe_load(open(config_file_path))
    config = Config(config_dict[args_config.config_name])
    config.update_args(args_config)
    return config