hook

package
v0.0.0-...-90badf6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClipGrad

func ClipGrad(max float64) func(params []layer.Parameter)
Example
package main

import (
	"fmt"

	"github.com/itsubaki/autograd/hook"
	"github.com/itsubaki/autograd/variable"
)

func main() {
	p := variable.New(1)
	p.Grad = variable.New(1, 2, 3, 4)

	h := hook.ClipGrad(1.0)
	h([]*variable.Variable{p})

	fmt.Println(p.Grad)

}
Output:

variable([0.18257415250172812 0.36514830500345624 0.5477224575051843 0.7302966100069125])
Example (Noclip)
package main

import (
	"fmt"

	"github.com/itsubaki/autograd/hook"
	"github.com/itsubaki/autograd/variable"
)

func main() {
	p := variable.New(1)
	p.Grad = variable.New(0.1, 0.2, 0.3, 0.4)

	h := hook.ClipGrad(1.0)
	h([]*variable.Variable{p})

	fmt.Println(p.Grad)

}
Output:

variable([0.1 0.2 0.3 0.4])

func WeightDecay

func WeightDecay(lambda float64) func(params []layer.Parameter)
Example
package main

import (
	"fmt"

	"github.com/itsubaki/autograd/hook"
	"github.com/itsubaki/autograd/variable"
)

func main() {
	p := variable.New(1.0)
	p.Grad = variable.New(1.0)

	h := hook.WeightDecay(0.1)
	h([]*variable.Variable{p})

	fmt.Println(p)

}
Output:

variable([1.1])

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL