<commit_before>#include "Layer/fully_connected_neural_network.hpp"

using namespace Convolutional;
using namespace Convolutional::Layer;

auto FullyConnectedNeuralNetwork::ProcessMultiMatrix(const MultiMatrix& multiMatrix) -> MultiMatrix {
	BuildNetwork(multiMatrix.GetDimensionCount() * multiMatrix.GetElementCount());
	LoadInputs(multiMatrix);
	ProcessOutputs();
	const auto outputs = GetOutputsAsMatrix();
	return MultiMatrix {{outputs}};
}

auto FullyConnectedNeuralNetwork::BuildNetwork(std::size_t inputCount) -> void {
	if (wasBuilt)
		return;

	inputNeurons = std::vector<Neuron>(inputCount, Neuron{});
	inputNeurons.push_back(BiasNeuron {});

	outputNeurons = std::vector<Neuron> {outputNeurons.size(), Neuron {inputCount + 1}};

	for (auto& input : inputNeurons)
		for (auto& output : outputNeurons)
			output.connections.push_back({input, output});

	wasBuilt = true;
}

auto FullyConnectedNeuralNetwork::LoadInputs(const MultiMatrix & multiMatrix) -> void {
	auto input = inputNeurons.begin();
	for (const auto& subMatrix : multiMatrix)
		for (const auto& element : subMatrix)
			(input++)->lastActionPotential = element;
}

auto FullyConnectedNeuralNetwork::ProcessOutputs() -> void {
	for (auto& neuron : outputNeurons) {
		for (const auto& connection : neuron.connections) {
			neuron.lastActionPotential += connection.from.lastActionPotential * connection.weight;
		}
		neuron.lastActionPotential = tanh(neuron.lastActionPotential);
	}
}

auto FullyConnectedNeuralNetwork::GetOutputsAsMatrix() const -> Matrix {
	Matrix::Size size;
	size.width = outputNeurons.size();
	size.height = 1;

	Matrix outputs(std::move(size));

	for (std::size_t i = 0; i < outputNeurons.size(); i++) {
		outputs.ElementAt({i, 0}) = outputNeurons[i].lastActionPotential;
	}
	return outputs;
}
<commit_msg>Remove superfluous brackets<commit_after>﻿#include "Layer/fully_connected_neural_network.hpp"

using namespace Convolutional;
using namespace Convolutional::Layer;

auto FullyConnectedNeuralNetwork::ProcessMultiMatrix(const MultiMatrix& multiMatrix) -> MultiMatrix {
	BuildNetwork(multiMatrix.GetDimensionCount() * multiMatrix.GetElementCount());
	LoadInputs(multiMatrix);
	ProcessOutputs();
	const auto outputs = GetOutputsAsMatrix();
	return MultiMatrix {{outputs}};
}

auto FullyConnectedNeuralNetwork::BuildNetwork(std::size_t inputCount) -> void {
	if (wasBuilt)
		return;

	inputNeurons = std::vector<Neuron>(inputCount, Neuron{});
	inputNeurons.push_back(BiasNeuron {});

	outputNeurons = std::vector<Neuron> {outputNeurons.size(), Neuron {inputCount + 1}};

	for (auto& input : inputNeurons)
		for (auto& output : outputNeurons)
			output.connections.push_back({input, output});

	wasBuilt = true;
}

auto FullyConnectedNeuralNetwork::LoadInputs(const MultiMatrix & multiMatrix) -> void {
	auto input = inputNeurons.begin();
	for (const auto& subMatrix : multiMatrix)
		for (const auto& element : subMatrix)
			(input++)->lastActionPotential = element;
}

auto FullyConnectedNeuralNetwork::ProcessOutputs() -> void {
	for (auto& neuron : outputNeurons) {
		for (const auto& connection : neuron.connections) {
			neuron.lastActionPotential += connection.from.lastActionPotential * connection.weight;
		}
		neuron.lastActionPotential = tanh(neuron.lastActionPotential);
	}
}

auto FullyConnectedNeuralNetwork::GetOutputsAsMatrix() const -> Matrix {
	Matrix::Size size;
	size.width = outputNeurons.size();
	size.height = 1;

	Matrix outputs(std::move(size));

	for (std::size_t i = 0; i < outputNeurons.size(); i++)
		outputs.ElementAt({i, 0}) = outputNeurons[i].lastActionPotential;

	return outputs;
}

{'fraction_non_alphanumeric': 0.12614360964790686, 'fraction_numerical': 0.0022179096201829776, 'mean_word_length': 6.378323108384458, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1793455', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1151, 'n_words': 230}