ComputeCost.cpp 806 B

12345678910111213141516171819202122
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Nodes/ComputeCost.h>
  9. #include <Models/MultilayerPerceptron.h>
  10. #include <Algorithms/LossFunctions.h>
  11. namespace MachineLearning
  12. {
  13. float ComputeCost::In(INeuralNetworkPtr Model, LossFunctions LossFunction, AZ::VectorN Activations, AZ::VectorN ExpectedOutput)
  14. {
  15. AZStd::unique_ptr<IInferenceContext> inferenceContext;
  16. inferenceContext.reset(Model->CreateInferenceContext());
  17. const AZ::VectorN* modelOutput = Model->Forward(inferenceContext.get(), Activations);
  18. return ComputeTotalCost(LossFunction, ExpectedOutput, *modelOutput);
  19. }
  20. }