//+------------------------------------------------------------------+ //| NeuronPrimitives.mqh | //| AnimateDread | //| https://www.mql5.com | //+------------------------------------------------------------------+ //| CConnection/CArrayCon - the per-synapse weight (+ Adam moment) | //| storage and its owning array, used by the CPU-only CNeuronBase/ | //| CNeuron neuron family (AI\NeuronCPU.mqh) as their fallback last- | //| resort weight representation (no DLL import, no OpenCL/DirectML).| //| Extracted verbatim out of AI\Network.mqh's own god-file (SOLID | //| cleanup) - no logic changes, this is the exact original code. | //+------------------------------------------------------------------+ #include class CConnection : public CObject { public: double weight; double deltaWeight; double mt; double vt; CConnection(double w) { weight = w; deltaWeight = 0; mt = 0; vt = 0; } ~CConnection() {}; //--- methods for working with files virtual bool Save(int const file_handle); virtual bool Load(int const file_handle); virtual int Type(void) const { return defConnect; } }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CConnection::Save(int file_handle) { if(file_handle == INVALID_HANDLE) return false; //--- if(FileWriteDouble(file_handle, weight) <= 0) return false; if(FileWriteDouble(file_handle, deltaWeight) <= 0) return false; if(FileWriteDouble(file_handle, mt) <= 0) return false; if(FileWriteDouble(file_handle, vt) <= 0) return false; //--- return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CConnection::Load(int file_handle) { if(file_handle == INVALID_HANDLE) return false; //--- weight = FileReadDouble(file_handle); deltaWeight = FileReadDouble(file_handle); mt = FileReadDouble(file_handle); vt = FileReadDouble(file_handle); //--- return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CArrayCon : public CArrayObj { public: CArrayCon(void) {}; ~CArrayCon(void) {}; //--- virtual bool CreateElement(int const index); virtual void IncreaseTotal() { m_data_total++; } virtual int Type(void) const { return defArrayConnects; } }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CArrayCon::CreateElement(int index) { if(index < 0 || index >= m_data_max) return false; //--- // Not fan-in-scaled like the CNeuronBaseOCL/CNeuronConvOCL/CNeuronLSTMOCL weight-init sites below // (see those for the LeCun-uniform rationale) - this legacy per-connection constructor has no // visibility into how many neurons share its (sending) layer, and this class family is only ever // reached as the deepest last-resort fallback (no DLL import, no OpenCL, no DirectML), not by the // live WarriorCPU.dll/WarriorDML.dll/OpenCL tiers this EA actually trains on. double weigh = (MathRand() + 1) / 32768.0 - 0.5; if(weigh == 0) weigh = 0.001; m_data[index] = new CConnection(weigh); if(CheckPointer(m_data[index]) == POINTER_INVALID) return false; //--- return (true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+