// NeuroSolutions v5.05

// Copyright (c) 1994-2006, NeuroDimension, Inc. All rights reserved.
// Author: Wesley Curtis Lefebvre

#ifndef __GLOBAL_H__
#define __GLOBAL_H__

#define PC
#define MS_VISUAL
#pragma warning(disable : 4996)

#include <stdio.h>
#include <float.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
#include <list>
#include <stddef.h>
#include <vector>

using namespace std ;

//#define NS_GUI_CHECKMEM

#define MAX_PATH_LENGTH					512
#define MAX_NAME_LENGTH					128
#define MAX_LABEL_LENGTH				32
#define SYMBOL_MAX_LINE_LENGTH			8196
#define FILE_MAX_LINE_LENGTH			100000
#define MAX_GENETIC_PARMS				72
#define WEIGHTFILEVERSION				243
#define nil                                     NULL
#define YES                                     1
#define NO                                      0
#define TINY							1.0e-16;// A small number.
#define FREE_ARG						char*
#ifndef MAX
#define MAX(x,y)                        x>y?x:y;
#endif
#ifndef MIN
#define MIN(x,y)                        x<y?x:y;
#endif
#ifndef SWAP_VALUES
#define SWAP_VALUES(a,b) {temp=(a);(a)=(b);(b)=temp;}
#endif
#ifndef PI
#define PI                                      3.1415927
#endif
#define NSInt                           int
#define NSUInt                          unsigned int
#define NSLong                          long
#define NSFloat                         double
#define USING_DOUBLE_PRECISION

#define MAX_DATAMATRIX_ROWS				1000
#define NSSEEK_CUR                      1
#define NSSEEK_END                      2
#define NSSEEK_SET                      0

#ifndef PC
#define SWAP
#endif

#ifdef MS_VISUAL
#define finite                          _finite
#else
#define finite(x)                       ((x>-1.0e12) && (x<1.0e12))
#endif

#define DLL_PARAM_ROWS          5
#define DLL_PARAM_COLS          3

#ifndef FALSE
#define FALSE                           0
#endif
#ifndef TRUE
#define TRUE                            1
#endif
#ifndef NULL
#define NULL                            0
#endif

#ifdef NS_GUI
#ifdef _DEBUG
#define new DEBUG_NEW
#define   malloc(s)         _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define   calloc(c, s)      _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define   realloc(p, s)     _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define   _expand(p, s)     _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define   free(p)           _free_dbg(p, _NORMAL_BLOCK)
#define   _msize(p)         _msize_dbg(p, _NORMAL_BLOCK)
#endif
#endif

typedef unsigned long       DWORD;
typedef unsigned char       BYTE;
typedef unsigned short      WORD;
typedef unsigned int        UINT;
typedef long				LONG;
typedef list<void *> LISTVOIDPOINTER;
typedef list<char *> LISTCHARPOINTER;
//Removed from code generation because did not compile under UNIX
//(Causes a warning when compiled with the highest warning level in VC6 that indicates a possible problem)
#ifdef NS_GUI
typedef vector<char *> VECTORCHARPOINTER;
typedef vector<BYTE> VECTORBYTE;
typedef vector<WORD> VECTORWORD;
typedef vector<VECTORCHARPOINTER *> VECTORVECTORCHARPOINTER;
#endif

//#ifndef NS_GUI
//typedef struct tagRGBQUAD {
//        BYTE    rgbBlue;
//        BYTE    rgbGreen;
//        BYTE    rgbRed;
//        BYTE    rgbReserved;
//} RGBQUAD;
//#endif

#ifndef NS_GUI
typedef int     BOOL;
#endif

typedef struct {
        NSFloat *data;
        int length;
} DLLWeights;

typedef struct {
        char parameters[DLL_PARAM_ROWS][DLL_PARAM_COLS][64];
        char parameterNames[DLL_PARAM_ROWS][DLL_PARAM_COLS][64];
        BOOL parameterReallocs[DLL_PARAM_ROWS][DLL_PARAM_COLS];
} DLLParameters;

typedef struct {
        DLLWeights *weights;
        DLLParameters *parameters;
        void *userData;
} DLLData;

typedef struct {
        void    *function,
                        *constructor,
                        *destructor;
        DLLData *instance;
} DLLStruct;

typedef DLLData         *(*DLL_Constructor)(DLLData *);
typedef DLLData         *(*DLL_Constructor_CSW)(DLLData *, void *);
typedef void            (*DLL_Destructor)(DLLData *);
typedef void            (*DLL_Destructor_CSW)(DLLData *, void *);

//void* NSMalloc(size_t);
//void* NSCalloc(size_t, size_t);
//void NSFreeMemory(void*);
//UINT NSBytesAllocated();
unsigned short int getWeightFileVersion(FILE *file);
FILE *seekComponent(FILE *, const char *, const char *);
FILE *seekComponentReturnNull(FILE *, const char *, const char *);
FILE *putComponent(FILE *, const char *, const char *);
void writeWeightFileVersion(FILE *);

#endif __GLOBAL_H__


// Author: Wesley Curtis Lefebvre

#ifndef __NSDLL_H__
#define __NSDLL_H__

void checkParameterIndices(int *row,int *col);
DLLData *allocDLLInstance(DLLData *oldInstance);
void freeDLLInstance(DLLData *instance);
DLLData *setWeights(DLLData *instance, int numberOfWeights);
DLLData *allocParameters(DLLData *instance);
NSFloat *getWeights(DLLData *instance);
void setUserData(DLLData *instance, void *userData);
void *getUserData(DLLData *instance);
void setParameterName(DLLData *instance, int row, int col, char *name, BOOL realloc);
int getIntParameter(DLLData *instance, int row, int col);
NSFloat getFloatParameter(DLLData *instance, int row, int col);
char *getStringParameter(DLLData *instance, int row, int col);
BOOL getBoolParameter(DLLData *instance, int row, int col);
void setIntParameter(DLLData *instance, int row, int col, int intValue, BOOL force);
void setFloatParameter(DLLData *instance, int row, int col, NSFloat floatValue, BOOL force);
void setStringParameter(DLLData *instance, int row, int col, char *stringValue, BOOL force);
void setBoolParameter(DLLData *instance, int row, int col, BOOL boolValue, BOOL force);

#endif __NSDLL_H__

// CoreObject

#ifndef __CoreObject_H__
#define __CoreObject_H__

class CoreObject
{
protected:
	char				m_sName[MAX_NAME_LENGTH];
public:
						CoreObject();
	virtual const char	*className() = 0;
	BOOL				convertPathToName(char *aPath, char *aName);
	BOOL				convertPathToDirectory(char *aPath, char *aDirectory);
	void				copyFile(char *oldPath, char *newPath, BOOL binary);
	virtual void		freeObject();
	virtual	bool		isKindOf(char *aString);
	BOOL				isStringNumeric(char* aString);
	void				makeUpper(char* aString);
	const char			*name(char *GUIClassName);
	BOOL				removeExtensionFromName(char *aName, char *result, char *extension);
	void				setName(const char *aString) { strcpy(m_sName,aString); };
};

#endif // __CoreObject_H__

#ifndef __PaletteView_H__
#define __PaletteView_H__

class PaletteView : public CoreObject
{
// Attributes
protected:

// Operations
public:
					PaletteView();
		const char	*className() { return "PaletteView"; };
};

#endif // __PaletteView_H__

#ifndef __MacroCell_H__
#define __MacroCell_H__

class MacroCell : public CoreObject
{
// Attributes
protected:

// Operations
public:
					MacroCell();
		const char	*className() { return "MacroCell"; };
};

#endif // __MacroCell_H__

#ifndef __Macro_H__
#define __Macro_H__

class Macro : public CoreObject
{
// Attributes
protected:

// Operations
public:
					Macro();
		const char	*className() { return "Macro"; };
};

#endif // __Macro_H__

#ifndef __ImageView_H__
#define __ImageView_H__

class ImageView : public CoreObject
{
// Attributes
protected:

// Operations
public:
					ImageView();
		const char	*className() { return "ImageView"; };
};

#endif // __ImageView_H__

#ifndef __Image_H__
#define __Image_H__

class Image : public CoreObject
{
// Attributes
protected:

// Operations
public:
					Image();
		const char	*className() { return "Image"; };
};

#endif // __Image_H__

#ifndef __ImageManager_H__
#define __ImageManager_H__

class ImageManager : public CoreObject
{
// Attributes
protected:

// Operations
public:
					ImageManager();
		const char	*className() { return "ImageManager"; };
};

#endif // __ImageManager_H__

#ifndef __ReceiverCell_H__
#define __ReceiverCell_H__

class ReceiverCell : public CoreObject
{
// Attributes
protected:

// Operations
public:
					ReceiverCell();
		const char	*className() { return "ReceiverCell"; };
};

#endif // __ReceiverCell_H__

#ifndef __TransmitterActionCell_H__
#define __TransmitterActionCell_H__

class TransmitterActionCell : public CoreObject
{
// Attributes
protected:

// Operations
public:
					TransmitterActionCell();
		const char	*className() { return "TransmitterActionCell"; };
};

#endif // __TransmitterActionCell_H__

#ifndef __View_H__
#define __View_H__

class View : public CoreObject
{
// Attributes
protected:

// Operations
public:
					View();
		const char	*className() { return "View"; };
};

#endif // __View_H__

#ifndef __Cable_H__
#define __Cable_H__

class Cable : public CoreObject
{
// Attributes
protected:

// Operations
public:
					Cable();
		const char	*className() { return "Cable"; };
};

#endif // __Cable_H__

#ifndef __CircularBuffer_H__
#define __CircularBuffer_H__

class CircularBuffer : public CoreObject
{
// Attributes
protected:

// Operations
public:
					CircularBuffer();
		const char	*className() { return "CircularBuffer"; };
};

#endif // __CircularBuffer_H__

#ifndef __Connector_H__
#define __Connector_H__

class Connector : public CoreObject
{
// Attributes
protected:

// Operations
public:
					Connector();
		const char	*className() { return "Connector"; };
};

#endif // __Connector_H__

#ifndef __GeneticParameter_H__
#define __GeneticParameter_H__

typedef enum {Binary=0, Boolean=1, Integer=2, FloatingPoint=3, FloatArray=4} ParameterDataType;
typedef enum {Gaussian=1, Uniform=2, Boundary=3, NonUniform=4} MutationType;

class GeneticParameter : public CoreObject
{
public:

// Attributes
protected:
	char				m_sParameterName[MAX_NAME_LENGTH];
    ParameterDataType	m_eDataType;
    MutationType		m_eMutationType;
	int					m_nIntValue,
						m_nParameterFunctionIndex,
						m_nGeneticParameterIndex,
						m_nBinaryCount,
						m_nFloatArrayCount,
						m_nBeginGeneIndex,
						m_nEndGeneIndex;
	NSFloat				m_fUpperBound,
						m_fLowerBound,
						m_fUpperBoundLimit,
						m_fLowerBoundLimit,
						m_fOffsetForDefaultBounds,
						m_fFloatValue;
	BOOL				m_bBoolValue;

public:
	BOOL				*m_bpBinaryArray;
	NSFloat				*m_fpFloatArray;

// Operations
public:
				GeneticParameter();
				~GeneticParameter();
	void		allocateBinaryArray(int arraySize);
	void		allocateFloatArray(int arraySize);
	int			beginGeneIndex() { return m_nBeginGeneIndex; };
	int			binaryCount() { return m_nBinaryCount; };
	BOOL		boolValue() { return m_bBoolValue; };
	const char *className() { return "GeneticParameter"; };
	int			dataType() { return (int)m_eDataType; };
	int			endGeneIndex() { return m_nEndGeneIndex; };
	NSFloat		engineValue(class Engine *anEngine, int arrayIndex=0);
	int			floatArrayCount() { return m_nFloatArrayCount; };
	NSFloat		floatValue() { return m_fFloatValue; };
	int			geneticParameterIndex() { return m_nGeneticParameterIndex; };
	void		initVariables();
	int			intValue() { return m_nIntValue; };
	BOOL		isDataTypeNumeric() { return (m_eDataType == FloatingPoint) || (m_eDataType == Integer); };
	NSFloat		lowerBound() { return m_fLowerBound; };
	NSFloat		lowerBoundLimit() { return m_fLowerBoundLimit; };
	int			mutationType() { return (int)m_eMutationType; };
	NSFloat		offsetForDefaultBounds() { return m_fOffsetForDefaultBounds; };
	int			parameterFunctionIndex() { return m_nParameterFunctionIndex; };
	char		*parameterName() { return m_sParameterName; };
	void		setBeginGeneIndex(int anIndex) { m_nBeginGeneIndex = anIndex; };
	void		setBinaryCount(int anInt) { m_nBinaryCount = anInt; };
	void		setBoolValue(BOOL aBool) { m_bBoolValue = aBool; };
	void		setBounds(NSFloat lowerBound, NSFloat upperBound);
	void		setBoundLimits(NSFloat lowerBound, NSFloat upperBound) { m_fLowerBoundLimit = lowerBound; m_fUpperBoundLimit = upperBound; };
	void		setDataType(char *aString);
	void		setDataTypeByInt(int anInt) { m_eDataType = (ParameterDataType)anInt; };
	void		setDefaultBounds(class Engine *anEngine);
	void		setEndGeneIndex(int anIndex) { m_nEndGeneIndex = anIndex; };
	void		setFloatArrayCount(int anInt) { m_nFloatArrayCount = anInt; };
	void		setFloatValue(NSFloat aFloat) { m_fFloatValue = aFloat; };
	void		setGeneticParameterIndex(int anInt) { m_nGeneticParameterIndex = anInt; };
	void		setLowerBound(NSFloat lowerBound);
	void		setLowerBoundLimit(NSFloat aFloat) { m_fLowerBoundLimit = aFloat; };
	void		setIntValue(int anInt) { m_nIntValue = anInt; };
	void		setMutationType(int anInt) { m_eMutationType = (MutationType)anInt; };
	void		setOffsetForDefaultBounds(NSFloat aFloat) { m_fOffsetForDefaultBounds = aFloat; };
	void		setParameterFunctionIndex(int anInt) { m_nParameterFunctionIndex = anInt; };
	void		setParameterName(char *aString) { strcpy(m_sParameterName, aString); };
	void		setUpperBound(NSFloat upperBound);
	void		setUpperBoundLimit(NSFloat aFloat) { m_fUpperBoundLimit = aFloat; };
	void		setValue(NSFloat aFloat, int geneIndex, int arrayIndex=0);
	NSFloat		upperBound() { return m_fUpperBound; };
	NSFloat		upperBoundLimit() { return m_fUpperBoundLimit; };
};

#endif // __GeneticParameter_H__


#ifndef __LearningGlobals_H__
#define __LearningGlobals_H__

class LearningGlobals {
public:
	class StaticControl	*m_pStaticControl;
	BOOL	WeightsRandomized,
			Initialized,
			m_bPhaseEndedCalled;

				 LearningGlobals();
	virtual void backpropComplete();
	virtual void epochEnded();
	virtual void fireConclude();
	virtual void freeMatricies();
	virtual void freeObject();
	virtual void initializeGlobals(StaticControl *aControl);
	virtual void networkWeightsUpdated();
	virtual void phaseEnded(int counter);
	virtual void preFireGetReady(BOOL backpropLearningOn);
	virtual void resetLearningParameters();
	virtual void updateNetworkWeights();
};

#endif

#ifndef __LMGlobals_H__
#define __LMGlobals_H__

class LMGlobals: public LearningGlobals {
public:
	NSFloat				**m_pfHessian,
						**m_pfLastGoodRunningHessian,
						**m_pfRunningHessian,
						**m_pfInverseResult,
						*m_pfMultiplicationResult,
						*m_pfGradientsSummedAcrossOutputs,
						*m_pfLastGoodWeights,
						**m_pfLastGoodGradients,
						**m_pfLastExemplarGradients,
						**m_pfJacobian,
						m_fInitialLambda,
						m_fLambda,
						m_fLastError;
	int					m_nAllocatedHessianDimension,
						m_nAllocatedOutputs;
	BOOL				m_bLearningParametersNeedResetting,
						m_bGoodWeightsSwapped,
						m_bLastGoodWeightsUpdated;

			LMGlobals();
			~LMGlobals();
	NSFloat *vector2(long nl, long nh);
	void	free_dvector(NSFloat *v, long nl, long nh);
	void	ludcmp(NSFloat **a, int n, int *indx, NSFloat *d);
	void	lubksb(NSFloat **a, int n, int *indx, NSFloat b[]);
	void	allocateMatrixBuffers();
	void	backpropComplete();
	void	computeHessian();
	void	computeMatrixInverse(NSFloat **sourceMatrix, int matrixSize, NSFloat **resultMatrix);
	void	epochEnded();
	void	fireConclude();
	void	freeMatricies();
	void	initializeGlobals(StaticControl *aControl);
	NSFloat	initialLambda() { return m_fInitialLambda; };
	void	preFireGetReady(BOOL backpropLearningOn);
	void	resetLearningParameters();
	void	setInitialLambda(NSFloat aFloat) { m_fInitialLambda = aFloat; };
	void	swapGoodWeights();
	void	updateNetworkWeights();
};

#endif

#ifndef __CGGlobals_H__
#define __CGGlobals_H__

class CGGlobals: public LearningGlobals {
public:
	double Lambda, LambdaBar, MSE, MSEOld, Sigma, SigmaK, AlphaK, MuK, DeltaK;
	BOOL Success,checkMSE, weightsStoredOnFireConclude;
	int NumWeights, EpochNumber;

		 CGGlobals();
	void combineGradients();
	void epochEnded();
	void fireConclude();
	void initializeGlobals(class StaticControl *aControl);
	void networkWeightsUpdated();
	void phaseEnded(int counter);
	void preFireGetReady(BOOL backpropLearningOn);
	void reloadOldWeights(void);
	void reloadOldWeightsOnFireConclude(void);
	void resetLearningParameters(void);
	void resetGradients(void);
	void storeOldWeights(void);
	void storeOldWeightsOnFireConclude(void);    // Neil: I don't think this is needed
};

#endif

#ifndef __LSWeightInitializer_H__
#define __LSWeightInitializer_H__

typedef enum {	hyperbolictangent=0, sigmoid=1, linear=2, bias=3, othertype=4 } Activation_Function_Type;

class LSWeightInitializer
{
public:

	double *hiddenWeightV;
	double *outputWeightV;
	int outp,exemp,inp,hiddenPE;
	double **desiredM;
	unsigned aTyp,aTyp2;
	double slop, slop2;
	double **inputM;
	Activation_Function_Type hiddenActivationType,outputActivationType;


	LSWeightInitializer(int exemplars, int inputs,int outputs, int hiddenPEs);
	virtual ~LSWeightInitializer();
	void MatTranspose(double **a, int n, int m,double **aprim);
	void MatrixMultiplication(double **Matrix1,int matrixSize11,int matrixSize12,double **Matrix2,int matrixSize21,int matrixSize22,double **ResultingMatrix);
	double vectorsMatrixMultiplication(double *vect,int sizevect,double *Matrix);
	void vectMatrixMultiplication(double *vect,int sizevect,int sizemat, double **Matrix,double *ResultingVec);
	void NonlinOut(double** a,int size1,int size2,int NLtype, double slope);
	void mlp(double **x,int N, int n, int NPE1, int NPE2, double *W1, double *W2,unsigned aType1,double slope1, unsigned aType2,double slope2,double **yy2,  double **yy1);
	double costFunction(double **y,double **d,int n2, int N, double *W);
	void NonlinDeriv(double** a,double** b, int size1,int size2,int NLtype, double slope);
	void NonlinInv(double** a,int size1,int size2,int NLtype, double slope);
	int *vector2(long nl, long nh);
	void gaussj(double **a, int n, double **b, int m);
	void computeMatrixInverse(double **sourceMatrix, int matrixSize, double **resultMatrix);
	void LSsolution(double **x, int n, int m, int S, double **d, double **G,int nltype, double slopi,double *W);
	void reshapeVect2Mat(double *Vect,int sizeVect,int sizeMat1,int sizeMat2, double **Mat);
	void solvLinEq(double **R, int n, int p, double ** Q, double *b,double *bnew) ;
	void qrdec(double **x,int n,int p, double **R);
	double abso(double criter);
	void calculateNewWeights(double *hiddenWeightVector, double *outputWeightVector, double *hiddenBiases,double *outputBiases);
	void setDesiredMatrix(double **desiredMatrix);
	void setHiddenWeights(double *weightVector);
	void setHiddenBiases(double *biasVector);
	void setOutputBiases(double *biasVector);
	void setHiddenActivationType(unsigned aType, double slope);
	void setInputMatrix(double **inputMatrix);
	void setOutputActivationType(unsigned aType, double slope);
	void setOutputWeights(double *weightVector);
};

#endif

// Engine

#ifndef __Engine_H__
#define __Engine_H__

typedef void (*Void_MAP)(DLLData *);

class Engine : public CoreObject
{
protected:
	StaticControl			*m_pStaticControl;
	class GeneticParameter	*m_pGeneticParameter[MAX_GENETIC_PARMS];
	BOOL					m_bGeneticParameterActive[MAX_GENETIC_PARMS],
							m_bGeneticControlNeedsResetting;
	int						m_nActiveGeneticParameters;
public:
	DLLStruct				dllEngineStruct;

public:
					Engine();
	int				activeGeneticParameters() { return m_nActiveGeneticParameters; };
	virtual BOOL	callBinaryGetFunction(int paramIndex, int arrayIndex);
	virtual void	callBinarySetFunction(int paramIndex, BOOL aBool, int arrayIndex);
	virtual BOOL	callBoolGetFunction(int paramIndex);
	virtual void	callBoolSetFunction(int paramIndex, BOOL aBool);
	virtual NSFloat callFloatArrayGetFunction(int paramIndex, int arrayIndex);
	virtual void	callFloatArraySetFunction(int paramIndex, NSFloat aFloat, int arrayIndex);
	virtual int		callIntGetFunction(int paramIndex);
	virtual void	callIntSetFunction(int paramIndex, int anInt);
	virtual NSFloat callFloatGetFunction(int paramIndex);
	virtual void	callFloatSetFunction(int paramIndex, NSFloat aFloat);
	virtual void	checkGeneticFloatArray();
	virtual void	preFireGetReady();
	virtual void	postFireGetReady();
	BOOL			geneticParameterActive(int index) { return ((index < MAX_GENETIC_PARMS) && (index >= 0)) ? m_bGeneticParameterActive[index] : FALSE; };
	virtual int		geneticParameterCount();
	virtual int		geneticParameterStartingIndex();
	virtual int		initializeGeneticParameters();
	bool			isKindOf(char *aString);
	void			setActiveGeneticParameters(int anInt) { m_nActiveGeneticParameters = anInt; };
	void			setGeneticParameter(int anIndex, GeneticParameter *aParameter) { m_pGeneticParameter[anIndex] = aParameter; };
	virtual void	setGeneticParameterActive(int index, BOOL aBool, BOOL setDefaultBounds=TRUE);
	StaticControl	*staticControl() { return m_pStaticControl; };
	void			setStaticControl(StaticControl *aControl) { m_pStaticControl = aControl; };
};

