当前位置: 首页>>代码示例>>Python>>正文


Python GeneralMethods.get_method_id方法代码示例

本文整理汇总了Python中library.classes.GeneralMethods.get_method_id方法的典型用法代码示例。如果您正苦于以下问题:Python GeneralMethods.get_method_id方法的具体用法?Python GeneralMethods.get_method_id怎么用?Python GeneralMethods.get_method_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在library.classes.GeneralMethods的用法示例。


在下文中一共展示了GeneralMethods.get_method_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: content_affinity_vs_distance

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def content_affinity_vs_distance():
        output_file = fld_data_analysis_results%GeneralMethods.get_method_id() + '.png'
        DataAnalysis._plot_affinities('similarity')
        plt.xlabel('Distance (miles)')
        plt.ylabel('Hashtags sharing similarity')
#        plt.show()
        savefig(output_file)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:9,代码来源:plots_nov_12.py

示例2: iid_vs_cumulative_distribution_and_peak_distribution

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def iid_vs_cumulative_distribution_and_peak_distribution():
        TIME_UNIT_IN_SECONDS = 10.*60.
        output_file_format = fld_data_analysis_results%GeneralMethods.get_method_id()+'/%s.png'
        ltuo_iid_and_interval_stats = [data for data in 
                                        FileIO.iterateJsonFromFile(f_iid_spatial_metrics, remove_params_dict=True)]
        ltuo_s_iid_and_interval_stats = sorted(ltuo_iid_and_interval_stats, key=itemgetter(0))
        ltuo_s_iid_and_tuo_is_peak_and_cumulative_percentage_of_occurrences = [(data[0], (data[1][0], data[1][2])) for data in ltuo_s_iid_and_interval_stats]
        total_peaks = sum([data[1][0] for data in ltuo_s_iid_and_tuo_is_peak_and_cumulative_percentage_of_occurrences])+0.0
        x_iids = []
        y_is_peaks = []
        z_cumulative_percentage_of_occurrencess = []
        for (iid, (is_peak, cumulative_percentage_of_occurrences)) in ltuo_s_iid_and_tuo_is_peak_and_cumulative_percentage_of_occurrences[:100]: 
            print (iid, (is_peak, cumulative_percentage_of_occurrences)) 
            x_iids.append((iid+1)*TIME_UNIT_IN_SECONDS/60)
            y_is_peaks.append(is_peak/total_peaks)
            z_cumulative_percentage_of_occurrencess.append(cumulative_percentage_of_occurrences)
        plt.figure(num=None, figsize=(4.3,3))
        plt.subplots_adjust(bottom=0.2, top=0.9, wspace=0, hspace=0)
        plt.plot(x_iids, y_is_peaks, marker='o', c='k')
        plt.ylabel('Distribution of hashtags')
        plt.xlabel('Hashtag peak (minutes)')
        plt.grid(True)
        plt.xlim(xmax=600)
        savefig(output_file_format%'peaks')
        plt.clf()
        plt.figure(num=None, figsize=(6,3))
        plt.subplots_adjust(bottom=0.2, top=0.9, wspace=0, hspace=0)
        plt.plot(x_iids, z_cumulative_percentage_of_occurrencess, lw=0, marker='o', c='k')
#        plt.xlabel('Minutes')
        plt.ylabel('CDF of occurrences')
        plt.xlabel('Time (Minutes)')
        plt.grid(True)
        plt.xlim(xmax=600)
        savefig(output_file_format%'cdf_occurrences_peak')
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:36,代码来源:plots_nov_12.py

