qol

package module
v0.0.0-...-708736a Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2022 License: MIT Imports: 7 Imported by: 1

README

nnqol

Neural Network Quality of Life Stuff

Documentation

Overview

package qol provides quality-of-life utilities for working with neural networks in Gorgonia.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassType

func ClassType() tensor.Dtype

ClassType returns the tensor.Dtype for Class. This allows it to be used in Gorgonia graphs.

func OneHotMatrix

func OneHotMatrix(a []Class, numClasses uint, dtype tensor.Dtype, opts ...G.NodeConsOpt) *G.Node

OneHotMatrix creates a node that represents a one-hot matrix.

func OneHotVector

func OneHotVector(a Class, numClasses uint, dtype tensor.Dtype, opts ...G.NodeConsOpt) *G.Node

OneHotVector creates a node that represents a one-hot vector.

func ToOneHotMatrix

func ToOneHotMatrix(a []Class, numClasses uint, dtype tensor.Dtype) *tensor.Dense

ToOneHotMatrix converts a slice of Class to a OneHotMatrix.

The dtype defaults to tensor.Float64 if an empty Dtype was passed in.

func ToOneHotVector

func ToOneHotVector(a Class, numClasses uint, dtype tensor.Dtype) *tensor.Dense

ToOneHotVector converts a Class to a OneHotVector.

The dtype defaults to tensor.Float64 if an empty Dtype was passed in.

func UnsafeToOneHotMatrix

func UnsafeToOneHotMatrix(a []Class, numClasses uint, reuse *tensor.Dense) *tensor.Dense

UnsafeToOneHotMatrix converts a slice of Class to a OneHotMatrix, in the given tensor.Tensor. It expects a matrix of shape (len(a), numClasses). Panics otherwise.

func UnsafeToOneHotVector

func UnsafeToOneHotVector(a Class, numClasses uint, reuse *tensor.Dense) *tensor.Dense

UnsafeToOneHotVector converts a class to a OneHotVector, in the given tensor.Tensor. It expects the MaxClass the length of the given vector. Panics otherwise.

Types

type Class

type Class uint

Class represents the class ID of a dataset. It is an unbound type with a minimum of 0.

func ToClass

func ToClass(a tensor.Tensor, threshold float64) Class

ToClass converts a OneHotVector to a Class. This function panics if `a` is not a vector.

The default threshold is 0.55 if 0 is passed in. The threshold does not apply to int tensors.

Some behavioural notes: This function is NOT an argmax function. If the following vector is passed in,

[0.1 0.1 0.6 0.7 0.1]

the class returned will be 2, not 3.

The same behaviour applies to `int` an `uint` tensor.

For int Tensors, it assumes any value larger or equal to 1 is 1, and any value < 0 is 0. So the Class of the following:

[0 -1 3 3 1 0]

will also be 2.

func ToClasses

func ToClasses(a tensor.Tensor, threshold float64) []Class

ToClass converts a OneHotMatrix to Classes. This function panics if `a` is not a matrix. The default threshold is 0.55 if 0 is passed in. The threshold does not apply to int tensors.

Some behavioural notes: This function is NOT an argmax function. If the following matrix is passed in,

[0.1 0.1 0.6 0.7 0.1]
[0.6 0.1 0.1 0.7 0.1]

the class returned will be [2 0], not [3 3].

The same behaviour applies to `int` an `uint` tensor.

For int Tensors, it assumes any value larger or equal to 1 is 1, and any value < 0 is 0. So the Class of the following:

[0 -1 3 3 1 0]
[2 0 -1 3 0 0]

will also be [2 0] and not [2 3] or [3 3].

type Classes

type Classes []Class

func (Classes) Clone

func (cs Classes) Clone() Classes

func (Classes) Distinct

func (cs Classes) Distinct() Classes

Distinct returns a Classes with only the distinct classes. This method clobbers the original order of data.

func (Classes) Len

func (cs Classes) Len() int

func (Classes) Less

func (cs Classes) Less(i, j int) bool

func (Classes) Swap

func (cs Classes) Swap(i, j int)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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