Warrior_EA/AI/Impl/NeuronPrimitives.mqh
AnimateDread 8d6842bbbf fix(ai): fold in the rest of the AI/Impl split - previous commit's git add aborted silently
A bad pathspec in a multi-file `git add` made the whole invocation a no-op except for
the 4 deletions already staged from an earlier `git rm` - Network.mqh's new inline
declarations, AI_NETWORK.md's table update, and the 4 new AI/Impl/*.mqh bodies never
landed in 46523dc. Same content already compiled clean; this just gets it into the
index. Tree is correct as of this commit; 46523dc alone is not.
2026-08-23 21:05:52 -04:00

83 lines
3.7 KiB
MQL5

//+------------------------------------------------------------------+
//| NeuronPrimitives.mqh |
//| |
//| CConnection/CArrayCon bodies - the per-synapse weight (+ Adam |
//| moment) storage and its owning array, used by the CPU-only |
//| CNeuronBase/CNeuron neuron family (AI\Network.mqh) as their |
//| fallback last-resort weight representation. |
//| |
//| Included from AI\Network.mqh AFTER every class declaration - |
//| bodies only, no declarations. Relocation is behaviour-neutral by |
//| construction: nothing here is reachable until Network.mqh ends. |
//+------------------------------------------------------------------+
#ifndef WARRIOR_AI_IMPL_NEURONPRIMITIVES_MQH
#define WARRIOR_AI_IMPL_NEURONPRIMITIVES_MQH
#include "..\..\System\Random.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CArrayCon::CreateElementScaled(int index, double weighScale)
{
if(index < 0 || index >= m_data_max)
return false;
//---
// Fan-in-scaled to match the CNeuronBaseOCL/CNeuronConvOCL/CNeuronLSTMOCL weight-init sites -
// callers now compute their own He/LeCun-uniform weighScale (same rationale as those) and pass it
// down through CNeuronBase::Init(), since this per-connection constructor has no visibility into
// its owning neuron's fan-in on its own. weighScale < 0 (no caller opinion) keeps the old flat
// draw as a safe default.
double weigh;
if(weighScale > 0.0)
weigh = WarriorRandSymmetric() * weighScale;
else
weigh = WarriorRandUniform() - 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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#endif // WARRIOR_AI_IMPL_NEURONPRIMITIVES_MQH
//+------------------------------------------------------------------+