Beispiel #1
0
 def summary_df(self, thresholds=None, lower_quantile=None, upper_quantile=None):
     """
     Calculates the pair of metrics for each threshold for each result.
     """
     if thresholds is None:
         thresholds = self.thresholds
     if lower_quantile is None:
         lower_quantile = self.config['lower_quantile']
     if upper_quantile is None:
         upper_quantile = self.config['upper_quantile']
     
     if self.n_current_results > self.n_cached_curves:
         # If there are new curves, recompute
         colnames = ['_'.join([metric, stat])
                     for metric in [self.metric1.name, self.metric2.name] 
                     for stat in ['Mean', 'Median',
                                  '%d_Percentile' % (100*lower_quantile),
                                  '%d_Percentile' % (upper_quantile*100)]]
         self.ret = pd.DataFrame(columns=colnames, index=thresholds, dtype='float64')
         
         for threshold in thresholds:
             m1s = Series([self.metric1.score(result, threshold) for result in self.results])
             m2s = Series([self.metric2.score(result, threshold) for result in self.results])
             self.ret.loc[threshold] = (m1s.mean(), m1s.quantile(.5), m1s.quantile(.05), m1s.quantile(.95),
                                        m2s.mean(), m2s.quantile(.5), m2s.quantile(.05), m2s.quantile(.95))
     return self.ret
def get_cutoffs(x, num_groups=10):
    """Get the cutoffs that splits `x` into `num_groups` equally sized groups."""
    series = Series(x)
    cutoffs = []
    for i in range(num_groups):
        perc_low = float(i) / num_groups
        perc_high = float(i + 1) / num_groups
        cutoffs.append((series.quantile(perc_low), series.quantile(perc_high)))
    return cutoffs
Beispiel #3
0
 def summary_df(self):
     lower_quantile = self.config['lower_quantile']
     upper_quantile = self.config['upper_quantile']
     
     vals = Series(self.summary)
     
     lower_bound = vals.quantile(lower_quantile)
     upper_bound = vals.quantile(upper_quantile)
     median = vals.quantile(0.5)
     mean = vals.mean()
     
     column_names = [ "Mean" , "Median" , "%d_Percentile" % (lower_quantile*100), "%d_Percentile" % (upper_quantile*100)]
     df = pd.DataFrame(dict(zip(column_names, [mean, median, lower_bound, upper_bound])), index=[0])
     
     return df
Beispiel #4
0
    def test_quantile_empty(self):

        # floats
        s = Series([], dtype='float64')

        res = s.quantile(0.5)
        self.assertTrue(np.isnan(res))

        res = s.quantile([0.5])
        exp = Series([np.nan], index=[0.5])
        tm.assert_series_equal(res, exp)

        # int
        s = Series([], dtype='int64')

        res = s.quantile(0.5)
        self.assertTrue(np.isnan(res))

        res = s.quantile([0.5])
        exp = Series([np.nan], index=[0.5])
        tm.assert_series_equal(res, exp)

        # datetime
        s = Series([], dtype='datetime64[ns]')

        res = s.quantile(0.5)
        self.assertTrue(res is pd.NaT)

        res = s.quantile([0.5])
        exp = Series([pd.NaT], index=[0.5])
        tm.assert_series_equal(res, exp)
Beispiel #5
0
#**********************************
# Set ABOVE
#**********************************


def parse_file(filepath):
    trace = Ftrace(filepath)
    return (filepath, trace)

if __name__ == '__main__':
    _files = glob.glob(r'{path}\*{file_ext}'.format(path=PATH, file_ext=FILE_EXT))
    F_DICT = {_fp: os.path.split(_fp)[1].split('.')[0] for _fp in _files}
    
    sb_all = DataFrame(columns=F_DICT.values())
    
    for _file in _files:
        
        fp, trace = parse_file(_file)

        total_duration = trace.duration if INTERVAL is None else INTERVAL
        ss = Series((event.interval.duration for event in trace.android.render_frame_intervals(interval=INTERVAL)))
        ss = ss * 1000. #
        summary = ss.describe()
        summary['90%'] = ss.quantile(.9)
        summary['Janks'] = trace.android.num_janks(interval=INTERVAL)
        summary['Janks Per Second'] = summary['Janks']/total_duration
        summary['Average FPS'] = trace.android.framerate(interval=INTERVAL)
        sb_all[F_DICT[fp]] = summary
    
    sb_all.to_csv(r'{path}\frame_stats.csv'.format(path=PATH))
        
