//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <vcl>
#include <vector>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <conio.h>
#define WM_TERM_VALUE (WM_USER+1)
#define WM_TERM_END (WM_USER+2)
#define WM_TSS      (WM_USER+3)
//---------------------------------------------------------------------------
using namespace std;
//---------------------------------------------------------------------------
class TMultiLayerPerceptron : public TThread
{
  protected :
    void __fastcall Execute(void);
  public :
    __fastcall TMultiLayerPerceptron(HANDLE AHandle):TThread(true)
      {
        VInputMatrix.clear();
        VOutput.clear();
        VAdd.clear();
        VDelta.clear();
        VLDelta.clear();
        VTarget.clear();
        FStudyAddition = 0.25;  // 학습 가중치
        FRun_Count = 100;
        Tss = 99.99;
        FHandle = AHandle;
      }
    __fastcall ~TMultiLayerPerceptron()
    {
      return;
    }
    void Study ( void ); // 학습 하는 루틴
    double	 Test ( vector <double	> Input ); // 학습의 결과를 테스트

    double	 StudyAddition( void ){return FStudyAddition;};
    void  StudyAddition( double	 AStudyAddition ){FStudyAddition= AStudyAddition;};

    vector<double> GetAddition(void)
      {
        return VAdd;
      }

    unsigned int Run_Count( void ){return FRun_Count;};
    void         Run_Count(unsigned int ARun_Count ) {FRun_Count=ARun_Count;};

    void InputMatrix ( vector < vector <double	> > AMatrix )
      {
        VInputMatrix.clear();
        VInputMatrix.assign(AMatrix.begin(),AMatrix.end());
      };

    void Target ( vector < double	 > ATarget )
      {
        VTarget.clear();
        VTarget.assign(ATarget.begin(),ATarget.end());
      };
    double TSS ( void ) { return Tss ; };

  private :
    HANDLE FHandle;
    vector < vector < double	 > > VInputMatrix; // 입력 매트릭스
    vector<double	> VOutput;  // Output Vector
    vector<double	> VAdd;     // 가중치 벡터
    vector<double	> VDelta;   // delta = 목표시 - 실 출력치  // delta = VTarget - VOutput
    vector<double	> VLDelta;  // LDelta = 학습 가중치 * 델타 * 입력치
    vector<double	> VTarget;  // Target
    double	 FStudyAddition;// = 0.25;  // 학습 가중치
    unsigned int FRun_Count;
    double	 Tss;

  // Functions
    double	 Vector_Multiple (const vector<double	> lhs , const vector<double	> rhs );
    double	 TSS(const vector<double	> V);
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#endif