#endif

#ifndef __MacroEngine_H__
#define __MacroEngine_H__

class MacroEngine : public Engine
{
// Attributes
protected:

// Operations
public:
					MacroEngine();
};

#endif // __MacroEngine_H__

#ifndef __EditEngine_H__
#define __EditEngine_H__

class EditEngine : public MacroEngine
{
// Attributes
protected:

// Operations
public:
					EditEngine();
		const char	*className() { return "EditEngine"; };
};

#endif // __EditEngine_H__

#ifndef __ButtonEngine_H__
#define __ButtonEngine_H__

class ButtonEngine : public EditEngine
{
// Attributes
protected:

// Operations
public:
					ButtonEngine();
		const char	*className() { return "ButtonEngine"; };
};

#endif // __ButtonEngine_H__

#ifndef __TextBoxEngine_H__
#define __TextBoxEngine_H__

class TextBoxEngine : public EditEngine
{
// Attributes
protected:

// Operations
public:
					TextBoxEngine();
		const char	*className() { return "TextBoxEngine"; };
};

#endif // __TextBoxEngine_H__

#ifndef __ArrowEngine_H__
#define __ArrowEngine_H__

class ArrowEngine : public Engine
{
// Attributes
protected:

// Operations
public:
					ArrowEngine();
		const char	*className() { return "ArrowEngine"; };
};

#endif // __ArrowEngine_H__

#ifndef __FANuggetEngine_H__
#define __FANuggetEngine_H__

class FANuggetEngine : public Engine
{
// Attributes
protected:

// Operations
public:
					FANuggetEngine();
		const char	*className() { return "FANuggetEngine"; };
};

#endif // __FANuggetEngine_H__

#ifndef __CNuggetEngine_H__
#define __CNuggetEngine_H__

class CNuggetEngine : public Engine
{
// Attributes
protected:

// Operations
public:
					CNuggetEngine();
		const char	*className() { return "CNuggetEngine"; };
};

#endif // __CNuggetEngine_H__

#ifndef __TSNuggetEngine_H__
#define __TSNuggetEngine_H__

class TSNuggetEngine : public Engine
{
// Attributes
protected:

// Operations
public:
					TSNuggetEngine();
		const char	*className() { return "TSNuggetEngine"; };
};

#endif // __TSNuggetEngine_H__

#ifndef __CTNuggetEngine_H__
#define __CTNuggetEngine_H__

class CTNuggetEngine : public Engine
{
// Attributes
protected:

// Operations
public:
					CTNuggetEngine();
		const char	*className() { return "CTNuggetEngine"; };
};

#endif // __CTNuggetEngine_H__

#ifndef __ANuggetEngine_H__
#define __ANuggetEngine_H__

class ANuggetEngine : public Engine
{
// Attributes
protected:

// Operations
public:
					ANuggetEngine();
		const char	*className() { return "ANuggetEngine"; };
};

#endif // __ANuggetEngine_H__

#ifndef __Control_H__
#define __Control_H__

class Control: public Engine
{
public:
					Control();
	bool			isKindOf(char *aString);
};

#endif

#ifndef __GeneticControl_H__
#define __GeneticControl_H__

class GeneticControl : public Control
{
public:
					GeneticControl();
	const char		*className() { return "GeneticControl"; };
};

#endif

#ifndef __StaticControl_H__
#define __StaticControl_H__

typedef enum {Backprop=0, CG=1, LM=2, DLL=3} NLearningType;

class StaticControl : public Control
{
protected:
	char					m_sCurrentAnnotation[MAX_LABEL_LENGTH],
							m_sAnnotationHeading[MAX_LABEL_LENGTH];
	int						m_nNetworkOutputs;
	LISTVOIDPOINTER			m_BackCriterionList;
	LISTVOIDPOINTER			m_CriterionList;
	LISTVOIDPOINTER			m_SynapseList;
	LISTVOIDPOINTER			m_AxonList;
	LISTVOIDPOINTER			m_GradientList;
	BOOL					m_bBackpropLearningOn,
							m_bOptimizeInitialWeights,
							m_bWeightsRandomized,
							m_bTerminateWOImprovement,
							m_bCrossValidationActive,
							m_bCrossValidationEnabled,
							m_bPauseForced,
							m_bGeneticControlNeedsResetting,
							m_bNetworkPaused,
							m_bDynamicCrossValidation,
							m_bLearning;
	NLearningType			m_LearningType;
	int						**m_weightOffsetPointer,
							m_nMaxEpochsWOImprovement,
							m_nActiveNumberOfExemplars,
							m_nShiftCrossValidationBy;
	void					**m_gradientComponentPointer;
	class Soma				**m_pEnginesToFire;
	int						m_nPhaseCounter,
							m_nPhases,
							m_nEnginesToFire,
							m_nExemplars,
							m_nEpochs,
							m_nSamples,
							m_nNetworkWeights,
							m_nAllocatedOffsets,
							m_nAllocatedOutputs,
							m_nEpochsPerTest,
							m_nExemplarCounter,
							m_nEpochCounter,
							m_nSampleCounter,
							m_nEpochOfBestWeights,
							m_nInputExemplars,
							m_nDesiredExemplars;
	class Criterion			*m_pFirstCriterion;
	class BackStaticControl	*m_pBackControl;
	NSFloat					**m_fpInputData,
							**m_fpDesiredData,
							m_fInitialLambda,
							m_fCostOfBestWeights;

public:
	class LearningGlobals	*learningGlobals;
	int						m_nAllocatedHessianDimension,
							m_nTempAllocatedOutputs;
	NSFloat					m_dLambda,
							m_dInitialLambda,
							m_dLastError,
							**m_pfHessian,
							**m_pfLastGoodRunningHessian,
							**m_pfRunningHessian,
							**m_pfInverseResult,
							*m_pfMultiplicationResult,
							*m_pfGradientsSummedAcrossOutputs,
							*m_pfLastGoodWeights,
							**m_pfLastGoodGradients,
							**m_pfLastExemplarGradients,
							**m_pfJacobian;
	BOOL					m_bInitialized,
							m_bTempWeightsRandomized,
							m_bPhaseEndedCalled,
							m_bLearningParametersNeedResetting,
							m_bGoodWeightsSwapped,
							m_bLastGoodWeightsUpdated;


public:
						StaticControl();
						~StaticControl();
	int					activeNumberOfExemplars() { return m_nActiveNumberOfExemplars; };
	void				addToEnginesToFireList(Soma *aSoma, BOOL frontOfList);
	int					allocatedOffsets() { return m_nAllocatedOffsets; };
	int					allocatedOutputs() { return m_nAllocatedOutputs; };
	void				allocateNewLearningGlobals();
	void				allocateTempMatricies();
	void				allocateWeightOffsetBuffers(int totalNetworkOutputs);
	char				*annotationHeading() { return m_sAnnotationHeading; };
	BackStaticControl	*backControl() { return m_pBackControl; };
	LISTVOIDPOINTER		*backCriterionList() { return &m_BackCriterionList; };
	void				backpropComplete();
	BOOL				backpropLearningOn() { return m_bBackpropLearningOn; };
	const char			*className() { return "StaticControl"; };
	void				clearComponentLists();
	void				clearEnginesToFire();
	NSFloat				costOfBestWeights() { return m_fCostOfBestWeights; };
	LISTVOIDPOINTER		*criterionList() { return &m_CriterionList; };
	BOOL				crossValidationActive() { return m_bCrossValidationActive; };
	char				*currentAnnotation() { return m_sCurrentAnnotation; };
	void				determineFiringSequence();
	BOOL				dynamicCrossValidation() { return m_bDynamicCrossValidation; }
	int					enginesToFire() { return m_nEnginesToFire; };
	Soma				*engineToFire(int anIndex) { return (*(m_pEnginesToFire+anIndex)); };
	int					epochCounter() { return m_nEpochCounter; };
	void				epochEnded();
	int					epochOfBestWeights() { return m_nEpochOfBestWeights; };
	int					epochs() { return m_nEpochs; };
	int					epochsPerTest() { return m_nEpochsPerTest; };
	int					exemplarCounter() { return m_nExemplarCounter; };
	int					exemplars() { return m_nExemplars; };
	void				fireConclude(void);
	void				fireConfirmReady();
	void				fireEngines();
	class Criterion		*firstCriterion() { return m_pFirstCriterion; };
	void				freeObject();
	void				freeTempMatricies();
	void				freeWeightOffsetBuffers();
	BOOL				geneticControlNeedsResetting() { return m_bGeneticControlNeedsResetting; };
	class Gradient		*gradientComponent(int weightIndex) { return (Gradient *)*(m_gradientComponentPointer + weightIndex); };
	LISTVOIDPOINTER		*gradientList() { return &m_GradientList; };
	void				incrementEpochCounter() { m_nEpochCounter++; };
	void				incrementExemplarCounter() { m_nExemplarCounter++; };
	void				incrementPhaseCounter() { m_nPhaseCounter++; };
	void				incrementSampleCounter() { m_nSampleCounter++; };
	NSFloat				initialLambda() { return m_fInitialLambda; };
	bool				isKindOf(char *aString);
	BOOL				learning() { return m_bLearning; };
	NLearningType		learningType() { return m_LearningType; };
	void				loadStateBeforeRun();
    void				loadWeights(FILE *, unsigned short int version=100);
	int					maxEpochsWOImprovement() { return m_nMaxEpochsWOImprovement; };
	int					networkOutputs() { return m_nNetworkOutputs; };
	BOOL				networkPaused() { return m_bNetworkPaused; };
	void				networkRandomize(void);
    void				networkReset(void);
	int					networkWeights() { return m_nNetworkWeights; };
	void				networkWeightsUpdated();
	BOOL				optimizeInitialWeights() { return m_bOptimizeInitialWeights; };
	BOOL				pauseForced() { return m_bPauseForced; };
	void				pauseNetwork(BOOL forcePause=TRUE) { m_bNetworkPaused = TRUE; m_bPauseForced = forcePause; };
	int					phaseCounter() { return m_nPhaseCounter; }
	void				phaseEnded(int count);
	int					phases() { return m_nPhases; }
	void				postFireGetReady();
	void				prepareToFire(class BackStaticControl *backControl);
	void				preFireGetReady(BOOL backpropLearningOn);
	void				refreshSynapseConnections();
	int					sampleCounter() { return m_nSampleCounter; }
	virtual int			samples() { return 1; };
	void				saveWeights(FILE *, BOOL addLineFeed=TRUE);
	void				setActiveNumberOfExemplars(int anInt) { m_nActiveNumberOfExemplars = anInt; };
	void				setAnnotationHeading(char *aString) { strcpy(m_sAnnotationHeading, aString); };
	void				setBackpropLearningOn(BOOL aBool) { m_bBackpropLearningOn = aBool; };
	void				setCostOfBestWeights(NSFloat aFloat) { m_fCostOfBestWeights = aFloat; };
	void				setCrossValidationActive(BOOL aBool) { m_bCrossValidationActive = aBool; };
	void				setCrossValidationEnabled(BOOL aBool) { m_bCrossValidationEnabled = aBool; };
	void				setCurrentAnnotation(char *aString) { strcpy(m_sCurrentAnnotation, aString); };
	void				setDesiredData(NSFloat **aMatrix, int anInt) { m_fpDesiredData = aMatrix; m_nDesiredExemplars = anInt; };
	void				setDynamicCrossValidation(BOOL aBool) { m_bDynamicCrossValidation = aBool; };
	void				setEpochCounter(int anInt);
	void				setEpochOfBestWeights(int anInt) { m_nEpochOfBestWeights = anInt; };
	void				setEpochs(int anInt) { m_nEpochs = anInt; };
	void				setEpochsPerTest(int anInt) { m_nEpochsPerTest = anInt; };
	void				setExemplarCounter(int anInt) { m_nExemplarCounter = anInt; };
	void				setExemplars(int anInt) { m_nExemplars = anInt; };
	void				setGeneticControlNeedsResetting(BOOL aBool) { m_bGeneticControlNeedsResetting = aBool; };
	void				setInitialLambda(NSFloat aFloat);
	void				setLearning(BOOL aBool) { m_bLearning = aBool; };
	void				setLearningType(NLearningType aType);
	void				setInputData(NSFloat **aMatrix, int anInt) { m_fpInputData = aMatrix; m_nInputExemplars = anInt; };
	void				setMaxEpochsWOImprovement(int anInt) { m_nMaxEpochsWOImprovement = anInt; };
	void				setNetworkOutputs(int anInt) { m_nNetworkOutputs = anInt; };
	void				setNetworkWeights(int anInt) { m_nNetworkWeights = anInt; };
	void				setNetworkPaused(BOOL aBool) { m_bNetworkPaused = aBool; };
	void				setOptimizeInitialWeights(BOOL aBool) { m_bOptimizeInitialWeights = aBool; };
	void				setPauseForced(BOOL aBool) { m_bPauseForced = aBool; };
	void				setPhaseCounter(int anInt) { m_nPhaseCounter = anInt; };
	void				setPhaseEndedCalled(BOOL aBool) { if (learningGlobals) learningGlobals->m_bPhaseEndedCalled = aBool; };
	void				setPhases(int anInt) { m_nPhases = anInt; };
	void				setSampleCounter(int anInt) { m_nSampleCounter = anInt; };
	void				setSamples(int anInt) { m_nSamples = anInt; };
	void				setShiftCrossValidationBy(int anInt) { m_nShiftCrossValidationBy = anInt; };
	void				setTerminateWOImprovement(BOOL aBOOL) { m_bTerminateWOImprovement = aBOOL; };
	void				setWeightsRandomized(BOOL aBool) { m_bWeightsRandomized = aBool; };
	int					shiftCrossValidationBy() { return m_nShiftCrossValidationBy; };
	BOOL				terminateWOImprovement() { return m_bTerminateWOImprovement; };
	BOOL				weightsRandomized() { return m_bWeightsRandomized; };
	LISTVOIDPOINTER		*synapseList() { return &m_SynapseList; };
	LISTVOIDPOINTER		*axonList() { return &m_AxonList; };
	int					weightingOffset(int weightIndex, int outputIndex) { return *(m_weightOffsetPointer[outputIndex] + weightIndex); };
	void				updateNetworkWeights();
};

#endif

#ifndef __DynamicControl_H__
#define __DynamicControl_H__

class DynamicControl: public StaticControl
{
protected:
	BOOL			m_bFixedPointMode,
					m_bStaticMode;
public:
					DynamicControl();
	const char		*className() { return "DynamicControl"; };
	BOOL			fixedPointMode() { return m_bFixedPointMode; };
	bool			isKindOf(char *aString);
	int				samples() { return staticMode() ? 1 : m_nSamples; };
	void			setFixedPointMode(BOOL aBool) { m_bFixedPointMode = aBool; };
	void			setStaticMode(BOOL aBool) { m_bStaticMode = aBool; if (!aBool && (m_nSamples == 1)) m_nSamples = 2; };
	BOOL			staticMode() { return (m_bStaticMode || (!fixedPointMode() && (m_nSamples == 1))); };
};

#endif

#ifndef __BackStaticControl_H__
#define __BackStaticControl_H__

class BackStaticControl: public Control
{
protected:
	char			m_sGradientClassName[64];

public:
					BackStaticControl();
	const char		*className() { return "BackStaticControl"; };
	const char		*gradientClassName() { return m_sGradientClassName; };
	bool			isKindOf(char *aString);
	void			setGradientClassName(const char *aString) { strcpy(m_sGradientClassName,aString); };
	void			setLearning(BOOL aBool) { if (staticControl()) staticControl()->setBackpropLearningOn(aBool); };
};

#endif

#ifndef __BackDynamicControl_H__
#define __BackDynamicControl_H__

class BackDynamicControl: public BackStaticControl
{
public:
					BackDynamicControl();
	const char		*className() { return "BackDynamicControl"; };
	bool			isKindOf(char *aString);
};

#endif

#ifndef __DataSource_H__
#define __DataSource_H__

class DataSource: public CoreObject
{
protected:

public:
	NSFloat						m_fNextSample;
	class MultiChannelStream	*m_OwnerEngine;
	NSUInt						m_nConnectCount;

public:
								DataSource();
	void						attach() { m_nConnectCount++; };
	const char					*className() { return "DataSource"; };
	virtual void 				close();
	NSUInt						connections() { return m_nConnectCount; };
	NSUInt						dataSize();
	NSUInt						detach() { return --m_nConnectCount; };
	virtual BOOL				getReadyToRun(class MultiChannelStream* sender);
	bool						isKindOf(char *aString);
	class MultiChannelStream	*multiChannel() { return m_OwnerEngine; };
	virtual NSFloat				*nextSamplePointer() { return &m_fNextSample; };
	MultiChannelStream			*ownerEngine() { return m_OwnerEngine; };
	void						setConnections(NSUInt anInt) { m_nConnectCount = anInt; };
	void						setNextSample(NSFloat aFloat) { m_fNextSample = aFloat; };
	virtual void 				setOwnerEngine(class MultiChannelStream* sender);
};

#endif

#ifndef __FunctionSource_H__
#define __FunctionSource_H__

class FunctionSource : public DataSource
{
protected:
	NSUInt				m_nSamplesPerCycle;
	NSFloat				m_Pos,
						m_fPhaseShift,
						m_StartPos,
						m_StepSize,
						m_fAmplitude,
						m_fOffset;

public:
						FunctionSource();
	NSFloat				amplitude() {return m_fAmplitude;};
	BOOL				getReadyToRun(class MultiChannelStream* sender);
	virtual void 		incrementPosition();
	NSFloat*		 	nextSamplePointer() { incrementPosition(); return DataSource::nextSamplePointer(); };
	NSFloat				offset() { return m_fOffset; };
	NSFloat				phaseShift() { return m_fPhaseShift; };
	NSUInt				samplesPerCycle() { return m_nSamplesPerCycle; };
	void				setAmplitude(NSFloat aFloat, MultiChannelStream* sender);
	void				setOffset(NSFloat aFloat, MultiChannelStream* sender);
	void				setPhaseShift(NSFloat aFloat, MultiChannelStream* sender);
	void				setSamplesPerCycle(NSUInt anInt, MultiChannelStream* sender);
};

#endif // FunctionSource

#ifndef __DLLFunction_H__
#define __DLLFunction_H__

class DLLFunction : public FunctionSource
{
typedef NSFloat (*Function_MAP)(DLLData *, NSFloat);
protected:
	void *function;
	DLLData *instance;

public:
						DLLFunction();
	BOOL				getReadyToRun(MultiChannelStream* sender);
	NSFloat				*nextSamplePointer();
	void				setFunction(void *aVoid) { function = aVoid; };
	void				setInstance(DLLData *aDLLData) { instance = aDLLData; };
};

#endif // DLLFunction

#ifndef __SinWaveFunction_H__
#define __SinWaveFunction_H__

class SinWaveFunction : public FunctionSource
{
public:
	NSFloat*	nextSamplePointer() { setNextSample(m_fAmplitude*(NSFloat)sin(2.0*PI*m_Pos) + m_fOffset); return FunctionSource::nextSamplePointer();};
};

#endif // SinWaveFunction

#ifndef __SquareWaveFunction_H__
#define __SquareWaveFunction_H__

class SquareWaveFunction : public FunctionSource
{
public:
	NSFloat*	nextSamplePointer () { setNextSample((m_Pos < 0.5) ? (m_fAmplitude + m_fOffset) : (-m_fAmplitude + m_fOffset)); return FunctionSource::nextSamplePointer();};
};

#endif // SquareWaveFunction

#ifndef __SawToothFunction_H__
#define __SawToothFunction_H__

class SawToothFunction : public FunctionSource
{
public:
	NSFloat*	nextSamplePointer() { setNextSample(m_fAmplitude*(NSFloat)2.0*(m_Pos - (NSFloat)0.5) + m_fOffset); return FunctionSource::nextSamplePointer();};
};

#endif // SawToothFunction

#ifndef __TriangleWaveFunction_H__
#define __TriangleWaveFunction_H__

class TriangleWaveFunction : public FunctionSource
{
public:
	NSFloat*	nextSamplePointer() { setNextSample((m_Pos < 0.5) ? (m_fAmplitude*(NSFloat)4.0*(m_Pos - (NSFloat)0.25) + m_fOffset) : (m_fAmplitude*(NSFloat)4.0*(-m_Pos + (NSFloat)0.75) + m_fOffset)); return FunctionSource::nextSamplePointer();};
};

#endif // TriangleWaveFunction

#ifndef __ImpulseFunction_H__
#define __ImpulseFunction_H__

class ImpulseFunction : public FunctionSource
{
protected:
	NSUInt	m_nStepCount;

public:
	BOOL		getReadyToRun(class MultiChannelStream* sender) { BOOL returnValue = FunctionSource::getReadyToRun(sender); m_nStepCount = (NSInt)(m_Pos/m_StepSize); if (m_nStepCount == m_nSamplesPerCycle) m_nStepCount = 0; return returnValue;};
	void		incrementPosition() { FunctionSource::incrementPosition(); m_nStepCount++; if (m_nStepCount == m_nSamplesPerCycle) m_nStepCount = 0; };
	NSFloat*	nextSamplePointer() { setNextSample(m_nStepCount ? 0 : m_fAmplitude + m_fOffset); return FunctionSource::nextSamplePointer(); };
};

#endif // ImpulseFunction

#ifndef __Impulse2Function_H__
#define __Impulse2Function_H__

class Impulse2Function : public ImpulseFunction
{
public:
	NSFloat*	nextSamplePointer() { setNextSample(m_nStepCount ? ((m_nStepCount == m_nSamplesPerCycle/2) ? (-m_fAmplitude - m_fOffset) : 0) : m_fAmplitude + m_fOffset); return FunctionSource::nextSamplePointer(); };
};

#endif // Impulse2Function

#ifndef __NoiseSource_H__
#define __NoiseSource_H__

class NoiseSource : public DataSource
{
protected:
	NSFloat				m_fVariance,
						m_fMean;

public:
						NoiseSource() { m_fVariance = (NSFloat)0.0; m_fMean = (NSFloat)0.0; };
	NSFloat				mean() { return m_fMean; };
	void				setMean(NSFloat aFloat, MultiChannelStream* sender);
	void				setVariance(NSFloat aFloat, MultiChannelStream* sender);
	NSFloat				variance() { return m_fVariance; };
};

#endif // NoiseSource

#ifndef __DLLNoise_H__
#define __DLLNoise_H__

class DLLNoise : public NoiseSource
{
typedef NSFloat (*Noise_MAP)(DLLData *, NSFloat, NSFloat);
protected:
	void *function;
	DLLData *instance;

public:
	BOOL				getReadyToRun(class MultiChannelStream* sender);
	NSFloat*			nextSamplePointer() { setNextSample((*(Noise_MAP)function)(instance, m_fVariance, m_fMean)); return NoiseSource::nextSamplePointer(); };
	void				setFunction(void *aVoid) { function = aVoid; };
	void				setInstance(DLLData *aDLLData) { instance = aDLLData; };
};

#endif // DLLNoise

