Wiki
linter / quality (push) Successful in 5m1s
tests / ci (8.4) (push) Successful in 5m8s
tests / ci (8.5) (push) Successful in 6m31s

This commit is contained in:
2026-09-15 19:44:58 +02:00
parent ca6c9fe38c
commit 6d4fdffee9
82 changed files with 29906 additions and 151 deletions
@@ -8,6 +8,8 @@ class PerceptronLimitedEpochEventBuffer implements IPerceptronIterationEventBuff
{
private array $data = [];
private array $lastEpochData = [];
private ?int $activeEpoch = null;
private bool $shouldBroadcastEpoch = false;
@@ -22,14 +24,20 @@ class PerceptronLimitedEpochEventBuffer implements IPerceptronIterationEventBuff
public function flush(): void
{
if ($this->data === []) {
if ($this->data !== []) {
$this->flushSelectedData();
return;
}
if ($this->lastEpochData === [] || $this->shouldBroadcastEpoch) {
return;
}
$this->waitForBroadcastInterval();
event(new PerceptronTrainingIteration($this->data, $this->sessionId, $this->trainingId));
event(new PerceptronTrainingIteration($this->lastEpochData, $this->sessionId, $this->trainingId));
$this->lastBroadcastAt = microtime(true);
$this->data = [];
$this->lastEpochData = [];
}
public function addIteration(int $epoch, int $exampleIndex, float $error, array $synaptic_weights): void
@@ -42,22 +50,37 @@ class PerceptronLimitedEpochEventBuffer implements IPerceptronIterationEventBuff
];
if ($this->activeEpoch !== $epoch) {
$this->flush();
$this->flushSelectedData();
$this->lastEpochData = [];
$this->activeEpoch = $epoch;
$this->shouldBroadcastEpoch = $epoch === 1 || $epoch % $this->epochInterval === 0;
}
if (! $this->shouldBroadcastEpoch) {
$this->lastEpochData[] = $newData;
return;
}
$this->data[] = $newData;
if ($this->payloadExceedsLimit() || count($this->data) >= config('perceptron.broadcast_iteration_size')) {
$this->flush();
$this->flushSelectedData();
}
}
private function flushSelectedData(): void
{
if ($this->data === []) {
return;
}
$this->waitForBroadcastInterval();
event(new PerceptronTrainingIteration($this->data, $this->sessionId, $this->trainingId));
$this->lastBroadcastAt = microtime(true);
$this->data = [];
}
private function payloadExceedsLimit(): bool
{
return strlen(json_encode([