diff --git a/optimizer/sgd.go b/optimizer/sgd.go index ac352e4..4f8e803 100644 --- a/optimizer/sgd.go +++ b/optimizer/sgd.go @@ -1,8 +1,6 @@ package optimizer -import ( - "github.com/itsubaki/autograd/matrix" -) +import "github.com/itsubaki/autograd/matrix" // SGD is an optimizer that the Stochastic Gradient Descent algorithm. type SGD struct { diff --git a/variable/variable.go b/variable/variable.go index cd6e6f3..0edc965 100644 --- a/variable/variable.go +++ b/variable/variable.go @@ -24,6 +24,10 @@ func NewOf(v ...[]float64) *Variable { return &Variable{Data: v} } +func ZeroLike(v *Variable) *Variable { + return &Variable{Data: matrix.ZeroLike(v.Data)} +} + func OneLike(v *Variable) *Variable { return &Variable{Data: matrix.OneLike(v.Data)} } diff --git a/variable/variable_test.go b/variable/variable_test.go index 6d922c9..604d822 100644 --- a/variable/variable_test.go +++ b/variable/variable_test.go @@ -42,6 +42,14 @@ func ExampleConst() { // const([1]) } +func ExampleZeroLike() { + v := variable.New(1, 2, 3, 4) + fmt.Println(variable.ZeroLike(v)) + + // Output: + // variable([0 0 0 0]) +} + func ExampleOneLike() { v := variable.New(1, 2, 3, 4) fmt.Println(variable.OneLike(v))