#ifndef __GaussianNoise_H__
#define __GaussianNoise_H__

class GaussianNoise : public NoiseSource
{
public:
	NSFloat*	nextSamplePointer() {unsigned tempRand = rand(); while ((tempRand == 0) || (tempRand == RAND_MAX)) tempRand = rand(); setNextSample((m_fVariance*(NSFloat)(sqrt(-2*log((NSFloat)tempRand/RAND_MAX))*cos(2*PI*((NSFloat)rand()/RAND_MAX))) + m_fMean)); return NoiseSource::nextSamplePointer();};
};

#endif // GaussianNoise

#ifndef __UniformNoise_H__
#define __UniformNoise_H__

class UniformNoise : public NoiseSource
{
public:
	NSFloat*	nextSamplePointer() { setNextSample(((NSFloat)sqrt(3*m_fVariance)*(NSFloat)(((NSFloat)rand()/RAND_MAX)-0.5)+m_fMean)); return NoiseSource::nextSamplePointer();};
};

#endif // UniformNoise

#ifndef __FileSource_H__
#define __FileSource_H__

class FileSource : public DataSource
{

protected:
	BOOL				m_bUseDefaultTranslator;
	char				m_sFileName[MAX_NAME_LENGTH];
	char				m_sFilePath[MAX_PATH_LENGTH];
	char				m_sFileExtension[MAX_NAME_LENGTH];
	char				m_sDataSet[MAX_NAME_LENGTH];
	char				m_sTranslatorName[MAX_NAME_LENGTH];
	char				m_sAppDirectory[MAX_PATH_LENGTH];
	char				m_sEmptyString[4];
	FILE				*m_FileStream;
	NSUInt				m_nExpandedOffset;
	BOOL				m_bUsedForNormalization;
	BOOL				m_bDirty;
	BOOL				m_bNumericWarningShown;
	char				*m_sStaticBuffer;
	char				*m_sReadBuffer;
	char				*m_sCurrentToken;
	class Translator	*m_Translator;
public:
	BYTE*				m_BlueBuffer;
	BYTE*				m_GreenBuffer;
	BYTE*				m_RedBuffer;
	UINT				m_nBitmapSize;
	class CDIB*			m_pCDIB;
	BYTE* 				m_pBitmapPtr;
#ifdef NS_GUI
	RGBQUAD*			m_pPalettePtr;
#endif
	int					m_nCurrentColor;
	UINT				m_nPixelCount;
	LONG				m_nWidthCount;
	BOOL				m_bUnreadIndex;
	BOOL				m_bIsMaster;

public:
						FileSource();
						~FileSource();
	char				*appDirectory() { return m_sAppDirectory; };
	const char			*className() { return "FileSource"; };
	void				close();
	void				checkFilePath();
	char				*currentToken() { return m_sCurrentToken; };
	char				*dataSet() { return m_sDataSet; }
	BOOL				dirty() { return m_bDirty; };
	char				*fileExtension() { return m_sFileExtension; };
	NSUInt				expandedOffset() { return m_nExpandedOffset; };
	char				*fileName() { return m_sFileName; };
	char				*filePath() { return m_sFilePath; };
	FILE				*fileStream() { return m_FileStream; };
	void				freeObject();
	BOOL				getReadyToRun(class MultiChannelStream* sender);
	bool				isKindOf(char *aString);
	BOOL				isMaster() { return m_bIsMaster; };
	NSFloat				*nextSamplePointer();
	virtual BOOL		open();
	char				*readBuffer() { return m_sReadBuffer; };
	virtual BOOL 		resetIO();
	void				setAppDirectory(char *aString) { strcpy(m_sAppDirectory, aString); };
	void				setCurrentToken(char *aBuffer) { m_sCurrentToken = aBuffer; };
	void				setDataSet(char *aString) { strcpy(m_sDataSet,aString); };
	void				setDirty(BOOL aBool) { m_bDirty = aBool; };
	void				setExpandedOffset(NSUInt anInt) { m_nExpandedOffset = anInt; };
	BOOL				setFile(char *aPath);
	void				setFileExtension(char *aString) { strcpy(m_sFileExtension,aString); };
	void				setFileName(char *aString) { strcpy(m_sFileName,aString); };
	void				setFilePath(char *aString) { strcpy(m_sFilePath,aString); };
	void				setFileStream(FILE *aFile) { m_FileStream = aFile; };
	void				setIsMaster(BOOL aBool) { m_bIsMaster = aBool; };
	void				setReadBuffer(char *aBuffer) { m_sReadBuffer = aBuffer; };
	void				setStaticBuffer(char *aBuffer) { m_sStaticBuffer = aBuffer; };
	void				setTranslator(Translator *aTranslator) { m_Translator = aTranslator; };
	void				setTranslatorName(char *aString) { strcpy(m_sTranslatorName,aString); };
	void				setUsedForNormalization(BOOL aBool) { m_bUsedForNormalization = aBool; };
	void				setUseDefaultTranslator(BOOL aBool) { m_bUseDefaultTranslator = aBool; };
	char				*staticBuffer() { return m_sStaticBuffer; };
	Translator			*translator() { return m_Translator; };
	char				*translatorName() { return m_sTranslatorName; };
	BOOL				useDefaultTranslator() { return m_bUseDefaultTranslator; };
	BOOL				usedForNormalization() { return m_bUsedForNormalization; };
};

#endif


#ifndef __ZeroFile_H__
#define __ZeroFile_H__

class ZeroFile : public FileSource
{
public:
						ZeroFile();
	NSFloat				*nextSamplePointer() { setNextSample((NSFloat)0); return DataSource::nextSamplePointer();};
	BOOL				open() { return TRUE; };
	BOOL				resetIO() { return TRUE; };
};

#endif // ZeroFile

#ifndef __FloatArraySource_H__
#define __FloatArraySource_H__

class FloatArraySource : public DataSource
{
protected:
	NSFloat				*m_fpCurrentFloat;
	NSFloat				*m_fpEndOfDataArray;
	NSFloat				*m_fpDataArray;

public:
						FloatArraySource();
	BOOL				getReadyToRun(class MultiChannelStream* sender);
	NSFloat				*nextSamplePointer() { if (m_fpCurrentFloat >= m_fpEndOfDataArray) return NULL; setNextSample(*m_fpCurrentFloat); m_fpCurrentFloat++; return DataSource::nextSamplePointer(); };
	void				setFloatData(NSFloat *aFloat, int elementCount, class MultiChannelStream* sender);
};

#endif // FloatArraySource

#ifndef __FileSourceContainer_H__
#define __FileSourceContainer_H__

class FileSourceContainer : public DataSource
{

protected:
	BOOL						m_bReadFromNormalizationDataSets,
								m_bSymbolFileDirty;
	LISTVOIDPOINTER				m_SourceObjectList;
	FileSource					*m_CurrentSource;
	LISTVOIDPOINTER::iterator	m_CurrentPos;
	FileSource					*m_MasterColumnSource;
	class ZeroFile				*m_ZeroFile;

public:
						FileSourceContainer();
	void				addFileSource(FileSource* aSource);
	const char			*className() { return "FileSourceContainer"; };
	void				cleanSymbolFile();
	int					columnSourceCount();
	void				deleteDirtyPatternFiles();
	void				dirtyAllDataSets();
	void				dirtyAllColumnDataSetsExcept(char *dataSet);
	void				dirtyDataSet(char *dataSet);
	void				dirtySymbolFile();
	BOOL				fileOutOfDateWithSource(char *aPath);
	FileSource			*fileSource(int index);
	int					fileSourceCount();
	LISTVOIDPOINTER 	*fileSourceList() { return &m_SourceObjectList; };
	FileSource			*fileSourceWithNameAndDataSet(char *aName, char *aDataSet);
	FileSource			*firstActiveFileSource();
	FileSource			*firstColumnSource(BOOL taggedAsMaster = FALSE);
	void				freeObject();
	void				generateTempDataFile(char *filePath);
	BOOL 				getReadyToRun(MultiChannelStream* sender);
	bool				isKindOf(char *aString);
	FileSource			*nextActiveFileSource();
	FileSource			*nextFileSource();
	NSFloat				*nextSamplePointer();
	FileSource			*masterColumnSource() { return m_MasterColumnSource; };
	BOOL				normalizationDataSetIsSame(char *dataSet);
	BOOL				readFromNormalizationDataSets() { return m_bReadFromNormalizationDataSets; };
	void				removeFileSource(FileSource* aSource);
	void				setCurrentSource(FileSource* aSource) { m_CurrentSource = aSource; };
	void				setMasterColumnSource(FileSource* newMasterSource);
	void				setReadFromNormalizationDataSets(BOOL aBool) { m_bReadFromNormalizationDataSets = aBool; };
	void				setSymbolFileDirty(BOOL aBool) { m_bSymbolFileDirty = aBool; };
	void				setZeroFile(ZeroFile *aFileSource) { m_ZeroFile = aFileSource; };
	int 				sourceListLength();
	BOOL				symbolFileDirty() { return m_bSymbolFileDirty; };
	BOOL				symbolFileNeedsRegenerating();
	BOOL				symbolsActive();
	void				updateMasterColumnSource();
};

#endif

#ifndef __Translator_H__
#define __Translator_H__

class Translator: public CoreObject
{
protected:
	NSUInt						m_nOffset;
	NSUInt						m_nDuration;
	NSUInt						m_nExpandedOffset;
	NSUInt						m_nExpandedDuration;
	BOOL						m_bSegment;
	NSUInt						m_nSampleCount;
 	char						m_sOpenFlags[8],
								m_sTempColumnName[MAX_LABEL_LENGTH];
	NSUInt						m_nReadBufferSize;
	class FileSource			*m_OwnerSource;

public:
	NSFloat						m_fNextSample;

public:
							Translator();
	const char				*className() { return "Translator"; };
	virtual const char*		defaultWindowTitle();
	NSUInt					duration() { return m_nDuration; };
	virtual char			*expandedColumnName(UINT i);
	virtual BOOL			fileReset(FileSource *ownerSource);
	class FileSource*		fileSource() { return m_OwnerSource; };
	char					*formatName() { return m_sName; };
	virtual void			getReadyToRun(class MultiChannelStream* sender);
	BOOL					getTokenFromString(char* source, char* dest, int index, int count);
	bool					isKindOf(char *aString);
	NSFloat					nextSample() { return m_fNextSample; };
	virtual NSFloat			*nextSamplePointer(FileSource* aSource);
	NSUInt					offset() { return m_nOffset; };
	char					*openFlags() { return m_sOpenFlags; };
	class File				*ownerFile();
	NSUInt					readBufferSize() { return m_nReadBufferSize; };
	NSUInt					sampleCount() { return m_nSampleCount; };
	BOOL					segment() { return m_bSegment; };
	void					setDuration(NSUInt anInt) { m_nDuration = anInt; };
	void					setNextSample(NSFloat aFloat) { m_fNextSample = aFloat; };
	void					setOffset(NSUInt anInt) { m_nOffset = anInt; };
	void					setOpenFlags(char *aString) { strcpy(m_sOpenFlags,aString); };
	void					setOwnerSource(FileSource *aSource) { m_OwnerSource = aSource; };
	void					setReadBufferSize(NSUInt anInt) { m_nReadBufferSize = anInt; };
	void					setSegment(BOOL aBool) { m_bSegment = aBool; };
};

#endif

#ifndef __BinaryTranslator_H__
#define __BinaryTranslator_H__

class BinaryTranslator : public Translator
{
protected:
public:
					BinaryTranslator();
	const char		*className() { return "BinaryTranslator"; };
	bool			isKindOf(char *aString);
	NSFloat*		nextSamplePointer(FileSource* aSource);
};

#endif


#ifndef __BookBinaryTranslator_H__
#define __BookBinaryTranslator_H__

class BookBinaryTranslator : public BinaryTranslator
{
protected:
public:
					BookBinaryTranslator();
	const char		*className() { return "BookBinaryTranslator"; };
	bool			isKindOf(char *aString);
	NSFloat*		nextSamplePointer(FileSource* aSource);
};

#endif

#ifndef __DLLTranslator_H__
#define __DLLTranslator_H__

class DLLTranslator : public Translator
{
typedef BOOL (*File_MAP)(DLLData *, void *, NSFloat *);
protected:
	void				*function, *resetFunction, *file;
	DLLData				*instance;
public:
					DLLTranslator();
	const char		*className() { return "DLLTranslator"; };
	BOOL 			fileReset(FileSource*);
	void 			getReadyToRun(class MultiChannelStream*);
	bool			isKindOf(char *aString);
	NSFloat			*nextSamplePointer(FileSource* aSource);
	void			setFunction(void *aVoid) { function = aVoid; };
	void			setInstance(DLLData *aDLLData) { instance = aDLLData; };
	void			setResetFunction(void *aVoid) { resetFunction = aVoid; };
};

#endif

#ifndef __BitmapTranslator_H__
#define __BitmapTranslator_H__

class BitmapTranslator : public Translator
{
protected:
public:
						BitmapTranslator();
	const char			*className() { return "BitmapTranslator"; };
	BOOL 				fileReset(class FileSource* aSource);
	bool				isKindOf(char *aString);
	virtual BYTE 		nextPixel(class FileSource* aSource);
	virtual NSFloat*	nextSamplePointer(FileSource* aSource);
	BYTE 				readPixelFromFile(class FileSource* aSource);
};

#endif

#ifndef __ColorBitmapTranslator_H__
#define __ColorBitmapTranslator_H__

class ColorBitmapTranslator : public BitmapTranslator
{
protected:
public:
					ColorBitmapTranslator();
	const char		*className() { return "ColorBitmapTranslator"; };
	bool			isKindOf(char *aString);
	BYTE			nextPixel(class FileSource* aSource);
	NSFloat*		nextSamplePointer(FileSource* aSource);
};

#endif

#ifndef __AsciiTranslator_H__
#define __AsciiTranslator_H__

class AsciiTranslator : public Translator
{
protected:
	char						m_sDelimeters[64];
	NSUInt						m_nCurrentColumn,
								m_nExpansionColsLeft;
	BOOL						m_bEOFReached,
								m_bProcessingSymbols,
								m_bReadingFirstLine;
public:
					AsciiTranslator();
	const char		*className() { return "AsciiTranslator"; };
	NSUInt			currentColumn() { return m_nCurrentColumn; };
	char			*delimeters() { return m_sDelimeters; };
	NSUInt			expansionColsLeft() { return m_nExpansionColsLeft; };
	BOOL			fileReset(FileSource *ownerSource);
	BOOL			getNextLine(char *aBuffer, NSUInt bufferSize, FILE *aStream);
	bool			isKindOf(char *aString);
	BOOL			isStringZero(char* aString);
	virtual void 	loadBuffer(class FileSource* aSource);
	BOOL 			moveToNextSample(class FileSource* aSource);
	virtual BOOL 	nextToken(class FileSource* aSource, BOOL* floatFound, char* aString, size_t bufferSize);
	NSFloat			*nextSamplePointer(FileSource* aSource);
	void			setCurrentColumn(NSUInt anInt) { m_nCurrentColumn = anInt; };
	void			setExpansionColsLeft(NSUInt anInt) { m_nExpansionColsLeft = anInt; };
};

#endif

#ifndef __ColumnTranslator_H__
#define __ColumnTranslator_H__

class ColumnTranslator : public AsciiTranslator
{
protected:
#ifdef NS_GUI
	VECTORBYTE					m_SymbolFlagArray;
	VECTORBYTE					m_IncludeFlagArray;
	VECTORBYTE					m_NumericFlagArray;
	VECTORBYTE					m_GeneticFlagArray;
	VECTORBYTE					m_ExpandedIncludeFlagArray;
	VECTORVECTORCHARPOINTER		m_SymbolPointer;
	VECTORVECTORCHARPOINTER		m_ExpansionPointer;
	VECTORCHARPOINTER			m_HeadingArray;
	VECTORCHARPOINTER			m_ExpandedHeadingArray;
	VECTORWORD					m_ExpansionColumnCountArray;
#endif
	char						m_LastFileName[MAX_NAME_LENGTH];
	char						m_LastFilePath[MAX_PATH_LENGTH];
	char						m_sSymbolReadBuffer[SYMBOL_MAX_LINE_LENGTH];
	char						m_sPermDataFilePath[MAX_PATH_LENGTH];
	char						m_sTempDataFilePath[MAX_PATH_LENGTH];
	UINT						m_nColumnCount;
	UINT						m_nSymbolColumns;
	UINT						m_nSymbolCount;
	UINT						m_nIncludeCount;
	UINT						m_nGeneticCount;
	BOOL						m_bManualGenerate,
								m_bWarnOfMissingSymbols,
								m_bRecalculateSymbols;
	long						m_CurrentFilePos;


public:
					ColumnTranslator();
					~ColumnTranslator();
#ifdef NS_GUI
	void			addGeneticFlag(BOOL aFlag) { m_GeneticFlagArray.push_back((BYTE)aFlag); };
#endif
	void			allocateChannelSwitches(int index=-1, BOOL aBool=FALSE);
	BOOL			binaryEncoding();
	BOOL			checkForDuplicateColumns();
	const char		*className() { return "ColumnTranslator"; };
#ifdef NS_GUI
	void			clearGeneticFlagArray() { m_GeneticFlagArray.clear(); };
#endif
	UINT			columnCount() { return m_nColumnCount; };
	char			*columnName(UINT i);
	int				columnWithLabel(char *aLabel);
	const char		*defaultWindowTitle();
	void 			encodeSymbol(int index, int size, char* expandString, BOOL binary);
	UINT			expandedColumnCount();
	char			*expandedColumnName(UINT i);
	UINT			expandedIncludeCount();
#ifdef NS_GUI
	BOOL		 	expandedIncludeFlag(UINT i);
	int				expansionColumnCount(UINT i);
	UINT			expansionPointerSize(UINT i);
	char			*expansionString(UINT columnIndex, UINT stringIndex);
#endif
	BOOL			fileReset(FileSource* aSource);
	BOOL			fileResetWithoutSymbols(FileSource* aSource);
	void			freeObject();
	void			generateSymbolFile();
	UINT			geneticCount() { return m_nGeneticCount; };
#ifdef NS_GUI
	BOOL			geneticFlag(UINT i);
#endif
	void			getReadyToRun(class MultiChannelStream* sender);
	BOOL			getTokenFromString(char* source, char* dest, int index, int count);
	UINT 			includeCount() { return m_nIncludeCount; };
#ifdef NS_GUI
	BOOL			includeFlag(UINT i);
#endif
	void 			insertString(char* source, char* destination);
	bool			isKindOf(char *aString);
	char 			*labelForGeneticColumn(UINT incIndex);
	char 			*labelForIncludedColumn(UINT incIndex);
	char			*labelForSymbolColumn(UINT incIndex);
	void 			loadBuffer(class FileSource* aSource);
	void			loadExpandedSymbols(BOOL readFromFile);
	BOOL			loadSymbolsFromFile(FileSource* aSource);
	void			loadTemporyDataFile(FileSource* aSource);
	NSFloat			*nextSamplePointer(FileSource* aSource);
	BOOL 			nextToken(class FileSource* aSource, BOOL* floatFound, char* aString, size_t bufferSize);
#ifdef NS_GUI
	BOOL			numericFlag(UINT i);
#endif
	void			processSymbols(FileSource* aSource, BOOL readFromFile);
	BOOL			saveSymbolsToFile(FileSource* aSource);
	void			setColumnCount(UINT anInt) { m_nColumnCount = anInt; };
	void			setColumnName(UINT anInt, char* aString);
	void			setExpandedColumnName(UINT anInt, char* aString);
#ifdef NS_GUI
	void			setExpandedIncludeFlag(UINT anInt, BOOL aBool) { if (m_ExpandedIncludeFlagArray.size() <= anInt) m_ExpandedIncludeFlagArray.resize(anInt+1, FALSE); m_ExpandedIncludeFlagArray[anInt] = (BYTE)aBool; };
#endif
	void			setExpansionString(UINT columnIndex, UINT stringIndex, char *sourceString);
	void			setExpansionColumnCount(UINT columnIndex, int anInt);
#ifdef NS_GUI
	void			setExpansionStringArray(UINT columnIndex, VECTORCHARPOINTER *aStringArray) { if (m_ExpansionPointer.size() <= columnIndex) m_ExpansionPointer.resize(columnIndex+1, NULL); m_ExpansionPointer[columnIndex] = aStringArray; };
#endif
	void			setGeneticCount(UINT anInt) { m_nGeneticCount = anInt; };
	void 			setGeneticFlag(int i, BOOL aBool, BOOL slave=FALSE);
	BOOL			setGeneticFlagForColumnWithLabel(char *aLabel);
	void			setIncludeCount(UINT anInt) { m_nIncludeCount = anInt; };
	void 			setIncludeFlag(int i, BOOL aBool, BOOL slave=FALSE);
	void			setIncludeFlagDirect(int i, BOOL aBool);
	BOOL			setIncludeFlagForColumnWithLabel(char *aLabel);
#ifdef NS_GUI
	void			setNumericFlag(int i, BOOL aBool) { if (m_NumericFlagArray.size() <= i) m_NumericFlagArray.resize(i+1, FALSE); m_NumericFlagArray[i] = (BYTE)aBool; };
#endif
	void			setSymbolColumns(UINT anInt) { m_nSymbolColumns = anInt; };
	void			setSymbolCount(UINT anInt) { m_nSymbolCount = anInt; };
	void 			setSymbolFlag(int i, BOOL aBool);
	void			setSymbolFlagDirect(int i, BOOL aBool);
	BOOL			setSymbolFlagForColumnWithLabel(char *aLabel);
	void			setSymbolString(UINT columnIndex, UINT stringIndex, char *sourceString);
#ifdef NS_GUI
	void			setSymbolStringArray(UINT columnIndex, VECTORCHARPOINTER *aStringArray) { if (m_SymbolPointer.size() <= columnIndex) m_SymbolPointer.resize(columnIndex+1, NULL); m_SymbolPointer[columnIndex] = aStringArray; };
#endif
	UINT			symbolColumns() { return m_nSymbolColumns; };
	UINT			symbolCount() { return m_nSymbolCount; };
	void			symbolFileLine(UINT column, int index, BOOL isLabelLine, char *returnValue);
	char			*symbolFileName();
	char			*symbolFilePath();
#ifdef NS_GUI
	BOOL			symbolFlag(UINT i);
	UINT			symbolPointerSize(UINT i);
	char			*symbolString(UINT columnIndex, UINT stringIndex);
#endif
	void			toggleIncludeFlag(int i);
	void			unloadTemporaryDataFile(FileSource* aSource);
	void			updateExpandedArrays();
	BOOL 			writeSymbolFile();
};

#endif


// Access

#ifndef __Access_H__
#define __Access_H__

class Access : public Engine
{
protected:
	int				m_nDataLength,
					m_nDataWidth;

public:
					Access();
	int				dataLength() { return m_nDataLength; };
	int				dataWidth() { return m_nDataWidth; };
	bool			isKindOf(char *aString);
	void			setDataLength(int anInt) { m_nDataLength = anInt; };
	void			setDataWidth(int anInt) { m_nDataWidth = anInt; };
};

