BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class FootballModel( NonLinearModel )Source

More or less complex model for the outcome of football marches.

The input values are a (nteams,2) list of integers. They represent teams that play a match, the first at home the other away.

For each team the complexity lists parameters

name complexity limits default comment
Attack 1 0<a n/a trials on the goal
Defensive strength 2 0<b<1 0 fraction of trials stopped
Midfield strength 3 0<c<2 1 relative strength of the team
Home advantage 4 0<d<2 1 advantage of playing at home
Strategy 5 0<e<2 1 defensive <-> offensive

Note: Computational runtime errors/warnings occur when (some of) the parameters are at their limits.

The default values are chosen such that they dont have effect on the results. I.e. a model with complexity=5 and all parameters at the defaults except for "trials", has the same result as a model with complexity 1 with the same "trials" value.

For information what is calculated at each level of complexity, see info at the methods goals1(), goals2(), ... goals5(), below.

Note This is about the game that most of the world calls football.

Examples

fm = FootballModel( 18 ) 
print( fm.npars )
90
  • Author : Do Kester

Attributes

  • nteams : int
         number of teams
  • complexity : int
         degree of complexity, default = 5.

Attributes from Model

     npchain, parameters, stdevs, xUnit, yUnit

Attributes from FixedModel

     npmax, fixed, parlist, mlist

Attributes from BaseModel

     npbase, ndim, priors, posIndex, nonZero, tiny, deltaP, parNames

FootballModel( nteams, complexity=5, copy=None, **kwargs )

Calculate the score of football matches

The number of parameters is ( nteams * complexity )

Parameters

  • nteams : int
         number of teams
  • complexity : 1 <= int <= 5
         of the model
  • copy : FootballModel
         model to copy
  • fixed : None or dictionary of {int:float|Model}
         int index of parameter to fix permanently.
         float|Model values for the fixed parameters.
         Attribute fixed can only be set in the constructor.
         See: FixedModel

copy( )

Copy method.

getPrior( k )
Return the prior of the parameter, indicated by k modulo the complexity

Parameters

  • k : int
         parameter number.

goals1( xdata, par )
Consider attack (a) only.

  S1 = a1
  S2 = a2

Parameters

  • xdata : array of int
         list of matches team 1 vs team 2
  • par : array_like
         attack values

goals2( xdata, par )
Consider attack (a) and defense (d).

  S1 = a1 * ( 1 - d2 )
  S2 = a2 * ( 1 - d1 )

Parameters

  • xdata : array of int
         list of matches team 1 vs team 2
  • par : array_like
         team values

goals3( xdata, par )
Consider attack (a), defense (d) and midfield (m).

The ratio of the midfield strength modifies attack and defense

  S1 = a1 * √(m1/m2) * ( 1 - d2 (m2/m1) )
  S2 = a2 * √(m2/m1) * ( 1 - d1 (m1/m2) )

Parameters

  • xdata : array of int
         list of matches team 1 vs team 2
  • par : array_like
         team values

goals4( xdata, par )
Consider attack (a), defense (d), midfield (m) and home advantage (h).

The strategy modifies the midfield strangth of the home team.

  mh = m1 * h1
  S1 = a1 * √(mh/m2) * ( 1 - d2 (m2/mh) )
  S2 = a2 * √(m2/mh) * ( 1 - d1 (mh/m2) )

Parameters

  • xdata : array of int
         list of matches team 1 vs team 2
  • par : array_like
         team values

goals5( xdata, par )
Consider attack (a), defense (d), midfield (m), home advantage (h), and strategy (s)

  A offensive strategy (s>1) strenghtens the attach and weakens the defense.
  A defensive strategy (s<1) strenghtens the defense and weakens the attack.

  mh = m1 * h1
  S1 = a1 * √(s1 * mh/m2) * ( 1 - d2 (s2 * m2/mh) )
  S2 = a2 * √(s2 * m2/mh) * ( 1 - d1 (s1 * mh/m2) )

Parameters

  • xdata : array of int
         list of matches team 1 vs team 2
  • par : array_like
         team values

baseResult( xdata, params )
Returns the partials at the input value.

The partials are the powers of x ( xdata ) from 0 to degree.

Parameters

  • xdata : array_like [2:nteams]
         list of team ids playing against each other.
  • params : array_like
         parameters for the model

basePartial( xdata, params, parlist=None )
Returns the partials at the input value.

The partials are the powers of x ( xdata ) from 0 to degree.

Parameters

  • xdata : array_like
         values at which to calculate the partials
  • params : array_like
         parameters for the model (ignored for LinearModels).
  • parlist : array_like
         list of indices of active parameters

part1( xdata, par )
Derivatives copies from https://www.derivative-calculator.net

Parameters

  • xdata : array_like [2:nteams]
         list of team ids playing against each other.
  • par : array_like
         parameters for the model

part2( xdata, par )
Derivatives copies from https://www.derivative-calculator.net

Parameters

  • xdata : array_like [2:nteams]
         list of team ids playing against each other.
  • par : array_like
         parameters for the model

part3( xdata, par )
Derivatives copies from https://www.derivative-calculator.net

Parameters

  • xdata : array_like [2:nteams]
         list of team ids playing against each other.
  • par : array_like
         parameters for the model

part4( xdata, par )
Derivatives copies from https://www.derivative-calculator.net

Parameters

  • xdata : array_like [2:nteams]
         list of team ids playing against each other.
  • par : array_like
         parameters for the model

part5( xdata, par )
Derivatives copies from https://www.derivative-calculator.net

Parameters

  • xdata : array_like [2:nteams]
         list of team ids playing against each other.
  • par : array_like
         parameters for the model

baseDerivative( xdata, params )
Return the derivative df/dx at each input (=x).

Parameters

  • xdata : array_like
         values at which to calculate the partials
  • params : array_like
         parameters for the model.

baseName( )
Returns a string representation of the model.

baseParameterName( k )
Return the name of the indicated parameter. Parameters
  • k : int
         parameter number.

baseParameterUnit( k )
Return the unit of the indicated parameter.

Parameters

  • k : int
         parameter number.
Methods inherited from NonLinearModel
Methods inherited from Model
Methods inherited from FixedModel
Methods inherited from BaseModel