クラス

次のクラスはグローバルで利用可能です。

  • 変更可能で共有可能な、所有するテンソルへの参照。

    宣言

    public final class Parameter<Scalar> where Scalar : TensorFlowScalar
    extension Parameter: CopyableToDevice
  • TensorHandle への C ポインターをラップするクラス。このクラスは TensorHandle を所有しており、それを破棄する責任があります。

    宣言

    public class TFETensorHandle : _AnyTensorHandle
    extension TFETensorHandle: Equatable
  • RMSProp オプティマイザー。

    RMSProp 最適化アルゴリズムを実装します。 RMSProp は確率的勾配降下法の一種で、勾配を最近の大きさの移動平均で割ります。 RMSProp は、各重みの二乗勾配の移動平均を保持します。

    参考文献:

    宣言

    public class RMSProp<Model: Differentiable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & PointwiseMultiplicative
        & ElementaryFunctions & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • AdaGrad オプティマイザー。

    AdaGrad (適応勾配) 最適化アルゴリズムを実装します。 AdaGrad にはパラメータ固有の学習率があり、トレーニング中にパラメータが更新される頻度に応じて調整されます。より多くの更新を受け取るパラメータの学習率は低くなります。

    AdaGrad は、勾配ノルムの累乗二乗和の平方根に反比例してスケーリングすることにより、すべてのモデル パラメーターの学習率を個別に適応させます。

    参考文献: 「オンライン学習と確率的最適化のための適応的劣勾配法」 (Duchi et al、2011)

    宣言

    public class AdaGrad<Model: Differentiable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & PointwiseMultiplicative
        & ElementaryFunctions & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • AdaDelta オプティマイザー。

    AdaDelta 最適化アルゴリズムを実装します。 AdaDelta は、一次情報に基づく確率的勾配降下法です。過去のすべての勾配を蓄積するのではなく、勾配更新の移動ウィンドウに基づいて学習率を適応させます。したがって、AdaDelta は、多くの更新が行われた場合でも学習を続けます。最適化問題空間のダイナミクスの変化により速く適応します。

    参考文献: 「ADADELTA: 適応学習率手法」 (Zeiler、2012)

    宣言

    public class AdaDelta<Model: Differentiable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & PointwiseMultiplicative
        & ElementaryFunctions & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • アダムオプティマイザー。

    Adam 最適化アルゴリズムを実装します。 Adam は、勾配の一次モーメントと二次モーメントの推定値からさまざまなパラメーターに対する個々の適応学習率を計算する確率的勾配降下法です。

    参考文献: 「Adam: 確率的最適化の手法」 (Kingma および Ba、2014)。

    例:

    • 単純な強化学習エージェントをトレーニングします。
    ...
    // Instantiate an agent's policy - approximated by the neural network (`net`) after defining it 
    in advance.
    var net = Net(observationSize: Int(observationSize), hiddenSize: hiddenSize, actionCount: actionCount)
    // Define the Adam optimizer for the network with a learning rate set to 0.01.
    let optimizer = Adam(for: net, learningRate: 0.01)
    ...
    // Begin training the agent (over a certain number of episodes).
    while true {
    ...
        // Implementing the gradient descent with the Adam optimizer:
        // Define the gradients (use withLearningPhase to call a closure under a learning phase).
        let gradients = withLearningPhase(.training) {
            TensorFlow.gradient(at: net) { net -> Tensor<Float> in
                // Return a softmax (loss) function
                return loss = softmaxCrossEntropy(logits: net(input), probabilities: target)
            }
        }
        // Update the differentiable variables of the network (`net`) along the gradients with the Adam 
    optimizer.
        optimizer.update(&net, along: gradients)
        ...
        }
    }
    
    • 敵対的生成ネットワーク (GAN) をトレーニングします。
    ...
    // Instantiate the generator and the discriminator networks after defining them.
    var generator = Generator()
    var discriminator = Discriminator()
    // Define the Adam optimizers for each network with a learning rate set to 2e-4 and beta1 - to 0.5.
    let adamOptimizerG = Adam(for: generator, learningRate: 2e-4, beta1: 0.5)
    let adamOptimizerD = Adam(for: discriminator, learningRate: 2e-4, beta1: 0.5)
    ...
    Start the training loop over a certain number of epochs (`epochCount`).
    for epoch in 1...epochCount {
        // Start the training phase.
        ...
        for batch in trainingShuffled.batched(batchSize) {
            // Implementing the gradient descent with the Adam optimizer:
            // 1) Update the generator.
            ...
            let 𝛁generator = TensorFlow.gradient(at: generator) { generator -> Tensor<Float> in
                ...
                return loss
                }
            // Update the differentiable variables of the generator along the gradients (`𝛁generator`) 
            // with the Adam optimizer.
            adamOptimizerG.update(&generator, along: 𝛁generator)
    
            // 2) Update the discriminator.
            ...
            let 𝛁discriminator = TensorFlow.gradient(at: discriminator) { discriminator -> Tensor<Float> in
                ...
                return loss
            }
            // Update the differentiable variables of the discriminator along the gradients (`𝛁discriminator`) 
            // with the Adam optimizer.
            adamOptimizerD.update(&discriminator, along: 𝛁discriminator)
            }
    }       
    

    宣言

    public class Adam<Model: Differentiable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & PointwiseMultiplicative
        & ElementaryFunctions & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • AdaMax オプティマイザー。

    無限規範に基づいたアダムの変形。

    参考: 「Adam - 確率的最適化の手法」のセクション 7

    宣言

    public class AdaMax<Model: Differentiable & KeyPathIterable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & PointwiseMultiplicative & ElementaryFunctions
        & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • AMSGrad オプティマイザー。

    このアルゴリズムは Adam を修正したもので、局所最適に近い場合の収束特性が向上します。

    参考: 「アダムとその先の融合について」

    宣言

    public class AMSGrad<Model: Differentiable & KeyPathIterable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & PointwiseMultiplicative & ElementaryFunctions
        & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • RAdam オプティマイザー。

    Rectified Adam。適応学習率の分散を修正するための項を導入した Adam のバリアントです。

    参考: 「適応学習率の分散とそれ以降について」

    宣言

    public class RAdam<Model: Differentiable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & PointwiseMultiplicative & ElementaryFunctions
        & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • サンプルのサイズが均一でない場合に DNN をトレーニングするのに適したサンプル バッチのコレクションの無限シーケンス。

    各エポックのバッチ:

    • すべてまったく同じ数のサンプルがあります。
    • 同様のサイズのサンプルから形成されます。
    • 最大サンプル サイズがエポックで使用されるすべてのサンプルの最大サイズであるバッチから開始します。

    宣言

    public final class NonuniformTrainingEpochs<
      Samples: Collection,
      Entropy: RandomNumberGenerator
    >: Sequence, IteratorProtocol
  • 複数の可能な最適化を表現できる一般的なオプティマイザー。オプティマイザーは、ParameterGroup から ParameterGroupOptimizer へのマッピングで構成されます。このオプティマイザーには、クロス レプリカ合計で動作する要素の数も含まれています。これは、勾配に対する複数の非効率な反復を防ぐための効率化のためです。

    宣言

    public class GeneralOptimizer<Model: EuclideanDifferentiable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & ElementaryFunctions & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • 確率的勾配降下法 (SGD) オプティマイザー。

    運動量、学習率の減衰、ネステロフ運動量をサポートする確率的勾配降下法アルゴリズムを実装します。運動量とネステロフ運動量 (別名ネステロフ加速勾配法) は、勾配降下法のトレーニング速度と収束率を向上させることができる一次最適化法です。

    参考文献:

    宣言

    public class SGD<Model: Differentiable>: Optimizer
    where
      Model.TangentVector: VectorProtocol & ElementaryFunctions & KeyPathIterable,
      Model.TangentVector.VectorSpaceScalar == Float
  • サンプルが均一である場合に DNN をトレーニングするのに適したバッチ サンプルのコレクションの無限シーケンス。

    各エポックのバッチはすべてまったく同じサイズです。

    宣言

    public final class TrainingEpochs<
      Samples: Collection,
      Entropy: RandomNumberGenerator
    >: Sequence, IteratorProtocol
  • 宣言

    public class EpochPipelineQueue
  • デバイス上のトレーニング ループの状態。

    宣言

    public class ThreadState<Model: Layer, Opt: Optimizer>
    where
      Opt.Model == Model, Opt.Scalar == Float, Model.Input == Tensor<Float>,
      Model.Output == Tensor<Float>,
      Model.TangentVector.VectorSpaceScalar == Float