// ART1MASPAR.h
// (c) Indra's Net Farm - 2002
// trans(c) Tim McFadden
// This code is released to be used entirely at the user's own risk
// for any consequences what so ever.
// Please keep the Indra's Net Farm name on copied code.

# ifndef _ART1MASPAR
# define _ART1MASPAR

#include "F1Layer.h"
#include "F2Layer.h"
#include "LayerFactory.h"
#include "Orienting.h"
#include "LTM.h"
#include "TraceParse.h"

const int maxInputs = 200; // maximum number of input traces.

//
// class ART1MASPAR - main control of layers.
// Parses input traces and feeds the layers.
// contains main()
class ART1MASPAR
{
private:

F1Layer* F1L;
F2Layer* F2L;

LayerFactory Fact;

TraceParse Parse; // parser for input params and traces.

Orienting* Ori;

LTM Ltm;

int N; // dimension of trace and F1 field.

int M; // dimension of F2 field.


// constants for F1 and F2 layers.

float A1;

float B1;

float C1;

float D1;

float Epsilon;

float A2;

float B2;

float C2;

float D2;

float BotupFact; // fudge factor for BU learning.

float L;


float rho; // orienting parameter for reset.

int rowCnt; // number of traces in array.

int DebugFlag; // debug level.


int (*inPuts)[maxM] ; // array of traces.


public:

ART1MASPAR(char* filenam) ;

void run();

void ART1_Interfac(int tri, char* filenam);

void ART1_Interfac(char* filenam);

friend TraceParse; // this allows TraceParse to set variables.

} ;

# endif

--------------------------------

// Dumpster.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _Dumpster

# define _Dumpster

#include <iostream>

//

// class Dumpster - vector and matrix dump utility.

//

class Dumpster

{

public :

Dumpster() {}


// dumpVecI().

void dumpVecI(int* I, int n)

{

cout << "vector[" << n << "]\n";

for (int i = 0; i < n; i++)

cout << I[i] << "\n";

cout << "---\n";

}


// dumpVecF()

void dumpVecF(float* I, int n)

{

cout.setf(ios::showpoint);

cout.precision(2);


cout << "vector[" << n << "]\n";

for (int i = 0; i < n; i++)

cout << I[i] << " ";

cout << "\n---\n";

}

// dumpMatrix()

void dumpMatrix(float *I, int n, int m)

{

cout.setf(ios::showpoint);

cout.precision(2);


cout << "matrix[" << n << "," << m << "]\n";

for (int i = 0; i < n; i++)

{

cout << "[" << i << "] ";

for (int j = 0; j < m; j++)

cout << *(I + i * 30 + j) << " ";

cout << "\n";

}

cout << "---\n";

}

// dumpXOR()

void dumpXOR(int *I, float* J, int n)

{

cout << "XOR\n";

for (int i = 0; i < n; i++)

{

int x;

float absJ = (int)J[i] > 0 ? 1 : -(int)J[i];


if (I[i] + absJ >= 2)

x = 0;

else

if (I[i] > 0)

x = 1;

else

if (absJ > 0)

x = 1;

else

x = 0;


cout << x << " ";

}

cout << "---\n";

}



} ;

# endif

--------------------------------

// F1Layer.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _F1Layer

# define _F1Layer

#include "Layer.h"

#include "FloatReg.h"

#include "IntReg.h"

#include "Orienting.h"

#include "LTMBottomUp.h"

#include "Up.h"

const int HISTNUM = 100;

const float HIST_MAX = 4.0;

const float HIST_MIN = 0.0;

const float HIST_DIF = (HIST_MAX - HIST_MIN) / HISTNUM;

//

// class F1Layer - process input traces and compare with

// memories from F2. Use orienting system for reset of F2.

//

class F1Layer : public Layer

{

float* X; // X[] of F1.

float* S; // output of F1.


// layer parameters.

float A1;

float B1;

float C1;

float D1;

float BotupFact; // multiplier for fadt learning.

int DebugFlag;



public :

Orienting* Ori;

FloatReg* VReg;

IntReg* IReg;

FloatReg* TReg;

LTMBottomUp* LTMBU;

int run() throw(Up);

float* getS();

void setI(int* i);


F1Layer (int m, float _A1, float _B1, float _C1, float _D1,

int debug);

} ;

# endif

--------------------------------


// F2Layer.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.


# ifndef _F2Layer

# define _F2Layer

#include "Layer.h"

#include "FloatReg.h"

#include "IntReg.h"

#include "LTMTopDown.h"

#include "Up.h"

//

// class F2Layer - process input from F1, run competition

// among nodes, and reset nodes.

//

class F2Layer : public Layer

{

public :


FloatReg* G;

float* Y; // Y[] of F2.

float* U; // output of F2.

int wini; // index of winning F2 node.

int DebugFlag;


int* droplist; // list of active nodes

// 1 => active.

// 0 => dropped by reset.

public :

FloatReg* TReg; // T[] in put.

FloatReg* VReg; // output from U.Ztd.

LTMTopDown* LTMTD;


F2Layer (int _m, int debug);

void init(); // initialize.

int run() throw(Up); // run the layer.

void compete(); // compete amongst F2 nodes.

void reset(); // drop a node from use.

} ;

# endif

--------------------------------

// FloatReg.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _FloatReg

# define _FloatReg


#include "RegisterCont.h"


// container for a register.

class FloatReg : public RegisterCont