def count_estims(dist, gamma = 0.95):
    '''
    Counts all estimates
    :param dist: dsitribution
    :param gamma: probability of realisation of value
    :return point: point estimates
    :return interval: confidance intervals for point estimates
    '''
    import numpy as np
    x = Series(dist)
    #Точечные оценки
    point = {}
    N = x.count()

    med_ = med_u(x)#
    med = np.median(dist)
    mad = x.mad()#
    mean_c = mean(dist)#
    var = np.var(dist)
    std = np.std(dist)
    mod = stats.mode(dist).mode#
    kurt = stats.kurtosis(dist)
    skew_my = stats.skew(dist)#
    Chi = 1/np.sqrt(np.abs(kurt))
    quantiles = np.round(x.quantile([0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95]), 5)
    W = std/mean_c;#

    quantiles_str = ""
    for index in quantiles.index:
        quantiles_str+='<p><pre>{0}\t{1}</pre></p>'.format(index, quantiles[index])

    point['MED'] = np.round(med, 5)
    point['MED*'] = np.round(med_, 5)
    point['MAD'] = np.round(mad, 5)
    point['Min'] = np.round(x.min(), 5)
    point['Max'] = np.round(x.max(), 5)
    point['Mean'] = np.round(mean_c, 5)
    point['S^2'] = np.round(var, 5)
    point['S'] = np.round(std, 5)
    point['MOD'] = np.round(mod, 5)
    point['E'] = np.round(kurt, 5)
    point['A'] = np.round(skew_my, 5)
    point['Chi'] = np.round(Chi, 5)
    point['X(alpha)'] = quantiles_str
    point['W'] = np.round(W, 5)



    #Интервальные оценки
    from scipy.stats import t, norm
    import numpy as np
    interval = {}
    if N < 61:
        l = t.ppf((1-gamma)/2, N-1)
        u = t.ppf(1-(1-gamma)/2, N-1)
    else:
        l = norm.ppf((1-gamma)/2)
        u = norm.ppf(1-(1-gamma)/2)
    X_cf = (mean_c+l*sigma_X(x), mean_c+u*sigma_X(x))
    A_cf = (skew_my + l * sigma_A(x), skew_my + u * sigma_A(x))
    S_cf = (std + l*sigma_S(x), std+u*sigma_S(x))
    E_cf = (kurt + l*sigma_E(x), kurt+u*sigma_E(x))
    if W < 1:
        v = l/np.sqrt(2*(N-1))
        W_cf = np.round((W/(1+v*np.sqrt(1+2*W**2)), W/(1-v*np.sqrt(1+2*W**2))), 5)
    else: W_cf = (None, None)

    interval['Mean'] = np.round(X_cf, 5)
    interval['S'] = np.round(S_cf, 5)
    interval['E'] = np.round(E_cf, 5)
    interval['A'] = np.round(A_cf, 5)
    interval['W'] = W_cf

    return point, interval
Beispiel #7
0
if __name__ == "__main__":
    _files = glob.glob(r"{path}\*{file_ext}".format(path=PATH, file_ext=FILE_EXT))
    F_DICT = {_fp: os.path.split(_fp)[1].split(".")[0] for _fp in _files}

    sb_all = DataFrame()

    for _file in _files:

        fp, trace = parse_file(_file)

        total_duration = trace.duration if INTERVAL is None else INTERVAL
        ss = Series(
            (event.interval.duration * 1000 for event in trace.android.input_latencies(TOUCH_IRQ, interval=INTERVAL))
        )
        summary = ss.describe()
        summary["90%"] = ss.quantile(0.9)
        summary["Janks Per Second"] = trace.android.jankrate(interval=INTERVAL)
        summary["Average FPS"] = trace.android.framerate(interval=INTERVAL)

        ss_first = Series(
            (
                event.interval.duration * 1000
                for event in trace.android.input_latencies(TOUCH_IRQ, interval=INTERVAL)
                if trace.cpu.frequency_intervals(cpu=0, interval=event.interval)
                and trace.cpu.frequency_intervals(cpu=0, interval=event.interval)[0] == 384000
            )
        )
        summary_first = ss_first.describe()
        summary_first["90%"] = ss_first.quantile(0.9)
        summary_first["Janks Per Second"] = summary["Janks Per Second"]
        summary_first["Average FPS"] = summary["Average FPS"]
with open('words.txt', 'r') as f:
    lines = f.readlines()

trigrams = {}
for line in lines:
    trigram = line.strip().lower()[0:3]
    if len(trigram) >= 3 and not nonalphabet.search(trigram):
        if trigram == "aaa":
            print "line: {0} trigram: {1}".format(line, trigram)
        trigrams.setdefault(trigram, 0)
        trigrams[trigram] += 1

trigram_series = Series(trigrams.values(), index=trigrams.keys())
trigram_series.sort(inplace=True, ascending=True)
print trigram_series
print "quartiles:\n{0}".format(trigram_series.quantile([.25, .50, .75, .99]).to_string())

print "median is: {0}".format(trigram_series.median())
unique_trigrams = []
for trigram, count in trigrams.iteritems():
    if count > trigram_series.quantile(.50):
        unique_trigrams.append(trigram)
    unique_trigrams.append(trigram)

print "saving trigrams"
with open("trigrams.json", "w") as f:
    json.dump(unique_trigrams, f)
print "saved {0} trigrams".format(len(unique_trigrams))

trie = {}
for trigram in unique_trigrams: