Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otTinn Class Reference
[Neural Network - Neural network library, Neural Network - Neural network library, Neural Network - Neural network library]

Small feed-forward neural network with generic float inference. More...

#include <otNeuralNetwork.h>


Public Member Functions

 otTinn ()
 Create an empty neural-network object.
bool init (int nips, int nops, int nhid, otFILE *fs=0)
 Initialize the neural network.
bool init (const otNNTopology &topology, otFILE *fs=0)
 Initialize from the generic topology descriptor.
void topology (otNNTopology &out) const
bool warmStartFrom (const otTinn &source, otTinnWarmStartReport &report)
 Initialize this already-allocated model from a trained source model.
void close ()
 Free all allocated resources.
float * predict (const float *in)
 Return an output prediction for an input vector.
void setQ15MemoryPolicy (otTinnMemoryPolicy policy)
 Select how prepareQ15() places its runtime buffers.
otTinnMemoryPolicy q15MemoryPolicy () const
 Return the currently selected Q15 memory policy.
otTinnMemoryMode q15MemoryMode () const
 Return the effective memory mode selected by the last prepareQ15().
const char * q15MemoryModeName () const
 Human-readable effective Q15 memory mode.
void q15MemoryInfo (otTinnQ15MemoryInfo &info) const
 Fill a stable snapshot of the Q15 memory state.
unsigned long q15FastBytes () const
 Requested payload bytes placed in fast / normal memory.
unsigned long q15NormalBytes () const
unsigned long q15RequiredBytes () const
int q15WeightsBank () const
 Actual bank used by each Q15 runtime buffer: 0=normal, 1/2=fast bank.
int q15InputBank () const
int q15HiddenBank () const
int q15OutputBank () const
bool prepareQ15 ()
 Build the Q15 inference representation from the current float weights.
void releaseQ15 ()
 Release the optional Q15 runtime buffers.
bool q15Ready () const
 Return whether a current Q15 representation is available.
bool quantizeInputQ15 (const float *in, short *outQ15) const
 Quantize one normalized float input vector to Q15.
const short * predictQ15Raw (const short *inQ15)
 Run the pure fixed-point Q15 inference core.
float * predictQ15 (const float *in)
 Compatibility wrapper accepting float input and returning float output.
float train (const float *in, const float *tg, float rate)
 Train the network with one input/target pair.
bool save (const char *path)
 Save the neural network using the historical text format.
bool load (const char *path)
 Load a neural network saved in the historical text format.
bool saveTrainingCheckpoint (const char *path)
 Save an exact training-checkpoint representation of the float model.
bool loadTrainingCheckpoint (const char *path)
 Load an exact model previously written by saveTrainingCheckpoint().
void print (const float *arr, const int size)
 Print an array of floats. Useful for inspecting predictions.
void properties (int &nips, int &nops, int &nhid) const
 Read the network dimensions.
bool valid () const
 Check whether all required network buffers are allocated.

Static Public Member Functions

static void makeSingleHiddenTopology (otNNTopology &topology, int nips, int nops, int nhid)
static bool topologyStructurallyValid (const otNNTopology &topology)
static bool supportsTopology (const otNNTopology &topology)
static bool supportsTrainingTopology (const otNNTopology &topology)
static bool supportsQ15Topology (const otNNTopology &topology)
static bool supportsLegacySerializationTopology (const otNNTopology &topology)
static bool supportsTrainingCheckpointTopology (const otNNTopology &topology)


Detailed Description

v0.23 Step 5 supports float forward/back-propagation, exact resumable checkpoints and Q15 inference through one to four hidden layers. The historical one-hidden float/Q15 paths and OTNNCP1 representation are retained unchanged for numerical/file compatibility. The human-readable .tinn exchange format remains intentionally single-layer.


Constructor & Destructor Documentation

otTinn.otTinn (   ) 
 

