Documentation
¶
Index ¶
- func DefaultPriors() map[PriorKey]models.BetaParams
- func PosteriorEntropy(params models.BetaParams) float64
- func PosteriorHDI(params models.BetaParams) (float64, float64)
- func ThompsonSample(params models.BetaParams) float64
- type Engine
- func (e *Engine) AllPosteriors() map[PriorKey]models.BetaParams
- func (e *Engine) BatchUpdate(taskType models.TaskType, categories []models.ChunkCategory, success bool)
- func (e *Engine) GetPosterior(taskType models.TaskType, category models.ChunkCategory) models.BetaParams
- func (e *Engine) PosteriorMean(taskType models.TaskType, category models.ChunkCategory) float64
- func (e *Engine) Sample(taskType models.TaskType, category models.ChunkCategory) float64
- func (e *Engine) Update(taskType models.TaskType, category models.ChunkCategory, success bool)
- type PriorKey
- type SQLiteStore
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPriors ¶
func DefaultPriors() map[PriorKey]models.BetaParams
DefaultPriors returns the informative prior Beta parameters per (task type, context category) pair. These encode domain knowledge about which context categories matter for which task types.
The prior "sample size" (alpha + beta) controls resistance to updating. Higher values = more data needed to shift the belief.
func PosteriorEntropy ¶
func PosteriorEntropy(params models.BetaParams) float64
PosteriorEntropy returns the differential entropy of the Beta distribution. Lower entropy = more concentrated/confident posterior.
func PosteriorHDI ¶
func PosteriorHDI(params models.BetaParams) (float64, float64)
PosteriorHDI returns the approximate 95% highest density interval for a Beta distribution. Uses quantiles as an approximation (exact HDI requires numerical optimization, but for Beta distributions the quantile-based interval is very close).
func ThompsonSample ¶
func ThompsonSample(params models.BetaParams) float64
ThompsonSample draws a sample from the Beta posterior for the given (task type, category) pair. This implements the exploration/exploitation trade-off: wide posteriors produce highly variable draws (exploration), while tight posteriors produce draws near the mean (exploitation).
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine manages Beta-Bernoulli posteriors for all (task type, category) pairs. It provides Thompson Sampling for decisions and conjugate updates for learning.
func (*Engine) AllPosteriors ¶
func (e *Engine) AllPosteriors() map[PriorKey]models.BetaParams
AllPosteriors returns a snapshot of all current posteriors.
func (*Engine) BatchUpdate ¶
func (e *Engine) BatchUpdate(taskType models.TaskType, categories []models.ChunkCategory, success bool)
BatchUpdate updates posteriors for multiple categories at once.
func (*Engine) GetPosterior ¶
func (e *Engine) GetPosterior(taskType models.TaskType, category models.ChunkCategory) models.BetaParams
GetPosterior returns the current posterior for a (task, category) pair.
func (*Engine) PosteriorMean ¶
PosteriorMean returns the posterior mean for a (task, category) pair.
type PriorKey ¶
type PriorKey struct {
TaskType models.TaskType `json:"task_type"`
Category models.ChunkCategory `json:"category"`
}
PriorKey uniquely identifies a (task type, chunk category) pair.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore persists posteriors to a SQLite database.
func NewSQLiteStore ¶
func NewSQLiteStore(dbPath string) (*SQLiteStore, error)
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
func (*SQLiteStore) LoadAll ¶
func (s *SQLiteStore) LoadAll() (map[PriorKey]models.BetaParams, error)
func (*SQLiteStore) Save ¶
func (s *SQLiteStore) Save(key PriorKey, params models.BetaParams) error
type Store ¶
type Store interface {
LoadAll() (map[PriorKey]models.BetaParams, error)
Save(key PriorKey, params models.BetaParams) error
}
Store is the persistence interface for posteriors.