### 2.8 Automatic Spur

Automatic spur is a means to implement the idea that an intrinsic feature of an intelligent system is adherence to the principle of minimum energy (or maximum probability). The use of automatic spur may substantially increase the optimality of output signals an actor emits. The automatic spur also makes it possible to use the actor in cases when there are no explicit spur increments supplied to it.

The automatic spur is useful when the actor models a finite automaton. In this case, the output signals of the actor represent its internal states, that is, finite automaton states, and each action choice state is a superposition of the previous internal state and an input signal received when the actor was in that previous internal state. The automatic spur is a measure of adequacy of a model of internal states to a sequence of input signals received.

In QSMM, a common approach to building a model of internal states of an entity to solve a problem is the use of a spur scheme with two spur types for inhibitory (negative) spur and excitatory (positive) spur countervailing each other. The inhibitory spur is the automatic spur typically with a normal way of perception. The excitatory spur is specific to the problem to solve.

If an actor uses the automatic spur, it is equal to the sum of automatic spur increments calculated by the function `qsmm_actor_reg_sig_in` for action choice states that have prior occurrences in the event history. For such an action choice state, `qsmm_actor_reg_sig_in` knows an output signal emitted at the previous occurrence of this action choice state. Note that for the last occurrence, an output signal emitted in the action choice state is not yet known in `qsmm_actor_reg_sig_in`.

The actor calculates an automatic spur increment for a pair representing the logical consequence h → z and consisting of an action choice state h and an output signal z emitted in this action choice state. The automatic spur increment is equal to the natural logarithm of the probability of occurrence of this pair in the event history:

This formula uses the following notations:

v(h,z)

The number of occurrences of the pair in the event history.

t0

The discrete time of the previous occurrence of the pair in the event history. The function `qsmm_actor_reg_sig_action` records that time.

0<K≤1

The mean number of output signals emitted per one unit of discrete time passed.

If an actor uses a single spur type, and it corresponds to the automatic spur, it is better to set the type of a relative probability function for the actor to `QSMM_RELPROB_BUILTIN2` or `QSMM_RELPROB_BUILTIN3`. However, it is also better to use the automatic spur in conjunction with the other countervailing spur evaluating progress in solving a problem in some other way.

Use the functions described below to query or set a spur type for the automatic spur. By default, an actor created by the function `qsmm_actor_create` does not use the automatic spur, except that an implicitly created small actor associated with the large actor uses it.

Function: int qsmm_get_actor_auto_spur_type (qsmm_actor_t actor)

This function returns the non-negative index of a spur type for automatic spur used by an actor or negative error code `QSMM_ERR_NOTFOUND` if the actor does not use the automatic spur.

Function: int qsmm_set_actor_auto_spur_type (qsmm_actor_t actor, int spur_type)

This function sets to spur_type the spur type for the automatic spur of an actor. Spur types have zero-based indices. If spur_type is equal to -1, the actor does not use the automatic spur; this condition does not affect the use of the automatic spur by a small actor associated with the large actor.

On success, the function returns a non-negative value. If spur_type is less than -1 or is greater than or equal to the number of spur types specified in the field `nspur` of `qsmm_actor_desc_s` structure when creating the actor, the function returns negative error code `QSMM_ERR_INVAL`.

Use the functions `qsmm_get_actor_naction_per_evt` and `qsmm_set_actor_naction_per_evt` to query and set the value of K.

A small actor can use at most one spur type for the automatic spur. The functions `qsmm_get_actor_auto_spur_type` and `qsmm_set_actor_auto_spur_type` called for a small actor query and set the index of a spur type for that automatic spur.

A large actor can use at most two spur types for the automatic spur. A small actor associated with the large actor can use the automatic spur of the first type—increment it for action choice states occurring in the event history of this small actor. Those action choice states represent Huffman tree nodes traversed to generate output signals by the large actor. The large actor itself can use the automatic spur of the second type—increment it for action choice states occurring in the event history of that large actor. The functions `qsmm_get_actor_auto_spur_type` and `qsmm_set_actor_auto_spur_type` called for a large actor query and set the index of a spur type for the latter automatic spur.

Historically, the function `qsmm_actor_create` creates a large actor with the automatic spur of the first type turned on by default. You may want to turn it off and make the large actor use the automatic spur of the second type instead. To turn off the use of the automatic spur of the first type by a large actor actor_large, write:

```qsmm_set_actor_auto_spur_type(
qsmm_get_actpair_actor_env(
qsmm_get_actpair(qsmm_get_actor_large_model(actor_large))),
-1)
```

To conserve memory, you can reuse a spur type for the automatic spur of the first type for another purpose. For a small actor associated with the large actor, this spur type has index 0. By default, the small actor uses discrete time to compute spur increment velocity for this spur type. For the large actor, this spur type has special index -1.