Documentation
¶
Index ¶
- Constants
- func CheckPanic()
- func MarshalIndex(w io.Writer, index *Index) error
- func MarshalUnifiedIndex(w io.Writer, index UnifiedIndex) error
- func NewMatrix32(row, col int) [][]float32
- func NewMatrixInt(row, col int) [][]int
- func NewRand(seed int64) *rand.Rand
- func NewTensor32(a, b, c int) [][][]float32
- func RangeInt(n int) []int
- func RepeatFloat32s(n int, value float32) []float32
- func ValidateId(text string) error
- type Index
- type RandomGenerator
- func (rng RandomGenerator) NewNormalVector(size int, mean, stdDev float32) []float32
- func (rng RandomGenerator) NormalMatrix(row, col int, mean, stdDev float32) [][]float32
- func (rng RandomGenerator) NormalVector(size int, mean, stdDev float32) []float32
- func (rng RandomGenerator) NormalVector64(size int, mean, stdDev float64) []float64
- func (rng RandomGenerator) Sample(low, high, n int, exclude ...mapset.Set[int]) []int
- func (rng RandomGenerator) SampleInt32(low, high int32, n int, exclude ...mapset.Set[int32]) []int32
- func (rng RandomGenerator) UniformMatrix(row, col int, low, high float32) [][]float32
- func (rng RandomGenerator) UniformVector(size int, low, high float32) []float32
- type UnifiedDirectIndex
- func (unified *UnifiedDirectIndex) CountContextLabels() int32
- func (unified *UnifiedDirectIndex) CountItemLabels() int32
- func (unified *UnifiedDirectIndex) CountItems() int32
- func (unified *UnifiedDirectIndex) CountUserLabels() int32
- func (unified *UnifiedDirectIndex) CountUsers() int32
- func (unified *UnifiedDirectIndex) EncodeContextLabel(label string) int32
- func (unified *UnifiedDirectIndex) EncodeItem(itemId string) int32
- func (unified *UnifiedDirectIndex) EncodeItemLabel(itemLabel string) int32
- func (unified *UnifiedDirectIndex) EncodeUser(userId string) int32
- func (unified *UnifiedDirectIndex) EncodeUserLabel(userLabel string) int32
- func (unified *UnifiedDirectIndex) GetContextLabels() []string
- func (unified *UnifiedDirectIndex) GetItemLabels() []string
- func (unified *UnifiedDirectIndex) GetItems() []string
- func (unified *UnifiedDirectIndex) GetUserLabels() []string
- func (unified *UnifiedDirectIndex) GetUsers() []string
- func (unified *UnifiedDirectIndex) Len() int32
- func (unified *UnifiedDirectIndex) Marshal(w io.Writer) error
- func (unified *UnifiedDirectIndex) Unmarshal(r io.Reader) error
- type UnifiedIndex
- type UnifiedMapIndex
- func (unified *UnifiedMapIndex) CountContextLabels() int32
- func (unified *UnifiedMapIndex) CountItemLabels() int32
- func (unified *UnifiedMapIndex) CountItems() int32
- func (unified *UnifiedMapIndex) CountUserLabels() int32
- func (unified *UnifiedMapIndex) CountUsers() int32
- func (unified *UnifiedMapIndex) EncodeContextLabel(label string) int32
- func (unified *UnifiedMapIndex) EncodeItem(itemId string) int32
- func (unified *UnifiedMapIndex) EncodeItemLabel(itemLabel string) int32
- func (unified *UnifiedMapIndex) EncodeUser(userId string) int32
- func (unified *UnifiedMapIndex) EncodeUserLabel(userLabel string) int32
- func (unified *UnifiedMapIndex) GetContextLabels() []string
- func (unified *UnifiedMapIndex) GetItemLabels() []string
- func (unified *UnifiedMapIndex) GetItems() []string
- func (unified *UnifiedMapIndex) GetUserLabels() []string
- func (unified *UnifiedMapIndex) GetUsers() []string
- func (unified *UnifiedMapIndex) Len() int32
- func (unified *UnifiedMapIndex) Marshal(w io.Writer) error
- func (unified *UnifiedMapIndex) Unmarshal(r io.Reader) error
- type UnifiedMapIndexBuilder
- func (builder *UnifiedMapIndexBuilder) AddCtxLabel(ctxLabel string)
- func (builder *UnifiedMapIndexBuilder) AddItem(itemId string)
- func (builder *UnifiedMapIndexBuilder) AddItemLabel(itemLabel string)
- func (builder *UnifiedMapIndexBuilder) AddUser(userId string)
- func (builder *UnifiedMapIndexBuilder) AddUserLabel(userLabel string)
- func (builder *UnifiedMapIndexBuilder) Build() UnifiedIndex
Constants ¶
const NotId = int32(-1)
NotId represents an ID doesn't exist.
Variables ¶
This section is empty.
Functions ¶
func MarshalIndex ¶
MarshalIndex marshal index into byte stream.
func MarshalUnifiedIndex ¶
func MarshalUnifiedIndex(w io.Writer, index UnifiedIndex) error
MarshalIndex marshal index into byte stream.
func NewMatrix32 ¶
NewMatrix32 creates a 2D matrix of 32-bit floats.
func NewMatrixInt ¶
NewMatrixInt creates a 2D matrix of integers.
func NewTensor32 ¶
NewTensor32 creates a 3D tensor of 32-bit floats.
func RepeatFloat32s ¶
RepeatFloat32s repeats value n times.
func ValidateId ¶
ValidateId validates user/item id. Id cannot be empty and contain [/,].
Types ¶
type Index ¶
type Index struct {
Numbers map[string]int32 // sparse ID -> dense index
Names []string // dense index -> sparse ID
}
Index manages the map between sparse Names and dense indices. A sparse ID is a user ID or item ID. The dense index is the internal user index or item index optimized for faster parameter access and less memory usage.
func UnmarshalIndex ¶
UnmarshalIndex unmarshal index from byte stream.
type RandomGenerator ¶
RandomGenerator is the random generator for gorse.
func NewRandomGenerator ¶
func NewRandomGenerator(seed int64) RandomGenerator
NewRandomGenerator creates a RandomGenerator.
func (RandomGenerator) NewNormalVector ¶
func (rng RandomGenerator) NewNormalVector(size int, mean, stdDev float32) []float32
NewNormalVector makes a vec filled with normal random floats.
func (RandomGenerator) NormalMatrix ¶
func (rng RandomGenerator) NormalMatrix(row, col int, mean, stdDev float32) [][]float32
NormalMatrix makes a matrix filled with normal random floats.
func (RandomGenerator) NormalVector ¶
func (rng RandomGenerator) NormalVector(size int, mean, stdDev float32) []float32
func (RandomGenerator) NormalVector64 ¶
func (rng RandomGenerator) NormalVector64(size int, mean, stdDev float64) []float64
NormalVector64 makes a vec filled with normal random floats.
func (RandomGenerator) SampleInt32 ¶
func (rng RandomGenerator) SampleInt32(low, high int32, n int, exclude ...mapset.Set[int32]) []int32
SampleInt32 n 32bit values between low and high, but not in exclude.
func (RandomGenerator) UniformMatrix ¶
func (rng RandomGenerator) UniformMatrix(row, col int, low, high float32) [][]float32
UniformMatrix makes a matrix filled with uniform random floats.
func (RandomGenerator) UniformVector ¶
func (rng RandomGenerator) UniformVector(size int, low, high float32) []float32
UniformVector makes a vec filled with uniform random floats,
type UnifiedDirectIndex ¶
type UnifiedDirectIndex struct {
N int32
}
UnifiedDirectIndex maps string to integer in literal.
func (*UnifiedDirectIndex) CountContextLabels ¶
func (unified *UnifiedDirectIndex) CountContextLabels() int32
CountContextLabels should be used by unit testing only.
func (*UnifiedDirectIndex) CountItemLabels ¶
func (unified *UnifiedDirectIndex) CountItemLabels() int32
CountItemLabels should be used by unit testing only.
func (*UnifiedDirectIndex) CountItems ¶
func (unified *UnifiedDirectIndex) CountItems() int32
CountItems should be used by unit testing only.
func (*UnifiedDirectIndex) CountUserLabels ¶
func (unified *UnifiedDirectIndex) CountUserLabels() int32
CountUserLabels should be used by unit testing only.
func (*UnifiedDirectIndex) CountUsers ¶
func (unified *UnifiedDirectIndex) CountUsers() int32
CountUsers should be used by unit testing only.
func (*UnifiedDirectIndex) EncodeContextLabel ¶
func (unified *UnifiedDirectIndex) EncodeContextLabel(label string) int32
EncodeContextLabel should be used by unit testing only.
func (*UnifiedDirectIndex) EncodeItem ¶
func (unified *UnifiedDirectIndex) EncodeItem(itemId string) int32
EncodeItem should be used by unit testing only.
func (*UnifiedDirectIndex) EncodeItemLabel ¶
func (unified *UnifiedDirectIndex) EncodeItemLabel(itemLabel string) int32
EncodeItemLabel should be used by unit testing only.
func (*UnifiedDirectIndex) EncodeUser ¶
func (unified *UnifiedDirectIndex) EncodeUser(userId string) int32
EncodeUser should be used by unit testing only.
func (*UnifiedDirectIndex) EncodeUserLabel ¶
func (unified *UnifiedDirectIndex) EncodeUserLabel(userLabel string) int32
EncodeUserLabel should be used by unit testing only.
func (*UnifiedDirectIndex) GetContextLabels ¶
func (unified *UnifiedDirectIndex) GetContextLabels() []string
GetContextLabels should be used by unit testing only.
func (*UnifiedDirectIndex) GetItemLabels ¶
func (unified *UnifiedDirectIndex) GetItemLabels() []string
GetItemLabels should be used by unit testing only.
func (*UnifiedDirectIndex) GetItems ¶
func (unified *UnifiedDirectIndex) GetItems() []string
GetItems should be used by unit testing only.
func (*UnifiedDirectIndex) GetUserLabels ¶
func (unified *UnifiedDirectIndex) GetUserLabels() []string
GetUserLabels should be used by unit testing only.
func (*UnifiedDirectIndex) GetUsers ¶
func (unified *UnifiedDirectIndex) GetUsers() []string
GetUsers should be used by unit testing only.
func (*UnifiedDirectIndex) Len ¶
func (unified *UnifiedDirectIndex) Len() int32
Len should be used by unit testing only.
type UnifiedIndex ¶
type UnifiedIndex interface {
Len() int32
EncodeUser(userId string) int32
EncodeItem(itemId string) int32
EncodeUserLabel(userLabel string) int32
EncodeItemLabel(itemLabel string) int32
EncodeContextLabel(ctxLabel string) int32
GetUsers() []string
GetItems() []string
GetUserLabels() []string
GetItemLabels() []string
GetContextLabels() []string
CountUsers() int32
CountItems() int32
CountUserLabels() int32
CountItemLabels() int32
CountContextLabels() int32
Marshal(w io.Writer) error
Unmarshal(r io.Reader) error
}
UnifiedIndex maps users, items and labels into a unified encoding space.
func NewUnifiedDirectIndex ¶
func NewUnifiedDirectIndex(n int32) UnifiedIndex
NewUnifiedDirectIndex creates a UnifiedDirectIndex.
func UnmarshalUnifiedIndex ¶
func UnmarshalUnifiedIndex(r io.Reader) (UnifiedIndex, error)
UnmarshalIndex unmarshal index from byte stream.
type UnifiedMapIndex ¶
type UnifiedMapIndex struct {
UserIndex *Index
ItemIndex *Index
UserLabelIndex *Index
ItemLabelIndex *Index
CtxLabelIndex *Index
}
UnifiedMapIndex is the id -> index mapper for factorization machines. The division of id is: | user | item | user label | item label | context label |
func (*UnifiedMapIndex) CountContextLabels ¶
func (unified *UnifiedMapIndex) CountContextLabels() int32
CountContextLabels returns the number of context labels.
func (*UnifiedMapIndex) CountItemLabels ¶
func (unified *UnifiedMapIndex) CountItemLabels() int32
CountItemLabels returns the number of item labels.
func (*UnifiedMapIndex) CountItems ¶
func (unified *UnifiedMapIndex) CountItems() int32
CountItems returns the number of items.
func (*UnifiedMapIndex) CountUserLabels ¶
func (unified *UnifiedMapIndex) CountUserLabels() int32
CountUserLabels returns the number of user labels.
func (*UnifiedMapIndex) CountUsers ¶
func (unified *UnifiedMapIndex) CountUsers() int32
CountUsers returns the number of users.
func (*UnifiedMapIndex) EncodeContextLabel ¶
func (unified *UnifiedMapIndex) EncodeContextLabel(label string) int32
EncodeContextLabel converts a context label to a integer in the encoding space.
func (*UnifiedMapIndex) EncodeItem ¶
func (unified *UnifiedMapIndex) EncodeItem(itemId string) int32
EncodeItem converts a item id to a integer in the encoding space.
func (*UnifiedMapIndex) EncodeItemLabel ¶
func (unified *UnifiedMapIndex) EncodeItemLabel(itemLabel string) int32
EncodeItemLabel converts a item label to a integer in the encoding space.
func (*UnifiedMapIndex) EncodeUser ¶
func (unified *UnifiedMapIndex) EncodeUser(userId string) int32
EncodeUser converts a user id to a integer in the encoding space.
func (*UnifiedMapIndex) EncodeUserLabel ¶
func (unified *UnifiedMapIndex) EncodeUserLabel(userLabel string) int32
EncodeUserLabel converts a user label to a integer in the encoding space.
func (*UnifiedMapIndex) GetContextLabels ¶
func (unified *UnifiedMapIndex) GetContextLabels() []string
GetContextLabels returns all context labels.
func (*UnifiedMapIndex) GetItemLabels ¶
func (unified *UnifiedMapIndex) GetItemLabels() []string
GetItemLabels returns all item labels.
func (*UnifiedMapIndex) GetItems ¶
func (unified *UnifiedMapIndex) GetItems() []string
GetItems returns all items.
func (*UnifiedMapIndex) GetUserLabels ¶
func (unified *UnifiedMapIndex) GetUserLabels() []string
GetUserLabels returns all user labels.
func (*UnifiedMapIndex) GetUsers ¶
func (unified *UnifiedMapIndex) GetUsers() []string
GetUsers returns all users.
func (*UnifiedMapIndex) Len ¶
func (unified *UnifiedMapIndex) Len() int32
Len returns the size of unified index.
type UnifiedMapIndexBuilder ¶
type UnifiedMapIndexBuilder struct {
UserIndex *Index
ItemIndex *Index
UserLabelIndex *Index
ItemLabelIndex *Index
CtxLabelIndex *Index
}
UnifiedMapIndexBuilder is the builder for UnifiedMapIndex.
func NewUnifiedMapIndexBuilder ¶
func NewUnifiedMapIndexBuilder() *UnifiedMapIndexBuilder
NewUnifiedMapIndexBuilder creates a UnifiedMapIndexBuilder.
func (*UnifiedMapIndexBuilder) AddCtxLabel ¶
func (builder *UnifiedMapIndexBuilder) AddCtxLabel(ctxLabel string)
AddCtxLabel adds a context label the unified index.
func (*UnifiedMapIndexBuilder) AddItem ¶
func (builder *UnifiedMapIndexBuilder) AddItem(itemId string)
AddItem adds a item into the unified index.
func (*UnifiedMapIndexBuilder) AddItemLabel ¶
func (builder *UnifiedMapIndexBuilder) AddItemLabel(itemLabel string)
AddItemLabel adds a item label into the unified index.
func (*UnifiedMapIndexBuilder) AddUser ¶
func (builder *UnifiedMapIndexBuilder) AddUser(userId string)
AddUser adds a user into the unified index.
func (*UnifiedMapIndexBuilder) AddUserLabel ¶
func (builder *UnifiedMapIndexBuilder) AddUserLabel(userLabel string)
AddUserLabel adds a user label into the unified index.
func (*UnifiedMapIndexBuilder) Build ¶
func (builder *UnifiedMapIndexBuilder) Build() UnifiedIndex
Build UnifiedMapIndex from UnifiedMapIndexBuilder.