MonoLayer Perceptron
This commit is contained in:
@@ -8,6 +8,10 @@ interface IDataSetReader
|
||||
|
||||
public function getInputSize(): int;
|
||||
|
||||
public function getOutputSize(): int;
|
||||
|
||||
public function getLabels(): array;
|
||||
|
||||
public function reset(): void;
|
||||
|
||||
public function getLastReadLineIndex(): int;
|
||||
|
||||
@@ -49,6 +49,19 @@ class LinearOrderDataSetReader implements IDataSetReader
|
||||
return count($this->lines[0]) - 1; // Don't count the label
|
||||
}
|
||||
|
||||
public function getOutputSize(): int
|
||||
{
|
||||
// Count the number of unique labels in the dataset
|
||||
$labels = array_map(fn ($line) => end($line), $this->lines);
|
||||
return count(array_unique($labels));
|
||||
}
|
||||
|
||||
public function getLabels(): array
|
||||
{
|
||||
$labels = array_map(fn ($line) => end($line), $this->lines);
|
||||
return array_values(array_unique($labels));
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
$this->currentLines = $this->lines;
|
||||
|
||||
@@ -55,6 +55,19 @@ class RandomOrderDataSetReader implements IDataSetReader
|
||||
return count($this->lines[0]) - 1; // Don't count the label
|
||||
}
|
||||
|
||||
public function getOutputSize(): int
|
||||
{
|
||||
// Count the number of unique labels in the dataset
|
||||
$labels = array_map(fn ($line) => end($line), $this->lines);
|
||||
return count(array_unique($labels));
|
||||
}
|
||||
|
||||
public function getLabels(): array
|
||||
{
|
||||
$labels = array_map(fn ($line) => end($line), $this->lines);
|
||||
return array_values(array_unique($labels));
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
$this->currentLines = $this->lines;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\SynapticWeightsProvider;
|
||||
|
||||
interface INetworkSynapticWeightsProvider
|
||||
{
|
||||
public function generate(int $input_size, int $output_size, int $hidden_layers_count, int $hidden_layers_neurons_count): array;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\SynapticWeightsProvider;
|
||||
|
||||
use App\Services\SynapticWeightsProvider\INetworkSynapticWeightsProvider;
|
||||
|
||||
class SimpleNetworkWeightsProvider implements INetworkSynapticWeightsProvider
|
||||
{
|
||||
public function __construct(
|
||||
private ISynapticWeightsProvider $synapticWeightsProvider,
|
||||
) {
|
||||
}
|
||||
|
||||
public function generate(int $input_size, int $output_size, int $hidden_layers_count, int $hidden_layers_neurons_count): array
|
||||
{
|
||||
$synaptic_weights = [];
|
||||
$lastLayerSize = $input_size;
|
||||
|
||||
// Generate Hidden Layer weights
|
||||
for ($hiddenLayerNeuronIndex = 0; $hiddenLayerNeuronIndex < $hidden_layers_count; $hiddenLayerNeuronIndex++) {
|
||||
for ($neuronIndex = 0; $neuronIndex < $hidden_layers_neurons_count; $neuronIndex++) {
|
||||
$synaptic_weights[] = $this->synapticWeightsProvider->generate($lastLayerSize);
|
||||
}
|
||||
$lastLayerSize = $hidden_layers_neurons_count;
|
||||
}
|
||||
|
||||
// Generate Output Layer weights
|
||||
$synaptic_weights[] = [];
|
||||
for ($outputNeuronIndex = 0; $outputNeuronIndex < $output_size; $outputNeuronIndex++) {
|
||||
$synaptic_weights[count($synaptic_weights) -1][] = $this->synapticWeightsProvider->generate($lastLayerSize);
|
||||
}
|
||||
|
||||
return $synaptic_weights;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user