#endif

// Probe

#ifndef __Probe_H__
#define __Probe_H__

class Probe : public Access
{
protected:

public:
					Probe();
		const char	*className() { return "Probe"; };
};

#endif

// Transmitter

#ifndef __TransmitterGUI_H__
#define __TransmitterGUI_H__

class TransmitterGUI : public Access
{
protected:

public:
					TransmitterGUI();
	const char		*className() { return "Transmitter"; };
};

#endif	// __TransmitterGUI_H__

// Scheduler

#ifndef __SchedulerGUI_H__
#define __SchedulerGUI_H__

class SchedulerGUI : public Access
{
protected:

public:
					SchedulerGUI();
	const char		*className() { return "Scheduler"; };
};

#endif	//__SchedulerGUI_H__

#ifndef __DLLInputGUI_H__
#define __DLLInputGUI_H__

class DLLInputGUI : public Access
{
// Attributes
protected:

// Operations
public:
					DLLInputGUI();
		const char	*className() { return "DLLInput"; };
};

#endif // __DLLInputGUI_H__

// StreamInput

#ifndef __StreamInput_H__
#define __StreamInput_H__

class StreamInput : public Access
{
protected:
	NSUInt			m_nDataCount,
					m_nSamples,
					m_nDataSize,
					m_nExemplarCounter;
	FILE			*m_NetworkStream;
	NSFloat			*m_DataBuffer,
					m_fDither;
	int				m_nDitherInputIndex,
					m_nGeneticSwitchedOn,
					m_nChannelsSwitchedOff,
					m_nTotalChannels,
					m_nXValSamples,
					m_nTrainingSamples,
					m_nTrainAndXValSamples;
	char			m_sNetworkStreamPath[MAX_PATH_LENGTH],
					m_sLastSaveName[MAX_NAME_LENGTH],
					m_sTempDocName[MAX_NAME_LENGTH],
					m_sDefaultBaseName[MAX_NAME_LENGTH],
					m_sPatternFilePath[MAX_PATH_LENGTH],
					m_sFutureBreadboardPath[MAX_PATH_LENGTH],
					m_sCurrentBreadboardPath[MAX_PATH_LENGTH],
					m_sCurrentBreadboardTitle[MAX_NAME_LENGTH],
					m_sTempDirectory[MAX_PATH_LENGTH],
					m_sDataDirectory[MAX_PATH_LENGTH],
					m_sGeneratedFileDirectory[MAX_PATH_LENGTH];
	char			*m_spCurrentStreamPath;
	BOOL			m_bUnarchivingInProgress,
					m_bStreamOn,
					m_bStreamConstant,
					m_bFixStream,
					m_bStreamValid,
					m_bStreamFixed,
					m_bRegenerateData,
					m_bStreamToAdvance,
					m_bInject,
					m_bSendOutputToInput,
					m_bDisableInvalidate,
					m_bFileErrorsActive,
					m_bStreamEnabled,
					m_bSamplesRevertNeeded,
					m_bChannelZeroForced,
					m_bFileTranslatedButBBNotSaved,
					*m_bpChannelSwitch,
					*m_bpGeneticSwitch;
	long			m_CurrentFilePosition,
					m_nCurrentTrainingOffset,
					m_nCurrentXValOffset;
	void			(StreamInput::*m_pStreamInputBinarySetFunction[1])(BOOL aBool, int arrayIndex);
	BOOL			(StreamInput::*m_pStreamInputBinaryGetFunction[1])(int arrayIndex);
	class Axon		*m_pAttachedAxon;

public:
					StreamInput();
					~StreamInput();
	virtual void	accessDataAt(NSFloat* aDataBuffer);
	void			advanceStream();
	void			allocateChannelSwitches(int channelCount, int index, BOOL aBool);
	virtual void	assignPatternFilePath(BOOL newDataSet);
	char			*breadboardPath() { return (strlen(futureBreadboardPath()) == 0) ? m_sCurrentBreadboardPath : futureBreadboardPath(); };
	char			*currentBreadboardTitle() { return m_sCurrentBreadboardTitle; };
	virtual void	calculateDataSize();
	BOOL			callBinaryGetFunction(int paramIndex, int arrayIndex);
	void			callBinarySetFunction(int paramIndex, BOOL aBool, int arrayIndex);
	virtual void	close();
	void			closeAndDeleteNetworkStream();
	BOOL			channelSwitch(int i) { if ((i>=0) && (i<totalChannels())) return *(m_bpChannelSwitch+i); return FALSE; };
	BOOL			channelSwitchFromGenetic(int i);
	BOOL			*channelSwitchPointer() { return m_bpChannelSwitch; };
	int				channelsSwitchedOff() { return m_nChannelsSwitchedOff; };
	long			currentFilePosition() { return m_CurrentFilePosition; };
	long			*currentFilePositionPointer() { return &m_CurrentFilePosition; };
	char			*currentStreamPath() { return m_spCurrentStreamPath; };
	NSFloat			*dataBuffer() { return m_DataBuffer; };
	NSUInt			dataCount() { return m_nDataCount; };
	char			*dataDirectory() { return m_sDataDirectory; };
	NSUInt			dataSize() { return m_nDataSize; };
	char			*defaultBaseName(char *dataSet);
	BOOL			disableInvalidate() { return m_bDisableInvalidate; };
	NSFloat			dither() { return m_fDither; };
	int				ditherInputIndex() { return m_nDitherInputIndex; };
	NSUInt			exemplarCounter() { return m_nExemplarCounter; };
	BOOL			fileErrorsActive() { return m_bFileErrorsActive; };
	BOOL			fileTranslatedButBBNotSaved() { return m_bFileTranslatedButBBNotSaved; };
	void			fireIsReady(StaticControl *aControl);
	BOOL			fixStream() { return m_bFixStream; };
	void			freeObject();
	char			*futureBreadboardPath() { return m_sFutureBreadboardPath; };
	char 			*generatedFileDirectory();
	int				geneticParameterCount();
	int				geneticParameterStartingIndex();
	int				geneticSwitchedOn() { return m_nGeneticSwitchedOn; };
	BOOL			geneticSwitch(int i) { if ((i>=0) && (i<totalChannels())) return *(m_bpGeneticSwitch+i); return FALSE; };
	BOOL			*geneticSwitchPointer() { return m_bpGeneticSwitch; };
	BOOL			inject() { return m_bInject; };
	void			invalidateStream();
	int				initializeGeneticParameters();
	bool			isKindOf(char *aString);
	char			*lastSaveName() { return m_sLastSaveName; };
	virtual void	loadStream();
	FILE			*networkStream() { return m_NetworkStream; };
	char			*networkStreamPath() { return m_sNetworkStreamPath; };
	virtual BOOL 	normalizationFileReadOnly();
	void			open();
	char			*patternFilePath() { assignPatternFilePath(FALSE); return m_sPatternFilePath; };
	void			readToStream(NSFloat *data, int length);
	BOOL			regenerateData() { return m_bRegenerateData; };
	void			resetIO();
	NSUInt			samples() { return m_nSamples; };
	BOOL			samplesRevertNeeded() { return m_bSamplesRevertNeeded; };
	void			seekToCurrentPosition();
	BOOL			sendOutputToInput() { return m_bSendOutputToInput; };
	void			setAttachedAxon(Axon *anAxon) { m_pAttachedAxon = anAxon; };
	void			setChannelSwitch(BOOL aBool, int i);
	void			setChannelSwitchPointer(BOOL *aBoolPtr) { m_bpChannelSwitch = aBoolPtr; };
	void			setChannelsSwitchedOff(int anInt) { m_nChannelsSwitchedOff = anInt; };
	void			setChannelSwitchFromGenetic(BOOL aBool, int geneticIndex);
	void			setCurrentBreadboardPath(char *aString) { strcpy(m_sCurrentBreadboardPath, aString); };
	void			setCurrentBreadboardTitle(char *aString) { strcpy(m_sCurrentBreadboardTitle, aString); };
	void			setCurrentFilePosition(long anIndex) { m_CurrentFilePosition = anIndex; };
	void			setCurrentStreamPath(char *aString) { m_spCurrentStreamPath = aString; };
	void			setDataBuffer(NSFloat *aBuffer) { m_DataBuffer = aBuffer; };
	void			setDataCount(NSUInt anInt) { m_nDataCount = anInt; };
	void			setDataDirectory(char *aString) { strcpy(m_sDataDirectory, aString); };
	void			setDataSize(NSUInt anInt) { m_nDataSize = anInt; };
	void			setDither(NSFloat aFloat) { m_fDither = aFloat; };
	void			setDitherInputIndex(int anInt) { m_nDitherInputIndex = anInt; };
	void			setDisableInvalidate(BOOL aBool) { m_bDisableInvalidate = aBool; };
	void			setExemplarCounter(NSUInt anInt) { m_nExemplarCounter = anInt; };
	void			setFileErrorsActive(BOOL aBool) { m_bFileErrorsActive = aBool; };
	void			setFileTranslatedButBBNotSaved(BOOL aBool) { m_bFileTranslatedButBBNotSaved = aBool; };
	void			setFixStream(BOOL aBool);
	void			setFutureBreadboardPath(char *aString) { strcpy(m_sFutureBreadboardPath, aString); };
	void			setGeneticSwitch(BOOL aBool, int i);
	void			setGeneticSwitchPointer(BOOL *aBoolPtr) { m_bpGeneticSwitch = aBoolPtr; };
	void			setGeneticSwitchedOn(int anInt) { m_nGeneticSwitchedOn = anInt; };
	void			setInject(BOOL aBool) { m_bInject = aBool; };
	void			setLastSaveName(char *aString) { strcpy(m_sLastSaveName, aString); };
	void			setNetworkStream(FILE *aFile) { if (m_NetworkStream) fclose(m_NetworkStream); m_NetworkStream = aFile; };
	void			setNetworkStreamFast(FILE *aFile) { m_NetworkStream = aFile; };
	void			setNetworkStreamPath(char *aString) { strcpy(m_sNetworkStreamPath, aString); setCurrentStreamPath(m_sNetworkStreamPath); };
	void			setPatternFilePath(char *aString) { strcpy(m_sPatternFilePath, aString); };
	void			setPositionPointers(DWORD aPos);
	void			setRegenerateData(BOOL aBool) { m_bRegenerateData = aBool; };
	void			setSamples(NSUInt anInt) { m_nSamples = anInt; };
	void			setSendOutputToInput(BOOL aBool) { m_bSendOutputToInput = aBool; };
	void			setStreamConstant(BOOL aBool) { m_bStreamConstant = aBool; };
	void			setStreamEnabled(BOOL aBool) { m_bStreamEnabled = aBool; };
	void			setStreamFixed(BOOL aBool) { m_bStreamFixed = aBool; };
	void			setStreamToAdvance(BOOL aBool) { m_bStreamToAdvance = aBool; };
	void			setStreamOn(BOOL aBool) { m_bStreamOn = aBool; };
	void			setStreamValid(BOOL aBool) { m_bStreamValid = aBool; };
	void			setTempDirectory(char *aString) { strcpy(m_sTempDirectory,aString); };
	void			setTotalChannels(int anInt) { m_nTotalChannels = anInt; };
	void			setUnarchivingInProgress(BOOL aBool) { m_bUnarchivingInProgress = aBool; };
	BOOL			streamConstant() { return m_bStreamConstant; };
	BOOL			streamEnabled() { return m_bStreamEnabled; };
	BOOL			streamFixed() { return m_bStreamFixed; };
	BOOL			streamToAdvance() { return m_bStreamToAdvance; };
	BOOL			streamOn() { return m_bStreamOn; };
	virtual BOOL	streamValid() { return m_bStreamValid; };
	virtual BOOL	symbolFileReadOnly();
	char			*tempDirectory() { return m_sTempDirectory; };
	char			*tempDocName() { return m_sTempDocName; };
	int				totalChannels() { return m_nTotalChannels; };
	BOOL			unarchivingInProgress() { return m_bUnarchivingInProgress; };
	void			updateAxonRows(int newRows);
	BOOL			usingTempDirectory(char *aPath);
	void			validateStream();
};

#endif

// MultiChannelStream

#ifndef __MultiChannelStream_H__
#define __MultiChannelStream_H__

class MultiChannelStream : public StreamInput
{
protected:
	char					m_sTempColumnName[MAX_LABEL_LENGTH];
	NSUInt					m_nEndChannel,
							m_AllocatedChannels;
	BOOL					m_bNormalizeByChannel,
							m_bScale,
							m_bNormalize;
	NSFloat					m_fLowerBound,
							m_fUpperBound;
	NSFloat					*m_fpAmplitude;
	NSFloat					*m_fpOffset;
	LISTVOIDPOINTER			m_SourceObjectList;
	class DataSource** 		m_DataSource;
	BOOL					m_bReportWarning;
	void					*m_pResetFunction,
							*m_pGetReadyFunction;

public:
					MultiChannelStream();
					~MultiChannelStream();
	void			addDataSource(DataSource* aSource);
	void			allocateAmplitudeAndOffset();
	void			allocateDataSourceArray(NSUInt numberOfChannels);
	void			allocateNewDataSource(NSUInt numberOfChannels);
	NSFloat			*amplitudePointer() { return m_fpAmplitude; };
	void 			applyNormalizationCoefficients();
	void			calculateDataSize();
	virtual	char	*columnName(int anIndex);
	virtual void	computeStandardDeviation();
	NSUInt			endChannel() { return m_nEndChannel; };
	void			freeObject();
	void			*getReadyFunction() { return m_pGetReadyFunction; };
	bool			isKindOf(char *aString);
	void			loadStream();
	NSFloat			lowerBound() { return m_fLowerBound; };
	virtual BOOL	normFileOutOfDate();
	virtual BOOL	normalizationDataSetIsSame();
	virtual char	*normalizationFilePath();
	BOOL 			normalizationFileReadOnly();
	BOOL			normalize() { return m_bNormalize; };
	BOOL			normalizeByChannel() { return m_bNormalizeByChannel; };
	NSFloat			*offsetPointer() { return m_fpOffset; };
	void 			performNormalizeByChannel();
	void 			performNormalizeOverStream();
	virtual void 	readNormalizationCoefficients();
	void			removeDataSource(DataSource* aSource);
	void			resetAndWriteStream();
	void			*resetFunction() { return m_pResetFunction; };
	BOOL			scale() { return m_bScale; };
	virtual void 	saveNormalizationCoefficients();
	void			setAmplitude(NSFloat aFloat) { *m_fpAmplitude = aFloat; };
	void			setDataSource(NSUInt anIndex, DataSource *aDataSource) { m_DataSource[anIndex] = aDataSource; };
	void			setEndChannel(NSUInt anInt) { m_nEndChannel = anInt; };
	void			setGetReadyFunction(void *aVoid) { m_pGetReadyFunction = aVoid; };
	void			setLowerBound(NSFloat aFloat) { m_fLowerBound = aFloat; };
	void			setNormalize(BOOL aBool) { m_bNormalize = aBool; };
	void			setNormalizeByChannel(BOOL aBool) { m_bNormalizeByChannel = aBool; };
	void			setOffset(NSFloat aFloat) { *m_fpOffset = aFloat; };
	virtual void	setReadFromNormalizationDataSets(BOOL aBool);
	void			setReportWarning(BOOL aBool) { m_bReportWarning = aBool; };
	void			setResetFunction(void *aVoid) { m_pResetFunction = aVoid; };
	void			setScale(BOOL aBool) { m_bScale = aBool; };
	void			setUpperBound(NSFloat aFloat) { m_fUpperBound = aFloat; };
	NSFloat			upperBound() { return m_fUpperBound; };
	virtual void 	writeStream();
};

#endif

#ifndef __Noise_H__
#define __Noise_H__

class Noise : public MultiChannelStream
{
// Attributes
protected:

// Operations
public:
					Noise();
		const char	*className() { return "Noise"; };
};

#endif // __Noise_H__

#ifndef __Function_H__
#define __Function_H__

class Function : public MultiChannelStream
{
// Attributes
protected:

// Operations
public:
					Function();
		const char	*className() { return "Function"; };
};

#endif // __Function_H__

#ifndef __OLEInput_H__
#define __OLEInput_H__

class OLEInput : public MultiChannelStream
{
// Attributes
protected:
	char				m_sNormalizationFilePath[MAX_PATH_LENGTH];

// Operations
public:
					OLEInput();
		const char	*className() { return "OLEInput"; };
		char		*normalizationFilePath() { return m_sNormalizationFilePath; };
		void		setNormalizationFilePath(char *aString);
};

#endif // __OLEInput_H__

// File

#ifndef __File_H__
#define __File_H__

class File : public MultiChannelStream
{
public:
	char					m_sNormalizationFilePath[MAX_PATH_LENGTH];

protected:
	LISTCHARPOINTER			m_DataSetList;
	int						m_nAnnotationColumn;
	char					m_sDataSetToTranslate[MAX_NAME_LENGTH];
	char					m_sNormalizationFileName[MAX_NAME_LENGTH];
	char					m_sSymbolFilePath[MAX_PATH_LENGTH];
	char					m_sSymbolFileName[MAX_NAME_LENGTH];
	char					m_sActiveFilePath[MAX_PATH_LENGTH];
	char					m_sDataSetForActiveFile[MAX_NAME_LENGTH];
	char					m_sActiveFileName[MAX_NAME_LENGTH];
	char					m_sActiveFileExtension[MAX_NAME_LENGTH];
	char					m_sXValStreamPath[MAX_PATH_LENGTH];
	char					m_sTrainingStreamPath[MAX_PATH_LENGTH];
	char					m_sAnnotationString[MAX_LABEL_LENGTH];
	char					m_sAnnotationHeading[MAX_LABEL_LENGTH];
	BOOL					m_bNormalizationFileReadOnly,
							m_bFileSourcesChanged,
							m_bFileErrorCheck,
							m_bStandardDeviationComputed,
							m_bDynamicCrossValidationActive,
							m_bSymbolFileReadOnly,
							m_sBinaryEncodingForSymbols,
							m_bNormFileIsDummy;
	class FileSource*		m_ActiveSource;
	FILE					*m_XValStream;
	FILE					*m_TrainingStream;
	FILE					*m_TrainingAnnotationStream;
	FILE					*m_XValAnnotationStream;

public:
							File();
	void					accessDataAt(NSFloat* aDataBuffer);
	char 					*activeFileExtension() { return m_sActiveFileExtension; };
	char					*activeFileName() { return m_sActiveFileName; };
	char					*activeFilePath() { return m_sActiveFilePath; };
	FileSource*				activeSource() { return m_ActiveSource; };
	int						annotationColumn() { return m_nAnnotationColumn; };
	void					assignPatternFilePath(BOOL newDataSet);
	BOOL					binaryEncodingForSymbols();
	const char				*className() { return "File"; };
	void					close();
	char					*columnName(int anIndex);
	void					computeStandardDeviation();
	char					*dataSetForActiveFile() { return m_sDataSetForActiveFile; };
	LISTCHARPOINTER			*dataSetList() { return &m_DataSetList; };
	char					*dataSetToTranslate() { return m_sDataSetToTranslate; };
//	void					decrementDynamicOffsets(long trainDecrement, long XValDecrement);
	void					epochEnded();
	FileSourceContainer		*fileContainer() { return dataCount() ? (FileSourceContainer*)m_DataSource[0] : NULL; };
	int						fileCount();
	char					*filePathAt(int i);
	BOOL 					fileOutOfDate(char *sourcePath);
	BOOL 					fileOutOfDate(char *sourcePath, char *patternPath);
	void					fireConclude();
	void					fireIsReady(StaticControl *aControl);
	FileSource				*firstFileSource();
	void					freeObject();
	bool					isKindOf(char *aString);
	void 					loadStream();
	NSFloat					lowerBound() { return m_fLowerBound; };
	void					moveOldFile(char *oldPath, char *newPath, BOOL binary);
	BOOL					normalizationDataSetIsSame();
	char 					*normalizationFileName();
	char					*normalizationFilePath();
	BOOL 					normalizationFileReadOnly();
	BOOL					normFileOutOfDate();
	void					patternFilePathForDataSet(char *dataSet, char *returnValue);
	void 					saveNormalizationCoefficients();
	void					setActiveFileExtension(char *aString) { strcpy(m_sActiveFileExtension, aString); };
	void					setActiveFileName(char *aString) { strcpy(m_sActiveFileName, aString); };
	void					setActiveFileNameAndDataSet(char *fileName, char *dataSet);
	void					setActiveFilePath(char *aPath, char *dataSet);
	void					setAnnotationColumn(int anInt);
	void					setAnnotationHeading(char *aString) { strcpy(m_sAnnotationHeading, aString); };
	void					setAnnotationString(char *aString) { strcpy(m_sAnnotationString, aString); };
	void					setBinaryEncodingForSymbols(BOOL aBool, BOOL dirtyColumnData = TRUE);
	void					setDataSetForActiveFile(char *aString) { strcpy(m_sDataSetForActiveFile, aString); };
	void					setDataSetToTranslate(char *aString) { strcpy(m_sDataSetToTranslate, aString); };
	void					setFileErrorCheck(BOOL aBool) { m_bFileErrorCheck = aBool; };
	void					setFileSourcesChanged(BOOL aBool) { m_bFileSourcesChanged = aBool; };
	void					setNormalizationFilePath(char *aString);
	void					setNormalizationFilePathDirect(char *aString) { strcpy(m_sNormalizationFilePath, aString); };
	void					setNormalizationFileReadOnly(BOOL aBool) { m_bNormalizationFileReadOnly = aBool; };
	void					setNormalizationFileToDefault();
	void					setReadFromNormalizationDataSets(BOOL aBool);
	void					setStandardDeviationComputed(BOOL aBool) { m_bStandardDeviationComputed = aBool; };
	void					setSymbolFilePath(char *aString, BOOL dirtyColumnData = TRUE);
	void					setSymbolFilePathWithoutRevert(char *aString);
	void					setSymbolFileReadOnly(BOOL aBool, BOOL dirtyColumnData = TRUE);
	void					setSymbolFileToDefault();
	void					setTrainingStream(FILE *aFile) { m_TrainingStream = aFile; };
	void					setTrainingStreamPath(char *aString) { strcpy(m_sTrainingStreamPath, aString); };
	void					setXValStream(FILE *aFile) { m_XValStream = aFile; };
	void					setXValStreamPath(char *aString) { strcpy(m_sXValStreamPath, aString); };
	BOOL					standardDeviationComputed() { return m_bStandardDeviationComputed; };
	char					*symbolFileName();
	char					*symbolFilePath();
	BOOL					symbolFileReadOnly();
	FILE					*trainingStream() { return m_TrainingStream; };
	char					*trainingStreamPath() { return m_sTrainingStreamPath; };
	void					verifyActiveFile();
	void					writeDummyNormFile(char *normFilePath);
 	void 					writeStream();
	FILE					*xValStream() { return m_XValStream; };
	char					*xValStreamPath() { return m_sXValStreamPath; };
};

#endif

// SpatialAccess

#ifndef __SpatialAccess_H__
#define __SpatialAccess_H__


