Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Sources/DeepLearning/Optimizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public class Adam<Model: Layer, Scalar: TensorFlowFloatingPoint>: Optimizer
public let decay: Scalar

public init(
for _: __shared Model,
learningRate: Scalar = 1e-3,
beta1: Scalar = 0.9,
beta2: Scalar = 0.999,
epsilon: Scalar = 1e-8,
decay: Scalar = 0,
modelType: Model.Type = Model.self,
scalarType: Scalar.Type = Scalar.self
scalarType: Scalar.Type
) {
precondition(learningRate >= 0, "Learning rate must be non-negative")
precondition(0 <= beta1 && beta1 <= 1, "Beta parameter must be between 0 and 1")
Expand Down Expand Up @@ -84,12 +84,12 @@ public class RMSProp<Model: Layer, Scalar: TensorFlowFloatingPoint>: Optimizer
public let decay: Scalar

public init(
for _: __shared Model,
learningRate: Scalar = 0.001,
rho: Scalar = 0.9,
epsilon: Scalar = 1e-8,
decay: Scalar = 0,
modelType: Model.Type = Model.self,
scalarType: Scalar.Type = Scalar.self
scalarType: Scalar.Type
) {
precondition(learningRate >= 0, "Learning rate must be non-negative")
precondition(rho >= 0, "Rho must be non-negative")
Expand Down Expand Up @@ -125,12 +125,12 @@ public class SGD<Model: Layer, Scalar: TensorFlowFloatingPoint>: Optimizer
public let nesterov: Bool

public init(
for _: __shared Model,
learningRate: Scalar = 0.01,
momentum: Scalar = 0,
decay: Scalar = 0,
nesterov: Bool = false,
modelType: Model.Type = Model.self,
scalarType: Scalar.Type = Scalar.self
scalarType: Scalar.Type
) {
precondition(learningRate >= 0, "Learning rate must be non-negative")
precondition(momentum >= 0, "Momentum must be non-negative")
Expand Down Expand Up @@ -171,7 +171,7 @@ public class RiemannSGD<Model: Layer, Scalar: FloatingPoint>: Optimizer
public init(
learningRate: Scalar,
modelType: Model.Type = Model.self,
scalarType: Scalar.Type = Scalar.self
scalarType: Scalar.Type
) {
self.learningRate = learningRate
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/DeepLearningTests/SequentialTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class SequentialTests: XCTestCase {
}
}
var model = Model()
let optimizer = SGD(learningRate: 0.02, modelType: type(of: model), scalarType: Float.self)
let optimizer = SGD(for: model, learningRate: 0.02, scalarType: Float.self)
let x: Tensor<Float> = [[0, 0], [0, 1], [1, 0], [1, 1]]
let y: Tensor<Float> = [0, 1, 1, 0]
let context = Context(learningPhase: .training)
Expand Down
2 changes: 1 addition & 1 deletion Tests/DeepLearningTests/TrivialModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ final class TrivialModelTests: XCTestCase {
return l2.applied(to: h1, in: context)
}
}
let optimizer = SGD<Classifier, Float>(learningRate: 0.02)
var classifier = Classifier(hiddenSize: 4)
let optimizer = SGD(for: classifier, learningRate: 0.02, scalarType: Float.self)
let x: Tensor<Float> = [[0, 0], [0, 1], [1, 0], [1, 1]]
let y: Tensor<Float> = [[0], [1], [1], [0]]

Expand Down