12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #pragma once
- #include <AzCore/Math/MatrixMxN.h>
- #include <MachineLearning/INeuralNetwork.h>
- #include <Models/Layer.h>
- namespace MachineLearning
- {
- //! This is a basic multilayer perceptron neural network capable of basic training and feed forward operations.
- class MultilayerPerceptron
- : public INeuralNetwork
- {
- public:
- AZ_TYPE_INFO(MultilayerPerceptron, "{E12EF761-41A5-48C3-BF55-7179B280D45F}");
- //! AzCore Reflection.
- //! @param context reflection context
- static void Reflect(AZ::ReflectContext* context);
- MultilayerPerceptron() = default;
- MultilayerPerceptron(AZStd::size_t activationCount);
- virtual ~MultilayerPerceptron() = default;
- void AddLayer(AZStd::size_t layerDimensionality);
- AZStd::size_t GetLayerCount() const;
- Layer& GetLayer(AZStd::size_t layerIndex);
- AZStd::size_t GetParameterCount() const override;
- const AZ::VectorN& FeedForward(const AZ::VectorN& activations) override;
- float ComputeCost(const AZ::VectorN& activations, const AZ::VectorN& expectedOutput, CostFunctions costFunction) override;
- private:
- void OnActivationCountChanged();
- float ComputeCost_Quadratic(const AZ::VectorN& activations, const AZ::VectorN& expectedOutput);
- //! The number of neurons in the activation layer.
- AZStd::size_t m_activationCount = 0;
- //! The set of layers in the network.
- AZStd::vector<Layer> m_layers;
- };
- }
|