示例3: ef_plot

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
 def ef_plot():
     output_file = fld_data_analysis_results%GeneralMethods.get_method_id()+'.png'
     data = [d for d in FileIO.iterateJsonFromFile(f_hashtag_spatial_metrics, remove_params_dict=True)]
     ltuo_hashtag_and_entropy_and_focus = map(itemgetter('hashtag', 'entropy', 'focus'), data)
     mf_norm_focus_to_entropies = defaultdict(list)
     for _, entropy, (_, focus) in ltuo_hashtag_and_entropy_and_focus:
         mf_norm_focus_to_entropies[round(focus, 2)].append(entropy)
     plt.figure(num=None, figsize=(6,3))
     x_focus, y_entropy = zip(*[(norm_focus, np.mean(entropies))
                                 for norm_focus, entropies in mf_norm_focus_to_entropies.iteritems()
                                 if len(entropies)>0])
     plt.subplots_adjust(bottom=0.2, top=0.9, wspace=0, hspace=0)
     plt.scatter(x_focus, y_entropy, s=50, lw=0, c='k')
     plt.xlim(xmin=-0.1, xmax=1.1)
     plt.ylim(ymin=-1, ymax=9)
     plt.xlabel('Mean hashtag focus')
     plt.ylabel('Mean hashtag entropy')
     plt.grid(True)
     savefig(output_file)
     ltuo_hashtag_and_r_entropy_and_focus =\
                                         sorted(ltuo_hashtag_and_entropy_and_focus, key=itemgetter(1), reverse=True)
     ltuo_hashtag_and_r_entropy_and_s_focus = sorted(ltuo_hashtag_and_r_entropy_and_focus, key=itemgetter(2))
     hashtags = zip(*ltuo_hashtag_and_r_entropy_and_s_focus)[0]
     print list(hashtags[:20])
     print list(reversed(hashtags))[:20]
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:27,代码来源:plots_nov_12.py

示例4: temporal_affinity_vs_distance

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def temporal_affinity_vs_distance():
        output_file = fld_data_analysis_results%GeneralMethods.get_method_id() + '.png'
        DataAnalysis._plot_affinities('adoption_lag')
        plt.xlabel('Distance (miles)')
        plt.ylabel('Hashtag adoption lag (hours)')
#        plt.show()
        savefig(output_file)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:9,代码来源:plots_nov_12.py

示例5: generate_data_for_significant_nei_utm_ids

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def generate_data_for_significant_nei_utm_ids():
        output_file = GeneralMethods.get_method_id()+'.json'
        so_hashtags, mf_utm_id_to_valid_nei_utm_ids = set(), {}
        for utm_object in \
                FileIO.iterateJsonFromFile(f_hashtags_by_utm_id, True):
            for hashtag, count in utm_object['mf_hashtag_to_count'].iteritems():
                if hashtag!='total_num_of_occurrences': so_hashtags.add(hashtag)
            mf_utm_id_to_valid_nei_utm_ids[utm_object['utm_id']] =\
                                                            utm_object['mf_nei_utm_id_to_common_h_count'].keys()
        hashtags = sorted(list(so_hashtags))
        mf_utm_id_to_vector = {}
        for utm_object in FileIO.iterateJsonFromFile(f_hashtags_by_utm_id, True):
#                print i, utm_object['utm_id']
            utm_id_vector =  map(lambda hashtag: utm_object['mf_hashtag_to_count'].get(hashtag, 0.0),
                                 hashtags)
            mf_utm_id_to_vector[utm_object['utm_id']] = robjects.FloatVector(utm_id_vector)
        for i, (utm_id, vector) in enumerate(mf_utm_id_to_vector.iteritems()):
            print '%s of %s'%(i+1, len(mf_utm_id_to_vector))
            ltuo_utm_id_and_vector = [(utm_id, vector)]
            for valid_nei_utm_id in mf_utm_id_to_valid_nei_utm_ids[utm_id]:
                if valid_nei_utm_id in mf_utm_id_to_vector and valid_nei_utm_id!=utm_id:
                    ltuo_utm_id_and_vector.append((valid_nei_utm_id, mf_utm_id_to_vector[valid_nei_utm_id]))
            od = rlc.OrdDict(sorted(ltuo_utm_id_and_vector, key=itemgetter(0)))
            df_utm_vectors = robjects.DataFrame(od)
            df_utm_vectors_json = R_Helper.get_json_for_data_frame(df_utm_vectors)
            dfm_dict = cjson.decode(df_utm_vectors_json)
            mf_utm_ids_to_utm_colnames = dict(zip(zip(*ltuo_utm_id_and_vector)[0], df_utm_vectors.colnames))
            utm_id_colname = mf_utm_ids_to_utm_colnames[utm_id]
            dfm_dict['prediction_variable'] = utm_id_colname
            dfm_dict['predictor_variables'] = filter(lambda colname: colname!=utm_id_colname,
                                                     df_utm_vectors.colnames)
            dfm_dict['mf_utm_colnames_to_utm_ids'] = dict(zip(df_utm_vectors.colnames, zip(*ltuo_utm_id_and_vector)[0]))
            FileIO.writeToFileAsJson(dfm_dict, output_file)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:35,代码来源:analysis.py

