// Gets the baysian.Classifier which has been trained on programming language
// samples from github.com/github/linguist after running the generator
//
// See also cmd/generate-classifier
197340
func getClassifier() *bayesian.Classifier {
	// NOTE(tso): this could probably go into an init() function instead
	// but this lazy loading approach works, and it's conceivable that the
	// analyse() function might not invoked in an actual runtime anyway
	if !classifier_initialized {
		data, err := data.Asset("classifier")
		if err != nil {
			log.Panicln(err)
		}
		reader := bytes.NewReader(data)
		classifier, err = bayesian.NewClassifierFromReader(reader)
		if err != nil {
			log.Panicln(err)
		}
		classifier_initialized = true
	}
	return classifier
}
489608
func (t *Template) GetAWSGlueClassifierWithName(name string) (*resources.AWSGlueClassifier, error) {
	if untyped, ok := t.Resources[name]; ok {
		switch resource := untyped.(type) {
		case *resources.AWSGlueClassifier:
			return resource, nil
		}
	}
	return nil, fmt.Errorf("resource %q of type AWSGlueClassifier not found", name)
}
1008880
func loadCascadeClassifier(haar string) *gocv.CascadeClassifier {
	if classifier != nil {
		return classifier
	}

	c := gocv.NewCascadeClassifier()
	c.Load(haar)
	classifier = &c
	return classifier
}
696906
func GetMethodLogger(methodName string) *MethodLogger {
	if binLogger == nil {
		return nil
	}
	return binLogger.getMethodLogger(methodName)
}
359043
func (cg ClassifierGroup) Classify(err error) bool {
	for _, classifier := range cg {
		if classifier.Classify(err) {
			return true
		}
	}
	return false
}
1185272
func NewBernoulliNBClassifier() *BernoulliNBClassifier {
	nb := BernoulliNBClassifier{}
	nb.condProb = make(map[string][]float64)
	nb.features = 0
	nb.trainingInstances = 0
	return &nb
}
66966
func (c *ClassifierDeserializer) GetU64ForKey(key string) (uint64, error) {
	b, err := c.GetBytesForKey(key)
	if err != nil {
		return 0, err
	}
	return UnpackBytesToU64(b), nil
}
327691
func getCallerInfo() string {
	var info string

	for i := 0; ; i++ {
		pc, file, line, ok := runtime.Caller(i)
		if !ok {
			break
		}

		// 定位以 _test.go 结尾的文件。
		basename := path.Base(file)
		if !strings.HasSuffix(basename, "_test.go") {
			continue
		}

		// 定位函数名为 Test 开头的行。
		// 为什么要定位到 TestXxx 函数，是因为考虑以下情况：
		//  func isOK(val interface{}, t *testing.T) {
		//      // do somthing
		//      assert.True(t, val)  // (1
		//  }
		//
		//  func TestOK(t *testing.T) {
		//      isOK("123", t)       // (2
		//      isOK(123, t)         // (3
		//  }
		// 以上这段代码，定位到 (2、(3 的位置比总是定位到 (1 的位置更直观！
		funcName := runtime.FuncForPC(pc).Name()
		index := strings.LastIndex(funcName, ".Test")
		if -1 == index {
			index = strings.LastIndex(funcName, ".Benchmark")
			if index == -1 {
				continue
			}
		}
		funcName = funcName[index+1:]

		// Go1.5 之后的匿名函数为 TestA.func1
		// 包含以下几种情况：
		// 调用函数内的匿名函数；
		// 采用 go func(){} 的形式调用函数内的匿名函数；
		// 采用 go func(){} 的形式调用外部函数；
		//
		// 但是无法处理 go xx() 的情况，该情况直接开启一个新的堆栈信息，无法定位当前函数中的调用位置。
		if index := strings.IndexByte(funcName, '.'); index > -1 {
			funcName = funcName[:index]
			info = funcName + "(" + basename + ":" + strconv.Itoa(line) + ")"
			continue
		}

		info = funcName + "(" + basename + ":" + strconv.Itoa(line) + ")"
		break
	}

	if info == "" {
		info = "<无法获取调用者信息>"
	}
	return info
}
357666
func NewPerceptronTagger() *PerceptronTagger {
	var wts map[string]map[string]float64
	var tags map[string]string
	var classes []string

	dec := model.GetAsset("classes.gob")
	util.CheckError(dec.Decode(&classes))

	dec = model.GetAsset("tags.gob")
	util.CheckError(dec.Decode(&tags))

	dec = model.GetAsset("weights.gob")
	util.CheckError(dec.Decode(&wts))

	return &PerceptronTagger{model: NewAveragedPerceptron(wts, tags, classes)}
}
306617
func (l *Language) Get(key string) interface{} {
	local := l.GetLocal(key)
	if local != nil {
		return local
	}
	return l.Cfg.Get(key)
}
622591
func GetLangByIndex(index int) string {
	if index < 0 || index >= len(locales.langs) {
		return ""
	}
	return locales.langs[index]
}
880777
func (p *Tagger) Train(sentences []treebank.SentenceTag, iterations int) {
	if p.progress != nil {
		defer func() {
			close(p.progress)
			p.progress = nil
		}()
	}

	p.fillCache(sentences)

	// Somehow sentenceTag.AnnotatedSentence() is memory leaky.
	// As a result, the more training iterations there is, the more memory is used and not released
	// hence the cache is necessary.
	cache := make(map[string]lingo.AnnotatedSentence)
	for iter := 0; iter < iterations; iter++ {
		c := 0
		n := 0
		shortcutted := 0

		var s lingo.AnnotatedSentence
		for _, sentenceTag := range sentences {
			tags := []lingo.POSTag{lingo.ROOT_TAG}
			tags = append(tags, sentenceTag.Tags...)

			var ok bool
			if s, ok = cache[sentenceTag.String()]; !ok {
				s = sentenceTag.AnnotatedSentence(p) // the fixer is used to extract cluster information, etc into the *Annotation
				cache[sentenceTag.String()] = s
			}

			length := len(s)
			if length == 0 {
				continue
			}

			for _, a := range s {
				if a == lingo.RootAnnotation() {
					continue
				}
				a.POSTag = lingo.X
			}

			for i, a := range s {
				// processing
				truth := tags[i]

				guess, ok := p.shortcut(a.Lexeme)
				if !ok {
					sf, tf := getFeatures(s, i)
					guess = p.perceptron.predict(sf, tf)
					p.perceptron.update(guess, truth, sf, tf)
				} else {
					shortcutted++
				}
				p.setTag(a, guess)

				if guess == truth {
					c++
				}
				n++
			}
		}

		if iter%150 == 0 {
			p.perceptron.average()
			logf("Averaged perceptron")
		}

		if p.progress != nil {
			p.progress <- Progress{Iter: iter, Correct: c, Count: n, ShortCutted: shortcutted}
		}

		treebank.ShuffleSentenceTag(sentences)
	}
	p.perceptron.average()
}
1212800
func (c *CheckRunAnnotation) GetAnnotationLevel() string {
	if c == nil || c.AnnotationLevel == nil {
		return ""
	}
	return *c.AnnotationLevel
}
447643
func GetTrueNegatives(class string, c ConfusionMatrix) float64 {
	ret := 0.0
	for k := range c {
		if k == class {
			continue
		}
		for l := range c[k] {
			if l == class {
				continue
			}
			ret += float64(c[k][l])
		}
	}
	return ret
}
633564
func (r Provisioning_Maintenance_Classification) GetMaintenanceClassification(maintenanceClassificationId *int) (resp []datatypes.Provisioning_Maintenance_Classification, err error) {
	params := []interface{}{
		maintenanceClassificationId,
	}
	err = r.Session.DoRequest("SoftLayer_Provisioning_Maintenance_Classification", "getMaintenanceClassification", params, &r.Options, &resp)
	return
}
274109
func (b *BinningFilter) Train() error {

	as := b.getAttributeSpecs()
	// Set up the AttributeSpecs, and values
	for attr := range b.attrs {
		if !b.attrs[attr] {
			continue
		}
		b.minVals[attr] = float64(math.Inf(1))
		b.maxVals[attr] = float64(math.Inf(-1))
	}

	err := b.train.MapOverRows(as, func(row [][]byte, rowNo int) (bool, error) {
		for i, a := range row {
			attr := as[i].GetAttribute()
			attrf := attr.(*base.FloatAttribute)
			val := float64(attrf.GetFloatFromSysVal(a))
			if val > b.maxVals[attr] {
				b.maxVals[attr] = val
			}
			if val < b.minVals[attr] {
				b.minVals[attr] = val
			}
		}
		return true, nil
	})

	if err != nil {
		return fmt.Errorf("Training error: %s", err)
	}
	b.trained = true
	return nil
}
225551
func (brewDep BrewDepModel) GetBinaryName() string {
	if brewDep.BinName != "" {
		return brewDep.BinName
	}
	return brewDep.Name
}