Keep Negative (resample)
    xlabel = "Max fraction of features kept"
    ylabel = "Negative mean model output"
    transform = "negate"
    sort_order = 11
327681
def keep_negative_resample(X, y, model_generator, method_name, num_fcounts=11):
    
    return __run_measure(measures.keep_resample, X, y, model_generator, method_name, -1, num_fcounts, __mean_pred)
66339
def copy_neg(self):
        
        result = mpfr.Mpfr_t.__new__(BigFloat)
        mpfr.mpfr_init2(result, self.precision)
        new_sign = not self._sign()
        mpfr.mpfr_setsign(result, self, new_sign, ROUND_TIES_TO_EVEN)
        return result
771415
def normalize(self, mag=1.):
        

        def f(dataset, s, null, mag):
            dataset[s] -= null
            dataset[s] /= mag

        if self.signed:
            mag = self.mag() / mag
        else:
            mag = self.max() / mag
        self.chunkwise(f, null=self.null, mag=mag)
        self._null = 0
533536
def sigma_fltr(dem, n=3):
    
    std = dem.std()
    u = dem.mean()
    print('Excluding values outside of range: {1:0.2f} +/- {0}*{2:0.2f}'.format(n, u, std))
    rangelim = (u - n*std, u + n*std)
    out = range_fltr(dem, rangelim)
    return out
1258461
def remove_positive_mask(X, y, model_generator, method_name, num_fcounts=11):
    
    return __run_measure(measures.remove_mask, X, y, model_generator, method_name, 1, num_fcounts, __mean_pred)
357596
def resample(self,N,**kwargs):
        
        lovals = self.mu - np.absolute(rand.normal(size=N)*self.siglo)
        hivals = self.mu + np.absolute(rand.normal(size=N)*self.sighi)

        u = rand.random(size=N)
        hi = (u < float(self.sighi)/(self.sighi + self.siglo))
        lo = (u >= float(self.sighi)/(self.sighi + self.siglo))

        vals = np.zeros(N)
        vals[hi] = hivals[hi]
        vals[lo] = lovals[lo]
        return vals
642310
def keep_absolute_resample__r2(X, y, model_generator, method_name, num_fcounts=11):
    
    return __run_measure(measures.keep_resample, X, y, model_generator, method_name, 0, num_fcounts, sklearn.metrics.r2_score)
56929
def resample(args):
    
    p = OptionParser(resample.__doc__)
    opts, args, iopts = p.set_image_options(args, figsize="8x4", dpi=300)

    if len(args) != 2:
        sys.exit(not p.print_help())

    dataA, dataB = args
    fig = plt.figure(1, (iopts.w, iopts.h))
    root = fig.add_axes([0, 0, 1, 1])
    A = fig.add_axes([.1, .18, .32, .64])
    B = fig.add_axes([.6, .18, .32, .64])
    dataA = import_data(dataA)
    dataB = import_data(dataB)
    xlabel = "Fraction of markers"
    ylabels = ("Anchor rate", "Runtime (m)")
    legend = ("anchor rate", "runtime")
    subplot_twinx(A, dataA, xlabel, ylabels,
                     title="Yellow catfish", legend=legend)
    subplot_twinx(B, dataB, xlabel, ylabels,
                     title="Medicago", legend=legend)

    labels = ((.04, .92, "A"), (.54, .92, "B"))
    panel_labels(root, labels)

    normalize_axes(root)
    image_name = "resample." + iopts.format
    savefig(image_name, dpi=iopts.dpi, iopts=iopts)
179921
def sample_normalize(self, k_samples=1000, overwrite=False):
        
        log = logUtil.getlogger()
        log.info("Calculating mean and std from samples")
        # if k_samples is negative then it goes through total dataset
        if k_samples < 0:
            audio_paths = self.audio_paths

        # using sample
        else:
            k_samples = min(k_samples, len(self.train_audio_paths))
            samples = self.rng.sample(self.train_audio_paths, k_samples)
            audio_paths = samples
        manager = Manager()
        return_dict = manager.dict()
        jobs = []
        for threadIndex in range(cpu_count()):
            proc = Process(target=self.preprocess_sample_normalize, args=(threadIndex, audio_paths, overwrite, return_dict))
            jobs.append(proc)
            proc.start()
        for proc in jobs:
            proc.join()

        feat = np.sum(np.vstack([item['feat'] for item in return_dict.values()]), axis=0)
        count = sum([item['count'] for item in return_dict.values()])
        feat_squared = np.sum(np.vstack([item['feat_squared'] for item in return_dict.values()]), axis=0)

        self.feats_mean = feat / float(count)
        self.feats_std = np.sqrt(feat_squared / float(count) - np.square(self.feats_mean))
        np.savetxt(
            generate_file_path(self.save_dir, self.model_name, 'feats_mean'), self.feats_mean)
        np.savetxt(
            generate_file_path(self.save_dir, self.model_name, 'feats_std'), self.feats_std)
        log.info("End calculating mean and std from samples")
1324709
def _keep_positive(self):
        ''''''
        nonpositive = [elem for elem, count in self.items() if not count > 0]
        for elem in nonpositive:
            del self[elem]
        return self