示例6: significant_nei_utm_ids

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
 def significant_nei_utm_ids():
     output_folder = fld_google_drive_data_analysis%GeneralMethods.get_method_id()+'/%s.png'
     for i, data in enumerate(FileIO.iterateJsonFromFile(f_significant_nei_utm_ids, remove_params_dict=True)):
         utm_lat_long = UTMConverter.getLatLongUTMIdInLatLongForm(data['utm_id'])
         nei_utm_lat_longs = map(
                           lambda nei_utm_id: UTMConverter.getLatLongUTMIdInLatLongForm(nei_utm_id),
                           data['nei_utm_ids']
                         )
         if nei_utm_lat_longs:
             output_file = output_folder%('%s_%s'%(utm_lat_long))
             plotPointsOnWorldMap(nei_utm_lat_longs,
                                  blueMarble=False,
                                  bkcolor='#CFCFCF',
                                  lw = 0,
                                  color = '#EA00FF',
                                  alpha=1.)
             _, m = plotPointsOnWorldMap([utm_lat_long],
                                  blueMarble=False,
                                  bkcolor='#CFCFCF',
                                  lw = 0,
                                  color = '#2BFF00',
                                  s = 40,
                                  returnBaseMapObject=True,
                                  alpha=1.)
             for nei_utm_lat_long in nei_utm_lat_longs:
                 m.drawgreatcircle(utm_lat_long[1],
                                   utm_lat_long[0],
                                   nei_utm_lat_long[1],
                                   nei_utm_lat_long[0],
                                   color='#FFA600',
                                   lw=1.5,
                                   alpha=1.0)
             print 'Saving %s'%(i+1)
             savefig(output_file)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:36,代码来源:plots.py

示例7: spatial_metrics_cdf

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
 def spatial_metrics_cdf():
     output_file_format = fld_data_analysis_results%GeneralMethods.get_method_id()+'/%s.png'
     def plot_graph(locality_measures, id):
         mf_apprx_to_count = defaultdict(float)
         for measure in locality_measures:
             mf_apprx_to_count[round(measure,3)]+=1
         total_hashtags = sum(mf_apprx_to_count.values())
         current_val = 0.0
         x_measure, y_distribution = [], []
         for apprx, count in sorted(mf_apprx_to_count.iteritems(), key=itemgetter(0)):
             current_val+=count
             x_measure.append(apprx)
             y_distribution.append(current_val/total_hashtags)
         plt.figure(num=None, figsize=(4.3,3))
         plt.subplots_adjust(bottom=0.2, top=0.9, left=0.15, wspace=0)
         plt.scatter(x_measure, y_distribution, lw=0, marker='o', c='k', s=25)
         plt.ylim(ymax=1.2)
         if id!='Coverage': plt.xlabel('%s'%id)
         else: plt.xlabel('%s (miles)'%id)
         plt.ylabel('CDF')
         plt.grid(True)
         savefig(output_file_format%('cdf_'+id))
     def plot_coverage(locality_measures, id):
         mf_apprx_to_count = defaultdict(float)
         for measure in locality_measures:
             mf_apprx_to_count[round(measure,3)]+=1
         total_hashtags = sum(mf_apprx_to_count.values())
         current_val = 0.0
         x_measure, y_distribution = [], []
         for apprx, count in sorted(mf_apprx_to_count.iteritems(), key=itemgetter(0)):
             current_val+=count
             x_measure.append(apprx)
             y_distribution.append(current_val/total_hashtags)
         plt.figure(num=None, figsize=(4.3,3))
         ax = plt.subplot(111)
         ax.set_xscale('log')
         plt.subplots_adjust(bottom=0.2, top=0.9, left=0.15, wspace=0)
         plt.scatter(x_measure, y_distribution, lw=0, marker='o', c='k', s=25)
         plt.ylim(ymax=1.2)
         if id!='Coverage': plt.xlabel('%s'%id)
         else: plt.xlabel('Spread (miles)')
         plt.ylabel('CDF')
         plt.xlim(xmin=1.)
         plt.grid(True)
         savefig(output_file_format%('cdf_'+id))
     data = [d for d in FileIO.iterateJsonFromFile(f_hashtag_spatial_metrics, remove_params_dict=True)]
     focuses = map(itemgetter(1), map(itemgetter('focus'), data))
     entropies = map(itemgetter('entropy'), data)
     coverages = map(itemgetter('spread'), data)
     print 'Mean entropy: ', np.mean(entropies)
     print 'Mean focus: ', np.mean(focuses)
     print 'Median entropy: ', np.median(entropies)
     print 'Median focus: ', np.median(focuses)
     plot_graph(focuses, 'Focus')
     plot_graph(entropies, 'Entropy')
     plot_coverage(coverages, 'Spread')
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:58,代码来源:plots_nov_12.py

