gorse: github.com/zhenghaoz/gorse/engine Index | Files

package engine

import "github.com/zhenghaoz/gorse/engine"

Package engine manages configuration, storage and update.

* configuration: load configurations from the TOML file.
* storage: manages data based on BoltDB.
* update: generate recommendations and save into the database.

Index

Package Files

config.go database.go doc.go update.go

func LoadModel Uses

func LoadModel(name string, params base.Params) core.ModelInterface

LoadModel creates model from name and parameters.

func LoadSimilarity Uses

func LoadSimilarity(name string) base.FuncSimilarity

LoadSimilarity creates similarity metric from name.

func Update Uses

func Update(config TomlConfig, metaData toml.MetaData, db *DB) error

Update all kinds recommendations for the database.

func UpdateItemPop Uses

func UpdateItemPop(cacheSize int, dataSet core.DataSetInterface, db *DB) error

UpdateItemPop updates popular items for the database.

func UpdateNeighbors Uses

func UpdateNeighbors(name string, cacheSize int, dataSet core.DataSetInterface, db *DB) error

UpdateNeighbors updates neighbors for the database.

func UpdateRecommends Uses

func UpdateRecommends(name string, params base.Params, cacheSize int, dataSet core.DataSetInterface, db *DB) error

UpdateRecommends updates personalized recommendations for the database.

type DB Uses

type DB struct {
    // contains filtered or unexported fields
}

DB manages all data for the engine.

func Open Uses

func Open(path string) (*DB, error)

Open a connection to the database.

func (*DB) Close Uses

func (db *DB) Close() error

Close the connection to the database.

func (*DB) CountFeedback Uses

func (db *DB) CountFeedback() (int, error)

CountFeedback returns the number of feedback in the database.

func (*DB) CountItems Uses

func (db *DB) CountItems() (int, error)

CountItems returns the number of items in the database.

func (*DB) GetFeedback Uses

func (db *DB) GetFeedback() (users []int, items []int, feedback []float64, err error)

GetFeedback returns all feedback in the database.

func (*DB) GetItems Uses

func (db *DB) GetItems() ([]int, error)

GetItems returns all items in the dataset.

func (*DB) GetMeta Uses

func (db *DB) GetMeta(name string) (string, error)

GetMeta gets the value of a metadata.

func (*DB) GetNeighbors Uses

func (db *DB) GetNeighbors(ItemId int, n int) ([]RecommendedItem, error)

GetNeighbors gets n neighbors for a item.

func (*DB) GetPopular Uses

func (db *DB) GetPopular(n int) ([]RecommendedItem, error)

GetPopular returns popular items from the database.

func (*DB) GetRandom Uses

func (db *DB) GetRandom(n int) ([]RecommendedItem, error)

GetRandom returns random items.

func (*DB) GetRecommends Uses

func (db *DB) GetRecommends(userId int, n int) ([]RecommendedItem, error)

GetRecommends gets n recommendations for a user.

func (*DB) GetUserFeedback Uses

func (db *DB) GetUserFeedback(userId int) ([]RecommendedItem, error)

func (*DB) InsertFeedback Uses

func (db *DB) InsertFeedback(userId, itemId int, feedback float64) error

InsertFeedback inserts a feedback into the database.

func (*DB) InsertItem Uses

func (db *DB) InsertItem(itemId int) error

InsertItem inserts a item into the database.

func (*DB) InsertMultiFeedback Uses

func (db *DB) InsertMultiFeedback(userId, itemId []int, feedback []float64) error

InsertMultiFeedback inserts multiple feedback into the database.

func (*DB) InsertMultiItems Uses

func (db *DB) InsertMultiItems(itemId []int) error

InsertMultiItems inserts multiple items into the database.

func (*DB) InsertMultiUserFeedback Uses

func (db *DB) InsertMultiUserFeedback(userId, itemId []int, feedback []float64) error

InsertMultiUserFeedback inserts multiple feedback into the user feedback bucket of the database.

func (*DB) InsertUserFeedback Uses

func (db *DB) InsertUserFeedback(userId, itemId int, feedback float64) error

InsertUserFeedback inserts a feedback into the user feedback bucket of the database.

func (*DB) LoadFeedbackFromCSV Uses

func (db *DB) LoadFeedbackFromCSV(fileName string, sep string, hasHeader bool) error

LoadFeedbackFromCSV import feedback from a CSV file into the database.

func (*DB) LoadItemsFromCSV Uses

func (db *DB) LoadItemsFromCSV(fileName string, sep string, hasHeader bool) error

LoadItemsFromCSV imports items from a CSV file into the database.

func (*DB) SaveFeedbackToCSV Uses

