Wiki
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user