class SpatialAccess: public Engine
{
protected:
        SpatialAccess *stackedAccess;
        BOOL m_bTesting, m_bAccessTesting;
public:
		static BOOL	m_bRefreshAccess;
        NSFloat *data;
        int rowCount, colCount, spatialCount;
        SpatialAccess();
        BOOL accessTesting() { return m_bAccessTesting; };
        void attachTo(SpatialAccess *);
        int cols() { return colCount; };
        virtual void reportSpatialAccess();
        virtual void reportSpatialAccess(NSFloat *);
        virtual void reportSpatialData();
        int S() { return spatialCount; };
        NSFloat &S(int i) { return *(data + i); };
        NSFloat &S(int i, int j) { return *(data + j + i*cols()); };
        int rows() { return rowCount; };
        void setAccessTesting(BOOL aBOOL) { m_bAccessTesting = aBOOL; };
        virtual void setData(NSFloat *, int, int=1);
        virtual void setStackedAccess(SpatialAccess *);
        void setTesting(BOOL aFlag) { m_bTesting = aFlag; };
        BOOL testing() { return m_bTesting; };
        virtual ~SpatialAccess();
};

#endif // __SpatialAccess_H__

// Author: Wesley Curtis Lefebvre

#ifndef __SpatialData_H__
#define __SpatialData_H__


class SpatialData: public SpatialAccess
{
protected:
        NSFloat         *allocatedData,
                        randomRange;
public:
		BOOL			m_bAccessEnabled;

public:
        SpatialData();
        void assignScalar(NSFloat);
		const char *className() { return "SpatialData"; };
        void copyDataFrom(NSFloat *);
        void copyDataFromDouble(NSFloat *);
        void copyDataTo(NSFloat *);
        virtual void deleteData();
        virtual void oversizeSpatialDimension(int);
        void randomize();
        virtual void setSpatialDimension(int, int=1);
        void zero();
        ~SpatialData();
};

#endif // __SpatialData_H__

#ifndef __InputSpatialData_h__
#define __InputSpatialData_h__

enum MODE       {ASCII = 0, BINARY, STANDARD };
enum RW         {WRITE = 0, READ };

class InputSpatialData: public SpatialData
{
protected:
        BOOL    m_bPerformNormalization;
        int     m_iAllocatedChannels;
		NSFloat	*m_fDenormalizedData;
        RW      m_readWrite;
public:
        NSFloat   *m_fAmplitude,
				*m_fOffset;
public:
                InputSpatialData();
                ~InputSpatialData();
//        NSFloat &amplitude(int i) { return *(m_fAmplitude+i); };
		void	denormalizeData();
		void	loadWeights(FILE *file, unsigned short int version);
		void	normalizeData();
//        NSFloat &offset(int i) { return *(m_fOffset+i); };
		void	saveWeights(FILE *file);
		void	setPerformNormalization(BOOL aBool) { m_bPerformNormalization = aBool; };
		void	setSpatialDimension(int rowInt, int colInt);
};

#endif // __InputSpatialData_h__

// File.h
// by David Scott Samson

#ifndef __DataFile_h__
#define __DataFile_h__


class DataFile: public InputSpatialData
{
protected:
        FILE    *m_pFileStream;
        char    m_sFilePath[1024];
        MODE    m_iMode;
        BOOL    m_AdvanceStream,
                m_StreamConstant,
                m_FixStream;
        int     m_iDitherInput;
        NSFloat   m_fDither;
public:
                DataFile();
                DataFile(char *, RW=READ, MODE=BINARY);
                ~DataFile();
        void    advanceStream();
        BOOL    closeFile();
        void    ditherInput(int, NSFloat aFloat=0.1);
        char    *filePath(){return m_sFilePath;};
        void    fixStream(BOOL);
        int     mode() {return m_iMode;};
        BOOL    openFile();
        void    reportSpatialData();
        void    setMode(RW, MODE);
        void    setFilePath(char *);
};

#endif // __DataFile_h__

#ifndef __DLLInput_H__
#define __DLLInput_H__


typedef DLLData *(*DLLInput_Constructor)(DLLData *, int, int);
typedef DLLData *(*DLLInput_Constructor_CSW)(DLLData *, int, int, void *);
typedef void (*DLLInput_MAP)(DLLData *, NSFloat *, int, int);
typedef void (*DLLInput_MAP_CSW)(DLLData *, NSFloat *, int, int, void *);

class DLLInput : public InputSpatialData
{
protected:
        DLLStruct                       *dllStruct;
		void							*m_pCallingObject;
public:
                                                DLLInput();
        void                            reportSpatialData();
        virtual void            constructDLL();
        virtual void            destroyDLL(DLLData *);
        virtual void            initializeDLL();
        void                            setData(NSFloat *, int, int);
        void                            setDLL(void *function, void *constructor=NULL, void *destructor=NULL, void *instance=NULL, void *callingObject=NULL);
        void                            setSpatialDimension(int, int);
};

#endif __DLLInput_H__

#ifndef __DLLPreprocessor_H__
#define __DLLPreprocessor_H__


typedef DLLData *(*DLLPreprocessor_Constructor)(DLLData *, int*, int*, BOOL);
typedef DLLData *(*DLLPreprocessor_Constructor_CSW)(DLLData *, int*, int*, BOOL, void *);
typedef BOOL (*DLLPreprocessor_MAP)(DLLData *, NSFloat *, NSFloat *, int, int, BOOL);
typedef BOOL (*DLLPreprocessor_MAP_CSW)(DLLData *, NSFloat *, NSFloat *, int, int, BOOL, void *);

class DLLPreprocessor : public DLLInput
{
protected:
        class   SpatialData     *m_pData;
                BOOL            m_bInputDataLocal;
public:
                                DLLPreprocessor();
                                ~DLLPreprocessor();
        void                    constructDLL();
        virtual BOOL            isPreprocessor();
        void                    reportSpatialData();
        void                    setInputData(SpatialData *);
};

#endif __DLLPreprocessor_H__

#ifndef __DLLPostprocessor_H__
#define __DLLPostprocessor_H__


class DLLPostprocessor : public DLLPreprocessor
{
public:
                                                DLLPostprocessor();
        BOOL                            isPreprocessor();
        void                            reportSpatialData();
};

#endif __DLLPostprocessor_H__

// Author: Wesley Curtis Lefebvre

#ifndef __Soma_H__
#define __Soma_H__


class Soma: public Engine {
        friend class Axon;
        friend class Synapse;
        friend class BackAxon;
        friend class BackSynapse;
        int cells;
protected:
        NSFloat *cell, *t, *T, *link, *bufPosition;
        int inputCells, outputCells, links, dllLinks, m_nNetworkOutputs, m_nSensitivityVectorOffset, m_nFiringSequence;
        NSFloat m_fWeightVariance, m_fWeightMean;
        int somaTemporalDimension;
        BOOL m_bWeightsFixed, m_bFreeCell, m_bWeightsLocallyAllocated, m_bIsAnOutputAxon;
		void *m_pCallingObject;
		Soma *m_pAttachedSoma;
		LISTVOIDPOINTER	m_BackCriterionList;

public:
        Soma *Next;
        SpatialAccess *activityAccess, *linkAccess, *dllLinkAccess;
        DLLStruct *dllStruct;
        Soma();
        virtual ~Soma(void);
		void checkGeneticFloatArray();
		const char *className() { return "Soma"; };
		void determineFiringSequence(int sequenceNumber);
        virtual void epochEnded();
		void freeObject();
		virtual void preFireGetReady();
        virtual void loadWeights(FILE *, unsigned short int version=100);
        virtual void loadStateVariables(FILE *file, unsigned short int version);
		virtual void retryConnections();
		virtual void saveWeights(FILE *, BOOL addLineFeed=TRUE);
        virtual void saveStateVariables(FILE *file);
        // DLL Stuff
        virtual const char *dllFunctionName();
        virtual void constructDLL(void);
        virtual void destroyDLL(DLLData *);
        virtual void initializeDLL(void);
        virtual void setDLLFunction(DLLStruct *);
        virtual void setDLL(void *function, void *constructor=NULL, void *destructor=NULL, void *instance=NULL, void *callingObject=NULL);
        //
        NSFloat weightMean(void) { return m_fWeightMean;} ;
        NSFloat weightVariance(void) { return m_fWeightVariance;} ;
        BOOL weightsFixed(void) { return m_bWeightsFixed;} ;
        void setWeightMean(NSFloat);
        void setWeightVariance(NSFloat);
        void setWeightsFixed(BOOL aBOOL) { m_bWeightsFixed = aBOOL; };
		void setSensitivityVectorOffset(int anInt) { m_nSensitivityVectorOffset = anInt; };
        virtual void rangeLinks(void);
        virtual void zeroState(void) {};
        virtual void networkReset(void);
        virtual BOOL isAnAxon(void) { return FALSE; };
        virtual BOOL isASynapse(void) { return FALSE; };
        virtual void storeBufPosition(void);
        virtual void recallBufPosition(void);
        virtual void allocateLinks(int _links, BOOL force=FALSE);
        void assignLinks(NSFloat *newLink, BOOL freeLater=TRUE);
        void attachTo(Soma *aSoma, int delay);
        void decrement(void) { if ((t -= cells) < cell) t = T - cells; };
        virtual void decrementTime(void);
        void deleteLinks(void);
        virtual void fire(void);
        virtual void fireDummy(void);
		BOOL firingSequence() { return m_nFiringSequence; };
        void increment(void) { if ((t += cells) >= T) t = cell; };
        virtual void incrementTime(void);
		BOOL isAnOutputAxon() { return m_bIsAnOutputAxon; };
        virtual void networkJog(void);
		int networkOutputs() { return m_nNetworkOutputs; };
        virtual void networkRandomize(void);
        virtual void activityAltered(void);
        virtual void linksAltered(void);
		void incrementNetworkOutputs(int anInt, class BackCriteriaControl *aBackCrit, class Soma *aSoma);
        virtual void setInputCells(int numberOfCells);
        void setActivityAccess(SpatialAccess *);
        void setLinkAccess(SpatialAccess *);
        void setDLLLinkAccess(SpatialAccess *);
        virtual void removeLast(Soma *) {};
        virtual void removeNext(Soma *, BOOL removeDelayedConnections=TRUE) {};
		void setIsAnOutputAxon(BOOL aBool) { m_bIsAnOutputAxon = aBool; };
        virtual void setLast(Soma *) {};
		virtual void setNetworkOutputs(int anInt);
        virtual void setNext(Soma *) {};
        virtual void setOutputCells(int numberOfCells);
        virtual void setTemporalDimension(int T);
        int temporalDimension(void) { return somaTemporalDimension; };
        int U(void) {return inputCells;};
        int V(void) {return outputCells;};
        NSFloat &V(int i) {return *(t+i);};
        NSFloat &w(int i) {/*ASSERT(!link || (i<W()));*/ return *(link+i);};
        int w(void) {return links;};
        int W(void) {return links+dllLinks;};
		BOOL weightsLocallyAllocated() { return m_bWeightsLocallyAllocated; };
		NSFloat *weightVector() { return link; };
};

#endif // __Soma_H__

// Author: Wesley Curtis Lefebvre
// Name:        Axon.h

#ifndef __Axon_H__
#define __Axon_H__


typedef void (*Axon_MAP)(DLLData *, NSFloat *, int, int);
typedef void (*Axon_MAP_CSW)(DLLData *, NSFloat *, int, int, void *);
typedef DLLData *(*Axon_Constructor)(DLLData *, int, int);
typedef DLLData *(*Axon_Constructor_CSW)(DLLData *, int, int, void *);

class Axon: public Soma {
protected:
        int m_iRows, m_iCols;
        int dummyFiredCounter, firedCounter, lastCount, m_iInputNeurons;
        Soma *forcedLast;
        BOOL m_bFireNext, m_bFireNextOnReset, m_bFirePending, m_bInitialized;
		NSFloat *m_pIPInputBuffer;
public:
		int nextCount;
		int nextCountIncludeDelayed;
		Soma *nextConnection[128];
		Soma *nextConnectionIncludeDelayed[128];
		BOOL m_bAutoAdjustPEs;
public:
        SpatialAccess *preActivityAccess;
        Axon();
        void activityAltered(void);
        virtual void assignCenters() {};
        virtual void assignVariance() {};
		virtual Activation_Function_Type activationFunctionType() { return othertype; };
        void loadWeights(FILE *, unsigned short int version=100);
        void saveWeights(FILE *, BOOL addLineFeed=TRUE);
		const char *className() { return "Axon"; };
        virtual NSFloat beta() { return 1.0; };
        int cols() { return m_iCols; };
        void constructDLL(void);
        void fire(void);
        void fireDummy(void);
        const char *dllFunctionName();
		void preFireGetReady();
        virtual void fireDLL(void);
        virtual void fireFeed(void);
        virtual void fireMap(void);
        BOOL fireNext(void) { return m_bFireNext; };
        BOOL fireNextOnReset(void) { return m_bFireNextOnReset; };
		void freeObject();
        void incrementTime(void);
        virtual void initialize(void);
        BOOL isAnAxon(void) { return TRUE; };
		bool isKindOf(char *aString);
		virtual void networkReset();
        void removeForcedLast(Soma *) { forcedLast=NULL; };
        void removeLast(Soma *aSoma);
        void removeNext(Soma *aSoma, BOOL removeDelayedConnections=TRUE);
        int rows() { return m_iRows; };
        virtual void setBeta(NSFloat aFloat) { };
        virtual void setBetaData(SpatialData *) {};
        void setCols(int);
        void setDLLFunction(DLLStruct *);
        void setFireNext(BOOL aBOOL) { m_bFireNext = aBOOL; };
        void setFireNextOnReset(BOOL aBOOL) { m_bFireNextOnReset = aBOOL; };
        void setForcedLast(Soma *aSoma) { forcedLast=aSoma; };
        virtual void setFullSynapse(class FullSynapse *anId) { };
        void setInputCells(int numberOfCells);
		void setIPInputBuffer(NSFloat *aBuffer) { m_pIPInputBuffer = aBuffer; };
        void setLast(Soma *aSoma);
        virtual void setMaxWinner(BOOL aBOOL) { };
        virtual void setMemoryTaps(int anInt) { };
        virtual void setMetric(int anInt) { };
		virtual	void setMFCount(int anInt) { };
		virtual	void setMFOutputAccess(SpatialAccess *aNSAccess) {};
        virtual void setNeighbors(int) {};
        void setNext(Soma *nextSoma);
		virtual void setNormalize(BOOL aBool) { };
//        void setOutputCells(int numberOfCells);
        void setPreActivityAccess(SpatialAccess *);
        void setRows(int);
 		virtual void setSlackEnabled(BOOL aBool) {};
		virtual void setSlackConstant(NSFloat aFloat) {};
        void setTemporalDimension(int T);
        virtual void setTapDelay(int anInt) {};
        virtual void setTaps(int anInt) {};
		virtual void setWinningPEAccess(SpatialAccess *anId) {};
        virtual int taps(void) { return 0; };
//      NSFloat &V(int i, int j) { return V(j + i*m_iCols); };
		virtual void updateInputsAndOutputs();
        ~Axon(void);
};

#endif // __Axon_H__
/*
#ifndef __ExpanderAxon_H__
#define __ExpanderAxon_H__

class ExpanderAxon: public Axon {
protected:
			int			m_nExpansionFactor;
public:
						ExpanderAxon();
			int			expansionFactor() { return m_nExpansionFactor; };
			void		fireMap(void);
			void		setInputCells(int anInt);
			void		setExpansionFactor(int anInt) { if (m_nExpansionFactor != anInt) {m_nExpansionFactor = anInt; initialize();} };
};

#endif // __ExpanderAxon_H__
*/

#ifndef __FuzzyAxon_H__
#define __FuzzyAxon_H__

typedef void (*FuzzyAxon_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *);
typedef void (*FuzzyAxon_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, void *);
typedef DLLData *(*FuzzyAxon_Constructor)(DLLData *, int, int, int *);
typedef DLLData *(*FuzzyAxon_Constructor_CSW)(DLLData *, int, int, int *, void *);

class FuzzyAxon: public Axon {
public:
			int			m_nMFCount;
protected:
			int				*m_WinningMF;
			NSFloat			*m_WinningInput;
			NSFloat			*m_MFOutput;
			SpatialAccess   *MFOutputAccess;
public:
			BOOL			m_bOldFuzzyFormat;
public:
						FuzzyAxon();
						~FuzzyAxon();
			void		activityAltered(void);
	virtual NSFloat		applyMF(int paramIndex, NSFloat x) = 0;
			const char	*className() { return "FuzzyAxon"; };
			void		constructDLL(void);
			const char	*dllFunctionName();
			void		fireDLL(void);
			void		fireMap(void);
			NSFloat		firingStrength(int index, BOOL callDLL = FALSE);
 			void		freeObject();
			void		initialize();
			int			MFMapping(int inputIndex, int outputIndex); //Comment for Single Connection
			int			MFCount() { return m_nMFCount; };
	virtual int			MFParameters() = 0;
			void		setInputCells(int anInt);
			void		setMFCount(int anInt) { if (m_nMFCount != anInt) {m_nMFCount = anInt; initialize();} };
			void		setMFOutputAccess(SpatialAccess *aNSAccess);
			void		setOldFuzzyFormat(BOOL aBool) { m_bOldFuzzyFormat = aBool; };
			NSFloat		winningInput(int i) { return *(m_WinningInput + i); };
			int			winningMF(int i) { return *(m_WinningMF + i); };
};

#endif // __FuzzyAxon_H__

#ifndef __BellFuzzyAxon_H__
#define __BellFuzzyAxon_H__

class BellFuzzyAxon: public FuzzyAxon {

public:
			NSFloat		applyMF(int paramIndex, NSFloat x);
			const char	*className() { return "BellFuzzyAxon"; };
			int			MFParameters() { return 3; };
			void		networkRandomize();
};

#endif // __BellFuzzyAxon_H__

#ifndef __GaussianFuzzyAxon_H__
#define __GaussianFuzzyAxon_H__

class GaussianFuzzyAxon: public FuzzyAxon {

public:
			NSFloat		applyMF(int paramIndex, NSFloat x);
			const char	*className() { return "GaussianFuzzyAxon"; };
			int			MFParameters() { return 2; };
			void		networkRandomize();
};

#endif // __GaussianFuzzyAxon_H__

#ifndef __CombinerAxon_H__
#define __CombinerAxon_H__

class CombinerAxon: public Axon {
public:
						CombinerAxon();
			void		activityAltered(void);
			const char	*className() { return "CombinerAxon"; };
			void		fireMap(void);
			void		setInputCells(int anInt);
};

#endif // __CombinerAxon_H__


//NormalizedAxon

#ifndef __NormalizedAxon_H__
#define __NormalizedAxon_H__

class NormalizedAxon: public Axon {
private:
	NSFloat		*m_WeightingFactorArray;
	int			m_nWeightingFactorArraySize;

public:
				NormalizedAxon() { m_nWeightingFactorArraySize = 0; m_WeightingFactorArray = NULL; };
				~NormalizedAxon() { 	if (m_WeightingFactorArray) free(m_WeightingFactorArray); };
	const char	*className() { return "NormalizedAxon"; };
	void		fireMap(void);
	NSFloat		*weightingFactorArray() { return m_WeightingFactorArray; };
};

#endif // __NormalizedAxon_H__


// Author: Wesley Curtis Lefebvre

#ifndef __BiasAxon_H__
#define __BiasAxon_H__


typedef void (*BiasAxon_MAP)(DLLData *, NSFloat *, int, int, NSFloat *);
typedef void (*BiasAxon_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, void *);

class BiasAxon: public Axon {
protected:
        void fireInline(register NSFloat &f, register NSFloat &fw) { f += fw; };
public:
		Activation_Function_Type activationFunctionType() { return bias; };
		const char	*className() { return "BiasAxon"; };
        const char *dllFunctionName();
        void fireDLL(void);
        void fireMap(void);
        void initialize(void);
};

#endif // __BiasAxon_H__


// Author: Wesley Curtis Lefebvre

#ifndef __LinearAxon_H__
#define __LinearAxon_H__


typedef void (*LinearAxon_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, NSFloat);
typedef void (*LinearAxon_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, NSFloat, void *);

class LinearAxon: public BiasAxon {
protected:
        NSFloat m_fBeta;
public:
        LinearAxon();
		Activation_Function_Type activationFunctionType() { return linear; };
		NSFloat beta() { return m_fBeta; };
 		const char	*className() { return "LinearAxon"; };
        const char *dllFunctionName();
        void fireInline(register NSFloat &f, register NSFloat &fw) { f *= m_fBeta; BiasAxon::fireInline(f,fw); };
        void fireDLL(void);
        void fireMap();
        virtual void setBeta(NSFloat aFloat) { m_fBeta = aFloat; };
};

#endif // __LinearAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __SigmoidAxon_H__
#define __SigmoidAxon_H__


class SigmoidAxon: public LinearAxon {
public:
		const char	*className() { return "SigmoidAxon"; };
		Activation_Function_Type activationFunctionType() { return sigmoid; };
        void fireInline(register NSFloat &f, register NSFloat &fw) { LinearAxon::fireInline(f,fw); f = 1.0/(1.0+(NSFloat)exp(-f));};
        void fireMap(void);
};

#endif // __SigmoidAxon_H__


//NormalizedSigmoidAxon

#ifndef __NormalizedSigmoidAxon_H__
#define __NormalizedSigmoidAxon_H__

class NormalizedSigmoidAxon: public SigmoidAxon {
private:
	NSFloat		*m_WeightingFactorArray;
	int			m_nWeightingFactorArraySize;

public:
				NormalizedSigmoidAxon() { m_nWeightingFactorArraySize = 0; m_WeightingFactorArray = NULL; };
				~NormalizedSigmoidAxon() { 	if (m_WeightingFactorArray) free(m_WeightingFactorArray); };
	const char	*className() { return "NormalizedSigmoidAxon"; };
	void		fireMap(void);
	NSFloat		*weightingFactorArray() { return m_WeightingFactorArray; };
};

#endif // __NormalizedSigmoidAxon_H__


// Author: Wesley Curtis Lefebvre

#ifndef __TanhAxon_H__
#define __TanhAxon_H__


class TanhAxon: public LinearAxon {
public:
		Activation_Function_Type activationFunctionType() { return hyperbolictangent; };
		const char	*className() { return "TanhAxon"; };
        void fireInline(register NSFloat &f, register NSFloat &fw) { LinearAxon::fireInline(f,fw); f = (NSFloat)tanh(f); };
        void fireMap(void);
};

#endif // __TanhAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __LinearSigmoidAxon_H__
#define __LinearSigmoidAxon_H__


class LinearSigmoidAxon: public SigmoidAxon {
public:
		const char	*className() { return "LinearSigmoidAxon"; };
        void fireInline(register NSFloat &f, register NSFloat &fw) { BiasAxon::fireInline(f,fw); f *= m_fBeta; if (f<0.0) f=0.0; else if (f>1.0) f=1.0; };
        void fireMap(void);
};

