-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiOffline.cpp
101 lines (75 loc) · 3.01 KB
/
MultiOffline.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
Author: Adriaan Tijsseling (AGT)
Copyright: (c) Copyright 2002-3 Adriaan Tijsseling. All rights reserved.
Description: Sample simulation file for using the Sequence API
This particular code trains a sequential network with a set of offline sequences
using the MultiSequence class.
Invoke with:
./seqnet -F 0 -f 10 -b king -d simulations/tekken -R 0.05 -p 0 -e 1000 > simulations/tekken/log.txt
*/
#include "MultiSequence.h"
// GLOBALS
extern SequenceAPI* gSequenceAPI; // the interface file to the API Library
// PROTOTYPES
bool InitNetwork( void );
void DoSimulation( void );
// initializes the network
bool InitNetwork( void )
{
int seqErr;
// every library output should go to cout
gSequenceAPI->SetSequenceLog( &cout );
// Create the network
seqErr = gSequenceAPI->SequenceSetupNetwork( true );
if ( seqErr != kNoErr ) return false;
// record current network settings to log file
gSequenceAPI->SequenceShow();
// Set the step parameters (subtraction and leaky-integration) for k layers
int k = gSequenceAPI->SequenceGetNumLayers();
gSequenceAPI->SequenceSetParameter( kParAs, gSequenceAPI->SequenceGetParameter( kParAi ) / (k+1) );
gSequenceAPI->SequenceSetParameter( kParPs, gSequenceAPI->SequenceGetParameter( kParPi ) / (k+1) );
return true;
}
// the meat of the simulation
void DoSimulation( void )
{
char filename[256];
bool retVal;
// create the multi sequence training instance
MultiSequence* multiSeq = new MultiSequence();
// We may want to test recalls for partial context and pattern cues.
// For this we load three different files:
// a contexts file, a cues file and a pattern list file
// Set names for test files. Directory names are internally suppended
multiSeq->SetPatternsFile( "patterns.txt" );
multiSeq->SetContextsFile( "contexts.txt" );
multiSeq->SetCuesFile( "cues.txt" );
// note that the patterns, cues and contexts files have labels!
if ( !multiSeq->LoadTestFiles() ) goto bail;
// record duration of simulation
gSequenceAPI->SequenceDuration( kStart );
// perform simulation for user-specified number of runs (usually just one)
for ( int run = 0; run < gSequenceAPI->SequenceGetRuns(); run++ )
{
*(gSequenceAPI->GetSequenceLog()) << "\nRUN " << run << endl;
// start clean: reset learning weights, activations
// (resetting weights also resets coincidence detector)
gSequenceAPI->SequenceReset( O_WT | O_ACT | O_CD );
// run the multi-sequence learning procedure
retVal = multiSeq->RunMultiSequenceSimulation();
// make sure we store the final values of the weights and context weights
strcpy( filename, gSequenceAPI->SequenceGetDirectory());
strcat( filename, "/seq" );
gSequenceAPI->SequenceSaveWeights( filename );
strcpy( filename, gSequenceAPI->SequenceGetDirectory());
strcat( filename, "/seqc" );
gSequenceAPI->SequenceSaveContext( filename );
if ( retVal == false ) goto bail;
// do big recall test
multiSeq->TestRecall( run );
}
// output duration of simulation
gSequenceAPI->SequenceDuration( kEnd );
bail:
delete multiSeq;
}