git init
Some checks failed
linter / quality (push) Failing after 6m40s
tests / ci (8.4) (push) Failing after 10s
tests / ci (8.5) (push) Failing after 11s

This commit is contained in:
2026-03-03 11:10:38 +01:00
commit 650cf56045
282 changed files with 27333 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Services;
class CsvReader {
private $file;
private array $headers;
public array $lines = [];
public function __construct(
public string $filename,
)
{
$this->file = fopen(public_path($filename), "r");
if (!$this->file) {
throw new \RuntimeException("Failed to open file: " . $filename);
}
$this->headers = $this->readNextLine();
}
public function readNextLine(): ?array
{
if (($data = fgetcsv($this->file, 1000, ",")) !== FALSE) {
return $data;
}
return null; // End of file or error
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Services;
class DataSetReader {
public array $lines = [];
private array $currentLines = [];
private int $lastReadLineIndex = -1;
public function __construct(
public string $filename,
) {
// For now, we only support CSV files, so we can delegate to CsvReader
$csvReader = new CsvReader($filename);
$this->readEntireFile($csvReader);
$this->reset();
}
private function readEntireFile(CsvReader $reader): void
{
while ($line = $reader->readNextLine()) {
$this->lines[] = $line;
}
}
public function getRandomLine(): array | null
{
if (empty($this->currentLines)) {
return null; // No more lines to read
}
$randomNumber = array_rand($this->currentLines);
$randomLine = $this->currentLines[$randomNumber];
// Remove the line from the current lines to avoid repetition
unset($this->currentLines[$randomNumber]);
$this->lastReadLineIndex = array_search($randomLine, $this->lines, true);
return $randomLine;
}
public function reset(): void
{
$this->currentLines = $this->lines;
}
public function getLastReadLineIndex(): int
{
return $this->lastReadLineIndex;
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Services;
interface ISynapticWeights {
public function generate(int $input_size): array;
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Services;
class RandomSynapticWeights implements ISynapticWeights {
public function generate(int $input_size): array
{
$weights = [];
for ($i = 0; $i < $input_size + 1; $i++) { // +1 for bias weight
$weights[] = rand(-100, 100) / 100; // Random weights between -1 and 1
}
return $weights;
}
}