This is the canonical constructor on every platform and the required form on the Blackfin GCC build. Call init() before using the network.


Member Function Documentation

void otTinn.close (   ) 
 

The function is idempotent and may safely be called more than once.

bool otTinn.init (  const otNNTopology &  topology,
otFILE *  fs = 0
) 
 

Parameters:
topology Requested network topology.
fs Optional otStudio filesystem binding.
Returns:
true when the topology is structurally valid and its float inference buffers can be allocated.
v0.23 Step 5 accepts one to four hidden layers for float predict()/train(), exact training checkpoints and Q15 inference. Legacy .tinn exchange capability remains queried separately.

bool otTinn.init (  int  nips,
int  nops,
int  nhid,
otFILE *  fs = 0
) 
 

Parameters:
nips Number of network inputs.
nops Number of network outputs.
nhid Number of neurons in the single hidden layer.
fs Pointer to the otStudio filesystem object. It may be null only when file-backed operations (save/load) are not used.
Returns:
true on successful allocation and initialization.

bool otTinn.load (  const char *  path  ) 
 

Parameters:
path Source filename/path.
Returns:
true on success.

bool otTinn.loadTrainingCheckpoint (  const char *  path  ) 
 

Parameters:
path Source filename/path.
Returns:
true only when the checkpoint is complete and structurally valid.

static void otTinn.makeSingleHiddenTopology (  otNNTopology &  topology,
int  nips,
int  nops,
int  nhid
)  [static]
 

Build the canonical one-hidden-layer topology used by legacy callers.

float* otTinn.predict (  const float *  in  ) 
 

Parameters:
in Input vector containing nips values.
Returns:
Internal output array, or null if the network is not valid.

float* otTinn.predictQ15 (  const float *  in  ) 
 

Parameters:
in Input vector containing nips normalized values in [-1,+1].
Returns:
Internal float output array, or null if prepareQ15() was not called.
This wrapper quantizes the input, runs predictQ15Raw(), then converts only the nops final Q15 outputs back to float. For performance measurements and real-time BF518 use, prefer predictQ15Raw() with pre-quantized inputs.

const short* otTinn.predictQ15Raw (  const short *  inQ15  ) 
 

Parameters:
inQ15 Q15 input vector containing nips samples.
Returns:
Internal Q15 output array, or null if prepareQ15() was not called.
The hot path contains no floating-point operations: input/hidden MACs, bias handling and sigmoid evaluation are all integer/fixed-point.

bool otTinn.prepareQ15 (   ) 
 

Returns:
true when the quantized runtime is ready for predictQ15().
Float weights remain authoritative and are not modified. The Q15 copy is invalidated by train(), init(), load() and close(), and can be rebuilt at any time by calling prepareQ15() again.

void otTinn.print (  const float *  arr,
const int  size
) 
 

Parameters:
arr Array to print.
size Number of values in the array.

void otTinn.properties (  int &  nips,
int &  nops,
int &  nhid
)  const
 

Parameters:
nips Receives the number of inputs.
nops Receives the number of outputs.
nhid Receives the number of hidden neurons.

unsigned long otTinn.q15FastBytes (   )  const
 

int otTinn.q15HiddenBank (   )  const
 

int otTinn.q15InputBank (   )  const
 

void otTinn.q15MemoryInfo (  otTinnQ15MemoryInfo &  info  )  const
 

Parameters:
info Destination POD structure.
The report is valid before and after prepareQ15(). totalBytes is derived from the current topology; placement/usage fields reflect the last successfully prepared runtime. On Windows fast-bank fields are zero.

otTinnMemoryMode otTinn.q15MemoryMode (   )  const
 

const char* otTinn.q15MemoryModeName (   )  const
 

otTinnMemoryPolicy otTinn.q15MemoryPolicy (   )  const
 

unsigned long otTinn.q15NormalBytes (   )  const
 

int otTinn.q15OutputBank (   )  const
 

