Documentation ¶
Index ¶
- Constants
- Variables
- func AccumulateStreak(p *Predictions, s *Streak) (cumprobs, cumspreads []float64)
- func MapSlice(s []string) map[string]bool
- func SliceMap(m map[string]bool) []string
- func SummarizeStreak(p *Predictions, s *Streak) (prob, spread float64)
- func TeamPermute(s TeamList, c chan<- TeamList)
- type Game
- type GameModel
- type GaussianSpreadModel
- type IdenticalPermutor
- type IndexPermutor
- type LineMap
- type Player
- type PlayerMap
- type PredictionModel
- type Predictions
- type RelativeLocation
- type Remaining
- type RemainingMap
- type Schedule
- type Streak
- func (s *Streak) Clone() *Streak
- func (s *Streak) FindTeam(team Team) int
- func (s *Streak) GetWeek(week int) TeamList
- func (s *Streak) NumWeeks() int
- func (s *Streak) PermuteTeamOrder(indexPermutation []int)
- func (s *Streak) Perturbate(src rand.Source, picksPerWeekAlso bool)
- func (s *Streak) PicksPerWeek(ppw []int) []int
- func (s *Streak) String() string
- type Team
- type TeamList
- type WeeksMap
Constants ¶
const ( // Home is a team's home field. Home RelativeLocation = 2 // Near is a field closer to a given team's home field than the team's opponent's home field. Near = 1 // Neutral is a truely neutral location. Neutral = 0 // Far is a field closer to a given team's opponent's home field than the team's home field. Far = -1 // Away is a team's opponent's home field. Away = -2 )
Variables ¶
var BYE = Team{Name4: "BYE"}
BYE represents a bye week for a team in a schedule.
var NONE = Team{Name4: "----"}
NONE represents a null pick--used when a player uses a pick bye on a week.
var NULLGAME = Game{NONE, NONE, Neutral}
NULLGAME represents a game that doesn't exsit. Go figure.
Functions ¶
func AccumulateStreak ¶
func AccumulateStreak(p *Predictions, s *Streak) (cumprobs, cumspreads []float64)
AccumulateStreak returns the accumulated probability of win a total spread for each week of the given streak.
func SummarizeStreak ¶
func SummarizeStreak(p *Predictions, s *Streak) (prob, spread float64)
SummarizeStreak returns the total predicted probability of beating a streak and the total spread.
func TeamPermute ¶
TeamPermute creates all possible permutations of a sort.Interface and issues them to a chan. This uses the non-recursive form of Heap's algorithm, which is well-suited for a goroutine. See https://en.wikipedia.org/wiki/Heap%27s_algorithm
Types ¶
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game represents a matchup between two teams.
func NewGame ¶
func NewGame(team1, team2 Team, locRelTeam1 RelativeLocation) *Game
NewGame makes a game between two teams.
func (*Game) LocationRelativeToTeam ¶
func (g *Game) LocationRelativeToTeam(t int) RelativeLocation
LocationRelativeToTeam returns the location of the game relative to the given team.
type GaussianSpreadModel ¶
type GaussianSpreadModel struct {
// contains filtered or unexported fields
}
GaussianSpreadModel implements PredictionModel and uses a normal distribution based on spreads to calculate win probabilities. The spread is determined by a team rating and where the game is being played (to account for bias).
func MakeGaussianSpreadModel ¶
func MakeGaussianSpreadModel(ratingsURL, performanceURL, modelName string) (*GaussianSpreadModel, error)
MakeGaussianSpreadModel makes a spread model by parsing Sagarin ratings and performance to date metrics.
func NewGaussianSpreadModel ¶
func NewGaussianSpreadModel(ratings map[Team]float64, stdDev, homeBias, closeBias float64) *GaussianSpreadModel
NewGaussianSpreadModel makes a model.
func (GaussianSpreadModel) MostLikelyOutcome ¶
func (m GaussianSpreadModel) MostLikelyOutcome(game *Game) (Team, float64, float64)
MostLikelyOutcome returns the most likely team to win a given game, the probability of win, and the predicted spread.
func (GaussianSpreadModel) Predict ¶
func (m GaussianSpreadModel) Predict(game *Game) (float64, float64)
Predict returns the probability and spread for team1.
func (GaussianSpreadModel) String ¶
func (m GaussianSpreadModel) String() string
type IdenticalPermutor ¶
type IdenticalPermutor struct {
// contains filtered or unexported fields
}
IdenticalPermutor permutes a set of potentially repeated integers with n_i copies of integers i=0 to i=N.
func NewIdenticalPermutor ¶
func NewIdenticalPermutor(setSizes ...int) *IdenticalPermutor
NewIdenticalPermutor creates an IdenticalPermutor for potentially duplicated integers in the range [0, len(setSizes)). Each passed ith value in the variatic argument represents the number of identical copies of integer i that is in the set to be permuted. For example:
NewIdenticalPermutor(2, 0, 3, 1)
This will create a permutor over the set [0, 0, 2, 2, 2, 3] (2 copies of 0, 0 copies of 1, 3 copies of 2, and 1 copy of 3).
func (*IdenticalPermutor) Iterator ¶
func (ip *IdenticalPermutor) Iterator() <-chan []int
Iterator returns a channel-backed iterator that produces iterations of the identical sets represented by an IdenticalPermutor. The channel closes once all the permutations have been pushed. The implementation uses Heap's algorithm (non-recursive) and a map of hashes to keep track of which permutations have been seen already. This means for very large permutations, there is some small probability that a hash collision will occur and certain permutations could be skipped in the iteration.
func (IdenticalPermutor) Len ¶
func (ip IdenticalPermutor) Len() int
Len returns the length of the set being permuted.
func (IdenticalPermutor) NumberOfPermutations ¶
func (ip IdenticalPermutor) NumberOfPermutations() *big.Int
NumberOfPermutations returns the number of permutations possible for the set.
type IndexPermutor ¶
type IndexPermutor struct {
// contains filtered or unexported fields
}
IndexPermutor permutes an integer range from 0 to N.
func NewIndexPermutor ¶
func NewIndexPermutor(size int) *IndexPermutor
NewIndexPermutor creates an IndexPermutor for the integer range [0, size)
func (*IndexPermutor) Iterator ¶
func (ip *IndexPermutor) Iterator() <-chan []int
Iterator returns a channel-backed iterator that produces iterations of the identical sets represented by an IdenticalPermutor. The channel closes once all the permutations have been pushed. The implementation uses Heap's algorithm (non-recursive).
func (IndexPermutor) Len ¶
func (ip IndexPermutor) Len() int
Len returns the length of the set being permuted.
func (IndexPermutor) NumberOfPermutations ¶
func (ip IndexPermutor) NumberOfPermutations() *big.Int
NumberOfPermutations returns the number of permutations possible for the set.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player represents a player's current status in the competition.
func (Player) RemainingIterator ¶
RemainingIterator returns an iterator over remaining team indices.
func (Player) RemainingTeams ¶
RemainingTeams returns the list of remaining teams.
func (Player) RemainingWeekTypes ¶
RemainingWeekTypes returns the list of remaining week types.
func (Player) RemainingWeeks ¶
RemainingWeeks calculates the number of weeks of picks this player has remaining.
func (Player) WeekTypeIterator ¶
WeekTypeIterator returns an iterator over remaining week types.
type PlayerMap ¶
PlayerMap associates a player's name with a status.
func MakePlayers ¶
MakePlayers parses a YAML file and produces a map of remaining players.
func (PlayerMap) Duplicates ¶
Duplicates returns a list of Players who are duplicates of one another.
func (PlayerMap) PlayerNames ¶
PlayerNames returns the unique names of the players in the PlayerMap.
type PredictionModel ¶
type PredictionModel interface { MostLikelyOutcome(*Game) (team Team, prob float64, spread float64) Predict(*Game) (prob float64, spread float64) }
PredictionModel describes an object that can predict the probability a given team will defeat another team, or the point spread if those teams were to play.
type Predictions ¶
type Predictions struct {
// contains filtered or unexported fields
}
Predictions represents the probability of win and predicted spread for every team for each week.
func EmptyPredictions ¶
func EmptyPredictions(teamList TeamList, nWeeks int) *Predictions
EmptyPredictions returns empty probabilities for a set of teams and a given number of weeks.
func MakePredictions ¶
func MakePredictions(s *Schedule, m PredictionModel) *Predictions
MakePredictions uses a schedule and a model to build a map of predictions for fast lookup.
func (*Predictions) FilterWeeks ¶
func (p *Predictions) FilterWeeks(w int)
FilterWeeks filters the Predictions by removing weeks prior to the given one.
func (*Predictions) GetProbability ¶
func (p *Predictions) GetProbability(team Team, week int) float64
GetProbability returns the probability that the given team wins in the given week. Bye weeks have a probability of 1.
func (*Predictions) GetSpread ¶
func (p *Predictions) GetSpread(team Team, week int) float64
GetSpread returns the predicted spread for a given team in a given week. Teams on bye weeks are given a spread of 0.
func (Predictions) String ¶
func (p Predictions) String() string
type RelativeLocation ¶
type RelativeLocation int
RelativeLocation describes where a game is being played relative to one team's home field.
type RemainingMap ¶
RemainingMap associates a player's name to the teams remaining.
type Schedule ¶
Schedule is a team's schedule for the year.
func MakeSchedule ¶
MakeSchedule parses a schedule YAML file.
func (*Schedule) FilterWeeks ¶
FilterWeeks filters the Predictions by removing weeks prior to the given one.
type Streak ¶
type Streak struct {
// contains filtered or unexported fields
}
Streak represents a potential streak selection for a contestant.
func NewStreak ¶
NewStreak creates a Streak from a list of teams, a selected number of picks per week, and a permutation of the teams into the week.
func (*Streak) Clone ¶
Clone clones the streak. This results in a new struct with all of the internal objects cloned.
func (*Streak) PermuteTeamOrder ¶
PermuteTeamOrder permutes the order of the streak by the given permutation index.
func (*Streak) Perturbate ¶
Perturbate randomly swaps two teams in the team order. If `picksPerWeekAlso` is `true`, will also randomly swap the picks per week for two weeks. This function is not guaranteed to produce a new distinct streak.
func (*Streak) PicksPerWeek ¶
PicksPerWeek sets the number of picks per week. A nil value as an argument returns the old picks per week value with no changes made.
type TeamList ¶
type TeamList []Team
TeamList implements the sort.Interface interface and represents a list of Teams.
func (TeamList) Len ¶
Len calculates the length of the TeamList (implements sort.Interface interface)