func main() { demo(mat.MakeDenseMatrix([]float64{ 25, 15, -5, 15, 18, 0, -5, 0, 11, }, 3, 3)) demo(mat.MakeDenseMatrix([]float64{ 18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106, }, 4, 4)) }
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]) }
func BenchmarkGoMatrixSvd(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() test := randomMatrix3() mat := matrix.MakeDenseMatrix(test[:], 3, 3) b.StartTimer() mat.SVD() } }
//Mints a new classifier. func (KNN *KNNClassifier) New(name string, labels []string, numbers []float64, x int, y int) { //Write in some error handling here // if x != len(KNN.Labels) { // return errors.New("KNN: There must be a label for each row") // } KNN.Data = *mat.MakeDenseMatrix(numbers, x, y) KNN.Name = name KNN.Labels = labels }
func Reduct() int { ret := 0 s := `[1 2 3;4 5 6]` A, err := matrix.ParseMatlab(s) Ar := matrix.MakeDenseMatrix([]float64{1, 2, 3, 4, 5, 6}, 2, 3) fmt.Print(A) fmt.Print(err) fmt.Print(Ar) return ret }
func Test_3x3_times_3xN(t *testing.T) { cols := 11 tests1 := randomMatrices(10000, 3, 3) tests2 := randomMatrices(10000, 3, cols) for i, test1 := range tests1 { test2 := tests2[i] // Compute our product. tC_ := mult_3x3_3xN(cols, test1, test2) tC := tmat(tC_[:]) // Now compute the "correct" product. mat1 := matrix.MakeDenseMatrix(test1, 3, 3) mat2 := matrix.MakeDenseMatrix(test2, 3, cols) aC_, _ := mat1.TimesDense(mat2) aC := tmat(aC_.Array()) if !tC.equal(aC) { t.Fatalf("The product of\n%s\nand\n%s\nis\n%s\nbut we said\n%s\n", tmat(test1), tmat(test2), aC, tC) } } }
func TestCovariant(t *testing.T) { cols := 11 tests1 := randomMatrices(10000, 3, cols) tests2 := randomMatrices(10000, 3, cols) for i, test1 := range tests1 { test2 := tests2[i] // Compute our covariant tC_ := covariant_3x3(cols, test1, test2) tC := tmat(tC_[:]) // Now compute the "correct" covariant. mat1 := matrix.MakeDenseMatrix(test1, 3, cols) mat2 := matrix.MakeDenseMatrix(test2, 3, cols) aC_, _ := mat1.TimesDense(mat2.Transpose()) aC := tmat(aC_.Array()) if !tC.equal(aC) { t.Fatalf("The covariant of\n%s\nand\n%s\nis\n%s\nbut we said\n%s\n", tmat(test1), tmat(test2), aC, tC) } } }
func main() { //Parses the infamous Iris data. cols, rows, _, labels, data := base.ParseCsv("datasets/randomdata.csv", 2, []int{0, 1}) newlabels := util.ConvertLabelsToFloat(labels) //Initialises a new KNN classifier knn := knnclass.KNNRegressor{} knn.New("Testing", newlabels, data, rows, cols) for { //Creates a random array of N float64s between 0 and Y randArray := util.RandomArray(2, 100) //Initialises a vector with this array random := mat.MakeDenseMatrix(randArray, 1, 2) //Calculates the Euclidean distance and returns the most popular label outcome, _ := knn.Predict(random, 3) fmt.Println(outcome) } }
func main() { //Parses the infamous Iris data. cols, rows, _, labels, data := base.ParseCsv("datasets/iris.csv", 4, []int{0, 1, 2}) //Initialises a new KNN classifier knn := knnclass.KNNClassifier{} knn.C knn.New("Testing", labels, data, rows, cols) for { //Creates a random array of N float64s between 0 and 7 randArray := util.RandomArray(3, 7) //Initialises a vector with this array random := mat.MakeDenseMatrix(randArray, 1, 3) //Calculates the Euclidean distance and returns the most popular label labels, _ := knn.Predict(random, 3) fmt.Println(labels) } }
func TestSvd(t *testing.T) { tests := randomMatrices3(10000) for _, test := range tests { // Compute our SVD. tU_, tV_ := matrix3(test).svd() tU, tV := tmat(tU_[:]), tmat(tV_[:]) // Now compute the "correct" SVD. mat := matrix.MakeDenseMatrix(test[:], 3, 3) U, _, V, _ := mat.SVD() aU, aV := tmat(U.Array()), tmat(V.Array()) // Now compare them. if !aU.equal(tU) { t.Fatalf("With matrix\n%s\nU =\n%s\nbut we said\n%s\n", tmat(test[:]), aU, tU) } if !aV.equal(tV) { t.Fatalf("With matrix\n%s\n, V =\n%s\n, but we said\n%s\n", tmat(test[:]), aV, tV) } } }
// choleskyMatrix takes the array of floats provided by the JSON data, and // converts it to a matrix. // Receiver: SimulationData // Params: none // Returns: *goMatrix.DenseMatrix func (s *SimulationData) choleskyMatrix() *goMatrix.DenseMatrix { vals := s.CholeskyDecomposition noOfVals := float64(len(vals)) noRows := int(math.Pow(noOfVals, 0.5)) return goMatrix.MakeDenseMatrix(vals, noRows, noRows) }
func shiftMatrix(A *matrix.DenseMatrix, x int, y int) *matrix.DenseMatrix { result := A // fmt.Println("Shift x: ", x) // fmt.Println("Shift y: ", y) // A*shiftRightOrUp will shift A right // shiftRightOrUp*A will shift A up shiftRightOrUp := matrix.MakeDenseMatrix([]float64{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 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println("Start Matrix: ", result.String(), "\n\n") if x < 0 { for i := x; i < 0; i++ { // fmt.Print("<") result = matrix.Product(result, shiftLeftOrDown) // fmt.Println("Shifted Matrix ", i, ": ", result.String(), "\n\n") } } else if x > 0 { for i := 0; i < x; i++ { // fmt.Print(">") result = matrix.Product(result, shiftRightOrUp) // fmt.Println("Shifted Matrix ", i, ": ", result.String(), "\n\n") } } // fmt.Println() if y < 0 { for i := y; i < 0; i++ { result = matrix.Product(shiftLeftOrDown, result) // fmt.Println("Shifted Matrix ", i, ": ", result.String(), "\n\n") } } else if y > 0 { for i := 0; i < y; i++ { result = matrix.Product(shiftRightOrUp, result) // fmt.Println("Shifted Matrix ", i, ": ", result.String(), "\n\n") } } // fmt.Println("Shifted Matrix: ", result.String()) return result }
func InitMatrices() { singlePawnMove = matrix.MakeDenseMatrix([]float64{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, 15, 15) }
//Mints a new classifier. func (KNN *KNNRegressor) New(name string, labels []float64, numbers []float64, x int, y int) { KNN.Data = *mat.MakeDenseMatrix(numbers, x, y) KNN.Name = name KNN.Labels = labels }
package main import ( "fmt" matrix "github.com/skelterjohn/go.matrix" "math" ) var relation = []float64{4, 1, 1, 0} var relation_mat = matrix.MakeDenseMatrix(relation, 2, 2) var initial_seq_values = []float64{8, 2} var init_mat = matrix.MakeDenseMatrix(initial_seq_values, 2, 1) var dict = make(map[float64]*matrix.DenseMatrix, 0) var pow = []float64{1, -1} /************************************************************************* function calculate_even_fib_until: Input: limit Integer Output: Computes the Even_Fibanacci_Series elements F(n) and F(n+1) where: F(n) < limit F(n+1) >= limit > Even_Fibanacci_Series: It is the series formed by even elements of Fibonacci Series: 2, 8, 34, 144, 610, ... It has a recurrence relation which be derived easily: |4, 1| * | F(n) | = |F(n+1)| |1, 0| |F(n-1)| | F(n) |
func getOptions() { reader := bufio.NewReader(os.Stdin) // Get the piece choice for { fmt.Println("Choose a Piece:") fmt.Println(" Pawn") fmt.Println(" Rook") fmt.Println(" Knight") fmt.Println(" Bishop") fmt.Println(" Queen") fmt.Println(" King") fmt.Println(" Puppy\n") fmt.Print(":: ") text, _ := reader.ReadString('\n') text = strings.ToLower(text) text = strings.TrimSpace(text) if text == "pawn" { piece = boards.Pawn break } else if text == "rook" { piece = boards.Rook break } else if text == "knight" { piece = boards.Knight break } else if text == "bishop" { piece = boards.Bishop break } else if text == "queen" { piece = boards.Queen break } else if text == "king" { piece = boards.King break } else if text == "puppy" { piece = boards.Puppy break } else { fmt.Println("Invalid Piece") } } for { fmt.Print("\nStart Position {a-h}{1-8}: ") text, _ := reader.ReadString('\n') text = strings.ToLower(text) text = strings.TrimSpace(text) if len(text) > 2 { fmt.Println("Invalid Location") continue } if strings.HasPrefix(text, "a") { startX = 1 } else if strings.HasPrefix(text, "b") { startX = 2 } else if strings.HasPrefix(text, "c") { startX = 3 } else if strings.HasPrefix(text, "d") { startX = 4 } else if strings.HasPrefix(text, "e") { startX = 5 } else if strings.HasPrefix(text, "f") { startX = 6 } else if strings.HasPrefix(text, "g") { startX = 7 } else if strings.HasPrefix(text, "h") { startX = 8 } else { fmt.Println("Invalid Location") continue } if strings.HasSuffix(text, "1") { startY = 1 break } else if strings.HasSuffix(text, "2") { startY = 2 break } else if strings.HasSuffix(text, "3") { startY = 3 break } else if strings.HasSuffix(text, "4") { startY = 4 break } else if strings.HasSuffix(text, "5") { startY = 5 break } else if strings.HasSuffix(text, "6") { startY = 6 break } else if strings.HasSuffix(text, "7") { startY = 7 break } else if strings.HasSuffix(text, "8") { startY = 8 break } fmt.Println("Invalid Location") } for { fmt.Print("\nGoal Position {a-h}{1-8}: ") text, _ := reader.ReadString('\n') text = strings.ToLower(text) text = strings.TrimSpace(text) if len(text) > 2 { fmt.Println("Invalid Location") continue } if strings.HasPrefix(text, "a") { goalX = 1 } else if strings.HasPrefix(text, "b") { goalX = 2 } else if strings.HasPrefix(text, "c") { goalX = 3 } else if strings.HasPrefix(text, "d") { goalX = 4 } else if strings.HasPrefix(text, "e") { goalX = 5 } else if strings.HasPrefix(text, "f") { goalX = 6 } else if strings.HasPrefix(text, "g") { goalX = 7 } else if strings.HasPrefix(text, "h") { goalX = 8 } else { fmt.Println("Invalid Location") continue } if strings.HasSuffix(text, "1") { goalY = 1 break } else if strings.HasSuffix(text, "2") { goalY = 2 break } else if strings.HasSuffix(text, "3") { goalY = 3 break } else if strings.HasSuffix(text, "4") { goalY = 4 break } else if strings.HasSuffix(text, "5") { goalY = 5 break } else if strings.HasSuffix(text, "6") { goalY = 6 break } else if strings.HasSuffix(text, "7") { goalY = 7 break } else if strings.HasSuffix(text, "8") { goalY = 8 break } fmt.Println("Invalid Location") } for { fmt.Print("\nLength of Trajectories: ") text, _ := reader.ReadString('\n') text = strings.TrimSpace(text) var err error maxLength, err = strconv.Atoi(text) if err == nil && maxLength > 0 { break } fmt.Println("Length must be a positive integer") } fmt.Println("\nEnter Holes {a-h}{1-8}") fmt.Println("Enter anything else to continue") boards.HoleBoard = matrix.MakeDenseMatrix(make([]float64, 225, 225), 15, 15) for { fmt.Print(":: ") text, _ := reader.ReadString('\n') text = strings.TrimSpace(text) if len(text) > 2 { break } var x int var y int if strings.HasPrefix(text, "a") { x = 0 } else if strings.HasPrefix(text, "b") { x = 1 } else if strings.HasPrefix(text, "c") { x = 2 } else if strings.HasPrefix(text, "d") { x = 3 } else if strings.HasPrefix(text, "e") { x = 4 } else if strings.HasPrefix(text, "f") { x = 5 } else if strings.HasPrefix(text, "g") { x = 6 } else if strings.HasPrefix(text, "h") { x = 7 } else { break } if strings.HasSuffix(text, "1") { y = 14 } else if strings.HasSuffix(text, "2") { y = 13 } else if strings.HasSuffix(text, "3") { y = 12 } else if strings.HasSuffix(text, "4") { y = 11 } else if strings.HasSuffix(text, "5") { y = 10 } else if strings.HasSuffix(text, "6") { y = 9 } else if strings.HasSuffix(text, "7") { y = 8 } else if strings.HasSuffix(text, "8") { y = 7 } else { break } boards.HoleBoard.Set(y, x, 500) } }