#endif // __LinearSigmoidAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __LinearTanhAxonAxon_H__
#define __LinearTanhAxonAxon_H__


class LinearTanhAxon: public TanhAxon {
public:
		const char	*className() { return "LinearTanhAxon"; };
        void fireInline(register NSFloat &f, register NSFloat &fw) { BiasAxon::fireInline(f,fw); f *= m_fBeta; if (f<-1.0) f=-1.0; else if (f>1.0) f=1.0; };
        void fireMap(void);
};

#endif // __LinearTanhAxonAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __SoftMaxAxon_H__
#define __SoftMaxAxon_H__


class SoftMaxAxon: public LinearAxon {
public:
        SoftMaxAxon();
		const char	*className() { return "SoftMaxAxon"; };
        void fireInline(register NSFloat &f, register NSFloat &fw) { f = 1.0; };
        void fireMap(void);
};

#endif // __SoftMaxAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __WinnerTakeAllAxon_H__
#define __WinnerTakeAllAxon_H__


class WinnerTakeAllAxon: public Axon {
protected:
        BOOL	m_bMaxWinner;
        SpatialAccess	*winningPEAccess;
		NSFloat			m_fWinningPE;

public:
        WinnerTakeAllAxon();
        ~WinnerTakeAllAxon();
		const char	*className() { return "WinnerTakeAllAxon"; };
        void fireMap(void);
        BOOL maxWinner() { return m_bMaxWinner; };
        void setMaxWinner(BOOL aBOOL) { m_bMaxWinner = aBOOL; };
		void setWinningPEAccess(SpatialAccess *anId);
};

#endif // __WinnerTakeAllAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __ThresholdAxon_H__
#define __ThresholdAxon_H__


class ThresholdAxon: public BiasAxon {
public:
		const char	*className() { return "ThresholdAxon"; };
        void fireInline(register NSFloat &f, register NSFloat &fw) { BiasAxon::fireInline(f,fw); f = f>0? 1.0: -1.0; };
        void fireMap(void);
};

#endif // __ThresholdAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __GaussianAxon_H__
#define __GaussianAxon_H__


class GaussianAxon: public LinearAxon {
protected:
        class FullSynapse *m_pFullSynapse;
        int     m_iNeighbors, m_iMetric;
		NSFloat	m_fSlackConstant;
        BOOL    m_bBetaDataLocal,
				m_bNormalize,
				m_bSlackEnabled;
public:
        class SpatialData *variance;
        GaussianAxon();
        ~GaussianAxon();
        void assignCenters();
        void assignVariance();
		const char	*className() { return "GaussianAxon"; };
        void fireInline(NSFloat &f, NSFloat &fw, NSFloat &fv) { BiasAxon::fireInline(f,fw); f = (NSFloat)exp(-fv*f*f); };
        void fireMap(void);
		void freeObject();
        void initialize();
        void loadWeights(FILE *, unsigned short int version=100);
        void saveWeights(FILE *, BOOL addLineFeed=TRUE);
        int neighbors() { return m_iNeighbors; };
        int metric() { return m_iMetric; };
        void setBeta(NSFloat);
        void setBetaData(SpatialData *);
        void setMetric(int anInt) { m_iMetric = anInt; };
        void setNeighbors(int);
        void setFullSynapse(FullSynapse *anId) { m_pFullSynapse = anId; };
		void setNormalize(BOOL aBool) { m_bNormalize = aBool; };
		void setSlackEnabled(BOOL aBool) { m_bSlackEnabled = aBool; };
		void setSlackConstant(NSFloat aFloat) { m_fSlackConstant = aFloat; };
		BOOL normalize() { return m_bNormalize; };
};

#endif // __GaussianAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __TDNNAxon_H__
#define __TDNNAxon_H__


typedef void (*TDNNAxon_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, int);
typedef void (*TDNNAxon_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, int, void *);
typedef DLLData *(*TDNNAxon_Constructor)(DLLData *, int, int, int);
typedef DLLData *(*TDNNAxon_Constructor_CSW)(DLLData *, int, int, int, void *);

class TDNNAxon: public Axon {
        Soma *delayedReference;
protected:
        int memoryTaps, delay;
public:
        TDNNAxon();
        void activityAltered(void);
		const char	*className() { return "TDNNAxon"; };
		void setTemporalDimension(int T);
        void loadWeights(FILE *, unsigned short int version=100);
        void saveWeights(FILE *, BOOL addLineFeed=TRUE);
        const char *dllFunctionName();
        void fireDLL(void);
        void fireMap(void);
		void freeObject();
        void initialize(void);
        void constructDLL(void);
        void incrementTime(void);
        void decrementTime(void);
        void loadStateVariables(FILE *file, unsigned short int version);
        void saveStateVariables(FILE *file);
        void recallBufPosition(void);
        void setDelay(int anInt);
        void setInputCells(int anInt);
//        void setOutputCells(int anInt);
        void setMemoryTaps(int anInt);
        void setTapDelay(int anInt);
        void setTaps(int anInt);
        void storeBufPosition(void);
        int tapDelay(void) { return delay; };
        int taps(void) { return memoryTaps; };
        NSFloat &Vd(int i) { return delayedReference->V(i); };
        void zeroState(void);
        ~TDNNAxon(void);
};

#endif // __TDNNAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __GammaAxon_H__
#define __GammaAxon_H__


typedef void (*GammaAxon_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, int, NSFloat *);
typedef void (*GammaAxon_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, int, NSFloat *, void *);

class GammaAxon: public TDNNAxon {
public:
		const char	*className() { return "GammaAxon"; };
        const char *dllFunctionName();
        void fireDLL(void);
        void fireMap(void);
        void initialize(void);
        void networkRandomize(void);
        void rangeLinks(void);
};

#endif // __GammaAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __LaguarreAxon_H__
#define __LaguarreAxon_H__


class LaguarreAxon: public GammaAxon {
public:
		const char	*className() { return "LaguarreAxon"; };
        void initialize(void);
        void fireMap(void);
        void networkRandomize(void);
        void rangeLinks(void);
};

#endif // __LaguarreAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __ContextAxon_H__
#define __ContextAxon_H__


typedef void (*ContextAxon_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, NSFloat);
typedef void (*ContextAxon_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, NSFloat, void *);

class ContextAxon: public LinearAxon {
        Soma *delayedReference;
protected:
        int delay;
public:
        ContextAxon();
		const char	*className() { return "ContextAxon"; };
        const char *dllFunctionName();
        void fireDLL(void);
        void fireMap(void);
		void freeObject();
        void incrementTime(void);
        void decrementTime(void);
        void initialize(void);
        void rangeLinks();
        void recallBufPosition(void);
        void loadStateVariables(FILE *file, unsigned short int version);
        void saveStateVariables(FILE *file);
        void storeBufPosition(void);
        NSFloat &Vd(int i) { return delayedReference->V(i); };
        void zeroState(void);
        ~ContextAxon(void);
};

#endif // __ContextAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __SigmoidContextAxon_H__
#define __SigmoidContextAxon_H__


class SigmoidContextAxon: public ContextAxon {
public:
		const char	*className() { return "SigmoidContextAxon"; };
        void fireMap();
};

#endif // __SigmoidContextAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __TanhContextAxon_H__
#define __TanhContextAxon_H__


class TanhContextAxon: public ContextAxon {
public:
		const char	*className() { return "TanhContextAxon"; };
        void fireMap();
};

#endif // __TanhContextAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __IntegratorAxon_H__
#define __IntegratorAxon_H__


class IntegratorAxon: public ContextAxon {
public:
		const char	*className() { return "IntegratorAxon"; };
        void fireMap(void);
};

#endif // __IntegratorAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __SigmoidIntegratorAxon_H__
#define __SigmoidIntegratorAxon_H__


class SigmoidIntegratorAxon: public IntegratorAxon {
public:
		const char	*className() { return "SigmoidIntegratorAxon"; };
        void fireMap();
};

#endif // __SigmoidIntegratorAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __TanhIntegratorAxon_H__
#define __TanhIntegratorAxon_H__


class TanhIntegratorAxon: public IntegratorAxon {
public:
		const char	*className() { return "TanhIntegratorAxon"; };
        void fireMap();
};

#endif // __TanhIntegratorAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __Synapse_H__
#define __Synapse_H__


typedef void (*Synapse_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, int, int);
typedef void (*Synapse_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, void *);
typedef DLLData *(*Synapse_Constructor)(DLLData *, int, int, int, int);
typedef DLLData *(*Synapse_Constructor_CSW)(DLLData *, int, int, int, int, void *);

class Synapse: public Soma {
//      class NAccess *initializationAccess;
public:
        Axon *Last, *Feed;
        Synapse();
        ~Synapse();
       virtual void allocateSynapticLinks(void);
        void detachYourself(void);
//      void exemplarStarting(void) { initializationAccess->dataAt(&V(0)); };
        void constructDLL(void);
        const char *dllFunctionName();
        virtual void fireDLL();
        void fire(void);
        virtual void fireFeed(void);
		void freeObject();
		bool isKindOf(char *aString);
        BOOL isASynapse(void) { return TRUE; };
        void loadStateVariables(FILE *file, unsigned short int version);
		void preFireGetReady();
        void saveStateVariables(FILE *file);
        void removeLast(Soma *aSoma);
        void removeNext(Soma *aSoma, BOOL removeDelayedConnections=TRUE);
        void retryConnections();
        void setDLLFunction(DLLStruct *);
//      void setInitializationAccess(NAccess *);
//        void setInputCells(int numberOfCells) { Soma::setInputCells(U()); };
        void setLast(Soma *aSoma);
//        void setOutputCells(int numberOfCells) { Soma::setOutputCells(V()); };
        void setNext(Soma *aSoma);
        void setTemporalDimension(int T);
        void zeroState();
};

#endif __Synapse_H__

// Author: Wesley Curtis Lefebvre

#ifndef __FullSynapse_H__
#define __FullSynapse_H__


typedef void (*FullSynapse_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *);
typedef void (*FullSynapse_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, void *);

class FullSynapse: public Synapse {
public:
        NSFloat &W(int i, int j) {return w(j+i*V());};
        void allocateSynapticLinks(void);
		const char *className() { return "FullSynapse"; };
        const char *dllFunctionName();
        void linksAltered(void);
        void fireDLL();
        void fireFeed(void);
};

#endif // __FullSynapse_H__

// SVMOutputSynapse

#ifndef __SVMOutputSynapse_H__
#define __SVMOutputSynapse_H__


class SVMOutputSynapse: public FullSynapse {

protected:
	NSFloat			*m_fpDesiredMatrix;
	NSFloat			*m_fSVMBiasVector;
//	BOOL			m_bRunningFirstEpoch;

public:
					SVMOutputSynapse();
	NSFloat			biasElement(int outIndex) { return m_fSVMBiasVector ? *(m_fSVMBiasVector+outIndex) : 0.0; };
	const char		*className() { return "SVMOutputSynapse"; };
	NSFloat			desiredElement(int outIndex, int exemplar) { return m_fpDesiredMatrix ? *(m_fpDesiredMatrix+outIndex*V()+exemplar) : 0.0; };
	void			epochEnded();
	void			fireFeed(void);
	void			linksAltered(void);
	void			loadStateVariables(FILE *file, unsigned short int version);
	void			networkReset();
	void			saveStateVariables(FILE *file);
	void			setBiasElement(int outIndex, NSFloat aFloat) { if (m_fSVMBiasVector) *(m_fSVMBiasVector+outIndex) = aFloat; };
	void			setDesiredElement(int outIndex, int exemplar, NSFloat aFloat);
//	void			setRunningFirstEpoch(BOOL aBool) { m_bRunningFirstEpoch = aBool; };
//	BOOL			runningFirstEpoch() { return m_bRunningFirstEpoch; };
	void			updateSVMBiasElement(int outIndex, int exemplar, NSFloat dAlpha) { if (m_fSVMBiasVector && m_fpDesiredMatrix) *(m_fSVMBiasVector+outIndex) += *(m_fpDesiredMatrix+outIndex*V()+exemplar) * dAlpha; };
};

#endif // __SVMOutputSynapse_H__


// Author: Wesley Curtis Lefebvre

#ifndef __ArbitrarySynapse_H__
#define __ArbitrarySynapse_H__


class ArbitrarySynapse: public Synapse {
        class ConnectionList *connections;
public:
        ArbitrarySynapse();
		const char *className() { return "ArbitrarySynapse"; };
        ConnectionList *connectionList(void) { return connections;};
        const char *dllFunctionName();
        void fireFeed();
		void freeConnectionList();
        void loadWeights(FILE *, unsigned short int version=100);
        void saveWeights(FILE *, BOOL addLineFeed=TRUE);
        void useConnectionList(ConnectionList *aList) { connections = aList; };
};

#endif // __ArbitrarySynapse_H__

// Author: Wesley Curtis Lefebvre
// Name: FunctionIO.h

#ifndef __FunctionIO_h__
#define __FunctionIO_h__


typedef void (*FunctionIO_MAP)(NSFloat *, int, int);
typedef void (*FunctionIO_MAP_CSW)(NSFloat *, int, int, void *);

class FunctionIO: public InputSpatialData
{
protected:
        void    *m_pFunction;
		void	*m_pCallingObject;
public:
                        FunctionIO();
        void    reportSpatialData();
        void    setFunction(void *aFunction, void *callingObject=NULL);
		void	setMode(RW readWrite);
};

#endif // __FunctionIO_h__

// Author: Wesley Curtis Lefebvre

#ifndef __BackAxon_H__
#define __BackAxon_H__


typedef void (*BackAxon_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *);
typedef void (*BackAxon_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, void *);
typedef DLLData *(*BackAxon_Constructor)(DLLData *, DLLData *, int, int);
typedef DLLData *(*BackAxon_Constructor_CSW)(DLLData *, DLLData *, int, int, void *);

class BackAxon: public Axon {
protected:
        BOOL gradientsEnabled;
        NSFloat *m_fWeightingVector;
        int m_nWeightingVectorSize;
        int m_nCurrentExemplar;
public:
        Axon *Dual;
public:
        BackAxon();
        void activityAltered();
        void linksAltered();
        virtual void backpropComplete();
        void backpropStarting();
        void constructDLL();
        void networkRandomize();
        void setBackpropOffset(int);
        void setCurrentExemplar(int exemplar);
        virtual void setDual(Soma *);
        void setGradientsEnabled(BOOL);
		void setNetworkOutputs(int anInt);
        virtual void setOffset(NSFloat aFloat) {};
        void setWeightingVector(NSFloat *aVector, int vectorSize);
        void updateExemplarCounter();
		void updateInputsAndOutputs();
        // Overridden virtual functions
        const char *dllFunctionName();
        void fireDLL();
        void fire();
        void incrementTime();
//        void setInputCells(int) { Soma::setInputCells(U()); };
//        void setOutputCells(int) { Soma::setOutputCells(V()); };
};

#endif // __BackAxon_H__

//BackFuzzyAxon

#ifndef __BackFuzzyAxon_H__
#define __BackFuzzyAxon_H__

typedef void (*BackFuzzyAxon_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, int, int, NSFloat, NSFloat *);
typedef void (*BackFuzzyAxon_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, int, int, NSFloat, NSFloat *, void *);

class BackFuzzyAxon: public BackAxon {
public:
	// DLL Code Here
			void		activityAltered(void);
			NSFloat		computeDerivative(int weightIndex, int outputIndex, BOOL dllActive);
			const char *dllFunctionName();
	virtual	NSFloat		derivative(int weightIndex, int outputIndex) = 0;
			void		fireDLL(void);
			void		fireMap();
			void		initialize();
};

#endif // __BackFuzzyAxon_H__

//BackBellFuzzyAxon

#ifndef __BackBellFuzzyAxon_H__
#define __BackBellFuzzyAxon_H__

class BackBellFuzzyAxon: public BackFuzzyAxon {
public:
	// DLL Code Here
	NSFloat		derivative(int weightIndex, int outputIndex);
};

#endif // __BackBellFuzzyAxon_H__

//BackGaussianFuzzyAxon

#ifndef __BackGaussianFuzzyAxon_H__
#define __BackGaussianFuzzyAxon_H__

class BackGaussianFuzzyAxon: public BackFuzzyAxon {
public:
	// DLL Code Here
	NSFloat		derivative(int weightIndex, int outputIndex);
};

#endif // __BackGaussianFuzzyAxon_H__

//BackCombinerAxon

#ifndef __BackCombinerAxon_H__
#define __BackCombinerAxon_H__

class BackCombinerAxon: public BackAxon {
public:
	void		fireMap(void);
};

#endif // __BackCombinerAxon_H__


//BackNormalizedAxon

#ifndef __BackNormalizedAxon_H__
#define __BackNormalizedAxon_H__

class BackNormalizedAxon: public BackAxon {
public:
	void fireMap(void);
};

#endif // __BackNormalizedAxon_H__


// Author: Wesley Curtis Lefebvre

#ifndef __BackBiasAxon_H__
#define __BackBiasAxon_H__


typedef void (*BackBiasAxon_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *);
typedef void (*BackBiasAxon_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, void *);

class BackBiasAxon: public BackAxon {
public:
        const char *dllFunctionName();
        void fireDLL();
        void fireMap();
        void initialize();
};

#endif // __BackBiasAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackLinearAxon_H__
#define __BackLinearAxon_H__


typedef void (*BackLinearAxon_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *,NSFloat);
typedef void (*BackLinearAxon_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *,NSFloat,void *);

class BackLinearAxon: public BackBiasAxon {
protected:
        NSFloat m_fOffset;
        class LinearAxon *linearAxon() { return (LinearAxon*)Dual; };
public:
        BackLinearAxon();
        const char *dllFunctionName();
        void fireDLL();
        void fireMap();
        NSFloat offset() { return m_fOffset; };
        void setOffset(NSFloat aFloat) { m_fOffset = aFloat; };
};

#endif // __BackLinearAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackSigmoidAxon_H__
#define __BackSigmoidAxon_H__


class BackSigmoidAxon: public BackLinearAxon {
public:
        void fireMap();
};

#endif // __BackSigmoidAxon_H__

//BackNormalizedSigmoidAxon

#ifndef __BackNormalizedSigmoidAxon_H__
#define __BackNormalizedSigmoidAxon_H__

class BackNormalizedSigmoidAxon: public BackSigmoidAxon {
public:
	void fireMap(void);
};

#endif // __BackNormalizedSigmoidAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackTanhAxon_H__
#define __BackTanhAxon_H__


class BackTanhAxon: public BackLinearAxon {
public:
        void fireMap();
};

#endif // __BackTanhAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackTDNNAxon_H__
#define __BackTDNNAxon_H__


typedef void (*BackTDNNAxon_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, int, NSFloat *);
typedef void (*BackTDNNAxon_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, int, NSFloat *, void *);
typedef DLLData *(*BackTDNNAxon_Constructor)(DLLData *, DLLData *, int, int, int);
typedef DLLData *(*BackTDNNAxon_Constructor_CSW)(DLLData *, DLLData *, int, int, int, void *);

class BackTDNNAxon: public BackAxon {
        Soma *delayedReference;
protected:
        int memoryTaps;
public:
        BackTDNNAxon();
        void activityAltered(void);
		void backpropComplete();
        void constructDLL(void);
        const char *dllFunctionName();
        void fireDLL();
        void fireMap(void);
		void freeObject();
        void incrementTime(void);
        void initialize(void);
        void loadStateVariables(FILE *file, unsigned short int version);
        void saveStateVariables(FILE *file);
        void setMemoryTaps(int anInt);
        int taps(void) { return memoryTaps; };
        NSFloat &Vd(int i) { return delayedReference->V(i); };
        void zeroState(void);
        ~BackTDNNAxon(void);
};

#endif // __BackTDNNAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackGammaAxon_H__
#define __BackGammaAxon_H__


typedef void (*BackGammaAxon_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, int, NSFloat *, NSFloat *, NSFloat *);
typedef void (*BackGammaAxon_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, int, NSFloat *, NSFloat *, NSFloat *, void *);

class BackGammaAxon: public BackTDNNAxon {
public:
        const char *dllFunctionName();
        void fireDLL();
        void fireMap(void);
        void initialize(void);
};

#endif // __BackGammaAxon_H__

// Author: Wesley Curtis Lefebvre
// Name:        Connection.h

#ifndef __Connection_h__
#define __Connection_h__


class Connection {
        int fromIndex, *toIndices, toCount, toAllocated;
public:
        Connection();
        ~Connection();
        void addConnection(int index);
        void allocateConnections(int number);
        int *connections(void) { return toIndices; };
        int count(void) { return toCount; };
        void empty(void);
        int feedingIndex(void) { return fromIndex; };
        void insertConnectionAt(int toIndex, int index);
        void removeConnection(int index);
        void setIndex(int index) {fromIndex = index; };
        Connection &operator=(Connection &aConnection);
};

#endif // __Connection_h__

// Author: Wesley Curtis Lefebvre

#ifndef __ConnectionList_h__
#define __ConnectionList_h__


class ConnectionList {
        class Connection **synapse;
        int synapseCount, synapseAllocated;
public:
        ConnectionList();
        ~ConnectionList(void);
        void addConnection(int fromIndex, int toIndex);
        void allocateSynapse(int number);
        Connection *connectionAt(int index) { return synapse[index]; };
        int count(void) { return synapseCount; };
        void empty(void);
        void insertConnectionAt(int fromIndex, int toIndex, int index);
        void removeConnection(int fromIndex, int toIndex);
        int weights(void);
};

#endif // __ConnectionList_h__

// Author: Wesley Curtis Lefebvre

#ifndef __BackLaguarreAxon_H__
#define __BackLaguarreAxon_H__


class BackLaguarreAxon: public BackGammaAxon {
public:
        void fireMap(void);
        void initialize(void);
};

#endif // __BackLaguarreAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackContextAxon_H__
#define __BackContextAxon_H__


typedef void (*BackContextAxon_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, NSFloat *, NSFloat, NSFloat *);
typedef void (*BackContextAxon_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, NSFloat *, NSFloat, NSFloat *, void *);

class BackContextAxon: public BackLinearAxon {
protected:
        Soma *delayedReference;
        NSFloat m_fOffset;
public:
        BackContextAxon();
        const char *dllFunctionName();
        void fireDLL(void);
        void fireMap(void);
		void freeObject();
        void incrementTime(void);
        void initialize(void);
        void loadStateVariables(FILE *file, unsigned short int version);
        void saveStateVariables(FILE *file);
        NSFloat &Vd(int i) { return delayedReference->V(i); };
        void zeroState(void);
        ~BackContextAxon(void);
};

#endif // __BackContextAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackSigmoidContextAxon_H__
#define __BackSigmoidContextAxon_H__


class BackSigmoidContextAxon: public BackContextAxon {
public:
        void fireMap(void);
};

#endif // __BackSigmoidContextAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackTanhContextAxon_H__
#define __BackTanhContextAxon_H__


class BackTanhContextAxon: public BackContextAxon {
public:
        void fireMap(void);
};

#endif // __BackTanhContextAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackIntegratorAxon_H__
#define __BackIntegratorAxon_H__


