This file is indexed.

/usr/share/gocode/src/github.com/influxdata/influxdb/influxql/neldermead/neldermead_test.go is in golang-github-influxdb-influxdb-dev 1.1.1+dfsg1-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package neldermead_test

import (
	"math"
	"testing"

	"github.com/influxdata/influxdb/influxql/neldermead"
)

func round(num float64, precision float64) float64 {
	rnum := num * math.Pow(10, precision)
	var tnum float64
	if rnum < 0 {
		tnum = math.Floor(rnum - 0.5)
	} else {
		tnum = math.Floor(rnum + 0.5)
	}
	rnum = tnum / math.Pow(10, precision)
	return rnum
}

func almostEqual(a, b, e float64) bool {
	return math.Abs(a-b) < e
}

func Test_Optimize(t *testing.T) {

	constraints := func(x []float64) {
		for i := range x {
			x[i] = round(x[i], 5)
		}
	}
	// 100*(b-a^2)^2 + (1-a)^2
	//
	// Obvious global minimum at (a,b) = (1,1)
	//
	// Useful visualization:
	// https://www.wolframalpha.com/input/?i=minimize(100*(b-a%5E2)%5E2+%2B+(1-a)%5E2)
	f := func(x []float64) float64 {
		constraints(x)
		// a = x[0]
		// b = x[1]
		return 100*(x[1]-x[0]*x[0])*(x[1]-x[0]*x[0]) + (1.0-x[0])*(1.0-x[0])
	}

	start := []float64{-1.2, 1.0}

	opt := neldermead.New()
	epsilon := 1e-5
	min, parameters := opt.Optimize(f, start, epsilon, 1)

	if !almostEqual(min, 0, epsilon) {
		t.Errorf("unexpected min: got %f exp 0", min)
	}

	if !almostEqual(parameters[0], 1, 1e-2) {
		t.Errorf("unexpected parameters[0]: got %f exp 1", parameters[0])
	}

	if !almostEqual(parameters[1], 1, 1e-2) {
		t.Errorf("unexpected parameters[1]: got %f exp 1", parameters[1])
	}

}