966553
def sample_with_temperature(logits, temperature, sampling_keep_top_k=-1):
  
  if temperature == 0.0:
    # TF argmax doesn't handle >5 dimensions, so we reshape here.
    logits_shape = shape_list(logits)
    argmax = tf.argmax(tf.reshape(logits, [-1, logits_shape[-1]]), axis=1)
    return tf.reshape(argmax, logits_shape[:-1])
  else:
    assert temperature > 0.0

    if sampling_keep_top_k != -1:
      if sampling_keep_top_k <= 0:
        raise ValueError("sampling_keep_top_k must either be -1 or positive.")

      vocab_size = shape_list(logits)[1]

      k_largest = tf.contrib.nn.nth_element(
          logits, n=sampling_keep_top_k, reverse=True)
      k_largest = tf.tile(tf.reshape(k_largest, [-1, 1]), [1, vocab_size])

      # Force every position that is not in the top k to have probability near
      # 0 by setting the logit to be very negative.
      logits = tf.where(tf.less_equal(logits, k_largest),
                        tf.ones_like(logits)*-1e6, logits)

    reshaped_logits = (
        tf.reshape(logits, [-1, shape_list(logits)[-1]]) / temperature)
    choices = tf.multinomial(reshaped_logits, 1)
    choices = tf.reshape(choices,
                         shape_list(logits)[:logits.get_shape().ndims - 1])
    return choices
377086
def normalize( trainingset ):
    
    
    def encoder( dataset ):
        for instance in dataset:
            if np.any(stds == 0):
                nonzero_indexes = np.where(stds!=0)
                instance.features[nonzero_indexes] = instance.features[nonzero_indexes] / stds[nonzero_indexes]
            else:
                instance.features = instance.features / stds
        return dataset
    #end
    
    training_data = np.array( [instance.features for instance in trainingset ] )
    stds = training_data.std(axis=0)
    
    return encoder
469460
def xloss(logits, labels, ignore=None):
    
    return F.cross_entropy(logits, Variable(labels), ignore_index=255)
227094
def xlim(self, low, high):
        
        self.chart['xAxis'][0]['min'] = low
        self.chart['xAxis'][0]['max'] = high
        return self
776212
def clean(self,x):
        """"""
        return x[~np.any(np.isnan(x) | np.isinf(x),axis=1)]
786918
def df2plotshape(dlen,xlabel_unit,ylabel_unit,
                 suptitle='',fix='h',xlabel_skip=[],
                 test=False):
    
    dlen['xlabel']=dlen.apply(lambda x : f"{x['_xlen']}" if not x['title'] in xlabel_skip else '',axis=1)
    dlen['ylabel']=dlen.apply(lambda x : "",axis=1)
    ylen=dlen['_ylen'].unique()[0]
    
    if test: print(dlen.columns)
    if fix=='h':    
        dlen['xlen']=dlen['_xlen']/dlen['_xlen'].max()/len(dlen)*0.8
        dlen['ylen']=0.8
        subsets=[]
        for subset in [c for c in dlen if c.startswith('_ylen ')]:
            subsetcol=subset.replace('_ylen','ylen')
            dlen[subsetcol]=0.25
            subsets.append(subsetcol)
        subsets2cols=dict(zip([subsetcol.replace('ylen ','') for s in subsets],subsets))
        if test: print(dlen.columns)
        if test: print(subsets2cols)
    elif fix=='w':    
        dlen['xlen']=0.8
        dlen['ylen']=dlen['_ylen']/dlen['_ylen'].max()/len(dlen)*0.85
   
    dlen=dlen.drop([c for c in dlen if c.startswith('_')],axis=1)    
    if test: print(dlen.columns)
    if fig is None:fig = plt.figure(figsize=[4,4])
    for idx in dlen.index:
        if idx==0:x_=0
        kws_plot_rect=makekws_plot_rect(dlen,fig,idx,x_)
        if test: print(kws_plot_rect)
        kws_plot_rect_big={k:kws_plot_rect[k] for k in kws_plot_rect if not 'ylen ' in k}
        kws_plot_rect_big['color']='gray'
        ax=plot_rect(**kws_plot_rect_big)
        for subset in subsets2cols:
            kws_plot_rect=makekws_plot_rect(dlen.drop('ylen',axis=1).rename(columns={subsets2cols[subset]:'ylen'}),fig,idx,x_)
            kws_plot_rect['title']=''
            kws_plot_rect['xlabel']=''
            kws_plot_rect['ylabel']=subset
            if idx!=0:kws_plot_rect['ylabel']=''
            if test: print(kws_plot_rect)
            ax=plot_rect(**kws_plot_rect)            
        x_=kws_plot_rect['x']+dlen.loc[idx,'xlen']+0.1  
    
    ax.text(x_/2.3,-0.1,xlabel_unit,ha='center')
    ax.text(x_/2.3,0.9,suptitle,ha='center')
    ax.text(-0.1,0.4,f"total ~{ylen}{ylabel_unit}",va='center',rotation=90)
    if fig is not None:
        return fig,ax
    else:
        return ax
54540
def _transform_data(self, X):
        """"""

        if self._binarizers == []:
            raise NotFittedError()

        if self.binarize is not None:
            X = binarize(X, threshold=self.binarize)

        if len(self._binarizers) != X.shape[1]:
            raise ValueError(
                "Expected input with %d features, got %d instead" %
                (len(self._binarizers), X.shape[1]))

        X_parts = []

        for i in range(X.shape[1]):

            X_i = self._binarizers[i].transform(X[:, i])

            # sklearn returns ndarray with shape (samples, 1) on binary input.
            if self._binarizers[i].classes_.shape[0] == 2:
                X_parts.append(1 - X_i)

            X_parts.append(X_i)

        return np.concatenate(X_parts, axis=1)