Next: , Previous: , Up: Machine learning with tarot   [Contents][Index]


5.3 Online learning with a multi-layer perceptron

Static learning models are great for the AI, because we learn them at compile time. However, it may be a good addition to have a learning algorithm that is able to learn to know a player.

struct: TarotPerceptron

A model that is capable of being learnt in the course of the program (at the end of a finished game).

Function: TarotPerceptron * tarot_perceptron_alloc (size_t nhiddenlayers, const size_t *hiddensizes, double learningrate)

Allocate a new perceptron with the given hyperparameters: the number of hidden layers, their corresponding sizes, and the learning rate.

Function: TarotPerceptron * tarot_perceptron_static_default ()

Allocate and return the best perceptron that the maintainer has been able to learn. This perceptron is static, because no learning will be remembered the next time you will call this function.

Function: void tarot_perceptron_eval (TarotPerceptron *perceptron, const TarotGame *base, size_t n, TarotGameEvent **candidates, size_t start, size_t max, double *scores)

Starting at base, for each of the n candidates, make a prediction using perceptron. Discard the predictions for the start first candidates, then store the following max predictions inside scores.

Function: void tarot_perceptron_learn (TarotPerceptron *perceptron, const TarotGame *base, const TarotGameEvent *event, double final_score)

Learn that playing event in base leads to the given final score.

Function: TarotPerceptron * tarot_perceptron_dup (const TarotPerceptron *perceptron)

Return an allocated copy of perceptron.

Function: void tarot_perceptron_free (TarotPerceptron *perceptron)

Delete a perceptron allocated by ‘tarot_perceptron_alloc’, ‘tarot_perceptron_dup’ or ‘tarot_perceptron_static_default’.

Function: void tarot_perceptron_set_learning_rate (TarotPerceptron *perceptron, double learning_rate)

Change the learning rate in perceptron.

Function: void tarot_perceptron_load (TarotPerceptron *perceptron, size_t start, size_t nweights, const double *parameters)

Load the internal parameters (size of nweights) into perceptron. If perceptron has n parameters, then we skip the first start ones.

Function: size_t tarot_perceptron_save (const TarotPerceptron *perceptron, size_t start, size_t max, double *parameters)

Get the max first internal parameters after skipping the start first and return the total number of parameters. The ‘_alloc’ function does all the allocations for you, and simply sets *n to the total number of parameters and copy them in the newly-allocated *data.


Next: , Previous: , Up: Machine learning with tarot   [Contents][Index]