Beispiel #1
0
    def guppy(self, data):

        fwidth = []
        swidth = []
        rwb = []
        sband_min = []
        sband_max = []

        for index, row in data.iterrows():
            fast = [
                row['ema3'], row['ema5'], row['ema7'], row['ema10'],
                row['ema12'], row['ema15']
            ]
            slow = [
                row['ema30'], row['ema35'], row['ema40'], row['ema45'],
                row['ema50'], row['ema60']
            ]
            fmin, fmax = utils.minmax(fast)
            smin, smax = utils.minmax(slow)
            sband_min.append(smin)
            sband_max.append(smax)

            if row['ema3'] > row['ema15']:
                fwidth.append(fmax - fmin)
            else:
                fwidth.append(fmin - fmax)

            if row['ema30'] > row['ema60']:
                swidth.append(smax - smin)
            else:
                swidth.append(smin - smax)

            if fmin > smax:
                rwb.append(fmin - smax)
            elif smin > fmax:
                rwb.append(fmax - smin)
            else:
                rwb.append(0.0)

        data['fwidth'] = fwidth
        data['fwidth_pb'] = utils.positive_bars(data['fwidth'])
        data['fwidth_roc'] = utils.roc(fwidth)
        data['fwidth_roc_pb'] = utils.positive_bars(data['fwidth_roc'])
        data['fwidth_ranking'] = utils.relative_rank(data['fwidth'])
        data['swidth'] = swidth
        data['sband_min'] = sband_min
        data['sband_max'] = sband_max
        data['swidth_pb'] = utils.positive_bars(data['swidth'])
        data['swidth_roc'] = utils.roc(swidth)
        data['swidth_roc_pb'] = utils.positive_bars(data['swidth_roc'])
        data['swidth_ranking'] = utils.relative_rank(data['swidth'])
        data['rwb'] = rwb
        data['rwb_pb'] = utils.positive_bars(data['rwb'])
        data['rwb_roc'] = utils.roc(rwb)
        data['rwb_roc_pb'] = utils.positive_bars(data['rwb_roc'])
        data['rwb_ranking'] = utils.relative_rank(data['rwb'])
Beispiel #2
0
 def limit(self, min_, max_):
     for x in np.nditer(self.u, op_flags=['readwrite']):
         if math.isnan(x):
             print 'drag_model contains NaN values: {}'.format(
                 self.drag_model.u)
             x[...] = 0.0
         x[...] = utils.minmax(min_, x, max_)
Beispiel #3
0
def part_2(nums, target):
    """
    Since we're considering sums of *contiguous* ranges, there's only one correct decision to make
    given each number we encounter: if the sum is currently too large, get rid of the leftmost num,
    and if the sum is too small, add the next number.

    We use minmax to compute the min and max simultaneously, a small optimization that saves us an
    extra pass over the selected range.
    """
    left = 0
    right = 0
    contiguous_sum = nums[0]
    while contiguous_sum != target:
        if contiguous_sum > target:
            contiguous_sum -= nums[left]
            left += 1
        if contiguous_sum < target:
            right += 1
            contiguous_sum += nums[right]
    contiguous_range = nums[left:right + 1]
    return sum(minmax(contiguous_range))
Beispiel #4
0
def rnd_bubblesort3( scores, Nrepeats=None ): ## make sure scores is a copy, b/c NaNs will get replaced in this copy
    lsc = len(scores)
    if Nrepeats is None:
        Nrepeats = lsc * 2
    ords = np.arange(lsc)
    rnd.shuffle(ords) ## start w/ random order
    tmp = ut.minmax(scores)
    R = 2.0 * ( tmp[1]-tmp[0] ) ## Denominator of value to compute prob. from
    the_max = tmp[1]
    n = lsc - 1
    sc = scores.copy()
    sc[ np.isnan(sc) ] = the_max ## replace NaN with maximum score
    switchesN = np.array([0]) ## count the number of switches. Not really necessary
    for i in xrange(Nrepeats):
        rnds = rnd.rand(n)
        code = """
        for ( int j=0; j<n; j++ ) {
          int o1 = ords(j), o2 = ords(j+1);
          double g1 = sc(o1), g2 = sc(o2);
          if ( g1 == g2 && g2 == (double)the_max ) continue;
          double p = 0.5 + ( g1 - g2 ) / (double)R; // compute prob of switching
          if ( rnds(j) < p ) { // switch???
            ords(j) = o2;
            ords(j+1) = o1;
            switchesN(0) ++;
          }
        }
        """
        ## See here for other weave options:
        ## https://mail.python.org/pipermail/cplusplus-sig/2002-January/000428.html
        scipy.weave.inline(code,['ords','n','sc','R','switchesN','rnds','the_max'],
                           type_converters=scipy.weave.converters.blitz,
                           compiler='gcc', extra_compile_args=['-O3','-malign-double','-funroll-loops'])
        if i % 1000 == 1:
            print i, switchesN[0], Nrepeats
    return ords
 def limit(self, min_, max_):
     for x in np.nditer(self.u, op_flags=['readwrite']):
         if math.isnan(x):
             print 'drag_model contains NaN values: {}'.format(self.drag_model.u)
             x[...] = 0.0
         x[...] = utils.minmax(min_, x, max_)
 def bound(self, position):
     for d in range(2):
         position[d] = utils.minmax(self.bounds[d, 0], position[d],
                                    self.bounds[d, 1])
Beispiel #7
0
 def bound(self, position):
     for d in range(2):
         position[d] = utils.minmax(self.bounds[d, 0], position[d], self.bounds[d, 1])
Beispiel #8
0
                             dest='base_slot_histogram',
                             help='Plot a histogram for each base slot')
    plot_parser.set_defaults(which='plot')

    args = parser.parse_args()
    '''
    Call appropriate functions based on arguments
    '''
    baseline_data = parse_data(args.baseline_data)
    if args.which == 'poc':
        positives_data = parse_data(args.positives_data)
        negatives_data = parse_data(args.negatives_data)
        main(baseline_data, positives_data, negatives_data, args.roc)
    elif args.which == 'utils':
        if args.minmax > 0:
            minmax = utils.minmax([row[1] for row in baseline_data],
                                  args.minmax)

            print('Minimal {} values:'.format(args.minmax))
            for n in minmax['mins']:
                print('\t{}'.format(n))

            print('Maximal {} values:'.format(args.minmax))
            for n in minmax['maxs']:
                print('\t{}'.format(n))
        if args.stats:
            stats = utils.stats([row[1] for row in baseline_data])

            print('Mean: {}\nStd. Deviation: {}'.format(
                stats['mean'], stats['std_dev']))
    elif args.which == 'plot':
        plt_counter = 1