示例8: hashtag_groups_dot_files

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
 def hashtag_groups_dot_files(association_measure_file=f_fisher_exact_association_measure):
     output_file_format = fld_google_drive_data_analysis%GeneralMethods.get_method_id()+\
                                                         '/'+association_measure_file.split('/')[-1]+'/%s.dot'
     for line_no, data in\
             enumerate(FileIO.iterateJsonFromFile(association_measure_file, remove_params_dict=True)):
         _, _, edges = data
         graph = nx.Graph()
         for edge in edges: 
             u,v,attr_dict = edge
             u = unicode(u).encode('utf-8')
             v = unicode(v).encode('utf-8')
             graph.add_edge(u,v, attr_dict)
         output_file = output_file_format%line_no
         print 'Writing file: ', output_file
         FileIO.createDirectoryForFile(output_file)
         nx.write_dot(graph, output_file)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:18,代码来源:analysis.py

示例9: top_k_locations_on_world_map

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def top_k_locations_on_world_map():
        output_file = fld_data_analysis_results%GeneralMethods.get_method_id() + '.png'
        ltuo_location_and_occurrence_count = []
        for location_object in\
                FileIO.iterateJsonFromFile(f_dense_hashtag_distribution_in_locations, remove_params_dict=True):
            ltuo_location_and_occurrence_count.append([
                                                      location_object['location'],
                                                      location_object['occurrences_count']
                                                    ])
        ltuo_lid_and_r_occurrence_count = sorted(ltuo_location_and_occurrence_count, key=itemgetter(1), reverse=True)
#        for i, d in enumerate(ltuo_lid_and_r_occurrence_count):
#            print i, d
#        exit()
        lids = zip(*ltuo_lid_and_r_occurrence_count)[0][:200]
        points = map(UTMConverter.getLatLongUTMIdInLatLongForm, lids)
        plotPointsOnWorldMap(points, blueMarble=False, bkcolor='#CFCFCF', c='m',  lw = 0, alpha=1.)
        savefig(output_file)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:19,代码来源:plots_nov_12.py

示例10: peak_stats

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def peak_stats():
        TIME_UNIT_IN_SECONDS = 10.*60.
        output_file_format = fld_data_analysis_results%GeneralMethods.get_method_id()+'/%s.png'
        data = [d for d in FileIO.iterateJsonFromFile(f_hashtag_spatial_metrics, remove_params_dict=True)]
        peaks = map(itemgetter('peak_iid'), data)
        peaks = filter(lambda i: i<288, peaks)
        ltuo_peak_and_count = [(peak, len(list(ito_peaks)))
                            for peak, ito_peaks in groupby(sorted(peaks))
                            ]
        ltuo_s_peak_and_count = sorted(ltuo_peak_and_count, key=itemgetter(0))        
        current_count = 0.0
        total_count = len(peaks)+0.
        print total_count
        ltuo_peak_and_cdf = []
        for peak, count, in ltuo_s_peak_and_count:
            current_count+=count
            ltuo_peak_and_cdf.append([(peak+1)*TIME_UNIT_IN_SECONDS/(60.), current_count/total_count ])
        x_peaks, y_cdf = zip(*ltuo_peak_and_cdf)
        plt.figure(num=None, figsize=(4.3,3))
        ax=plt.subplot(111)
        ax.set_xscale('log')
        plt.subplots_adjust(bottom=0.2, top=0.9, left=0.15)
        plt.scatter(x_peaks, y_cdf, c='k', s=50, lw=0)
        plt.xlabel('Time (minutes)')
        plt.ylabel('CDF')
        plt.xlim(xmin=5.)
        plt.grid(True)
#        plt.show()             
        savefig(output_file_format%'peak_cdf')
        plt.clf()
        
