Documentation ¶
Overview ¶
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 ¶
- Constants
- func LoadModel(name string, params base.Params) core.ModelInterface
- func LoadSimilarity(name string) base.FuncSimilarity
- func Update(config TomlConfig, metaData toml.MetaData, db *DB) error
- func UpdateLatest(cacheSize int, db *DB) error
- func UpdateNeighbors(name string, cacheSize int, dataSet core.DataSetInterface, db *DB) error
- func UpdatePopItem(cacheSize int, db *DB) error
- func UpdatePopularity(dataSet core.DataSetInterface, db *DB) error
- func UpdateRecommends(name string, params base.Params, cacheSize int, fitJobs int, once bool, ...) error
- type DB
- func (db *DB) Close() error
- func (db *DB) CountFeedback() (int, error)
- func (db *DB) CountItems() (int, error)
- func (db *DB) CountUsers() (int, error)
- func (db *DB) GetFeedback() (users, items []string, feedback []float64, err error)
- func (db *DB) GetIdentList(bucketName string, id string, n int) ([]RecommendedItem, error)
- func (db *DB) GetItem(itemId string) (Item, error)
- func (db *DB) GetItems() ([]Item, error)
- func (db *DB) GetItemsByID(id []string) ([]Item, error)
- func (db *DB) GetList(name string, n int) ([]RecommendedItem, error)
- func (db *DB) GetMeta(name string) (string, error)
- func (db *DB) GetRandom(n int) ([]RecommendedItem, error)
- func (db *DB) GetUserFeedback(userId string) ([]Feedback, error)
- func (db *DB) GetUsers() ([]string, error)
- func (db *DB) InsertFeedback(userId, itemId string, feedback float64) error
- func (db *DB) InsertItem(itemId string, timestamp *time.Time) error
- func (db *DB) InsertItems(itemId []string, timestamps []time.Time) error
- func (db *DB) InsertMultiFeedback(userId, itemId []string, feedback []float64) error
- func (db *DB) InsertMultiUserFeedback(userId, itemId []string, feedback []float64) error
- func (db *DB) InsertUserFeedback(userId, itemId string, feedback float64) error
- func (db *DB) LoadFeedbackFromCSV(fileName string, sep string, hasHeader bool) error
- func (db *DB) LoadItemsFromCSV(fileName string, sep string, hasHeader bool, dateColumn int) error
- func (db *DB) PutIdentList(bucketName string, id string, items []RecommendedItem) error
- func (db *DB) PutList(name string, items []RecommendedItem) error
- func (db *DB) SaveFeedbackToCSV(fileName string, sep string, header bool) error
- func (db *DB) SaveItemsToCSV(fileName string, sep string, header bool, date bool) error
- func (db *DB) SetMeta(name string, val string) error
- func (db *DB) ToDataSet() (*core.DataSet, error)
- func (db *DB) UpdatePopularity(itemId []string, popularity []float64) error
- type DatabaseConfig
- type Feedback
- type FeedbackKey
- type Item
- type ParamsConfig
- type RecommendConfig
- type RecommendedItem
- type RecommendedItems
- type ServerConfig
- type TomlConfig
Constants ¶
const ( BucketNeighbors = "neighbors" // Bucket name for neighbors BucketRecommends = "recommends" // Bucket name for recommendations BucketReads = "reads" // Bucket name for reads )
const ( ListPop = "pop" // List name for popular items ListLatest = "latest" // List name for latest items )
Variables ¶
This section is empty.
Functions ¶
func LoadModel ¶
func LoadModel(name string, params base.Params) core.ModelInterface
LoadModel creates model from name and parameters.
func LoadSimilarity ¶
func LoadSimilarity(name string) base.FuncSimilarity
LoadSimilarity creates similarity metric from name.
func Update ¶
func Update(config TomlConfig, metaData toml.MetaData, db *DB) error
Update all kinds recommendations for the database.
func UpdateLatest ¶
UpdateLatest updates latest items.
func UpdateNeighbors ¶
UpdateNeighbors updates neighbors for the database.
func UpdatePopItem ¶
UpdatePopItem updates popular items for the database.
func UpdatePopularity ¶
func UpdatePopularity(dataSet core.DataSetInterface, db *DB) error
UpdatePopularity updates popularity for all items.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB manages all data for the engine.
func (*DB) CountFeedback ¶
CountFeedback returns the number of feedback in the database.
func (*DB) CountItems ¶
CountItems returns the number of items in the database.
func (*DB) CountUsers ¶
CountUsers returns the number of users in the database.
func (*DB) GetFeedback ¶
GetFeedback returns all feedback in the database.
func (*DB) GetIdentList ¶
GetRecommends gets n recommendations for a user.
func (*DB) GetItemsByID ¶
GetItem gets items from database by item IDs.
func (*DB) GetList ¶
func (db *DB) GetList(name string, n int) ([]RecommendedItem, error)
GetList gets a list from the database.
func (*DB) GetRandom ¶
func (db *DB) GetRandom(n int) ([]RecommendedItem, error)
GetRandom returns random items.
func (*DB) GetUserFeedback ¶
GetUserFeedback get a user's feedback.
func (*DB) InsertFeedback ¶
InsertFeedback inserts a feedback into the database.
func (*DB) InsertItem ¶
InsertItem inserts a item into the database.
func (*DB) InsertItems ¶
InsertItems inserts multiple items into the database.
func (*DB) InsertMultiFeedback ¶
InsertMultiFeedback inserts multiple feedback into the database.
func (*DB) InsertMultiUserFeedback ¶
InsertMultiUserFeedback inserts multiple feedback into the user feedback bucket of the database.
func (*DB) InsertUserFeedback ¶
InsertUserFeedback inserts a feedback into the user feedback bucket of the database.
func (*DB) LoadFeedbackFromCSV ¶
LoadFeedbackFromCSV import feedback from a CSV file into the database.
func (*DB) LoadItemsFromCSV ¶
LoadItemsFromCSV imports items from a CSV file into the database.
func (*DB) PutIdentList ¶
func (db *DB) PutIdentList(bucketName string, id string, items []RecommendedItem) error
SetRecommends sets recommendations for a user.
func (*DB) PutList ¶
func (db *DB) PutList(name string, items []RecommendedItem) error
PutList saves a list into the database.
func (*DB) SaveFeedbackToCSV ¶
SaveFeedbackToCSV exports feedback from the database into a CSV file.
func (*DB) SaveItemsToCSV ¶
SaveItemsToCSV exports items from the database into a CSV file.
type DatabaseConfig ¶
type DatabaseConfig struct {
File string `toml:"file"`
}
DatabaseConfig is the configuration for the database.
type FeedbackKey ¶
FeedbackKey identifies feedback.
type ParamsConfig ¶
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 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.
type RecommendConfig ¶
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"` FitJobs int `toml:"fit_jobs"` Once bool `toml:"once"` }
RecommendConfig is the configuration for recommendation.
type RecommendedItem ¶
RecommendedItem is the structure for a recommended item.
func Ranking ¶
func Ranking(items []RecommendedItem, n int, p, t, c float64) []RecommendedItem
Ranking ranks items by popularity, timestamps and collaborative filtering scores..
type RecommendedItems ¶
type RecommendedItems []RecommendedItem
func (RecommendedItems) Len ¶
func (items RecommendedItems) Len() int
func (RecommendedItems) Less ¶
func (items RecommendedItems) Less(i, j int) bool
func (RecommendedItems) Swap ¶
func (items RecommendedItems) Swap(i, j int)
type ServerConfig ¶
ServerConfig is the configuration for the server.
type TomlConfig ¶
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 ¶
func LoadConfig(path string) (TomlConfig, toml.MetaData)
LoadConfig loads configuration from toml file.
func (*TomlConfig) FillDefault ¶
func (config *TomlConfig) FillDefault(meta toml.MetaData)
FillDefault fill default values for missing values.