class BackIntegratorAxon: public BackContextAxon {
public:
        void fireMap(void);
};

#endif // __BackIntegratorAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackSigmoidIntegratorAxon_H__
#define __BackSigmoidIntegratorAxon_H__


class BackSigmoidIntegratorAxon: public BackIntegratorAxon {
public:
        void fireMap(void);
};

#endif // __BackSigmoidIntegratorAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackTanhIntegratorAxon_H__
#define __BackTanhIntegratorAxon_H__


class BackTanhIntegratorAxon: public BackIntegratorAxon {
public:
        void fireMap(void);
};

#endif // __BackTanhIntegratorAxon_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackSynapse_H__
#define __BackSynapse_H__


typedef void (*BackSynapse_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *);
typedef void (*BackSynapse_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, void *);
typedef DLLData *(*BackSynapse_Constructor)(DLLData *, DLLData *, int, int, int, int);
typedef DLLData *(*BackSynapse_Constructor_CSW)(DLLData *, DLLData *, int, int, int, int, void *);

class BackSynapse: public Synapse {
protected:
        BOOL gradientsEnabled;
        NSFloat *m_fWeightingVector;
        int m_nWeightingVectorSize;
        int m_nCurrentExemplar;
public:
        Synapse *Dual;
public:
        BackSynapse();
        void activityAltered();
		const char *className() { return "BackSynapse"; };
        const char *dllFunctionName();
        void fireDLL();
        void linksAltered();
        void backpropComplete();
        void backpropStarting();
        void constructDLL();
        void networkRandomize();
        virtual void setDual(Soma *);
        void setCurrentExemplar(int exemplar);
        void setGradientsEnabled(BOOL);
        void setWeightingVector(NSFloat *aVector, int vectorSize);
        void updateExemplarCounter();
        // Overridden virtual functions
        void fire();
        void incrementTime();
};

#endif // __BackSynapse_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackFullSynapse_H__
#define __BackFullSynapse_H__


typedef void (*BackFullSynapse_MAP)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, NSFloat *, NSFloat *);
typedef void (*BackFullSynapse_MAP_CSW)(DLLData *, DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, NSFloat *, NSFloat *, void *);

class BackFullSynapse: public BackSynapse {
protected:
        NSFloat &W(int i, int j) { return Dual->w(i+j*U()); };
public:
        void allocateSynapticLinks();
		const char *className() { return "BackFullSynapse"; };
        const char *dllFunctionName();
        void fireDLL();
        void fireFeed();
        void linksAltered();
};

#endif // __BackFullSynapse_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackArbitrarySynapse_H__
#define __BackArbitrarySynapse_H__


class BackArbitrarySynapse: public BackSynapse {
        class ConnectionList *connections;
public:
        void allocateSynapticLinks(void);
		const char *className() { return "BackArbitrarySynapse"; };
        const char *dllFunctionName();
        void fireFeed(void);
		void loadWeights(FILE *file, unsigned short int version);
        void setDual(Soma *aSoma);
};

#endif // __BackArbitrarySynapse_H__

// Author: Wesley Curtis Lefebvre

#ifndef __BackCriteriaControl_H__
#define __BackCriteriaControl_H__


class BackCriteriaControl: public BackAxon {
protected:
        BOOL streamFixed;
protected:
        void fireMap();
public:
						BackCriteriaControl();
						~BackCriteriaControl();
						const char		*dllFunctionName();
        void			fixStream(BOOL aFlag) { streamFixed = aFlag; };
		void			freeObject();
		bool			isKindOf(char *aString);
		virtual void	preFireGetReady();
		virtual void	postFireGetReady();
		void			incrementTime();
};

#endif // __BackCriteriaControl_H__

// Author: Wesley Curtis Lefebvre

#ifndef __Criterion_H__
#define __Criterion_H__


typedef NSFloat (*Criterion_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, BOOL);
typedef NSFloat (*Criterion_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, NSFloat *, BOOL, void *);

class Criterion: public Axon {
		int								tempCounter,
										m_iCheckCostEvery,
                                        m_iSensitivityCounter;
        NSFloat                         *m_fWeightingVector;
        int                             m_nWeightingVectorSize;
        int                             m_nCurrentExemplar,
										m_nTotalNetworkWeights,
										m_nTotalNetworkWeightsOnLastRun,
										m_nConfusionRows;
public:
        int                             costCounter;
		BOOL							m_bIgnoreNextError;
		NSFloat							*m_fOffsetVector;

protected:
        BOOL                            testing,
										m_bAutoSave,
										m_bOnIncrease,
										m_bTrainBestCostUpdated,
                                        m_bSensitivity;
		double							*m_dfSumYY,
										*m_dfSumY,
										*m_dfTempSumY,
										*m_dfSumXY,
										*m_dfSumX,
										*m_dfSumXX,
										*m_dfTempSumXY,
										*m_dfTempSumX,
										*m_dfTempSumXX,
										*m_dfTempSumYY;
        NSFloat                         E,
										m_fRunningMSE,
										m_fTempRunningMSE,
										m_fTempPercentError,
                                        runningE,
										*errorByOutput,
//										*runningEByOutput,
//										*EByOutput,
//										*m_fLastReportedTrainCostByOutput,
										m_fPercentError,
										m_fConfusionThreshold,
										m_fCorrelationAverage,
										m_fNMSE,
										m_fAIC,
										m_fMDL,
										*m_fROC,
										*m_fTempConfusion,
										*m_fConfusion,
										*m_fPerformanceMeasures,
										*m_fConfusionAsPercent,
										*m_fCorrelation,
										m_fLastReportedTrainBestCost,
										m_fLastReportedTestBestCost,
										m_fLastReportedTestCost,
										m_fLastReportedTrainCost,
										m_fLastUncheckedCost,
										m_fBestCost,
										m_fLastCost,
										m_nROCMinValue,
										m_nROCMaxValue,
                                        tempE,
                                        *desired;
        SpatialAccess                   *costAccess,
                                        *runningCostAccess,
										*performanceMeasuresAccess,
										*confusionAccess,
										*rOCAccess,
										*confusionAsPercentAccess,
										*correlationAccess,
                                        *desiredAccess;
        SpatialData                     *m_pFixedOutput,
                                        *m_pSensitivity,
                                        *m_pRawSensitivity,
                                        *m_pSensitivityTotals;
        BOOL                            m_bSensitivityDataLocal,
                                        m_bRawSensitivityDataLocal,
                                        m_bSensitivityTotalsDataLocal;
		int								m_nROCThresholds,
										m_nROCChannel,
										*m_nTempROCCounters,
										*m_nROCCounters;
public:
                                        Criterion();
                                        ~Criterion();
		BOOL					autoSave() { return m_bAutoSave; };
		NSFloat					bestCost() { return m_fBestCost; };
		BOOL					checkForSaveBest(BOOL, NSFloat, BOOL);
		BOOL					checkForSaveBest(NSFloat, BOOL);
		void					computePerformanceStats();
        virtual void			determineCost();
        virtual void			determineCostDerivative()=0;
        const char              *dllFunctionName();
        void					epochEnded();
        void                    fireDLL();
		virtual void			fireGetReady();
		void					preFireGetReady();
        void                    fireMap();
        void                    fireSensitivity();
		void					freeObject();
        void                    incrementTime();
		void					ignoreNextError();
        void                    initialize();
		bool					isKindOf(char *aString);
		NSFloat					lastErrorForOutput(int index) { return *(errorByOutput + index); };
		NSFloat					lastReportedTestCost() { return m_fLastReportedTestCost; };
		NSFloat					lastReportedTrainCost() { return m_fLastReportedTrainCost; };
//		NSFloat					lastReportedTrainCostForOutput(int index) { return *(m_fLastReportedTrainCostByOutput + index); };
		NSFloat					lastUncheckedCost() { return m_fLastUncheckedCost; };
        void                    networkRandomize();
        void                    networkReset();
		void					phaseEnded(int counter);
        NSFloat                 reportCost(BOOL reportSpatial = TRUE, BOOL resetCounter = TRUE);
		void					reportPerformanceAccess();
//		int						saveCounter() { return m_iSaveCounter; };
        BOOL                    sensitivity() { return m_bSensitivity; };
        void                    setAutoSave(BOOL aBool) { m_bAutoSave = aBool; };
		void					setBestCost(NSFloat aFloat) { m_fBestCost = aFloat; };
		void					setCheckCostEvery(int anInt) { m_iCheckCostEvery = anInt; };
		void					setConfusionAccess(SpatialAccess* anId);
		void					setConfusionAsPercentAccess(SpatialAccess* anId);
		void					setConfusionThreshold(NSFloat aFloat) { m_fConfusionThreshold = aFloat; };
		void					setCorrelationAccess(SpatialAccess* anId);
        void                    setCostAccess(SpatialAccess *);
        void                    setCurrentExemplar(int exemplar);
        void                    setDesiredAccess(SpatialAccess *);
		void					setOnIncrease(BOOL aBool) { m_bOnIncrease = aBool; };
		void					setOffsetVector(NSFloat *aFloatPointer) { m_fOffsetVector = aFloatPointer; }
		void					setPerformanceMeasuresAccess(SpatialAccess *anId);
		void                    setRunningCostAccess(SpatialAccess *);
        void                    setRawSensitivityData(SpatialData *anId);
		void					setROCAccess(SpatialAccess* anId);
		void					setROCThresholds(int anInt) { m_nROCThresholds = anInt; initialize(); };
		void					setROCChannel(int anInt) { m_nROCChannel = anInt; };
		void					setROCMinValue(NSFloat aFloat) { m_nROCMinValue = aFloat; };
		void					setROCMaxValue(NSFloat aFloat) { m_nROCMaxValue = aFloat; };
//		void					setSaveCounter(int anInt) { m_iSaveCounter = anInt; };
        void                    setSensitivityData(SpatialData *);
        void                    setSensitivityTotalsData(SpatialData *);
        void                    setSensitivity(BOOL);
        virtual NSFloat         setTesting(BOOL);
		void					setTotalNetworkWeights(int anInt) { m_nTotalNetworkWeights = anInt; };
        void                    setSensitivityInputs(int);
        void                    setWeightingVector(NSFloat *aVector, int vectorSize);
        void                    updateWeightedCost();
        BOOL                    isTesting() { return testing; };
};

#endif // __Criterion_H__

// Author: Wesley Curtis Lefebvre

#ifndef __L1Criterion_H__
#define __L1Criterion_H__


class L1Criterion: public Criterion {
protected:
        void determineCost();
        void determineCostDerivative();
};

#endif // __L1Criterion_H__

// Author: Wesley Curtis Lefebvre

#ifndef __L2Criterion_H__
#define __L2Criterion_H__


class L2Criterion: public Criterion {
protected:
        void determineCost();
        void determineCostDerivative();
};

#endif // __L2Criterion_H__

// SVML2Criterion

#ifndef __SVML2Criterion_H__
#define __SVML2Criterion_H__


class SVML2Criterion: public L2Criterion {
private:
	SVMOutputSynapse		*m_pOutputSynapse;
//	BOOL					m_bRunningFirstEpoch;
//	int						m_nExemplarCount;

public:
			SVML2Criterion();
	void	determineCost();
	void	determineCostDerivative();
	void	epochEnded();
//	int		exemplarCount() { return m_nExemplarCount; };
	void	loadStateVariables(FILE *file, unsigned short int version);
	void	networkReset();
//	BOOL	runningFirstEpoch() { return m_bRunningFirstEpoch; };
	void	saveStateVariables(FILE *file);
	void	setSVMOutputSynapse(SVMOutputSynapse *aSynapse) { m_pOutputSynapse = aSynapse; };
//	void	setExemplarCount(int anInt) { m_nExemplarCount = anInt; };
//	void	setRunningFirstEpoch(BOOL aBool) { m_bRunningFirstEpoch = aBool; };

};

#endif // __SVML2Criterion_H__

// L2TemporalCriterion

#ifndef __L2TemporalCriterion_H__
#define __L2TemporalCriterion_H__


class L2TemporalCriterion: public Criterion {
protected:
	NSFloat				m_fLargeChangeRightDirectionScale,
						m_fLargeChangeWrongDirectionScale,
						m_fSmallChangeRightDirectionScale,
						m_fSmallChangeWrongDirectionScale,
						m_fRightDirectionScale,
						m_fWrongDirectionScale,
						m_fLargeChangeScale,
						m_fSmallChangeScale,
						*m_fLastActivity,
						*m_fLastDesired,
						m_fDiscountRate,
						*m_fOverallScale;
	BOOL				m_bMagnitudeOfChange,
						m_bDirectionOfChange,
						m_bStandardDeviationComputed,
						m_bMemoryNeedsReallocating,
						m_bDataPreDifferenced,
						m_bRecencyOfObservation;
	int					m_nActiveNumberOfExemplars,
						m_nCVNumberOfExemplars,
						m_nNumberOfExemplars,
						m_nExemplarNumber,
						m_nMode;

	void determineCost();
	void determineCostDerivative();
	NSFloat determineDirectionalProfitScale(NSFloat desired, NSFloat lastDesired, NSFloat activity, NSFloat lastActivity, NSFloat standardDeviation, NSFloat normalizationOffset);
	NSFloat determineDirectionScale(NSFloat desired, NSFloat lastDesired, NSFloat activity, NSFloat lastActivity, NSFloat normalizationOffset);
	NSFloat determineMagnitudeScale(NSFloat desired, NSFloat lastDesired, NSFloat standardDeviation);
	NSFloat determineRecencyScale();
    void initialize(void);
	void linksAltered(void);

public:
			L2TemporalCriterion();
			~L2TemporalCriterion();
	bool	isKindOf(char *aString);
    void	epochEnded();
	void	fireGetReady();
	void	freeObject();
    void	networkReset();
	NSFloat setTesting(BOOL);
	NSFloat	largeChangeRightDirectionScale() { return m_fLargeChangeRightDirectionScale; };
	NSFloat	largeChangeWrongDirectionScale() { return m_fLargeChangeWrongDirectionScale; };
	NSFloat	smallChangeRightDirectionScale() { return m_fSmallChangeRightDirectionScale; };
	NSFloat	smallChangeWrongDirectionScale() { return m_fSmallChangeWrongDirectionScale; };
	NSFloat	rightDirectionScale() { return m_fRightDirectionScale; };
	NSFloat	wrongDirectionScale() { return m_fWrongDirectionScale; };
	NSFloat	largeChangeScale() { return m_fLargeChangeScale; };
	NSFloat	smallChangeScale() { return m_fSmallChangeScale; };
	NSFloat	discountRate() { return m_fDiscountRate; };
	BOOL	magnitudeOfChange() { return m_bMagnitudeOfChange; };
	BOOL	directionOfChange() { return m_bDirectionOfChange; };
	BOOL	recencyOfObservation() { return m_bRecencyOfObservation; };
	BOOL	dataPreDifferenced() { return m_bDataPreDifferenced; };
	void	networkRandomize();
	void	setActiveNumberOfExemplars(int anInt) { m_nActiveNumberOfExemplars = anInt; };
	void	setCVNumberOfExemplars(int anInt) { m_nCVNumberOfExemplars = anInt; };
	void	setLargeChangeRightDirectionScale(NSFloat aFloat) { m_fLargeChangeRightDirectionScale = aFloat; };
	void	setLargeChangeWrongDirectionScale(NSFloat aFloat) { m_fLargeChangeWrongDirectionScale = aFloat; };
	void	setSmallChangeRightDirectionScale(NSFloat aFloat) { m_fSmallChangeRightDirectionScale = aFloat; };
	void	setSmallChangeWrongDirectionScale(NSFloat aFloat) { m_fSmallChangeWrongDirectionScale = aFloat; };
	void	setRightDirectionScale(NSFloat aFloat) { m_fRightDirectionScale = aFloat; };
	void	setWrongDirectionScale(NSFloat aFloat) { m_fWrongDirectionScale = aFloat; };
	void	setLargeChangeScale(NSFloat aFloat) { m_fLargeChangeScale = aFloat; };
	void	setSmallChangeScale(NSFloat aFloat) { m_fSmallChangeScale = aFloat; };
	void	setDiscountRate(NSFloat aFloat) { m_fDiscountRate = aFloat; };
	void	setMagnitudeOfChange(BOOL aBool) { m_bMagnitudeOfChange = aBool; m_bMemoryNeedsReallocating = TRUE; m_nMode = ((int) m_bRecencyOfObservation) * 1 + ((int) m_bDirectionOfChange) * 2 + ((int) m_bMagnitudeOfChange) * 4; };
	void	setDirectionOfChange(BOOL aBool) { m_bDirectionOfChange = aBool; m_bMemoryNeedsReallocating = TRUE; m_nMode = ((int) m_bRecencyOfObservation) * 1 + ((int) m_bDirectionOfChange) * 2 + ((int) m_bMagnitudeOfChange) * 4; };
	void	setRecencyOfObservation(BOOL aBool) { m_bRecencyOfObservation = aBool; m_bMemoryNeedsReallocating = TRUE; m_nMode = ((int) m_bRecencyOfObservation) * 1 + ((int) m_bDirectionOfChange) * 2 + ((int) m_bMagnitudeOfChange) * 4; };
	void	setDataPreDifferenced(BOOL aBool) { m_bDataPreDifferenced = aBool; m_bMemoryNeedsReallocating = TRUE; };
	void	setExemplarNumber(int anInt) { m_nExemplarNumber = anInt; };
	BOOL	standardDeviationComputed() { return m_bStandardDeviationComputed; };
	void	setStandardDeviationComputed(BOOL aBool) { m_bStandardDeviationComputed = aBool; };
};

#endif // __L2TemporalCriterion_H__

// Author: Wesley Curtis Lefebvre

#ifndef __LpCriterion_H__
#define __LpCriterion_H__


class LpCriterion: public Criterion {
        int m_nP;
protected:
        void determineCost();
        void determineCostDerivative();
public:
        void setP(int anInt);
        int  p() { return m_nP; };
        LpCriterion();
};

#endif // __LpCriterion_H__

// Author: Wesley Curtis Lefebvre

#ifndef __LinfinityCriterion_H__
#define __LinfinityCriterion_H__


class LinfinityCriterion: public Criterion {
protected:
        void determineCost();
        void determineCostDerivative();
};

#endif // __LinfinityCriterion_H__

// Author: Wesley Curtis Lefebvre

#ifndef __Gradient_H__
#define __Gradient_H__


class Gradient: public Engine {
        NSFloat maxWeight;
public:
        class Soma *errorSoma;
        class Soma *forwardSoma;
protected:
        DLLStruct *dllStruct;
		void *m_pCallingObject;
//		int	m_nExemplarCount;
//		BOOL m_bRunningFirstEpoch;
		NSFloat dummyStep;
//		Criterion *m_Criterion;
public:
        int linksAllocated;
        Gradient();
        virtual ~Gradient();
        virtual void allocateLinks(int anInt);
		virtual const char *className();
        virtual void constructDLL();
		virtual NSFloat defaultStepSize(void) { return 1.0; };
        virtual void destroyDLL(DLLData *);
		virtual void epochEnded();
        virtual void fireGetReady();
		void freeObject();
        void preFireGetReady();
        virtual NSFloat getDefaultMomentum(void) { return 0.5; };
		virtual void initialize(void);
        virtual void initializeDLL();
		virtual BOOL isWeightedComponent();
        virtual const char *dllFunctionName();
        virtual void loadWeights(FILE *, unsigned short int version=100);
        virtual void loadStateVariables(FILE *file, unsigned short int version);
        virtual void saveWeights(FILE *);
        virtual void saveStateVariables(FILE *file);
        virtual void networkRandomize(void);
//		void setCriterion(Criterion *aCriterion);
		virtual void setDecayRate(NSFloat aFloat) { };
		virtual void setDecayWeights(BOOL aBool) { };
        virtual void setDefaultMomentum(NSFloat aFloat) {};
		virtual void setDefaultStepSize(NSFloat aFloat) {};
        virtual void setDeltaEAccess(SpatialAccess *) {};
        virtual void setDeltaWAccess(SpatialAccess* anNSAccess) {};
//		void setExemplarCount(int anInt) { m_nExemplarCount = anInt; };
		virtual void setIndividualSteps(BOOL aFlag) {};
		virtual NSFloat &step(int i) { return dummyStep; };
		virtual void setStepDivisor(int anInt) {};
        virtual void setKappa(NSFloat aFloat) {};
        virtual void setBeta(NSFloat aFloat) {};
        virtual void setZeta(NSFloat aFloat) {};
        virtual void setMomentumAccess(SpatialAccess* anNSAccess) {};
        virtual void setDLLFunction(DLLStruct *aDLL);
        void setDLL(void *function, void *constructor=NULL, void *destructor=NULL, void *instance=NULL, void *callingObject=NULL);
        void setErrorSoma(Soma *aSoma);
        void setForwardSoma(Soma *aSoma) { forwardSoma = aSoma; };
//		void setRunningFirstEpoch(BOOL aBool) { m_bRunningFirstEpoch = aBool; };
		virtual void setStepAccess(SpatialAccess *anNSAccess) {};
        virtual void setWeightLimit(NSFloat aFloat);
        virtual void update(Soma *aSoma);
        virtual void updateDLL(Soma *aSoma);
        void updateWeights(Soma *aSoma);
        NSFloat weightLimit(void) {return maxWeight;};
		int weightRatio();
        virtual void networkReset(void);
};

#endif // __Gradient_H__

// Author: Wesley Curtis Lefebvre

#ifndef __Step_H__
#define __Step_H__


typedef DLLData *(*Step_Constructor)(DLLData *, int, BOOL);
typedef DLLData *(*Step_Constructor_CSW)(DLLData *, int, BOOL, void *);
typedef void (*Step_MAP)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL, int, BOOL, NSFloat);
typedef void (*Step_MAP_CSW)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL, int, BOOL, NSFloat, void *);

class Step: public Gradient {
        int stepCount;
protected:
    NSFloat m_fDefaultStepSize, *stepSize;
    SpatialAccess *stepAccess;
    BOOL individualSteps;
	BOOL m_bDecayWeights;
	NSFloat m_fDecayRate;
	int m_nStepDivisor;

public:
    Step();
    void addToStepSize(NSFloat aFloat);
	const char *className();
    void constructDLL();
    const char *dllFunctionName();
    NSFloat defaultStepSize(void) { return m_fDefaultStepSize; };
	void freeObject();
	BOOL isWeightedComponent();
    void multByStepSize(NSFloat aFloat);
    virtual void setIndividualSteps(BOOL aFlag);
    void setDefaultStepSize(NSFloat aFloat);
	void setDecayRate(NSFloat aFloat) { m_fDecayRate = aFloat; };
	void setDecayWeights(BOOL aBool) { m_bDecayWeights = aBool; };
    void setStepAccess(SpatialAccess *anNSAccess);
	void setStepDivisor(int anInt) { m_nStepDivisor = anInt; };
    NSFloat &step(int i) { return (individualSteps && (i<stepCount))? *(stepSize+i): *stepSize; };
    int step(void) { return stepCount; };
    // Overwritten virtual functions
    void allocateLinks(int anInt);
    void networkReset(void);
    void update(Soma *aSoma);
    void updateDLL(Soma *aSoma);
    virtual ~Step(void);
};