#        plt.figure(num=None, figsize=(4.3,3))
        ax=plt.subplot(111)
        ax.set_xscale('log')
        ax.set_yscale('log')
        x_peaks, y_counts = zip(*ltuo_s_peak_and_count)
        x_peaks = [(peak+1)*TIME_UNIT_IN_SECONDS/(60.) for peak in x_peaks]
        y_counts = [count/total_count for count in y_counts]
        plt.scatter(x_peaks, y_counts, c='k', s=50, lw=0)
        plt.xlabel('Time (minutes)')
        plt.ylabel('Distribution of hashtags')
        plt.xlim(xmin=5)
        plt.ylim(ymax=1., ymin=0.00005)
        plt.grid(True)
        savefig(output_file_format%'peak_dist')
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:47,代码来源:plots_nov_12.py

示例11: significant_nei_utm_ids

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def significant_nei_utm_ids():
        mf_utm_id_to_valid_nei_utm_ids = {}
        def get_utm_vectors():
            so_hashtags = set()
            for utm_object in \
                    FileIO.iterateJsonFromFile(f_hashtags_by_utm_id, True):
                for hashtag, count in utm_object['mf_hashtag_to_count'].iteritems():
                    if hashtag!='total_num_of_occurrences': so_hashtags.add(hashtag)
                mf_utm_id_to_valid_nei_utm_ids[utm_object['utm_id']] =\
                                                                utm_object['mf_nei_utm_id_to_common_h_count'].keys()
            hashtags, ltuo_utm_id_and_vector = sorted(list(so_hashtags)), []
            for i, utm_object in enumerate(FileIO.iterateJsonFromFile(f_hashtags_by_utm_id, True)):
#                print i, utm_object['utm_id']
                utm_id_vector =  map(lambda hashtag: utm_object['mf_hashtag_to_count'].get(hashtag, 0.0),
                                     hashtags)
                ltuo_utm_id_and_vector.append((utm_object['utm_id'], 
                                               robjects.FloatVector(utm_id_vector)))
            od = rlc.OrdDict(sorted(ltuo_utm_id_and_vector, key=itemgetter(0)))
            df_utm_vectors = robjects.DataFrame(od)
            return df_utm_vectors
        output_file = fld_google_drive_data_analysis%GeneralMethods.get_method_id()
        df_utm_vectors = get_utm_vectors()
#        print df_utm_vectors.nrow
#        exit()
        utm_colnames = df_utm_vectors.colnames
        mf_utm_id_to_utm_colnames = dict(zip(sorted(mf_utm_id_to_valid_nei_utm_ids), utm_colnames))
        mf_utm_colnames_to_utm_id = dict(zip(utm_colnames, sorted(mf_utm_id_to_valid_nei_utm_ids)))
        for i, utm_colname in enumerate(utm_colnames):
            utm_id = mf_utm_colnames_to_utm_id[utm_colname]
            prediction_variable = utm_colname
            print i, utm_id
            predictor_variables = [mf_utm_id_to_utm_colnames[valid_nei_utm_ids]
                                    for valid_nei_utm_ids in mf_utm_id_to_valid_nei_utm_ids[utm_id]
                                        if valid_nei_utm_ids in mf_utm_id_to_utm_colnames and
                                           valid_nei_utm_ids != utm_id ]
            selected_utm_colnames =  R_Helper.variable_selection_using_backward_elimination(
                                                                                               df_utm_vectors,
                                                                                               prediction_variable,
                                                                                               predictor_variables,
                                                                                               debug=True
                                                                                            )
            nei_utm_ids = [mf_utm_colnames_to_utm_id[selected_utm_colname]
                                for selected_utm_colname in selected_utm_colnames]
            print 'Writing to: ', output_file
            FileIO.writeToFileAsJson({'utm_id': utm_id, 'nei_utm_ids': nei_utm_ids}, output_file)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:47,代码来源:analysis.py

示例12: plot_global_influencers

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def plot_global_influencers(ltuo_model_id_and_hashtag_tag):
        tuples_of_boundary_and_boundary_label = [
                ([[-90,-180], [90, 180]], 'World', 'm'),
            ]
        for model_id, hashtag_tag in ltuo_model_id_and_hashtag_tag:
            print model_id, hashtag_tag
            tuples_of_location_and_color = []
            for boundary, boundary_label, boundary_color in tuples_of_boundary_and_boundary_label:
                tuo_location_and_influence_scores = Experiments.load_tuo_location_and_boundary_influence_score(model_id, hashtag_tag, boundary)
                tuo_location_and_influence_scores = sorted(tuo_location_and_influence_scores, key=itemgetter(1))[:10]
                locations = zip(*tuo_location_and_influence_scores)[0]
                for location in locations: tuples_of_location_and_color.append([getLocationFromLid(location.replace('_', ' ')), boundary_color])
            locations, colors = zip(*tuples_of_location_and_color)
            plotPointsOnWorldMap(locations, blueMarble=False, bkcolor='#CFCFCF', c=colors,  lw = 0, alpha=1.)
            for _, boundary_label, boundary_color in tuples_of_boundary_and_boundary_label: plt.scatter([0], [0], label=boundary_label, c=boundary_color, lw = 0)