bool otTinn.q15Ready (   )  const
 

unsigned long otTinn.q15RequiredBytes (   )  const
 

int otTinn.q15WeightsBank (   )  const
 

bool otTinn.quantizeInputQ15 (  const float *  in,
short *  outQ15
)  const
 

Parameters:
in Input vector containing nips values, normally in [-1,+1].
outQ15 Caller-provided array of at least nips shorts.
Returns:
true on success. Values outside [-1,+1] are saturated.
This conversion is intentionally separated from the fixed-point inference core so real-time applications can quantize sensor inputs once, or acquire them directly in fixed-point form.

void otTinn.releaseQ15 (   ) 
 

This does not modify the float network or its trained weights.

bool otTinn.save (  const char *  path  ) 
 

Parameters:
path Destination filename/path.
Returns:
true on success.

bool otTinn.saveTrainingCheckpoint (  const char *  path  ) 
 

Parameters:
path Destination filename/path.
Returns:
true on success.
Unlike the historical human-readable .tinn format, the checkpoint path stores each IEEE-754 float as its exact 32-bit hexadecimal bit pattern. It is intended for pause/resume training, where even small decimal round-trip changes would break deterministic continuation.

void otTinn.setQ15MemoryPolicy (  otTinnMemoryPolicy  policy  ) 
 

AUTO is the default. On BF518 it prefers Bank 2 for quantized weights and Bank 1 for input/hidden/output scratch. If a preferred bank cannot satisfy an allocation, AUTO falls back to the normal heap rather than failing. The selected policy survives close()/load()/re-initialization cycles.

static bool otTinn.supportsLegacySerializationTopology (  const otNNTopology &  topology  )  [static]
 

Return whether the historical human-readable .tinn format supports it.

static bool otTinn.supportsQ15Topology (  const otNNTopology &  topology  )  [static]
 

Return whether the current Q15 runtime supports this topology.

static bool otTinn.supportsTopology (  const otNNTopology &  topology  )  [static]
 

Return whether the current core can execute float inference for this topology.

static bool otTinn.supportsTrainingCheckpointTopology (  const otNNTopology &  topology  )  [static]
 

Return whether exact OTNNCP1/OTNNCP2 training checkpoints support it.

static bool otTinn.supportsTrainingTopology (  const otNNTopology &  topology  )  [static]
 

Return whether the float back-propagation/training path supports it.

void otTinn.topology (  otNNTopology &  out  )  const
 

Copy the topology currently owned by this model.

static bool otTinn.topologyStructurallyValid (  const otNNTopology &  topology  )  [static]
 

Validate descriptor shape independently of current execution capability.

float otTinn.train (  const float *  in,
const float *  tg,
float  rate
) 
 

Parameters:
in Training input vector.
tg Target output vector.
rate Learning rate.
Returns:
Target-to-output error, or a negative value on invalid input/state.

bool otTinn.valid (   )  const
 

Returns:
true when the object is ready for predict()/train().

bool otTinn.warmStartFrom (  const otTinn &  source,
otTinnWarmStartReport &  report
) 
 

Exact same-topology copies clone every float weight/bias. Width-only expansions with the same hidden-layer count preserve the complete source subnetwork exactly: old weights/biases are copied and connections from newly added neurons into old neurons/output are zeroed. Random weights belonging only to new neurons are retained (clamped to the source matrix magnitude) so they can break symmetry during subsequent training without changing the initial function.

Same-depth narrowing uses a deterministic structured PRUNE-COPY: for every narrower hidden layer, neurons with the greatest total absolute outgoing weight are retained and all adjacent matrices are copied with coherent row/column remapping. This is knowledge-preserving in the engineering sense, but not mathematically function-preserving, so report.functionPreserved=0.

Depth changes are deliberately rejected: with sigmoid layers there is no exact identity insertion/removal in this core, so such Candidates remain freshly randomized.


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-25 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0