numpy.nanargmax

Here are the examples of the python api numpy.nanargmax taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

Example 1

Project: icu_rnn Source File: evaluation.py
def optimize_threshold_with_f1(f1c, thresholds, criterion='max'):
    #f1c[np.isnan(f1c)] = 0
    if criterion == 'max':
        ti = np.nanargmax(f1c)
    else:
        ti = np.nanargmin(np.abs(thresholds-0.5*f1c))
        #assert(np.all(thresholds>=0))
        #idx = (thresholds>=f1c*0.5-mp) & (thresholds<=f1c*0.5+mp)
        #assert(np.any(idx))
        #ti = np.where(idx)[0][f1c[idx].argmax()]
    return thresholds[ti], ti

Example 2

Project: histwords Source File: analogy_eval.py
Function: guess
def guess(representation, sims, xi, a, a_, b):
    sa = sims[xi[a]]
    sa_ = sims[xi[a_]]
    sb = sims[xi[b]]
    
    add_sim = -sa+sa_+sb
    if a in representation.wi:
        add_sim[representation.wi[a]] = 0
    if a_ in representation.wi:
        add_sim[representation.wi[a_]] = 0
    if b in representation.wi:
        add_sim[representation.wi[b]] = 0
    b_add = representation.iw[np.nanargmax(add_sim)]
    
    mul_sim = sa_*sb*np.reciprocal(sa+0.01)
    if a in representation.wi:
        mul_sim[representation.wi[a]] = 0
    if a_ in representation.wi:
        mul_sim[representation.wi[a_]] = 0
    if b in representation.wi:
        mul_sim[representation.wi[b]] = 0
    b_mul = representation.iw[np.nanargmax(mul_sim)]
    
    return b_add, b_mul

Example 3

Project: GroundedTranslation Source File: Callbacks.py
    def early_stop_decision(self, epoch, val_metric, val_loss):
        '''
	Stop training if validation loss has stopped decreasing and
	validation BLEU score has not increased for --patience epochs.

        WARNING: quits with sys.exit(0).

	TODO: this doesn't yet support early stopping based on TER
        '''

	if val_loss < self.best_val_loss:
	    self.wait = 0
        elif val_metric > self.best_val_metric or self.args.no_early_stopping:
            self.wait = 0
        else:
            self.wait += 1
            if self.wait >= self.patience:
                # we have exceeded patience
                if val_loss > self.best_val_loss:
                    # and loss is no longer decreasing
                    logger.info("Epoch %d: early stopping", epoch)
                    handle = open("checkpoints/%s/summary"
                                  % self.args.run_string, "a")
                    handle.write("Early stopping because patience exceeded\n")
                    best_bleu = np.nanargmax(self.val_metric)
                    best_loss = np.nanargmin(self.val_loss)
                    logger.info("Best Metric: %d | val loss %.5f score %.2f",
                                best_bleu+1, self.val_loss[best_bleu],
                                self.val_metric[best_bleu])
                    logger.info("Best loss: %d | val loss %.5f score %.2f",
                                best_loss+1, self.val_loss[best_loss],
                                self.val_metric[best_loss])
                    handle.close()
                    sys.exit(0)

Example 4

Project: GroundedTranslation Source File: Callbacks.py
Function: log_performance
    def log_performance(self):
        '''
        Record model performance so far, based on validation loss.
        '''
        handle = open("checkpoints/%s/summary" % self.args.run_string, "w")

        for epoch in range(len(self.val_loss)):
            handle.write("Checkpoint %d | val loss: %.5f bleu %.2f\n"
                         % (epoch+1, self.val_loss[epoch],
                            self.val_metric[epoch]))

        logger.info("---")  # break up the presentation for clarity

        # BLEU is the quickest indicator of performance for our task
        # but loss is our objective function
        best_bleu = np.nanargmax(self.val_metric)
        best_loss = np.nanargmin(self.val_loss)
        logger.info("Best Metric: %d | val loss %.5f score %.2f",
                    best_bleu+1, self.val_loss[best_bleu],
                    self.val_metric[best_bleu])
        handle.write("Best Metric: %d | val loss %.5f score %.2f\n"
                     % (best_bleu+1, self.val_loss[best_bleu],
                        self.val_metric[best_bleu]))
        logger.info("Best loss: %d | val loss %.5f score %.2f",
                    best_loss+1, self.val_loss[best_loss],
                    self.val_metric[best_loss])
        handle.write("Best loss: %d | val loss %.5f score %.2f\n"
                     % (best_loss+1, self.val_loss[best_loss],
                        self.val_metric[best_loss]))
        logger.info("Early stopping marker: wait/patience: %d/%d\n",
                    self.wait, self.patience)
        handle.write("Early stopping marker: wait/patience: %d/%d\n" %
                     (self.wait, self.patience))
        handle.close()

Example 5

Project: chumpy Source File: ch_ops.py
Function: argf
    def argf(self, *args, **kwargs): return np.nanargmax(*args, **kwargs)
    

class Extremum(ch.Ch):