// Return the most likely correction for the input term
541306
func (model *Model) SpellCheck(input string) string {
	model.RLock()
	suggestions := model.suggestPotential(input, false)
	model.RUnlock()
	return best(input, suggestions)
}
851348
func (c *Command) predict(a Args) (options []string, only bool) {

	// search sub commands for predictions first
	subCommandFound := false
	for i, arg := range a.Completed {
		if cmd, ok := c.Sub[arg]; ok {
			subCommandFound = true

			// recursive call for sub command
			options, only = cmd.predict(a.from(i))
			if only {
				return
			}

			// We matched so stop searching. Continuing to search can accidentally
			// match a subcommand with current set of commands, see issue #46.
			break
		}
	}

	// if last completed word is a global flag that we need to complete
	if predictor, ok := c.GlobalFlags[a.LastCompleted]; ok && predictor != nil {
		Log("Predicting according to global flag %s", a.LastCompleted)
		return predictor.Predict(a), true
	}

	options = append(options, c.GlobalFlags.Predict(a)...)

	// if a sub command was entered, we won't add the parent command
	// completions and we return here.
	if subCommandFound {
		return
	}

	// if last completed word is a command flag that we need to complete
	if predictor, ok := c.Flags[a.LastCompleted]; ok && predictor != nil {
		Log("Predicting according to flag %s", a.LastCompleted)
		return predictor.Predict(a), true
	}

	options = append(options, c.Sub.Predict(a)...)
	options = append(options, c.Flags.Predict(a)...)
	if c.Args != nil {
		options = append(options, c.Args.Predict(a)...)
	}

	return
}
349679
func (c *Command) Predict(a Args) []string {
	options, _ := c.predict(a)
	return options
}
989823
func (d *SequenceDiffer) computeOptimal(ai, bi int, m blockMode) int32 {
	// base case: no more lines to align
	if ai > len(d.a)-1 || bi > len(d.b)-1 {
		return 0
	}

	// return memoized result
	if d.solution[ai][bi] != Unknown {
		return d.ab[ai][bi]
	}
	// initialize score to infinity
	d.ab[ai][bi] = -math.MaxInt32

	// case: skip a, addition in b (deletion in a)
	if ai < len(d.a) {
		s := d.computeOptimal(ai+1, bi, modeDeleteA)
		s += d.weights.Deletion
		if m != modeDeleteA {
			s += d.weights.NewMode
		}
		if s >= d.ab[ai][bi] {
			d.ab[ai][bi] = s
			d.solution[ai][bi] = LineFromA
		}
	}

	// case: skip b, addition in a (deletion in b)
	if bi < len(d.b) {
		s := d.computeOptimal(ai, bi+1, modeDeleteB)
		s += d.weights.Deletion
		if m != modeDeleteB {
			s += d.weights.NewMode
		}
		if s >= d.ab[ai][bi] {
			d.ab[ai][bi] = s
			d.solution[ai][bi] = LineFromB
		}
	}

	// align lines
	if ai < len(d.a) && bi < len(d.b) {
		var n blockMode
		var s int32
		if d.isLineEqual(d.a[ai], d.b[bi]) {
			n = modeMatch
			s = d.weights.Match
		} else {
			n = modeMismatch
			s = d.weights.Mismatch
		}
		s += d.computeOptimal(ai+1, bi+1, n)
		if m != n {
			s += d.weights.NewMode
		}
		if s >= d.ab[ai][bi] {
			d.ab[ai][bi] = s
			// todo: consolidate with n
			if n == modeMatch {
				d.solution[ai][bi] = LineFromBoth
			} else {
				d.solution[ai][bi] = LineFromBothEdit
			}
		}
	}

	return d.ab[ai][bi]
}
699797
func (model *Model) SpellCheckSuggestions(input string, n int) []string {
	model.RLock()
	suggestions := model.suggestPotential(input, true)
	model.RUnlock()
	return bestn(input, suggestions, n)
}
916890
func (api trackApi) GetCorrection(args map[string]interface{}) (result TrackGetCorrection, err error) {
	defer func() { appendCaller(err, "lastfm.Track.Correction") }()
	err = callGet("track.getcorrection", api.params, args, &result, P{
		"plain": []string{"artist", "track"},
	})
	return
}
376007
func getChangeStatus(lastSeq string, currSeq string) int {
	seqPrev, err := common.ParseSequence(lastSeq)
	if err != nil {
		log.Panicf("Unable to parse previous sequence string: %v", err)
	}
	seqCurr, err := common.ParseSequence(currSeq)
	if err != nil {
		log.Panicf("Unable to parse current sequence string: %v", err)
	}
	return seqCurr.Compare(seqPrev)
}
1304434
func (b *AnnealingEpsilonGreedy) Epsilon() float64 {
	// Compute epsilon based on the total number of trials
	t := uint64(1)
	for _, i := range b.counts {
		t += i
	}

	// The more trials the smaller that epsilon is
	return 1 / math.Log(float64(t)+0.0000001)
}
510739
func GetFalseNegatives(class string, c ConfusionMatrix) float64 {
	ret := 0.0
	for k := range c[class] {
		if k == class {
			continue
		}
		ret += float64(c[class][k])
	}
	return ret
}
780830
func calculateSigma(dimensions, guesses int) float64 {
	return math.Pow(3*math.Pow(float64(guesses), 1/float64(dimensions)), -1)
}
1169393
func (t *TFIDF) MostImportantWords(sentence string, n int) Frequencies {
	sentence, _, _ = transform.String(t.sanitize, sentence)
	document := t.Tokenizer.Tokenize(sentence)

	freq := TermFrequencies(document)
	for i := range freq {
		freq[i].TFIDF = freq[i].Frequency * t.InverseDocumentFrequency(freq[i].Word)
		freq[i].Frequency = float64(0.0)
	}

	// sort into slice
	sort.Sort(sort.Reverse(freq))

	if n > len(freq) {
		return freq
	}

	return freq[:n]
}
823739
func (t *Tokenizer) CorrectOffset(currentOff int) int {
	assert2(t.Input != nil, "this tokenizer is closed")
	if v, ok := t.Input.(CharFilterService); ok {
		return v.CorrectOffset(currentOff)
	}
	return currentOff
}
1314862
func errorWithPrecision(bits uint) (latErr, lngErr float64) {
	b := int(bits)
	latBits := b / 2
	lngBits := b - latBits
	latErr = math.Ldexp(180.0, -latBits)
	lngErr = math.Ldexp(360.0, -lngBits)
	return
}
527990
func (s *Softmax) Predict(x []float64, normalize ...bool) ([]float64, error) {
	if len(s.Parameters) != 0 && len(x)+1 != len(s.Parameters[0]) {
		return nil, fmt.Errorf("Error: Parameter vector should be 1 longer than input vector!\n\tLength of x given: %v\n\tLength of parameters: %v (len(theta[0]) = %v)\n", len(x), len(s.Parameters), len(s.Parameters[0]))
	}

	if len(normalize) != 0 && normalize[0] {
		base.NormalizePoint(x)
	}

	result := make([]float64, s.k)
	var denom float64

	for i := 0; i < s.k; i++ {
		// include constant term in sum
		sum := s.Parameters[i][0]

		for j := range x {
			sum += x[j] * s.Parameters[i][j+1]
		}

		result[i] = math.Exp(sum)
		denom += result[i]
	}

	for i := range result {
		result[i] /= denom
	}

	return result, nil
}
750049
func (l *Lexer) ReverseTrim() {
	for i := len(l.input) - 1; i >= 0; i-- {
		if !unicode.IsSpace(rune(l.input[i])) {
			if i < (len(l.input) - 1) {
				//u.Warnf("trim: '%v'", l.input[:i+1])
				l.input = l.input[:i+1]
			}
			break
		}
	}
}
80216
func (i *Index) IterateSimilar(input string, min float64, limit int) <-chan MatchResult {
  c := make(chan MatchResult)
  go i.iterateSimilar(c, input, min, limit)
  return c
}
247952
func (p PredictFunc) Predict(a Args) []string {
	if p == nil {
		return nil
	}
	return p(a)
}