-
Notifications
You must be signed in to change notification settings - Fork 12
03 tokens
Package tokens
could be loaded via the standalone binary, or in Lua with
require("aprilann.tokens")
.
A Token
is an abstract C++ class which has different specializations for
different tasks and purposes. This class and its specializations are binded
to Lua, allowing Lua scripts to be a glue language between C++ algorithms which
are developed over the Token
abstraction.
In this way, the current implementation of Artificial Neural Networks (ANNs)
receives as input a token and produce a as output a token. Normally, for ANNs,
this token contains a matrix
, but it is also possible to wrap matrix.sparse
objects and token vectors. Every ANN component checks the token type, and
specialized computations could be done depending in the token type.
From Lua side, matrix
instances can be given and taken as tokens.
This class defines the basic interface shared for all token types. It is an abstract class which couldn't be instantiated in Lua. If you try, you will see the following message:
> tokens.base()
tokens.base:tokens.base: Abstract class!!!
stack traceback:
[C]: in function 'base'
stdin:1: in main chunk
[C]: in ?
Usually, C++ method calls return an instance to the class tokens.base
, but in
some cases it is possible to transform the generic reference to any of the child
classes, or in other cases, it is possible to retrieve the contained data.
The transformation between tokens and matrix instances is performed automatically by the glue code between C++ and Lua.
The following methods are in the generic interface of tokens.base
class.
token = t:clone()
The method clone is implemented in all the tokens, and returns a deep copy of the caller.
tokens.vector.bunch
The token bunch vector is an array of tokens. Some ANN components allow to receive a vector of tokens which could contain sparse vectors.
> t = tokens.vector.bunch()
> t = tokens.vector.bunch(10)
> t = tokens.vector.bunch{ t1, t2, ... }
t = t:clear()
number = t:size()
t = t:set(position, token)
> = t:set(1, matrix(2,3):linear())
t = t:push_back(token)
> = t:push_back(matrix(1,2):linear())
token = t:at(position)
> = t:at(1)
> = t:at(2)
lua iterator = t:iterate()
> for i,v in t:iterate() do print(i) print(v) end