/*HtTrendLine - Hilbert Transform - Instantaneous Trendline

Input = double

Output = double

*/
481194
func HtTrendLine(real []float64) []float64 {
	var outBegIdx C.int
	var outNBElement C.int
	outReal := make([]float64, len(real))
	C.TA_HT_TRENDLINE(0, C.int(len(real)-1), (*C.double)(unsafe.Pointer(&real[0])), &outBegIdx, &outNBElement, (*C.double)(unsafe.Pointer(&outReal[0])))
	return outReal[:outNBElement]
}
788539
func (l *LeastSquares) J() (float64, error) {
	var sum float64

	for i := range l.trainingSet {
		prediction, err := l.Predict(l.trainingSet[i])
		if err != nil {
			return 0, err
		}

		sum += (l.expectedResults[i] - prediction[0]) * (l.expectedResults[i] - prediction[0])
	}

	// add regularization term!
	//
	// notice that the constant term doesn't matter
	for i := 1; i < len(l.Parameters); i++ {
		sum += l.regularization * l.Parameters[i] * l.Parameters[i]
	}

	return sum / float64(2*len(l.trainingSet)), nil
}
1252861
func getSplitEntropyFast(s [2][]int) float64 {
	ret := 0.0
	count := 0
	for a := range s {
		for c := range s[a] {
			count += s[a][c]
		}
	}
	for a := range s {
		total := 0.0
		for c := range s[a] {
			total += float64(s[a][c])
		}
		for c := range s[a] {
			if s[a][c] != 0 {
				ret -= float64(s[a][c]) / float64(count) * math.Log(float64(s[a][c])/float64(count)) / math.Log(2)
			}
		}
		ret += total / float64(count) * math.Log(total/float64(count)) / math.Log(2)
	}
	return ret
}
246120
func (c C) HypotApx(val Input) Input {
	if v, ok := val.(C); ok {
		var (
			x = float32(math.Abs(float64(c))) + float32(math.Abs(float64(v)))
			y = float32(math.Min(math.Abs(float64(c)), math.Abs(float64(v))))
		)
		return C(x - ((float32(math.Sqrt(2)) - 1) * y))
	}
	return val.HypotApx(c)
}
1318613
func (f *Fpdf) TransformTranslate(tx, ty float64) {
	f.Transform(TransformMatrix{1, 0, 0, 1, tx * f.k, -ty * f.k})
}
723460
func (s *StdoutClient) GaugeDelta(stat string, value int64) error {
	// Gauge Deltas are always sent with a leading '+' or '-'. The '-' takes care of itself but the '+' must added by hand
	if value < 0 {
		return s.send(stat, "%d|g", value)
	}
	return s.send(stat, "+%d|g", value)
}
317583
func StandardDeviationSample(input Float64Data) (sdev float64, err error) {

	if input.Len() == 0 {
		return math.NaN(), EmptyInputErr
	}

	// Get the sample variance
	vs, _ := SampleVariance(input)

	// Return the sample standard deviation
	return math.Pow(vs, 0.5), nil
}
685793
func (s *fseDecoder) transform(t []baseOffset) error {
	tableSize := uint16(1 << s.actualTableLog)
	s.maxBits = 0
	for i, v := range s.dt[:tableSize] {
		if int(v.addBits) >= len(t) {
			return fmt.Errorf("invalid decoding table entry %d, symbol %d >= max (%d)", i, v.addBits, len(t))
		}
		lu := t[v.addBits]
		if lu.addBits > s.maxBits {
			s.maxBits = lu.addBits
		}
		s.dt[i&maxTableMask] = decSymbol{
			newState: v.newState,
			nbBits:   v.nbBits,
			addBits:  lu.addBits,
			baseline: lu.baseLine,
		}
	}
	return nil
}
1242494
func futureEvalTimePretty(evalID string, client *api.Client) string {
	evaluation, _, err := client.Evaluations().Info(evalID, nil)
	// Eval time is not a critical output,
	// don't return it on errors, if its not set or already in the past
	if err != nil || evaluation.WaitUntil.IsZero() || time.Now().After(evaluation.WaitUntil) {
		return ""
	}
	return prettyTimeDiff(evaluation.WaitUntil, time.Now())
}
564103
func (ts TimeSeries) GetValueFormatters() (x, y ValueFormatter) {
	x = TimeValueFormatter
	y = FloatValueFormatter
	return
}
880461
func DiffDelta(src, tgt []byte) []byte {
	return diffDelta(new(deltaIndex), src, tgt)
}
626643
func (p *Point) MultiplyScalar(s float32) *Point {
	p.X *= s
	p.Y *= s
	return p
}
176837
func (ei *escapeInterpreter) outputNormal() error {
	for _, param := range ei.csiParam {
		p, err := strconv.Atoi(param)
		if err != nil {
			return errCSIParseError
		}

		switch {
		case p >= 30 && p <= 37:
			ei.curFgColor = Attribute(p - 30 + 1)
		case p == 39:
			ei.curFgColor = ColorDefault
		case p >= 40 && p <= 47:
			ei.curBgColor = Attribute(p - 40 + 1)
		case p == 49:
			ei.curBgColor = ColorDefault
		case p == 1:
			ei.curFgColor |= AttrBold
		case p == 4:
			ei.curFgColor |= AttrUnderline
		case p == 7:
			ei.curFgColor |= AttrReverse
		case p == 0:
			ei.curFgColor = ColorDefault
			ei.curBgColor = ColorDefault
		}
	}

	return nil
}
1270717
func (s *EmptyTransformer) Transform(inp Expression) Expression {
	inp.Accept(s.RealSelf)
	return s.Result
}
406437
func (pca *PCA) Transform(X *mat.Dense) *mat.Dense {
	if pca.svd == nil {
		panic("You should to fit PCA model first")
	}

	num_samples, num_features := X.Dims()

	vTemp := new(mat.Dense)
	pca.svd.VTo(vTemp)
	//Compute to full data
	if pca.Num_components == 0 || pca.Num_components > num_features {
		return compute(X, vTemp)
	}

	X = compute(X, vTemp)
	result := mat.NewDense(num_samples, pca.Num_components, nil)
	result.Copy(X)
	return result
}
1048779
func ioOutputFormatMinute(ld *LineData, b *bytes.Buffer) error {
	_, err := b.WriteString(fmt.Sprintf("%02d", ld.TimeStamp.Minute()))
	return err
}
1338828
func (sk *Sketch) maybeToNormal() {
	if uint32(len(sk.tmpSet))*100 > sk.m {
		sk.mergeSparse()
		if uint32(sk.sparseList.Len()) > sk.m {
			sk.toNormal()
		}
	}
}