You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GradientDescentOptimizer.cs 2.2 kB

6 years ago
6 years ago
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*****************************************************************************
  2. Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ******************************************************************************/
  13. namespace Tensorflow.Train
  14. {
  15. /// <summary>
  16. /// Optimizer that implements the gradient descent algorithm.
  17. /// </summary>
  18. public class GradientDescentOptimizer : Optimizer
  19. {
  20. /// <summary>
  21. /// Construct a new gradient descent optimizer.
  22. /// </summary>
  23. /// <param name="learning_rate">A Tensor or a floating point value. The learning
  24. /// rate to use.</param>
  25. /// <param name="use_locking">If true use locks for update operations.</param>
  26. /// <param name="name">Optional name prefix for the operations created when applying
  27. /// gradients.Defaults to "GradientDescent".</param>
  28. /// <remarks>
  29. /// When eager execution is enabled, `learning_rate` can be a callable that
  30. /// takes no arguments and returns the actual value to use.This can be useful
  31. /// for changing these values across different invocations of optimizer
  32. /// functions.
  33. /// </remarks>
  34. public GradientDescentOptimizer(float learning_rate, bool use_locking = false, string name = "GradientDescent")
  35. : base(learning_rate, use_locking, name)
  36. {
  37. _lr = learning_rate;
  38. }
  39. public override void _prepare()
  40. {
  41. var lr = _call_if_callable(_lr);
  42. _lr_t = ops.convert_to_tensor(lr, name: "learning_rate");
  43. }
  44. }
  45. }