예제 #1
0
def merge_results_d(result_a, result_b, repository):
    if result_a.label_map != result_b.label_map:
        print('error, label mappings dont match, intervention required')
        Tracer()()

    class_to_idx = result_a.label_map
    samples_1 = repository.get_samples_by_uid(result_a.ids)
    samples_2 = repository.get_samples_by_uid(result_b.ids)
    templates_1 = repository.get_templates_by_uid(result_a.template_order,
                                                  samples_1)
    templates_2 = repository.get_templates_by_uid(result_b.template_order,
                                                  samples_2)

    Tracer()()
    X_a, y_a, ids_a = extract_features(samples_1, templates_2, class_to_idx)
    X_b, y_b, ids_b = extract_features(samples_2, templates_1, class_to_idx)

    # take special notice to the flipped use of feature vectors due to
    # template matching results concatentation

    for i, x in enumerate(result_a.X):
        X_a[i].extend(x)
    for i, x in enumerate(X_b):
        result_b.X[i].extend(x)

    data = FeatureData()
    data.X = X_a + result_b.X
    data.y = result_a.y + result_b.y
    data.ids = result_a.ids + result_b.ids
    data.label_map = class_to_idx
    data.template_order = result_a.template_order + result_b.template_order
예제 #2
0
def run(batch_size,nb_classes,nb_epoch,data_augmentation,img_rows, img_cols,img_channels,weightfilepath,logfilepath,bestweightfilepath,Load_model   ):
    #function to run the actual test
    # the data, shuffled and split between train and test sets
    X_train,y_train,X_test,y_test,X_val,y_val = load_data()
    X_train,Y_train,X_test,Y_test,X_val,Y_val = normalize_date(X_train,y_train,X_test,y_test,X_val,y_val,nb_classes)

    
    print('Loading and formatiing of data complete...')
    
    #load the model defined in model_architecture function
    model = model_architecture(img_rows,img_cols,img_channels,nb_classes)

    # training the model using SGD + momentum
    adm = Adam(lr=0.00001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
    model.compile(loss='categorical_crossentropy',
                  optimizer=adm,
                  metrics=[get_categorical_accuracy_keras])

  
    if Load_model:
        Tracer()()
        model.load_weights(weightfilepath )

    save_model_per_epoch = ModelCheckpoint1(weightfilepath,logfilepath,bestweightfilepath, monitor='val_loss', verbose=1, save_best_only=False)
    model.fit(X_train,Y_train,
              batch_size=batch_size,
              nb_epoch=nb_epoch,
              validation_data=(X_val, Y_val),
              shuffle=True,
              verbose=2,
              callbacks=[save_model_per_epoch])
예제 #3
0
    def coco_modify_segs(self):
        for count, im_idx in enumerate(self.D.image_index):
            if count % 100 == 0:
                print 'Image {:d} of {:d}'.format(count,
                                                  len(self.D.image_index))
            seg_filename = self.D.seg_path_from_index(im_idx)
            im = cv2.imread(im_filename)
            if im is None:
                print 'Could not read ', im_filename
                sys.exit(-1)
            seg = self.get_seg(im)

            # get annotations
            c = self.D._COCO
            ann_ids = c.getAnnIds(imgIds=im_idx, iscrowd=False)
            anns = c.loadAnns(ann_ids)
            mask = np.zeros(seg.shape, dtype=np.int)
            for ann in anns:
                if 'segmentation' not in ann:
                    continue
                cat_id = ann['category_id'] + 9
                if type(ann['segmentation']) == list:
                    for s in ann['segmentation']:
                        poly = np.array(s).reshape((len(s) / 2, 2))
                        poly = Polygon(poly)
                        pth = path.Path(poly.get_xy(), closed=True)
                        y, x = np.mgrid[:seg.shape[0], :seg.shape[1]]
                        points = np.transpose((x.ravel(), y.ravel()))
                        m = pth.contains_points(points).reshape(mask.shape)
                        mask[m > 0] = cat_id * m[m > 0]
                else:
                    Tracer()()
            # superimpose mask on seg
            seg[mask > 0] = mask[mask > 0]
            cv2.imwrite(seg_filename, seg)
예제 #4
0
파일: main.py 프로젝트: herrfeder/PyThek
    def store_media_data(self,broadcast_data,entry_name,broadcast_key):

        self.download_media_data.update(broadcast_data)
        create_broadcast_view(self.download_media_data,self.left_box)
        broadcast_data[broadcast_key]['episodes'][entry_name] = self.download_dict[entry_name]
        Tracer()()
        create_episode_view(self.download_media_data["episodes"][entry_name],self.middle_box)
예제 #5
0
    def map_FirstHaloInFOFgroup(self,tree):
            
        first_halo = np.empty(len(tree),np.int32)
        first_halo.fill(-1)
        host_inds = (np.where(tree['pid'] == -1))[0]
        if len(host_inds) > 0:
            ## Host halos points to themselves
            first_halo[host_inds] = host_inds
            
            ## Now set the subhalos
            hostids = tree['id'][host_inds]
            for host_loc,hostid in zip(host_inds,hostids):
                ind_subs = (np.where(tree['pid'] == hostid))[0]
                if len(ind_subs) > 0:
                    assert np.max(first_halo[ind_subs]) == -1,'First halo inds should not already have been assigned'
                    first_halo[ind_subs] = host_loc
            
                
            if min(first_halo) < 0:
                Tracer()()

            return first_halo
        print("tree = {}".format(tree))
        print("returning none. expect code to break")
        return None
예제 #6
0
def breakpoint():
    try:
        from IPython.core.debugger import Tracer
        Tracer()()
    except:
        import pdb
        pdb.set_trace()
예제 #7
0
def main():
    file_names = get_data_file_names()

    game_logs_created = 0
    start_connection()
    for fname in file_names:
        with open('pickles/{}'.format(fname), 'rb') as f:
            season, season_type, team = get_info_from_filename(fname)

            lines = map(lambda x: x.split(),
                        filter(lambda x: len(x) > 10, f.readlines()))

            for gl in lines[1:]:
                gl[0] = gl[0][
                    2:]  # removes 'aV' from first element of each row
                try:
                    create_gamelog(gl, season, season_type, team)
                    game_logs_created += 1
                except:
                    Tracer()()
                    pass

            print fname + ': ' + str(len(lines[1:]))

    print str(game_logs_created) + ' game logs created.'
예제 #8
0
 def TracerFactory():
     """
     Returns a callable `Tracer` object.
     When this object is called it starts the ipython commandline debugger
     in that place.
     """
     return Tracer(colors='Linux')
예제 #9
0
def canonical_cumsum(array, n, axis, crop=True):
    from IPython.core.debugger import Tracer
    debug_here = Tracer()
    ''' Input:
         > array : np-array or list
         > n     : windowsize (n>0)
         > axis  : axis along which the cumsum will be taken
         > crop  : bool | will crop the beginning of the output array, 
                          where the sum runs over uncomplete window.
                   note: if ndim of array is >1 then the output will always be cropped.
                         --> did not find a function like np.take to /access/ an array.
    '''
    ndims = len(array.shape)
    # pandas doesn't know negative axes-allocation
    if axis < 0:
        axis = ndims + axis

    if n <= 0:
        sys.exis('The windowsize n must be chosen greater than 0!')
    if ndims == 1:
        b = utils_ana.nancumsum(array)
        b[n:] = b[n:] - b[:-n]
        if crop == True:
            b = b[n - 1:]
        return (b)
    else:
        lenax = array.shape[axis]
        b = utils_ana.nancumsum(array, axis=axis)
        b_first = np.expand_dims(np.take(b, n - 1, axis=axis), axis=axis)
        c = np.take(b, np.arange(n, lenax), axis=axis) - np.take(
            b, np.arange(lenax - n), axis=axis)
        d = np.concatenate((b_first, c), axis=axis)
        return (d)
예제 #10
0
    def train_step(self, data, **kwargs):
        # torch.autograd.set_detect_anomaly(True)
        loss, data_dict, r = self.model(
            data['X'],
            actions=data['action'].cuda().float(),
            rewards=data['reward'].cuda().float().squeeze(-1),
            mask=data['done'].cuda().float().squeeze(-1),
            pretrain=kwargs['pretrain'])
        self.optimizer.zero_grad()
        torch.mean(-1. * loss).backward()
        if self.clip_gradient:
            torch.nn.utils.clip_grad_norm_(self.model.parameters(),
                                           self.clip_gradient_value)
        for n, p in self.model.named_parameters():
            if p.grad is not None:
                # print(f'{n}: {p.grad.max()} {p.grad.min()} {p.grad.mean()}')
                if not torch.isfinite(p.grad.mean()):
                    from IPython.core.debugger import Tracer
                    Tracer()()
        self.optimizer.step()
        # if self.num_steps % 150 == 0 and kwargs['visdom']:
        #     if kwargs['pretrain']:
        #         self.visdom_logger.log_visdom(data['X'].flatten(end_dim=1), data_dict['masks'], data_dict['reconstruction'], 6)
        #     else:
        #         self.visdom_logger.log_visdom(data['X'][0], data_dict['masks'][0], data_dict['reconstruction'][0], 6)
        self.num_steps += 1

        return data_dict
예제 #11
0
 def parse_tweet(self, tweet, response):
     tweet_item = items.TwitterscraperItem()
     tweet_item['session_id'] = self.session_id
     tweet_item['tweet_id'] = tweet['tweet_id']
     tweet_item['text'] = tweet['text']
     tweet_item['user_id'] = tweet['user_id']
     tweet_item['user_screen_name'] = tweet['user_screen_name']
     tweet_item['user_name'] = tweet['user_name']
     tweet_item['created_at_ts'] = tweet['created_at_ts']
     tweet_item['created_at_iso'] = tweet['created_at_iso']
     # tweet_item['convo_url'] = tweet['convo_url']
     # tweet_item['image_url'] = tweet['image_url']
     tweet_item['num_retweets'] = tweet['num_retweets']
     tweet_item['num_favorites'] = tweet['num_favorites']
     tweet_item['keyword'] = tweet['keyword']
     tweet_item['query'] = self.query
     # referring_url = response.request.headers.get('Referer', None)
     tweet_item['referring_url'] = response.request.headers.get(
         'Referer', None) or self.start_urls[0]
     tweet_item['request_url'] = response.url
     tweet_item['quote_tweet_id'] = tweet['quote_tweet_userid']
     tweet_item['quote_tweet_userid'] = tweet['quote_tweet_userid']
     tweet_item['quote_tweet_username'] = tweet['quote_tweet_username']
     tweet_item['quote_tweet_screenname'] = tweet['quote_tweet_screenname']
     tweet_item['quote_tweet_text'] = tweet['quote_tweet_text']
     try:
         tweet_item['html'] = tweet['html']
     except Exception, e:
         Tracer()()
         pass
예제 #12
0
    def button_press_callback(self, event):
        """Left button: add point; middle button: delete point;
        right button: fill polygon and stop interaction.
        """
        from IPython.core.debugger import Tracer
        Tracer()()
        if event.inaxes:
            x, y = event.xdata, event.ydata
            ax = event.inaxes

            if event.button == 1:  # If you press the left button
                if self.circ == None:  # if there is no line, create a line
                    self.circ = plt.Circle((x, y),
                                           0.5,
                                           facecolor='none',
                                           edgecolor='r')
                    ax.add_artist(self.circ)

                # add a segment
                else:  # if there is a line, create a segment
                    self.circ.set_color('b')
                    self.circ.set_alpha(0.3)
                    self.disconnect()

            elif event.button == 3 and self.circ != None:  # middle button: remove last segment
                # ax.artists.remove(self.circ)
                self.circ.remove()
                self.circ = None
            self.fig.canvas.draw()
예제 #13
0
    def iou_calc(self, boxes1, boxes2): #x, y, w, h
        boxes1 = torch.stack([boxes1[:, :, :, 0] - boxes1[:,  :, :, 2] / 2.0,
                           boxes1[:, :, :, 1] - boxes1[:, :,  :, 3] / 2.0,
                           boxes1[:, :, :, 0] + boxes1[:, :,  :, 2] / 2.0,
                           boxes1[:, :, :, 1] + boxes1[:, :,  :, 3] / 2.0])
        boxes1 = boxes1.permute(1, 2, 3, 0)

        boxes2 = torch.stack([boxes2[:, :, :, 0] - boxes2[:, :, :, 2] / 2.0,
                           boxes2[:, :, :, 1] - boxes2[:, :, :, 3] / 2.0,
                           boxes2[:, :, :, 0] + boxes2[:, :, :, 2] / 2.0,
                           boxes2[:, :, :, 1] + boxes2[:, :, :, 3] / 2.0])
        boxes2 = boxes2.permute(1, 2, 3, 0)
        # calculate the left up point & right down point
        lu = torch.max(boxes1[:, :, :, :2], boxes2[:, :, :, :2])
        rb = torch.min(boxes1[:, :, :, 2:], boxes2[:, :, :, 2:])
        # intersection
        intersection = torch.max((rb - lu), Variable(torch.zeros(rb.size())))
        inter_square = intersection[:, :, :, 0] * intersection[:, :, :, 1]

        square1 = (boxes1[:, :, :, 2] - boxes1[:, :, :, 0]) * \
                (boxes1[:, :, :, 3] - boxes1[:, :, :, 1])
        square2 = (boxes2[:, :, :, 2] - boxes2[:, :, :, 0]) * \
                (boxes2[:, :, :, 3] - boxes2[:, :, :, 1])
        square1 = torch.clamp(square1, 0.00001, self.img_size*self.img_size)
        square2 = torch.clamp(square2, 0.00001, self.img_size*self.img_size)
        union_square = square1 + square2 - inter_square
        result = inter_square / union_square
        if math.isnan(torch.sum(result).data.cpu().numpy()):
            Tracer()()
        return result #shape = (batch_size, 7, 7, 2)
예제 #14
0
def open_logs(season, season_type, team):
    driver = get_page_driver(BASE_URL)
    #soup = BS(driver.page_source, 'html.parser')
    close_stat_filter(driver)
    select_options(driver, season, season_type, team)
    press_run_button(driver)
    open_all_logs(driver)
    rows = get_table_rows(driver)
    Tracer()()
예제 #15
0
def get_U(pulse, wd, gate=None, J_T=None, dissipation=True,
        keep_runfolder=None):
    """Propagate pulse in the given rotating frame, using the non-Hermitian
    Schrödinger equation, and return the resulting (non-unitary, due to
    population loss) gate U"""

    assert 5000 < wd < 7000
    assert isinstance(pulse, QDYN.pulse.Pulse)
    rf = get_temp_runfolder('evaluate_universal_hs')
    n_qubit = 5
    n_cavity = 6
    kappa = list(np.arange(n_cavity) * 0.05)[1:-1] + [10000.0, ]  # MHz
    gamma = [0.012, 0.024, 0.033, 10000.0]  # MHz
    if not dissipation:
        kappa = list(np.arange(n_cavity) * 0.0)[1:-1] + [0.0, ]  # MHz
        gamma = [0.0, 0.0, 0.0, 0.0]  # MHz

    if gate is None:
        gate = GATE['BGATE']
    assert isinstance(gate, QDYN.gate2q.Gate2Q)
    if J_T is None:
        J_T = 'sm'

    model = transmon_model(
        n_qubit, n_cavity, w1, w2, wc, wd, alpha1, alpha2, g, gamma, kappa,
        lambda_a=1.0, pulse=pulse, dissipation_model='non-Hermitian',
        gate=gate, J_T=J_T, iter_stop=1)

    # write to runfolder
    model.write_to_runfolder(rf)
    np.savetxt(
        os.path.join(rf, 'rwa_vector.dat'),
        model.rwa_vector, header='rwa vector [MHz]')
    gate.write(os.path.join(rf, 'target_gate.dat'), format='array')

    # propagate
    env = os.environ.copy()
    env['OMP_NUM_THREADS'] = '4'
    try:
        stdout = sp.check_output(
            ['qdyn_prop_gate', '--internal-units=GHz_units.txt', rf], env=env,
            universal_newlines=True)
    except sp.CalledProcessError as exc_info:
        from IPython.core.debugger import Tracer
        Tracer()()
        print(exc_info)

    # evaluate error
    for U_t in get_prop_gate_of_t(os.path.join(rf, 'U_over_t.dat')):
        U = U_t
    if keep_runfolder is not None:
        if os.path.isdir(keep_runfolder):
            rmtree(keep_runfolder)
        copytree(rf, keep_runfolder)
    rmtree(rf)

    return U
예제 #16
0
def translate_nfhs_to_geo(state, district):
    res = get_proper_state_name((state, district))
    all = []
    for r in res:
        if r in map_names:
            all.append(map_names[r])
    if len(all) == 0:
        Tracer()()
    return all
예제 #17
0
    def iou_calc(self, boxes1, boxes2): #x, y, w, h
        boxes1 = torch.stack([boxes1[:, :, :, :, 0] - boxes1[:, :, :, :, 2] / 2.0,
                           boxes1[:, :, :, :, 1] - boxes1[:, :, :, :, 3] / 2.0,
                           boxes1[:, :, :, :, 0] + boxes1[:, :, :, :, 2] / 2.0,
                           boxes1[:, :, :, :, 1] + boxes1[:, :, :, :, 3] / 2.0])
        boxes1 = boxes1.permute(1, 2, 3, 4, 0)

        boxes2 = torch.stack([boxes2[:, :, :, :, 0] - boxes2[:, :, :, :, 2] / 2.0,
                           boxes2[:, :, :, :, 1] - boxes2[:, :, :, :, 3] / 2.0,
                           boxes2[:, :, :, :, 0] + boxes2[:, :, :, :, 2] / 2.0,
                           boxes2[:, :, :, :, 1] + boxes2[:, :, :, :, 3] / 2.0])
        boxes2 = boxes2.permute(1, 2, 3, 4, 0)
#        print('boxes1')
#        print(boxes1)
#        print('boxes2')
#        print (boxes2)
        # calculate the left up point & right down point
        lu = torch.max(boxes1[:, :, :, :, :2], boxes2[:, :, :, :, :2])
        rb = torch.min(boxes1[:, :, :, :, 2:], boxes2[:, :, :, :, 2:])
#        print('lu')
#        print(lu)
#        print('rb')
#        print(rb)
        # intersection
        intersection = torch.max((rb - lu), Variable(torch.zeros(rb.size())))
        inter_square = intersection[:, :, :, :, 0] * intersection[:, :, :, :, 1]
#        print('intersection')
#        print(intersection)
#        print('inter_square')
#        print(inter_square)

        square1 = (boxes1[:, :, :, :, 2] - boxes1[:, :, :, :, 0]) * \
                (boxes1[:, :, :, :, 3] - boxes1[:, :, :, :, 1])
        square2 = (boxes2[:, :, :, :, 2] - boxes2[:, :, :, :, 0]) * \
                (boxes2[:, :, :, :, 3] - boxes2[:, :, :, :, 1])
        square1 = torch.clamp(square1, 0.00001, self.img_size*self.img_size)
        square2 = torch.clamp(square2, 0.00001, self.img_size*self.img_size)
#        print('square1')
#        print(square1)
#        print('square2')
#        print(square2)
        union_square = square1 + square2 - inter_square
#        print('uniou_square')
#        print(union_square)
#        print('iou')
#        print(inter_square / union_square)
        result = inter_square / union_square
#        for i0 in range(100):
#            for i1 in range(7):
#                for i2 in range(7):
#                    for i3 in range(2):
#                        if math.isnan(result[i0,i1,i2,i3].data.cpu().numpy()):
#                            Tracer()()
        if math.isnan(torch.sum(result).data.cpu().numpy()):
            Tracer()()
        return result #shape = (batch_size, 7, 7, 2)
예제 #18
0
    def _do_start(_startc):
        if _startc != 0:
            Tracer()()
        if _startc > 3:
            try_again = False
            print('ERROR COULD NOT START PROCESSES {} TIMES.'.format(_startc))
            Tracer()()
            if not try_again: return

        for pidx in xrange(num_proc):
            try:
                procs[pidx].start()
            except OSError as e:
                print('Error: {}'.format(e))
                if pidx is 0:
                    _do_start(_startc + 1)
                else:
                    print('WARNING: pidx != 0: {}'.format(pidx))
                    Tracer()()
예제 #19
0
def valid_eval_tfomics(nnt, val_dat, N=14, fragLen=330):
    """
    Properly calidates current CNN filters by passing filters over retained validation set N number of times and averaging
    the set of predictions for each pair
    
    inputs---
        nnt: tfomics nntrainer object
        val_dat: 2-D numpy array of downsampled fluorescence traces
        N: number of separate start positions for each test fragment to be averaged for each pair
        fragLen: length of trained CNN filter, in time points/samples
    outputs---
        pred_lbl: 1-D numpy array of predicted connectivity
    """

    avg_F = np.mean(val_dat,axis=0)

    startgap = np.ceil((val_dat.shape[1] - fragLen)/N).astype('int')

    pred_lbl = np.zeros((val_dat.shape[0]*val_dat.shape[0],), dtype='float32')
    # Counter for the "pred_lbl" array
    cnt_u = 0
    for a in range(val_dat.shape[0]):
        if a%100 == 0:
            print('\r' + 'X'*(a//100))

        # Create batch array to send thru network
        im_eval = np.empty((N*val_dat.shape[0],3,fragLen,1), dtype='float32')

        # Count the number of traces in each batch
        cnt = 0

        for b in range(val_dat.shape[0]):

            for n in range(0, val_dat.shape[1] - fragLen, startgap):
                try:
                    im_eval[cnt,:,:,0] = np.vstack((val_dat[a,n:n+fragLen],
                                         val_dat[b,n:n+fragLen],
                                         avg_F[n:n+fragLen]))
                except:
                    from IPython.core.debugger import Tracer
                    Tracer()()

                cnt += 1

        #im_eval = np.tile(im_eval,(100,1,1,1))
        # Run batch through network
        test = {'inputs': im_eval, 'keep_prob_dense': 1, 'keep_prob_conv': 1, 'is_training': False}
        pred_stop = nnt.get_activations(test, layer='output')[:,0]
        # Average output over each group of N traces
        for u in range(0, len(pred_stop), N):
            pred_lbl[cnt_u] = np.mean(pred_stop[u:u+N])
            cnt_u += 1  
    return pred_lbl
예제 #20
0
    def get_halotypes_for_tree_root(self,trees_dir='./',forests=None,locations=None):
        if forests is None:
            forests = load_forests(trees_dir)

        if locations is None:
            locations = self.load_locations(trees_dir)

        treeparser = TreesDir(trees_dir)
	p = treeparser._get_ParseFields([])

        tree_types  = dict()
        ## This is an embarrassingly parallel loop
        for tree_root_id,(offset,filename) in locations.items():
            tree_filename = generate_filename(trees_dir+'/'+filename)
            if tree_filename is None:
                raise IOError('Could not find tree file'.format(trees_dir+'/'+filename))


            with opener(tree_filename,'rb') as f:
                f.seek(offset)

                ## now read the first output for this tree root
                line = f.next()
                try:
                    X = p.pack(p.parse_line(line))
                    tree_types[tree_root_id] = 1 if X['pid'] == -1 else 0
                except:
                    Tracer()()


        # nforests = len(forests)
        isolated_forest = []
        for root_id,tree_ids in forests.items():
            try:
                num_fofs_max_scale = sum(tree_types[tree_id] for tree_id in tree_ids)
                isolated_forest.append(False if (num_fofs_max_scale > 1) else True)
            except:
                Tracer()()

        return tree_types,np.array(isolated_forest,dtype=bool)
예제 #21
0
    def updatecontstat(self, t0 = 36*3600, t1 = 144*3600):

        try:
            cstat = self.cont_stat[0]
        except:
            cstat = self.cont_stat

        if np.size(np.shape(self.onTime))>1:
            onTs    = np.min(np.squeeze(self.onTime))
            offTs   = np.max(np.squeeze(self.offTime))
        else:
            onTs    = np.min(self.onTime)
            offTs   = np.max(self.offTime)

        try:
            tcheck = onTs <= t0 and offTs >= t1
        except:
            Tracer()()

        try:
            if not tcheck and cstat == 1:
            # change this cell to NOT continuous
                f1          = h5py.File(self.HDF5_tag[0], 'r+')
                data        = f1['neurons/neuron_'+str(self.HDF5_tag[1])+'/cont_stat']
                data[...]   = float(0)
                f1.close()
                print('Changed this cell from continuous to not.')

            elif tcheck and cstat == 0:
                # change this cell to continuous
                f1          = h5py.File(self.HDF5_tag[0], 'r+')
                data        = f1['neurons/neuron_'+str(self.HDF5_tag[1])+'/cont_stat']
                data[...]   = float(1)
                f1.close()
                print('Changed this cell to continuous.')
            else:
                print('Continuous status stays as {}.'.format(cstat))
        except:
            print('Caught at 535')
            Tracer()()
예제 #22
0
def fillboard(board, topleft, mines_left, rowrem, colrem):
    col = len(board[0])
    row = len(board)
    if min(rowrem, colrem) == 2 and mines_left > 0:
        return False
    if rowrem == 1 or colrem == 1:
        return False
    else:
        reduct = max(rowrem, colrem)
        if reduct == colrem:
            tmp = min(col - 2, mines_left + topleft[1])
            board[topleft[0]] = ['*'] * tmp + ['.'] * (col - tmp)
            mines_left -= tmp - topleft[1]
            # Tracer()()
            if mines_left > 0:
                if topleft[0] + 1 == row:
                    return False
                if topleft[0] + 3 == row:
                    return False
                board[topleft[0] + 1][topleft[1]] = '*'
                mines_left -= 1
        else:
            tmp = min(row - 2, mines_left + topleft[0])
            for i in xrange(tmp):
                board[i][topleft[1]] = '*'
            mines_left -= tmp - topleft[0]
            if mines_left > 0:
                if topleft[1] + 1 == col:
                    return False
                if topleft[1] + 3 == col:
                    return False
                board[topleft[0]][topleft[1] + 1] = '*'
                mines_left -= 1
        if mines_left > 0:
            Tracer()()

        boola = False
        boolb = False
        boolc = False
        if row - 2 >= 0 and board[row - 2][col - 1] == '*':
            boola = True
        if col - 2 >= 0 and board[row - 1][col - 2] == '*':
            boolb = True
        if col - 2 >= 0 and row - 2 >= 0 and board[row - 2][col - 2] == '*':
            boolc = True
        if boola and boolb and boolc:
            board[row - 1][col - 1] = 'c'
            return True
        elif boola or boolb or boolc:
            return False
        board[row - 1][col - 1] = 'c'
        return True
예제 #23
0
def showResults(data, schedule, results):

    players_np = np.array(data)
    scores_np = np.array(results['scores'][0])
    results_selection = results['x']
    days = results['days'][0][0]
    start_index = results['start_index'][0][0]
    curr_team = players_np[np.nonzero(results['curr_team'][0])].tolist()
    curr_team_mask = results['curr_team'][0]
    for index in xrange(days):
        team_players = players_np[np.nonzero(
            results_selection[index])].tolist()
        team_player_scores = scores_np[np.nonzero(
            results_selection[index])].tolist()
        if index == 0:
            coming_in = [
                int(x < 0) for x in [
                    x - y
                    for x, y in zip(curr_team_mask, results_selection[index])
                ]
            ]

            going_out = [
                int(x > 0) for x in [
                    x - y
                    for x, y in zip(curr_team_mask, results_selection[index])
                ]
            ]
        else:
            going_out = [
                int(x < 0) for x in [
                    x - y for x, y in zip(results_selection[index],
                                          results_selection[index - 1])
                ]
            ]
            coming_in = [
                int(x > 0) for x in [
                    x - y for x, y in zip(results_selection[index],
                                          results_selection[index - 1])
                ]
            ]
        print "These players leaving:\n {0}".format(
            players_np[np.nonzero(going_out)].tolist())
        print "These players coming in:\n {0}".format(
            players_np[np.nonzero(coming_in)].tolist())
        print schedule['schedule'][index + start_index]
        print team_player_scores
        print team_players
        # Tracer()()
        print "\n\n\n"
    Tracer()()
예제 #24
0
def main():
    global hmm
    Tracer()()
    pwd = os.getcwd()
    basepath = pwd + "/corpora/"
    # Name of text files in /corpora/ directory
    paths = ("ai.txt", "mahabharat.txt")
    paths = tuple([basepath + path for path in paths])

    texts = [readAndProcess(path) for path in paths]
    N = 10
    hmm = LetterHMM(texts, N)
    Tracer()()
    while True:
        sample = hmm.randomwalk(2000)
        # print sample
        # print "\n"
        obj = re.findall("[A-Z][A-Za-z:\- ,;]{19,}\.", sample)
        if len(obj) < 1:
            continue
        for sentence in obj:
            sentence.translate(string.maketrans("", ""),
                               string.punctuation).lower()
            counts = [0, 0, 0, 0]
            for word in sentence.split():
                if word in hmm.word_distros[0] and word in hmm.word_distros[1]:
                    counts[2] += 1
                elif word in hmm.word_distros[0]:
                    counts[0] += 1
                elif word in hmm.word_distros[1]:
                    counts[1] += 1
                else:
                    counts[3] += 1
            if counts[0] >= 2 and counts[1] >= 2:
                print sentence
                print counts
                print "\n"
        time.sleep(1)
def main():
    # ImageNetData needs path to meta.mat, path to images and path to annotations.
    # The images are assumed to be in folders according to their synsets names
    #imnet = ImageNetData("ILSVRC2011_devkit-2.0/data", "unpacked", "annotation")
    imnet = ImageNetData(
        "/nfs3group/chlgrp/datasets/ILSVRC2010/devkit-1.0/data",
        bow_path="/nfs3group/chlgrp/datasets/ILSVRC2010")

    features, labels = imnet.load_bow()
    features_val, labels_val = imnet.load_bow('val')

    from IPython.core.debugger import Tracer
    tracer = Tracer(colors="LightBG")
    tracer()
예제 #26
0
 def forward(self, x):
     x = self.pool(F.leaky_relu(self.batchnorm1(self.conv1(x))))
     x = self.pool(F.leaky_relu(self.batchnorm2(self.conv2(x))))
     x = self.pool(F.leaky_relu(self.batchnorm3(self.conv3(x))))
     x = self.pool(F.leaky_relu(self.batchnorm4(self.conv4(x))))
     x = self.batchnorm5(self.conv5(x))
     x = x.contiguous().view(self.batch_size, -1)
     x = self.classifier(x)
     x = torch.sigmoid(x)
     x = x.contiguous().view(self.batch_size, -1, self.cell_size, self.cell_size)
     x = x.permute(0,2,3,1)
     if math.isnan(torch.sum(x).data.cpu().numpy()):
         Tracer()()
     return x
예제 #27
0
def setbp():
    try:
        try:
            from traitlets.config.configurable import MultipleInstanceError
        except ImportError:
            from IPython.config.configurable import MultipleInstanceError
        try:
            import ipdb
            return ipdb.set_trace
        except (ImportError, MultipleInstanceError):
            from IPython.core.debugger import Tracer
            return Tracer()
    except Exception:
        import pdb
        return pdb.set_trace
예제 #28
0
 def train_step(self, data, **kwargs):
     # torch.autograd.set_detect_anomaly(True)
     loss, data_dict, r = self.model(data['X'], actions=data['a'].cuda().float(), pretrain=kwargs['pretrain'])
     self.optimizer.zero_grad()
     torch.mean(-1. * loss).backward()
     if self.clip_gradient:
         torch.nn.utils.clip_grad_norm_(self.model.parameters(), self.clip_gradient_value)
     for n, p in self.model.named_parameters():
         if p.grad is not None:
             # print(f'{n}: {p.grad.max()} {p.grad.min()} {p.grad.mean()}')
             if not torch.isfinite(p.grad.mean()):
                 from IPython.core.debugger import Tracer
                 Tracer()()
     self.optimizer.step()
     return data_dict
예제 #29
0
파일: regression.py 프로젝트: BenikaH/NBA
def main():

    team = 'BOS'
    games = get_season_games_for_team(season='2015-16', team=team)
    games = sorted(games, key=lambda x: x.date)
    assert_ordered_games(games)
    win_points = [0]
    wins = 0
    for g in games:
        wins = update_wins(wins, team, g)
        win_points.append(wins)

    plt.scatter(x=[i for i in range(0, len(win_points))], y=win_points)
    plt.show()
    Tracer()()
예제 #30
0
def check_idempotent_create(expr):
    """Check that an expression is 'idempotent'"""
    from qalgebra.core.abstract_algebra import Expression

    print("*** CHECKING IDEMPOTENCY of %s" % expr)
    if isinstance(expr, Expression):
        new_expr = expr.create(*expr.args, **expr.kwargs)
        if new_expr != expr:
            # noinspection PyPackageRequirements
            from IPython.core.debugger import Tracer

            Tracer()()
            print(expr)
            print(new_expr)
    print("*** IDEMPOTENCY OK")