#            plt.legend(loc=3, ncol=4, mode="expand",)
#            plt.show()
            savefig(fld_results%(GeneralMethods.get_method_id()) +'%s_%s.png'%(model_id, hashtag_tag))
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:20,代码来源:plots.py

示例13: entropy_examples

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
 def entropy_examples():
     output_file_format = fld_data_analysis_results%GeneralMethods.get_method_id()+'/%s.png'
     data = [d for d in FileIO.iterateJsonFromFile(f_hashtag_spatial_metrics, remove_params_dict=True)]
     ltuo_hashtag_and_num_of_occurrences_and_entropy =\
                                                 map(
                                                     itemgetter('hashtag', 'num_of_occurrenes', 'entropy'),
                                                     data
                                                     )
     ltuo_hashtag_and_num_of_occurrences_and_entropy =\
                                                 map(
                                                     lambda (h, n, e): (h, n, round(e,0)),
                                                     ltuo_hashtag_and_num_of_occurrences_and_entropy
                                                     )
     for entropy, entropy_data in \
             GeneralMethods.group_items_by(ltuo_hashtag_and_num_of_occurrences_and_entropy, itemgetter(2)):
         entropy_data.sort(key=itemgetter(1))
         hashtags = map(itemgetter(0), entropy_data)
         print entropy, len(entropy_data), hashtags[:25]
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:20,代码来源:plots_nov_12.py

示例14: compare_zones_with_test_set

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
    def compare_zones_with_test_set(ltuo_model_id_and_hashtag_tag, test_model_id):
        output_file = fld_results%GeneralMethods.get_method_id()+'results.csv'
        GeneralMethods.runCommand('rm -rf %s'%output_file)
        mf_model_id_to_misrank_accuracies = defaultdict(list)
        mf_model_id_to_mf_location_to_zone_id = {}
        for model_id, hashtag_tag in ltuo_model_id_and_hashtag_tag:
                no_of_zones, ltuo_location_and_influence_score_and_zone_id = Experiments.get_location_with_zone_ids(model_id, hashtag_tag)
                locations, influence_scores, zone_ids = zip(*ltuo_location_and_influence_score_and_zone_id)
                mf_model_id_to_mf_location_to_zone_id[model_id] = dict(zip(locations, zone_ids))
        ltuo_hashtag_and_ltuo_location_and_occurrence_time = Experiments.load_ltuo_hashtag_and_ltuo_location_and_occurrence_time()
        for hashtag_count, (hashtag, ltuo_location_and_occurrence_time) in\
                enumerate(ltuo_hashtag_and_ltuo_location_and_occurrence_time):
#            print hashtag_count

#            if hashtag_count==10: break;
            ltuo_location_and_occurrence_time = sorted(ltuo_location_and_occurrence_time, key=itemgetter(1))
#            hashtag_zone_ids = [for ltuo_location, _ in ltuo_location_and_occurrence_time]
            locations = reduce(InfluenceAnalysis._to_locations_based_on_first_occurence, zip(*ltuo_location_and_occurrence_time)[0], [])
#            mf_location_to_hashtags_location_rank = dict(zip(locations, range(len(locations))))

#        for hashtag_count, (hashtag, ltuo_location_and_pure_influence_score) in \
#                enumerate(Experiments.load_ltuo_test_hashtag_and_ltuo_location_and_pure_influence_score(test_model_id)):
#            locations = zip(*ltuo_location_and_pure_influence_score)[0]
            for model_id, mf_location_to_zone_id in \
                    mf_model_id_to_mf_location_to_zone_id.iteritems():
                models_location_rank = [mf_location_to_zone_id[location] for location in locations if location in mf_location_to_zone_id]
