Exemplo n.º 1
0
func main() {
	m1 := matrix.MakeDenseMatrix([]float64{1, 2, 3, 4, 5, 6}, 3, 2)
	fmt.Println(m1)
	fmt.Println(matrix.Transpose(m1))
	res, _ := http.Get("http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv")
	defer res.Body.Close()

	reader := csv.NewReader(res.Body)
	reader.Comma = ';'
	//contents, _ := ioutil.ReadAll(res.Body)
	testData := make([][]float64, 0)
	for {
		col, err := reader.Read()
		if err == io.EOF {
			break
		}
		//strings.Split(col, ";")
		x := make([]float64, len(col))
		for i := range col {
			x[i], _ = strconv.ParseFloat(col[i], 64)
		}
		testData = append(testData, x)
	}
	ae := NewAutoEncoder()
	ae.Train(testData[1])

}
Exemplo n.º 2
0
func randmatstat(t int) (float64, float64) {
	n := 5
	var v stats.Stats
	var w stats.Stats
	for i := 0; i < t; i++ {
		a := matrix.Zeros(n, n)
		b := matrix.Zeros(n, n)
		c := matrix.Zeros(n, n)
		d := matrix.Zeros(n, n)
		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				a.Set(j, k, rand.NormFloat64())
				b.Set(j, k, rand.NormFloat64())
				c.Set(j, k, rand.NormFloat64())
				d.Set(j, k, rand.NormFloat64())
			}
		}
		P := matrix.Zeros(n, 4*n)
		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				P.Set(j, k, a.Get(j, k))
				P.Set(j, n+k, b.Get(j, k))
				P.Set(j, 2*n+k, c.Get(j, k))
				P.Set(j, 3*n+k, d.Get(j, k))
			}
		}
		Q := matrix.Zeros(2*n, 2*n)
		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				Q.Set(j, k, a.Get(j, k))
				Q.Set(j, n+k, b.Get(j, k))
				Q.Set(n+j, k, c.Get(j, k))
				Q.Set(n+j, n+k, d.Get(j, k))
			}
		}
		P = matrix.Product(matrix.Transpose(P), P)
		P = matrix.Product(P, P)
		P = matrix.Product(P, P)
		Q = matrix.Product(matrix.Transpose(Q), Q)
		Q = matrix.Product(Q, Q)
		Q = matrix.Product(Q, Q)
		v.Update(P.Trace())
		w.Update(Q.Trace())
	}
	return v.PopulationStandardDeviation() / float64(v.Count()) / v.Mean(), w.PopulationStandardDeviation() / float64(w.Count()) / w.Mean()
}