func (db *DB) SaveFeedbackToCSV(fileName string, sep string, header bool) error

SaveFeedbackToCSV exports feedback from the database into a CSV file.

func (*DB) SaveItemsToCSV Uses

func (db *DB) SaveItemsToCSV(fileName string, sep string, header bool) error

SaveItemsToCSV exports items from the database into a CSV file.

func (*DB) SetMeta Uses

func (db *DB) SetMeta(name string, val string) error

SetMeta sets the value of a metadata.

func (*DB) SetNeighbors Uses

func (db *DB) SetNeighbors(itemId int, items []RecommendedItem) error

SetNeighbors sets neighbors for a item.

func (*DB) SetPopular Uses

func (db *DB) SetPopular(items []RecommendedItem) error

SetPopular sets popular items in the database.

func (*DB) SetRecommends Uses

func (db *DB) SetRecommends(userId int, items []RecommendedItem) error

SetRecommends sets recommendations for a user.

func (*DB) ToDataSet Uses

func (db *DB) ToDataSet() (*core.DataSet, error)

ToDataSet creates a dataset from the database.

type DatabaseConfig Uses

type DatabaseConfig struct {
    File string `toml:"file"`
}

DatabaseConfig is the configuration for the database.

type FeedbackKey Uses

type FeedbackKey struct {
    UserId int
    ItemId int
}

type ParamsConfig Uses

type ParamsConfig struct {
    // Hyper-parameters
    Lr            float64 `toml:"lr"`              // learning rate
    Reg           float64 `toml:"reg"`             // regularization strength
    NEpochs       int     `toml:"n_epochs"`        // number of epochs
    NFactors      int     `toml:"n_factors"`       // number of factors
    RandomState   int     `toml:"random_state"`    // random state (seed)
    UseBias       bool    `toml:"use_bias"`        // use bias
    InitMean      float64 `toml:"init_mean"`       // mean of gaussian initial parameter
    InitStdDev    float64 `toml:"init_std"`        // standard deviation of gaussian initial parameter
    InitLow       float64 `toml:"init_low"`        // lower bound of uniform initial parameter
    InitHigh      float64 `toml:"init_high"`       // upper bound of uniform initial parameter
    NUserClusters int     `toml:"n_user_clusters"` // number of user cluster
    NItemClusters int     `toml:"n_item_clusters"` // number of item cluster
    Type          string  `toml:"type"`            // type for KNN
    UserBased     bool    `toml:"user_based"`      // user based if true. otherwise item based.
    Similarity    string  `toml:"similarity"`      // similarity metrics
    K             int     `toml:"k"`               // number of neighbors
    MinK          int     `toml:"min_k"`           // least number of neighbors
    Optimizer     string  `toml:"optimizer"`       // optimizer for optimization (SGD/ALS/BPR)
    Shrinkage     int     `toml:"shrinkage"`       // shrinkage strength of similarity
    Alpha         float64 `toml:"alpha"`           // alpha value, depend on context
}

ParamsConfig is the configuration for hyper-parameters of the recommendation model.

func (*ParamsConfig) ToParams Uses

func (config *ParamsConfig) ToParams(metaData toml.MetaData) base.Params

ToParams convert a configuration for hyper-parameters into hyper-parameters.

type RecommendConfig Uses

type RecommendConfig struct {
    Model           string `toml:"model"`
    Similarity      string `toml:"similarity"`
    CacheSize       int    `toml:"cache_size"`
    UpdateThreshold int    `toml:"update_threshold"`
    CheckPeriod     int    `toml:"check_period"`
}

RecommendConfig is the configuration for recommendation.

type RecommendedItem Uses

type RecommendedItem struct {
    ItemId int     // identifier
    Score  float64 // score
}

RecommendedItem is the structure for a recommended item.

type ServerConfig Uses

type ServerConfig struct {
    Host string `toml:"host"`
    Port int    `toml:"port"`
}

ServerConfig is the configuration for the server.

type TomlConfig Uses

type TomlConfig struct {
    Server    ServerConfig    `toml:"server"`
    Database  DatabaseConfig  `toml:"database"`
    Params    ParamsConfig    `toml:"params"`
    Recommend RecommendConfig `toml:"recommend"`
}

TomlConfig is the configuration for the engine.

func LoadConfig Uses

func LoadConfig(path string) (TomlConfig, toml.MetaData)

LoadConfig loads configuration from toml file.

func (*TomlConfig) FillDefault Uses

func (config *TomlConfig) FillDefault(meta toml.MetaData)

FillDefault fill default values for missing values.

Package engine imports 16 packages (graph) and is imported by 2 packages. Updated 2019-06-03. Refresh now. Tools for package owners.