Some bugfixes and misc
This commit is contained in:
@@ -20,6 +20,7 @@ class MonoLayerPerceptronTraining extends NetworkTraining
|
||||
private array $labels;
|
||||
|
||||
public ActivationsFunctions $activationFunction = ActivationsFunctions::LINEAR;
|
||||
|
||||
public ?ActivationsFunctions $presentationLayerActivationFunction = ActivationsFunctions::STEP;
|
||||
|
||||
private float $epochError;
|
||||
@@ -62,7 +63,7 @@ class MonoLayerPerceptronTraining extends NetworkTraining
|
||||
while ($nextRow = $this->datasetReader->getNextLine()) {
|
||||
$inputsForCurrentEpoch[] = $nextRow;
|
||||
$inputs = array_slice($nextRow, 0, -1);
|
||||
$correctOutput = (int) end($nextRow);
|
||||
$correctOutput = (float) end($nextRow);
|
||||
|
||||
$iterationError = $this->iterationFunction($inputs, $correctOutput);
|
||||
|
||||
@@ -108,7 +109,7 @@ class MonoLayerPerceptronTraining extends NetworkTraining
|
||||
return $condition;
|
||||
}
|
||||
|
||||
private function iterationFunction(array $inputs, int $correctOutput): array
|
||||
private function iterationFunction(array $inputs, float $correctOutput): array
|
||||
{
|
||||
$outputs = $this->network->test($inputs);
|
||||
$desiredOutput = $this->getDesiredOutputFromCorrectOutput($correctOutput);
|
||||
@@ -137,10 +138,10 @@ class MonoLayerPerceptronTraining extends NetworkTraining
|
||||
return [$updatedWeights];
|
||||
}
|
||||
|
||||
private function getDesiredOutputFromCorrectOutput(int $correctOutput): array
|
||||
private function getDesiredOutputFromCorrectOutput(float $correctOutput): array
|
||||
{
|
||||
$desiredOutput = array_fill(0, count($this->labels), -1);
|
||||
$labelIndex = Arr::first(array_keys($this->labels), fn($key) => $this->labels[$key] == $correctOutput);
|
||||
$labelIndex = Arr::first(array_keys($this->labels), fn ($key) => $this->labels[$key] == $correctOutput);
|
||||
if ($labelIndex !== null) {
|
||||
$desiredOutput[$labelIndex] = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user