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 offline.go online.go

Constants

const (
    BucketNeighbors  = "neighbors"  // Bucket name for neighbors
    BucketRecommends = "recommends" // Bucket name for recommendations

)
const (
    ListPop    = "pop"    // List name for popular items
    ListLatest = "latest" // List name for latest items
)

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 UpdateLatest Uses

func UpdateLatest(cacheSize int, db *DB) error

UpdateLatest updates latest items.

func UpdateNeighbors Uses

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

UpdateNeighbors updates neighbors for the database.

func UpdatePopItem Uses

func UpdatePopItem(cacheSize int, db *DB) error

UpdatePopItem updates popular items for the database.

func UpdatePopularity Uses

func UpdatePopularity(dataSet core.DataSetInterface, db *DB) error

UpdatePopularity updates popularity for all items.

func UpdateRecommends Uses

func UpdateRecommends(name string, params base.Params, cacheSize int, fitJobs 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) CountUsers Uses

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

CountUsers returns the number of users in the database.

func (*DB) GetFeedback Uses

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

GetFeedback returns all feedback in the database.

func (*DB) GetIdentList Uses

func (db *DB) GetIdentList(bucketName string, id string, n int) ([]RecommendedItem, error)

GetRecommends gets n recommendations for a user.

func (*DB) GetItem Uses

func (db *DB) GetItem(itemId string) (Item, error)

GetItem gets a item from database by item ID.

func (*DB) GetItems Uses

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

GetItems returns all items in the dataset.

func (*DB) GetItemsByID Uses

func (db *DB) GetItemsByID(id []string) ([]Item, error)

GetItem gets items from database by item IDs.

func (*DB) GetList Uses

func (db *DB) GetList(name string, n int) ([]RecommendedItem, error)

GetList gets a list from the database.

func (*DB) GetMeta Uses

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

GetMeta gets the value of a metadata.

func (*DB) GetRandom Uses

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

GetRandom returns random items.

func (*DB) GetUserFeedback Uses

func (db *DB) GetUserFeedback(userId string) ([]Feedback, error)

GetUserFeedback get a user's feedback.

func (*DB) GetUsers Uses

func (db *DB) GetUsers() ([]string, error)

GetUsers get all user IDs.

func (*DB) InsertFeedback Uses

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

InsertFeedback inserts a feedback into the database.

func (*DB) InsertItem Uses

func (db *DB) InsertItem(itemId string, timestamp *time.Time) error

InsertItem inserts a item into the database.

func (*DB) InsertItems Uses

func (db *DB) InsertItems(itemId []string, timestamps []time.Time) error

InsertItems inserts multiple items into the database.

func (*DB) InsertMultiFeedback Uses

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

InsertMultiFeedback inserts multiple feedback into the database.

func (*DB) InsertMultiUserFeedback Uses

func (db *DB) InsertMultiUserFeedback(userId, itemId []string, 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 string, 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, dateColumn int) error

LoadItemsFromCSV imports items from a CSV file into the database.

func (*DB) PutIdentList Uses

func (db *DB) PutIdentList(bucketName string, id string, items []RecommendedItem) error

SetRecommends sets recommendations for a user.

func (*DB) PutList Uses

func (db *DB) PutList(name string, items []RecommendedItem) error

PutList saves a list 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, date 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) ToDataSet Uses

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

ToDataSet creates a dataset from the database.

func (*DB) UpdatePopularity Uses

func (db *DB) UpdatePopularity(itemId []string, popularity []float64) error

UpdatePopularity update popularity of items.

type DatabaseConfig Uses

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

DatabaseConfig is the configuration for the database.

type Feedback Uses

type Feedback struct {
    FeedbackKey
    Rating float64
}

Feedback stores feedback.

type FeedbackKey Uses

type FeedbackKey struct {
    UserId string
    ItemId string
}

FeedbackKey identifies feedback.

type Item Uses

type Item struct {
    ItemId     string
    Popularity float64
    Timestamp  time.Time
}

Item stores meta data about item.

func TopItems Uses

func TopItems(itemId []Item, weight []float64, n int) (topItemId []Item, topWeight []float64)

TopItems finds top items by weights.

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
    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"`
    FitJobs         int    `toml:"fit_jobs"`
}

RecommendConfig is the configuration for recommendation.

type RecommendedItem Uses

type RecommendedItem struct {
    Item
    Score float64 // score
}

RecommendedItem is the structure for a recommended item.

func Ranking Uses

func Ranking(items []RecommendedItem, n int, p, t, c float64) []RecommendedItem

Ranking ranks items by popularity, timestamps and collaborative filtering scores..

type RecommendedItems Uses

type RecommendedItems []RecommendedItem

func (RecommendedItems) Len Uses

func (items RecommendedItems) Len() int

func (RecommendedItems) Less Uses

func (items RecommendedItems) Less(i, j int) bool

func (RecommendedItems) Swap Uses

func (items RecommendedItems) Swap(i, j int)

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 19 packages (graph) and is imported by 2 packages. Updated 2020-02-07. Refresh now. Tools for package owners.