#endif  // __Step_H__

#ifndef __SVMStep_H__
#define __SVMStep_H__

class SVMStep: public Step {
protected:

public:
				SVMStep();
	const char *className();
	void		epochEnded();
//	int			exemplarCount() { return m_nExemplarCount; };
	BOOL 		isWeightedComponent();
	void		loadStateVariables(FILE *file, unsigned short int version);
	void		networkReset();
//	BOOL		runningFirstEpoch() { return m_bRunningFirstEpoch; };
	void		saveStateVariables(FILE *file);
	void		update(Soma *aSoma);
};

#endif // __SVMStep_H__

//ConjugateGradient

#ifndef __ConjugateGradient_H__
#define __ConjugateGradient_H__


//typedef DLLData *(*ConjugateGradient_Constructor)(DLLData *, int, BOOL);
//typedef DLLData *(*ConjugateGradient_Constructor_CSW)(DLLData *, int, BOOL, void *);
//typedef void (*ConjugateGradient_MAP)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL);
//typedef void (*ConjugateGradient_MAP_CSW)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL, void *);

class ConjugateGradient: public Gradient {

public:
		NSFloat *StoredWeightsOnFireConclude;
		NSFloat *StoredWeights;
		NSFloat *combinedGradients;

		double *Pvec;
		double *Gvec;
		double *SKvec;

public:
        ConjugateGradient();
        virtual ~ConjugateGradient(void);
//        void constructDLL();
//        const char *dllFunctionName();
        // Overwritten virtual functions
        void allocateLinks(int anInt);
		const char *className();
		void freeObject();
		void loadStateVariables(FILE *file, unsigned short int version);
		void saveStateVariables(FILE *file);
//        void updateDLL(Soma *aSoma);
};

#endif  // __ConjugateGradient_H__

//LevenbergMarquardt

#ifndef __LevenbergMarquardt_H__
#define __LevenbergMarquardt_H__


//typedef DLLData *(*LevenbergMarquardt_Constructor)(DLLData *, int, BOOL);
//typedef DLLData *(*LevenbergMarquardt_Constructor_CSW)(DLLData *, int, BOOL, void *);
//typedef void (*LevenbergMarquardt_MAP)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL);
//typedef void (*LevenbergMarquardt_MAP_CSW)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL, void *);

class LevenbergMarquardt: public Gradient {

protected:

public:
        LevenbergMarquardt();
        virtual ~LevenbergMarquardt(void);
//        void constructDLL();
//        const char *dllFunctionName();
        // Overwritten virtual functions
        void allocateLinks(int anInt);
		const char *className();
		BOOL isWeightedComponent();
		void loadStateVariables(FILE *file, unsigned short int version);
		void saveStateVariables(FILE *file);
//        void updateDLL(Soma *aSoma);
};

#endif  // __LevenbergMarquardt_H__

// Author: Wesley Curtis Lefebvre

#ifndef __Momentum_H__
#define __Momentum_H__


typedef void (*Momentum_MAP)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL, int, BOOL, NSFloat, NSFloat, NSFloat *);
typedef void (*Momentum_MAP_CSW)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL, int, BOOL, NSFloat, NSFloat, NSFloat *, void *);

class Momentum: public Step {
protected:
        int momentumCount;
        NSFloat defaultMomentum, *momentumSize, *delta;
        SpatialAccess *deltaWAccess, *momentumAccess;
        BOOL individualMomentums;
public:
        Momentum();
        void addToMomentum(NSFloat aFloat);
		const char *className();
        NSFloat &dW(int i) { return *(delta+i); };
		void freeObject();
        NSFloat getDefaultMomentum(void) { return defaultMomentum; };
		BOOL isWeightedComponent();
        NSFloat &momentum(int i) { return individualMomentums? *(momentumSize+i): *momentumSize; };
        int momentum(void) { return momentumCount; };
        void multByMomentum(NSFloat aFloat);
        void loadStateVariables(FILE *file, unsigned short int version);
        void saveStateVariables(FILE *file);
        void setDeltaWAccess(SpatialAccess* anNSAccess);
        virtual void setDefaultMomentum(NSFloat aFloat);
        virtual void setIndividualMomentums(BOOL aFlag);
        virtual void setMomentumAccess(SpatialAccess* anNSAccess);
        // Overwritten virtual functions
        void allocateLinks(int anInt);
        const char *dllFunctionName();
        void networkReset(void);
        void update(Soma *aSoma);
        void updateDLL(Soma *aSoma);
        ~Momentum(void);
};

#endif // __Momentum_H__

// Author: Wesley Curtis Lefebvre

#ifndef __Quickprop_H__
#define __Quickprop_H__


typedef void (*Quickprop_MAP)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL, int, BOOL, NSFloat, NSFloat *, NSFloat *, NSFloat, NSFloat *);
typedef void (*Quickprop_MAP_CSW)(DLLData *, NSFloat *, int, NSFloat *, NSFloat *, BOOL, int, BOOL, NSFloat, NSFloat *, NSFloat *, NSFloat, NSFloat *, void *);

class Quickprop: public Momentum {
        NSFloat *deltaE;
protected:
        SpatialAccess *deltaEAccess;
public:
        Quickprop();
        void setDeltaEAccess(SpatialAccess *);
        // Overwritten virtual functions
        void allocateLinks(int anInt);
		const char *className();
        NSFloat &dE(int i) { return *(deltaE+i); };
        const char *dllFunctionName();
		void freeObject();
        void loadStateVariables(FILE *file, unsigned short int version);
        void saveStateVariables(FILE *file);
        void setDefaultMomentum(NSFloat aFloat);
        void update(Soma *aSoma);
        void updateDLL(Soma *aSoma);
        void networkReset(void);
        ~Quickprop(void);
};

#endif //__Quickprop_H__

// Author: Wesley Curtis Lefebvre

#ifndef __DeltaBarDelta_H__
#define __DeltaBarDelta_H__


typedef void (*DeltaBarDelta_MAP)(DLLData *, NSFloat *, int, NSFloat, NSFloat *, NSFloat *, NSFloat *, NSFloat, NSFloat, NSFloat);
typedef void (*DeltaBarDelta_MAP_CSW)(DLLData *, NSFloat *, int, NSFloat, NSFloat *, NSFloat *, NSFloat *, NSFloat, NSFloat, NSFloat, void *);

class DeltaBarDelta: public Quickprop {
        NSFloat kappaValue, betaValue, zetaValue;
protected:
        NSFloat &D(int i) { return errorSoma->w(i); };
        NSFloat &S(int i) { return dE(i); };
        // Overwritten virtual functions
public:
        DeltaBarDelta();
		const char *className();
        const char *dllFunctionName();
        NSFloat beta() { return betaValue; };
        NSFloat kappa() { return kappaValue; };
        NSFloat zeta() { return zetaValue; };
        void networkReset(void);
        void setDefaultMomentum(NSFloat);
        void setIndividualSteps(BOOL aFlag);
        void setKappa(NSFloat aFloat);
        void setBeta(NSFloat aFloat);
        void setZeta(NSFloat aFloat);
        void update(Soma *aSoma);
        void updateDLL(Soma *aSoma);
};

#endif // __DeltaBarDelta_H__

// Author: Wesley Curtis Lefebvre

#ifndef __UnsupervisedFull_H__
#define __UnsupervisedFull_H__


typedef void (*Unsupervised_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, NSFloat);
typedef void (*Unsupervised_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, NSFloat, void *);

class UnsupervisedFull: public FullSynapse {
protected:
        SpatialAccess *stepAccess;
        BOOL m_bLearning, m_bTempLearning;
        NSFloat step, m_fStep;
        void fireDLL();
        void fireFeed();
        virtual void fireRule();
        virtual void fireRuleDLL();
		SpatialAccess *forcingAccess;
        NSFloat *forcingFeed, *feed;
        BOOL m_bForcing;
		BOOL m_bWeightNormalize;
		BOOL m_bLearningOnReset;
public:
        UnsupervisedFull();
        const char *dllFunctionName();
		bool isKindOf(char *aString);
        BOOL learning() { return m_bLearning; };
		void networkReset();
        void setLearningOnReset(BOOL aBOOL) { m_bLearningOnReset = aBOOL; };
        void setLearning(BOOL aBOOL) { m_bLearning = aBOOL; };
        void setLearningNO() { m_bTempLearning = m_bLearning; m_bLearning = NO; };
        void setLearningYES() { m_bLearning = m_bTempLearning;  m_bTempLearning = NO; };
        void setStepAccess(SpatialAccess *);
        void setStepSize(NSFloat);
        NSFloat stepSize() { return step; };
        void preFireGetReady(void);
        void allocateForce(void);
		void allocateSynapticLinks(void);
		void fire(void);
		void setForcing(BOOL);
        void setForcingAccess(SpatialAccess *);
		void setWeightNormalize(BOOL aBOOL) { m_bWeightNormalize = aBOOL; };
};

#endif // __UnsupervisedFull_H__

// SVMInputSynapse

#ifndef __SVMInputSynapse_H__
#define __SVMInputSynapse_H__


class SVMInputSynapse: public UnsupervisedFull {
protected:
 //   BOOL	m_bRunningFirstEpoch,
	BOOL	m_bDotProductMetric;
//	int		m_nExemplarCount;

public:
				SVMInputSynapse();
	void		epochEnded();
//	int			exemplarCount() { return m_nExemplarCount; };
	void		fireFeed(void);
	void		fireRule(void);
	void		loadStateVariables(FILE *file, unsigned short int version);
	void		networkReset();
//	BOOL		runningFirstEpoch() { return m_bRunningFirstEpoch; };
	void		saveStateVariables(FILE *file);
	void		setDotProductMetric(BOOL aBool) { m_bDotProductMetric = aBool; };
//	void		setExemplarCount(int anInt) { m_nExemplarCount = anInt; };
//	void		setRunningFirstEpoch(BOOL aBool) { m_bRunningFirstEpoch = aBool; };
};

#endif // __SVMInputSynapse_H__

// Author: Wesley Curtis Lefebvre

#ifndef __HebbianFull_H__
#define __HebbianFull_H__


class HebbianFull: public UnsupervisedFull {
protected:

public:
				HebbianFull();
	const char	*className() { return "HebbianFull"; };
    void		fireRule(void);
    void		fireRuleDLL();
    void		storeHopfield(int);
};

#endif // __HebbianFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __OjasFull_H__
#define __OjasFull_H__


class OjasFull: public UnsupervisedFull {
protected:
		const char *className() { return "OjasFull"; };
        void fireRule(void);
};

#endif // __OjasFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __SangersFull_H__
#define __SangersFull_H__


class SangersFull: public UnsupervisedFull {
protected:
		const char *className() { return "SangersFull"; };
        void fireRule(void);
};

#endif // __SangersFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __CompetitiveFull_H__
#define __CompetitiveFull_H__


typedef enum {DotProduct=0, Euclidean=1, BoxCar=2} NMetricType;
typedef void (*Competitive_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, NSFloat, int);
typedef void (*Competitive_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, NSFloat, int, void *);

class CompetitiveFull: public UnsupervisedFull {
protected:
        NMetricType					m_eMetricType;
        int							winningIndex,
									m_nNumSamples;
		SpatialAccess				*unifiedDistanceAccess,
									*quantizationMetricAccess;
        NSFloat						*m_fpDistanceMatrix;
        NSFloat						m_fQuantizationMetric,
									m_fSumError;

public:
        CompetitiveFull();
		NSFloat distance(int r1, int c1, int r2, int c2, NSFloat *input, int koh_cols, int orig_cols);
        const char *dllFunctionName();
		void epochEnded();
        void fireDLL();
        void fireFeed();
        void fireRule();
        virtual void fireWinner();
        virtual void fireWinnerDLL();
		void linksAltered(void);
		void networkReset();
        NMetricType metric() { return m_eMetricType; };
        void setMetric(NMetricType anEnum) { m_eMetricType = anEnum; };
		void setQuantizationMetricAccess(SpatialAccess *anId);
		void setUnifiedDistanceAccess(SpatialAccess *anId);
};

#endif // __CompetitiveFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __StandardFull_H__
#define __StandardFull_H__


class StandardFull: public CompetitiveFull {
protected:
        void standardUpdate(int i, int j) { W(i, j) += step * (V(j) - W(i, j)); };
        void fireWinner(void);
};

#endif // __StandardFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __ConscienceFull_H__
#define __ConscienceFull_H__


class ConscienceFull: public StandardFull {
protected:
        class SpatialData       *frequency, *bias;
        NSFloat                         m_fBeta, m_fGamma;
		BOOL					m_bBiasDataLocal, m_bFrequencyDataLocal;
public:
        ConscienceFull();
        ~ConscienceFull();
        void allocateSynapticLinks();
        NSFloat beta() { return m_fBeta; };
		const char *className() { return "ConscienceFull"; };
        void fireRule(void);
 		void freeObject();
        NSFloat gamma() { return m_fGamma; };
        void networkReset();
        void setBeta(NSFloat aFloat) { m_fBeta = aFloat; };
        void setBiasData(SpatialData *);
        void setFrequencyData(SpatialData *);
        void setGamma(NSFloat aFloat) { m_fGamma = aFloat; };
};

#endif // __ConscienceFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __KohonenFull_H__
#define __KohonenFull_H__


typedef void (*Kohonen_MAP)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, NSFloat, int, int, int);
typedef void (*Kohonen_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat *, int, int, NSFloat *, NSFloat, int, int, int, void *);

class KohonenFull: public ConscienceFull {
protected:
        SpatialAccess           *neighborhoodAccess,
								*componentPlaneAccess;
        NSFloat                 m_fNeighborhood;
        NSFloat                 *m_fpComponentPlaneMatrix;
		int						m_iNeighborhood;
        int                     startRow, stopRow, m_nComponentPlane,
                                startCol, stopCol,
                                winningRow, winningCol;
public:
        KohonenFull();
		const char *className() { return "KohonenFull"; };
		int componentPlane();
        const char *dllFunctionName();
		void epochEnded();
		void linksAltered(void);
        int neighborhood() { return (int)m_fNeighborhood; };
		void networkReset();
		void setNeighborhood(int);
        void setNeighborhoodAccess(SpatialAccess *);
        void fireWinner();
        void fireWinnerDLL();
        virtual void fireWinningShape();
		void setComponentPlane(int anInt);
		void setComponentPlaneAccess(SpatialAccess *anId);
};

#endif // __KohonenFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __LineKohonenFull_H__
#define __LineKohonenFull_H__


class LineKohonenFull: public KohonenFull {
protected:
		const char *className() { return "LineKohonenFull"; };
        void fireWinner();
};

#endif // __LineKohonenFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __SquareKohonenFull_H__
#define __SquareKohonenFull_H__


class SquareKohonenFull: public KohonenFull {
protected:
        void fireWinningShape();
};

#endif  __SquareKohonenFull_H__

// Author: Wesley Curtis Lefebvre

#ifndef __DiamondKohonenFull_H__
#define __DiamondKohonenFull_H__


class DiamondKohonenFull: public KohonenFull {
protected:
	const char					*className() { return "DiamondKohonenFull"; };
    void						fireWinningShape();
};

#endif  __DiamondKohonenFull_H__

// Author: Wesley Curtis Lefebvre
// Name: Transmitter.h

#ifndef __Transmitter_H__
#define __Transmitter_H__


typedef BOOL (*Transmitter_MAP)(DLLData *, NSFloat *, int);
typedef BOOL (*Transmitter_MAP_CSW)(DLLData *, NSFloat *, int, void *);
typedef void (*TransmitterSend_FUNCTION)(void *, const char *);

class Transmitter: public SpatialData
{
protected:
        DLLStruct *dllStruct;
        void *m_pSendFunction;
		void *m_pCallingObject;
        unsigned int receiverCount;
        char *receiverName[128];
        void *receiverID[128];
public:
        Transmitter();
        ~Transmitter();
        void addReceiver(void *anId, const char *);
        virtual void constructDLL(void);
        virtual void destroyDLL(DLLData *);
        virtual void initializeDLL(void);
        void reportSpatialData();
        virtual void sendTransmitterActions();
        virtual void setDLLFunction(DLLStruct *);
        virtual void setDLL(void *function, void *constructor=NULL, void *destructor=NULL, void *instance=NULL, void *callingObject=NULL);
        void setSendFunction(void *aFunction);
        virtual BOOL shouldTransmit(NSFloat *someData);
        virtual BOOL shouldTransmitDLL(NSFloat *someData);
};

#endif __Transmitter_H__

// Author: Wesley Curtis Lefebvre
// Name: ThresholdTransmitter.h

#ifndef __ThresholdTransmitter_H__
#define __ThresholdTransmitter_H__


typedef DLLData *(*ThresholdTransmitter_Constructor)(DLLData *, int, int);
typedef DLLData *(*ThresholdTransmitter_Constructor_CSW)(DLLData *, int, int, void *);
typedef BOOL (*ThresholdTransmitter_MAP)(DLLData *, NSFloat *, int, int, NSFloat, BOOL, int, int);
typedef BOOL (*ThresholdTransmitter_MAP_CSW)(DLLData *, NSFloat *, int, int, NSFloat, BOOL, int, int, void *);

class ThresholdTransmitter: public Transmitter
{
protected:
        class   SpatialAccess	*m_thresholdAccess;
        class   SpatialData		*m_pSmooth;
		NSFloat					m_threshold,
								m_thresholdDecay,
								m_fBeta,
								m_fInitialValue,
								m_startingThreshold;
		int						m_sendAfter, m_sendAfterCounter, m_thresholdType, m_nChannelNumber;
		BOOL					m_bSmoothingDataLocal, m_lessThan, m_bMultBy, m_bAbs;
public:
								ThresholdTransmitter();
								~ThresholdTransmitter();
		NSFloat					absolute(NSFloat &aFloat) { return m_bAbs? (NSFloat)fabs(aFloat): aFloat; };
		BOOL					absoluteValue() { return m_bAbs; };
		BOOL					allLessThan(NSFloat *data,int length);
		BOOL					averageLessThan(NSFloat *data,int length);
		NSFloat					beta(){return m_fBeta;};
		void					constructDLL();
		NSFloat					initialValue(){return m_fInitialValue;};
		BOOL					lessThan(){return m_lessThan;};
		BOOL					multBy(){return m_bMultBy;};
		void					networkReset();
		BOOL					oneLessThan(NSFloat *data,int length);
		BOOL					overThreshold(NSFloat *someData);
		int						sendAfter(){return m_sendAfter;};
		void					sendTransmitterActions();
		void					setAbsoluteValue(BOOL aBOOL) { m_bAbs = aBOOL; };
		void					setBeta(NSFloat aFloat) { m_fBeta = aFloat; };
		void					setChannelNumber(int anInt);
		void					setInitialValue(NSFloat aFloat);
		void					setData(NSFloat *aFloat, int rows, int cols=1);
		void					setSpatialDimension(int, int);
		void					setLessThan(BOOL aFlag);
		void					setMultBy(BOOL aFlag);
		void					setSendAfter(int anInt);
		void					setSmoothingData(SpatialData *);
		void					setThreshold(NSFloat aFloat);
		void					setThresholdDecay(NSFloat aFloat);
		void					setThresholdType(int anInt);
		void					setThresholdAccess(SpatialAccess *);
		BOOL					shouldTransmit(NSFloat *);
		BOOL					shouldTransmitDLL(NSFloat *);
		NSFloat					threshold(){return m_startingThreshold;};
		NSFloat					thresholdDecay(){return m_thresholdDecay;};
		int						thresholdType(){return m_thresholdType;};
        virtual NSFloat			*weightedAverage(NSFloat *);
};
#endif

// Author: Wesley Curtis Lefebvre
// Name: DeltaTransmitter.h

#ifndef __DeltaTransmitter_H__
#define __DeltaTransmitter_H__


class DeltaTransmitter: public ThresholdTransmitter
{
protected:
                NSFloat                 *m_lastData, *m_deltaData;
public:

                                        DeltaTransmitter();
                                        ~DeltaTransmitter();
                DeltaTransmitter        *allocateLastData();
                NSFloat                 *weightedAverage(NSFloat *);
                void                    setData(NSFloat *, int, int cols=1);
                void                    setSpatialDimension(int, int);

};

#endif __DeltaTransmitter_H__

#ifndef __Scheduler_H__
#define __Scheduler_H__


typedef DLLData *(*Scheduler_Constructor)(DLLData *, int);
typedef DLLData *(*Scheduler_Constructor_CSW)(DLLData *, int, void *);
typedef void (*Scheduler_MAP)(DLLData *, NSFloat *, int, NSFloat);
typedef void (*Scheduler_MAP_CSW)(DLLData *, NSFloat *, int, NSFloat, void *);

class Scheduler : public SpatialData
{
protected:
        NSFloat                         m_fBeta, m_fMin, m_fMax;
        int                             m_iStart, m_iStop;
        DLLStruct                       *dllStruct;
		void							*m_pCallingObject;
public:
                                                Scheduler();
        virtual void            applyDLL();
        virtual void            applySchedule(){};
        void                            attachTo(SpatialAccess *);
        NSFloat                         beta() { return m_fBeta; };
        void                            constrain(NSFloat &f) { if (f>m_fMax) f=m_fMax; else if (f<m_fMin) f=m_fMin; };
        const char                      *dllFunctionName();
        void                            epochEnded(int);
        void                            constructDLL();
        void                            destroyDLL(DLLData *);
        void                            initializeDLL();
        NSFloat                         maximum() { return m_fMax; };
        NSFloat                         minimum() { return m_fMin; };
        void                            setBeta(NSFloat aFloat) { m_fBeta = aFloat; };
        void                            setData(NSFloat *, int, int);
        void                            setDLL(void *function, void *constructor=NULL, void *destructor=NULL, void *instance=NULL, void *callingObject=NULL);
        void                            setMaximum(NSFloat aFloat) { m_fMax = aFloat; };
        void                            setMinimum(NSFloat aFloat) { m_fMin = aFloat; };
        void                            setSpatialDimension(int, int);
        void                            setStart(int anInt) { m_iStart = anInt; };
        void                            setStop(int anInt) { m_iStop = anInt; };
        int                                     start() { return m_iStart; };
        int                                     stop() { return m_iStop; };
};

#endif __Scheduler_H__

// Author: Wesley Curtis Lefebvre

#ifndef __ExpScheduler_H__
#define __ExpScheduler_H__


class ExpScheduler : public Scheduler
{
public:
                                ExpScheduler();
        void            applySchedule();
};

#endif __ExpScheduler_H__

// Author: Wesley Curtis Lefebvre

#ifndef __LogScheduler_H__
#define __LogScheduler_H__


class LogScheduler : public Scheduler
{
public:
                                LogScheduler();
        void            applySchedule();
};

#endif __LogScheduler_H__

// Author: Wesley Curtis Lefebvre

#ifndef __LinearScheduler_H__
#define __LinearScheduler_H__


class LinearScheduler : public Scheduler
{
public:
                                LinearScheduler();
        void            applySchedule();
};

#endif __LinearScheduler_H__