#                print models_location_rank
                if len(models_location_rank)>1:
                    misrank_accuracies = map(
                          InfluenceAnalysis._get_rank_accuracy,
                          zip(models_location_rank, [models_location_rank]*len(models_location_rank))
                          )
                    mf_model_id_to_misrank_accuracies[model_id].append(np.mean(misrank_accuracies))
                    
                    #Random model
#                    random_location_rank = range(len(locations))
                    random_location_rank = models_location_rank
                    random.shuffle(random_location_rank)
                    random_misrank_accuracies = map(
                          InfluenceAnalysis._get_rank_accuracy,
                          zip(random_location_rank, [random_location_rank]*len(random_location_rank))
                          )
                    data = ', '.join([str(hashtag_count), str(len(ltuo_location_and_occurrence_time)), str(np.mean(misrank_accuracies)), str(np.mean(random_misrank_accuracies)), str(len(models_location_rank))])
                    FileIO.writeToFile(data, output_file)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:46,代码来源:plots.py

示例15: ef_plots_for_peak

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import get_method_id [as 别名]
 def ef_plots_for_peak():
     output_file_format = fld_data_analysis_results%GeneralMethods.get_method_id()+'/%s.png'
     def getNearestNumber(num): return  (int(round(num,2)*100/100)*100 + int((round(num,2)*100%100)/3)*3)/100.
     def plot_correlation_ef_plot(condition, id, hashtags, focuses, entropies, peaks):
         TIME_UNIT_IN_SECONDS = 10.*60.
         mf_norm_focus_to_entropies = defaultdict(list)
         mf_norm_focus_to_peaks = defaultdict(list)
         for focus, entropy, peak in zip(focuses,entropies, peaks):
             if condition(peak):
                 mf_norm_focus_to_entropies[round(focus, 2)].append(entropy)
                 mf_norm_focus_to_peaks[round(focus, 2)].append(peak)
         x_focus, y_entropy = zip(*[(norm_focus, np.mean(entropies)) for norm_focus, entropies in mf_norm_focus_to_entropies.iteritems() if len(entropies)>5])
         _, z_peak = zip(*[(norm_focus, np.mean(peaks)*TIME_UNIT_IN_SECONDS/60) for norm_focus, peaks in mf_norm_focus_to_peaks.iteritems() if len(peaks)>5])
         plt.figure(num=None, figsize=(6,3))
         plt.subplots_adjust(bottom=0.2, top=0.9, wspace=0, hspace=0)
         cm = matplotlib.cm.get_cmap('cool')
         sc = plt.scatter(x_focus, y_entropy, c=z_peak, cmap=cm, s=50, lw=0,)
         plt.colorbar(sc)
         plt.xlim(xmin=-0.1, xmax=1.1)
         plt.ylim(ymin=-1, ymax=9)
         plt.xlabel('Mean hashtag focus')
         plt.ylabel('Mean hashtag entropy')
         plt.grid(True)
         savefig(output_file_format%id)
         ltuo_hashtag_and_entropy_and_focus = zip(hashtags, entropies, focuses)
         ltuo_hashtag_and_r_entropy_and_focus = sorted(ltuo_hashtag_and_entropy_and_focus, key=itemgetter(1), reverse=True)
         ltuo_hashtag_and_r_entropy_and_s_focus = sorted(ltuo_hashtag_and_r_entropy_and_focus, key=itemgetter(2))
         hashtags = zip(*ltuo_hashtag_and_r_entropy_and_s_focus)[0]
         print id, list(hashtags)
         print id, list(reversed(hashtags))
     data = [d for d in FileIO.iterateJsonFromFile(f_hashtag_spatial_metrics, remove_params_dict=True)]
     hashtags = map(itemgetter('hashtag'), data)
     focuses = map(itemgetter(1), map(itemgetter('focus'), data))
     entropies = map(itemgetter('entropy'), data)
     peaks = map(itemgetter('peak_iid'), data)
     def gt_288(peak):
         if 288>peak and peak<1008: return True
     def lt_6(peak):
         if peak < 6: return True
     def lt_144(peak):
         if peak < 144: return True
     plot_correlation_ef_plot(gt_288, 'gt_288', hashtags, focuses, entropies, peaks)
     plot_correlation_ef_plot(lt_6, 'lt_6', hashtags, focuses, entropies, peaks)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:45,代码来源:plots_nov_12.py


注:本文中的library.classes.GeneralMethods.get_method_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。