{

public :

float* Reg;


FloatReg (int _m)

{

length = _m;

Reg = new float[_m];

}

} ;

# endif

--------------------------------

// IntReg.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _IntReg

# define _IntReg

#include "RegisterCont.h"

// container for a register.

class IntReg : RegisterCont

{

public :

int* Reg;


IntReg (int _m)

{

length = _m;

Reg = new int[_m];

}

} ;

# endif

--------------------------------


// Layer.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.


# ifndef _Layer

# define _Layer

//

// class Layer - mother of layers and holder of

// utilties.

class Layer

{

public :


int nodeNum; // count of nodes in layer.


// main constructor

Layer(int _nodeNum) {nodeNum = _nodeNum; }

// default utility constructor

Layer() {}

int magIt(int* _I, int n); // count of 1's int int[].

float magItF(float* _I, int n); // count of 1's in float[].

} ;

# endif

--------------------------------


// LayerFactory.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _LayerFactory

# define _LayerFactory

#include "F1Layer.h"

#include "F2Layer.h"

//

// class LayerFactory - for future use. Current version does little.

//

class LayerFactory

{

public:


F1Layer* Make1(int M, float _A1, float _B1, float _C1, float _D1,

int debug);

F2Layer* Make2(int N, int debug);

} ;

# endif

--------------------------------

// LTM.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _LTM

# define _LTM

const int maxM = 30;

const int maxN = 30;

//

// class LTM - parent of LTMs.

//

class LTM

{

protected :


int n; // width of trace and F1 layer.

int m; // width F2 layer.


public :


LTM() {}

LTM(int _n, int _m) {n = _n; m = _m;}

virtual float* dot(float* x); // dot into LTM.

virtual void dump(); // dump LTM.

} ;

# endif

--------------------------------

// LTMBottomUp.h

// (c) Indra's Net Farm

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.


# ifndef _LTMBottomUp

# define _LTMBottomUp

#include "LTM.h"

#include "Up.h"

class LTMBottomUp : public LTM

{

float L;

int DebugFlag;

float BotupFact; // muliplier for fast learning.


public :


float (*Z)[maxM]; // bottom up LTM.

LTMBottomUp (int _n, int m, float l, float BotupFact, int debug);


float* dot(float* z); // dot z with LTM.

void learn(int wini, float* S) throw(Up); // fast learning.

void dump(); // dump LTM.

} ;

# endif

--------------------------------


// LTMTopDown.h

// (c) Indra's Net Farm

// trans(c) Tim McFadden

# ifndef _LTMTopDown

# define _LTMTopDown

#include "LTM.h"

#include "Up.h"

//

// class LTMTopDown - maintain top down LTM.

//

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

class LTMTopDown : public LTM

{

float B1;

float D1;

int DebugFlag;


public :

float (*Z)[maxN]; // top down LTM.



LTMTopDown(int mz, int nz, float b1, float d1, int debug);

float* dot(float* z); // dot the vector z with the top down LTM.

void learn(int wini, float* S) throw(Up); // fast learning.

void dump(); // dump the top down LTM

} ;

# endif

--------------------------------


// Orienting.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _Orienting

# define _Orienting

#include "Layer.h"

//

// class Orienting - operate the orienting subsystem.

//

class Orienting : Layer

{

float rho;

int N;


public :


Orienting(float _rho, int _N);

int doReset(int* _I, float* _X); // check to see if there is a reset.

} ;

# endif


--------------------------------

// RegisterCont.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _RegisterCont

# define _RegisterCont

// container for a register.

class RegisterCont

{

public :

int length;

} ;

# endif

--------------------------------

// TraceParse.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

# ifndef _TraceParse

# define _TraceParse

#include "ART1MASPAR.h"

#include <fstream.h>

class ART1MASPAR; // forward declaration

# define PARSE_LOOK_DIGIT 1

# define PARSE_LOOK_LETTER (PARSE_LOOK_DIGIT << 1)

# define PARSE_LOOK_PAREN (PARSE_LOOK_LETTER << 1)

# define PARSE_LOOK_FLOAT (PARSE_LOOK_PAREN << 1)


//

// class TraceParse - utility for parsing input file,

// using Lisp-like sybtax.

// Friend to ART1MASPAR.

//

class TraceParse

{

ART1MASPAR* MASp;

void header();

void trace();

int rowCnt;

ifstream Ins;

public :

enum keyNames {NAME_M, NAME_N, NAME_A1, NAME_B1, NAME_C1,

NAME_EPSILON, NAME_A2 , NAME_B2,

NAME_C2, NAME_RHO, NAME_L,

NAME_D1, NAME_D2, NAME_DEBUG, NAME_NOT_HERE,

NAME_BUPF};

void parse(ART1MASPAR* z, char* fnam);

void lexChar(unsigned int flags) throw (Up);

} ;

# endif


// Up.h

// (c) Indra's Net Farm - 2002

// trans(c) Tim McFadden

// This code is released to be used entirely at the user's own risk

// for any consequences what so ever.

// Please keep the Indra's Net Farm name on copied code.

#include <iostream>

# ifndef _Up

# define _Up

// class Up - is a utility class to be thrown.

class Up

{

char* S;


public :

Up(char* _S) : S(_S) {}

Up(char* _S, char* _T) { S = strcat(_S, _T);}

Up(const Up& _u) : S(_u.S) {cout << "copy Up\n";}


char* getUp() const {return S;}

} ;

# endif