Documentation
¶
Index ¶
- func Abs(v []float64) []float64
- func Add(v, w []float64) []float64
- func Argmax(v []float64) int
- func Choice(p []float64, s ...randv2.Source) int
- func Contains[T comparable](v T, s []T) bool
- func Cos(x, y []float64) float64
- func Div(v []float64, a float64) []float64
- func Equals(x, y []int) bool
- func Int(v []float64) []int
- func MatchCount[T comparable](x, y []T) int
- func Max[T int | float64](v []T) T
- func Mean(v []float64) float64
- func Mul(v []float64, a float64) []float64
- func Pow2(v []float64) []float64
- func Rand(n int, s ...randv2.Source) []float64
- func Randn(n int, s ...randv2.Source) []float64
- func Reverse[T any](xs []T) []T
- func Shuffle[T any](x, t []T, s ...randv2.Source) ([]T, []T)
- func Sum(v []float64) float64
- func T[T any](v []T) [][]T
- func Zero(n int) []float64
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, -2, -3} fmt.Println(vector.Abs(v)) }
Output: [1 2 3]
func Add ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, 2, 3} w := []float64{4, 5, 6} fmt.Println(vector.Add(v, w)) }
Output: [5 7 9]
func Argmax ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, 2, 3} fmt.Println(vector.Argmax(v)) }
Output: 2
func Choice ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/rand" "github.com/itsubaki/neu/math/vector" ) func main() { s := rand.Const(1) p := []float64{0.1, 0.2, 0.3, 0.4} for i := 0; i < 10; i++ { fmt.Print(vector.Choice(p, s)) } }
Output: 1202321031
Example (Rand) ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { p := []float64{0.1, 0.2, 0.3, 0.4} if vector.Choice(p) < 0 { fmt.Println("invalid") } }
Output:
func Contains ¶
func Contains[T comparable](v T, s []T) bool
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { fmt.Println(vector.Contains(3, []int{1, 2, 3})) fmt.Println(vector.Contains(0, []int{1, 2, 3})) }
Output: true false
func Cos ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { x := []float64{1, 2, 3} y := []float64{1, 2, 4} fmt.Println(vector.Cos(x, y)) }
Output: 0.9914601333935124
func Div ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, 2, 3} fmt.Println(vector.Div(v, 2)) }
Output: [0.5 1 1.5]
func Equals ¶
Equals returns true if x and y are the same.
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { fmt.Println(vector.Equals( []int{1, 2, 3, 4, 5}, []int{1, 2, 3, 4, 5}, )) fmt.Println(vector.Equals( []int{1, 2, 3, 4, 5}, []int{0, 2, 4, 3, 5}, )) fmt.Println(vector.Equals( []int{1, 2, 3}, []int{0, 2, 4, 3, 5}, )) }
Output: true false false
func Int ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, 2, 3} fmt.Println(vector.Int(v)) }
Output: [1 2 3]
func MatchCount ¶
func MatchCount[T comparable](x, y []T) int
MatchCount returns the number of matches.
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { fmt.Println(vector.MatchCount( []int{1, 2, 3, 4, 5}, []int{0, 2, 4, 3, 5}, )) }
Output: 2
func Max ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []int{1, 2, 3} fmt.Println(vector.Max(v)) }
Output: 3
func Mean ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, 2, 3} fmt.Println(vector.Mean(v)) }
Output: 2
func Mul ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, 2, 3} fmt.Println(vector.Mul(v, 2)) }
Output: [2 4 6]
func Pow2 ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, 2, 3} fmt.Println(vector.Pow2(v)) }
Output: [1 4 9]
func Rand ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/rand" "github.com/itsubaki/neu/math/vector" ) func main() { fmt.Println(vector.Rand(3, rand.Const(1))) fmt.Println(len(vector.Rand(10))) }
Output: [0.23842319087387442 0.50092138792625 0.04999911180706662] 10
func Randn ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/rand" "github.com/itsubaki/neu/math/vector" ) func main() { fmt.Println(vector.Randn(3, rand.Const(1))) fmt.Println(len(vector.Randn(10))) }
Output: [-0.8024826241110656 0.424707052949676 -0.4985070978632815] 10
func Reverse ¶
func Reverse[T any](xs []T) []T
Reverse reverses the slice.
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { fmt.Println(vector.Reverse([]int{1, 2, 3, 4, 5, 6, 7, 8, 9})) }
Output: [9 8 7 6 5 4 3 2 1]
func Shuffle ¶
Shuffle shuffles the dataset.
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/rand" "github.com/itsubaki/neu/math/vector" ) func main() { x := [][]float64{{0, 1}, {0, 2}, {0, 3}, {0, 4}} t := [][]float64{{1, 0}, {2, 0}, {3, 0}, {4, 0}} s := rand.Const(1234) fmt.Println(vector.Shuffle(x, t, s)) fmt.Println(vector.Shuffle(x, t, s)) fmt.Println(vector.Shuffle(x, t, s)) fmt.Println(x, t) fmt.Println(vector.Shuffle([][]float64{{0}}, [][]float64{{1}})) fmt.Println(vector.Shuffle([][]int{{1, 2, 3}, {4, 5, 6}}, [][]int{{7, 8, 9}, {10, 11, 12}}, rand.Const(2))) }
Output: [[0 4] [0 3] [0 2] [0 1]] [[4 0] [3 0] [2 0] [1 0]] [[0 3] [0 4] [0 2] [0 1]] [[3 0] [4 0] [2 0] [1 0]] [[0 3] [0 2] [0 1] [0 4]] [[3 0] [2 0] [1 0] [4 0]] [[0 1] [0 2] [0 3] [0 4]] [[1 0] [2 0] [3 0] [4 0]] [[0]] [[1]] [[4 5 6] [1 2 3]] [[10 11 12] [7 8 9]]
func Sum ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/math/vector" ) func main() { v := []float64{1, 2, 3} fmt.Println(vector.Sum(v)) }
Output: 6
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.