Загрузка данных


<?php
/**
 * Класс, реализующий простую многослойную нейронную сеть.
 */
class NeuronNetwork {
    private float $threshold;
    private array $wFirst;
    private array $wSecond;

    /**
     * Инициализация весов и порога срабатывания.
     */
    public function __construct(
        float $threshold = 0.7,
        array $wFirst = ['music' => 0.3, 'house' => 0.2],
        array $wSecond = ['beauty' => 0.5, 'music' => -0.3, 'house' => 0.2]
    ) {
        $this->threshold = $threshold;
        $this->wFirst = $wFirst;
        $this->wSecond = $wSecond;
    }

    /**
     * Вычисление первого слоя.
     */
    public function firstLayer(float $music, float $house): float {
        return $music * $this->wFirst['music'] + $house * $this->wFirst['house'];
    }

    /**
     * Вычисление второго слоя.
     */
    public function secondLayer(float $beauty, float $music, float $house): float {
        return $beauty * $this->wSecond['beauty'] + $music * $this->wSecond['music'] + $house * $this->wSecond['house'];
    }

    /**
     * Принятие решения на основе итоговой оценки.
     */
    public function makeDecision(float $beauty, float $music, float $house): array {
        $score1 = $this->firstLayer($music, $house);
        $score2 = $this->secondLayer($beauty, $music, $house);
        $total = $score1 + $score2;

        return [
            'first'    => $score1,
            'second'   => $score2,
            'total'    => $total,
            'decision' => ($total >= $this->threshold) ? "Нравится" : "Не нравится"
        ];
    }
}
?>