Cancel Training
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
namespace App\Models\NetworksTraining;
|
||||
|
||||
use App\Events\PerceptronTrainingEnded;
|
||||
use App\Exceptions\TrainingCancelledException;
|
||||
use App\Models\ActivationsFunctions;
|
||||
use App\Services\DatasetReader\IDataSetReader;
|
||||
use App\Services\IterationEventBuffer\IPerceptronIterationEventBuffer;
|
||||
use Closure;
|
||||
|
||||
abstract class NetworkTraining
|
||||
{
|
||||
@@ -24,6 +26,7 @@ abstract class NetworkTraining
|
||||
protected IPerceptronIterationEventBuffer $iterationEventBuffer,
|
||||
protected string $sessionId,
|
||||
protected string $trainingId,
|
||||
protected ?Closure $isCancelled = null,
|
||||
) {}
|
||||
|
||||
abstract public function start(): void;
|
||||
@@ -50,9 +53,18 @@ abstract class NetworkTraining
|
||||
|
||||
protected function addIterationToBuffer(float $error, array $synapticWeights)
|
||||
{
|
||||
if ($this->isCancelled !== null && ($this->isCancelled)()) {
|
||||
throw new TrainingCancelledException;
|
||||
}
|
||||
|
||||
$this->iterationEventBuffer->addIteration($this->epoch, $this->datasetReader->getLastReadLineIndex(), $error, $synapticWeights);
|
||||
}
|
||||
|
||||
public function cancel(): void
|
||||
{
|
||||
$this->broadcastTrainingEnded('Entraînement annulé');
|
||||
}
|
||||
|
||||
public function getEpoch(): int
|
||||
{
|
||||
return $this->epoch;
|
||||
|
||||
Reference in New Issue
Block a user