interface.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of NeuralNetwork project https://git.semlanik.org/semlanik/NeuralNetwork
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. package neuralnetwork
  26. import (
  27. training "git.semlanik.org/semlanik/NeuralNetwork/training"
  28. mat "gonum.org/v1/gonum/mat"
  29. )
  30. const (
  31. StateIdle = 1
  32. StateLearning = 2
  33. StateValidation = 3
  34. StatePredict = 4
  35. )
  36. type SubscriptionFeatures uint8
  37. const (
  38. ActivationsSubscription SubscriptionFeatures = 1 << iota
  39. BiasesSubscription
  40. WeightsSubscription
  41. TrainingSubscription
  42. ValidationSubscription
  43. StateSubscription
  44. AllSubscription = 0xFF
  45. )
  46. type StateWatcher interface {
  47. Init(nn *NeuralNetwork)
  48. UpdateState(state int)
  49. UpdateActivations(l int, a *mat.Dense)
  50. UpdateBiases(l int, biases *mat.Dense)
  51. UpdateWeights(l int, weights *mat.Dense)
  52. UpdateTraining(t int, epocs int, samplesProcced int, totalSamplesCount int)
  53. UpdateValidation(validatorCount int, failCount int)
  54. GetSubscriptionFeatures() SubscriptionFeatures
  55. }
  56. func (f SubscriptionFeatures) Has(flag SubscriptionFeatures) bool {
  57. return f&flag != 0
  58. }
  59. func (f *SubscriptionFeatures) Set(flag SubscriptionFeatures) {
  60. *f |= flag
  61. }
  62. func (f *SubscriptionFeatures) Unset(flag SubscriptionFeatures) {
  63. *f &= (^flag)
  64. }
  65. func (f *SubscriptionFeatures) Clear() {
  66. *f = 0
  67. }
  68. type BatchWorker interface {
  69. Run(trainer training.Trainer, startIndex, endIndex int)
  70. Result(layer int) (dB, dW *mat.Dense, batchSize int)
  71. }
  72. type BatchWorkerFactory interface {
  73. GetBatchWorker() BatchWorker
  74. GetAvailableThreads() int
  75. }
  76. type EarlyStop interface {
  77. Test() bool
  78. Reset()
  79. }