2.7.3 Assigning a Preloaded Probability Profile

You can assign a preloaded probability profile to a number of action choice states. Output signals emittable in the action choice states will have weights defined by the preloaded probability profile.

If a current action choice state is an action choice state with the preloaded probability profile assigned, the function qsmm_actor_calc_action_prob called for a small actor applies the weights by copying them from the preloaded probability profile to the array of output signal weights accessible by the functions qsmm_get_actor_sig_weight and qsmm_set_actor_sig_weight.

For a large actor, the function qsmm_get_actor_sig_action uses an output signal choice tree defined by the preloaded probability profile to select an output signal in an action choice state with the preloaded probability profile assigned.

The purpose of the following functions is to retrieve or set up a correspondence between an action choice state and a preloaded probability profile.

Function: int qsmm_get_actor_ngram_profile (qsmm_actor_t actor, unsigned int flags, size_t *profile_p, size_t *permut_p, const qsmm_sig_t *sig_ngram_p)

This function retrieves a correspondence between an action choice state of an actor and a preloaded probability profile. A probabilities list in normal form and a permutation of output signals define the preloaded probability profile. The array sig_ngram_p with length specified in the field ngram_sz of qsmm_actor_desc_s structure when creating the actor encodes the action choice state. The argument flags must be equal to QSMM_MODE_2.

If profile_p is not NULL, the function sets *profile_p equal to the index of a probabilities list in normal form for the preloaded probability profile. If permut_p is not NULL, the function sets *permut_p equal to the index of a permutation of output signals for the preloaded probability profile. If the function sets *profile_p and *permut_p equal to (size_t) -1, this means that the action choice state has default output signal weights. For a small actor, default output signal weights are all equal. For a large actor, default output signal weights following from the structure of a default output signal choice tree are equal if the number of output signals is a positive integer power of tree arity.

On success, the function returns a non-negative value. If the array sig_ngram_p does not contain a valid array of signal identifiers encoding an action choice state, the function returns negative error code QSMM_ERR_NGRAM.

Function: int qsmm_set_actor_ngram_profile (qsmm_actor_t actor, int rez1, size_t profile, size_t permut, const qsmm_sig_t *sig_ngram_p)

This function sets up a correspondence between an action choice state of an actor and a preloaded probability profile. A probabilities list in normal form and a permutation of output signals define the preloaded probability profile. The argument profile specifies the index of the probabilities list in normal form. The argument permut specifies the index of the permutation of output signals. The array sig_ngram_p with length specified in the field ngram_sz of qsmm_actor_desc_s structure when creating the actor encodes the action choice state. The argument rez1 is for future use and must be equal to 0.

A special combination of profile and permut both equal to (size_t) -1 is the indication to assign default output signal weights to the action choice state. For a small actor, default output signal weights are all equal. For a large actor, default output signal weights following from the structure of a default output signal choice tree are equal if the number of output signals is a positive integer power of tree arity.

The function keeps intact statistics collected for the action choice state and held in statistics storage with a handle retrievable by the function qsmm_get_actor_storage for the actor. However, for a large actor, the function qsmm_set_actor_ngram_profile destroys the old output signal choice tree of the action choice state. The output signal choice tree holds the other part of statistics collected for the action choice state.

The function returns a non-negative value on success or a negative error code on failure. Currently, the function can return the following error codes.

QSMM_ERR_INVAL

The argument profile is not a valid index of a probabilities list in normal form, or the argument permut is not a valid index of a permutation of output signals, and, at the same time, profile and permut are not both equal to (size_t) -1, or the length of a probabilities list in normal form specified by profile is not equal to the length of a permutation of output signals specified by permut.

QSMM_ERR_NGRAM

The array sig_ngram_p is not a valid array of signal identifiers encoding an action choice state. To determine array validity, the function checks it for accordance with allowed ranges of signal identifiers specified by the field range_sig_p of qsmm_actor_desc_s structure when creating the actor.

QSMM_ERR_STORAGE

Statistics storage failure. See Getting the Reason of a Storage Failure, for how to get an error message describing the failure.

QSMM_ERR_STATS

Inconsistent statistics on an action choice state or cycle type detected.

QSMM_ERR_ILSEQ

A generated error message is not convertible to a wide string according to a current locale, or a storage redirection function reported QSMM_ERR_ILSEQ.

QSMM_ERR_NOMEM

There was not enough memory to perform the operation. This error can leave a large actor in inconsistent state. If after removing a reason of this error a repeated call to this function succeeds, the actor’s state becomes consistent.