This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3161ba8
commit fe84326
Showing
4 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package solver | ||
|
||
import ( | ||
"fmt" | ||
|
||
G "gorgonia.org/gorgonia" | ||
) | ||
|
||
// RMSProprConfig implements a specific configuration of the RMSProp | ||
// solver | ||
type RMSPropConfig struct { | ||
StepSize float64 | ||
Epsilon float64 | ||
Eta float64 // Only default value of 0.001 supported by Gorgonia | ||
Rho float64 | ||
Batch int | ||
Clip float64 // <= 0 if no clipping | ||
} | ||
|
||
// NewDefaultRMSProp returns a new RMSProp Solver with default | ||
// hyperparameters | ||
func NewDefaultRMSProp(stepSize float64, batchSize int) (*Solver, error) { | ||
return NewRMSProp(stepSize, 1e-8, 0.001, 0.999, batchSize, -1.0) | ||
} | ||
|
||
// NewRMSProp returns a new RMSProp Solver | ||
func NewRMSProp(stepSize, epsilon, eta, rho float64, batchSize int, | ||
clip float64) (*Solver, error) { | ||
if eta != 0.001 { | ||
return nil, fmt.Errorf("newRMSProp: only the default value of " + | ||
"η = 0.001 is currently supported") | ||
} | ||
|
||
rmsprop := RMSPropConfig{ | ||
StepSize: stepSize, | ||
Epsilon: epsilon, | ||
Eta: eta, | ||
Rho: rho, | ||
Batch: int(batchSize), | ||
Clip: clip, | ||
} | ||
|
||
return newSolver(RMSProp, rmsprop) | ||
} | ||
|
||
// Create returns a new Gorgonia RMSProp Solver as described by the | ||
// RMSPropConfig | ||
func (r RMSPropConfig) Create() G.Solver { | ||
var solver G.Solver | ||
|
||
if r.Clip <= 0 { | ||
solver = G.NewRMSPropSolver( | ||
G.WithLearnRate(r.StepSize), | ||
G.WithEps(r.Epsilon), | ||
// G.WithEta(r.Eta), // Unsupported by Gorgonia | ||
G.WithRho(r.Rho), | ||
G.WithBatchSize(float64(r.Batch)), | ||
) | ||
} else { | ||
solver = G.NewAdamSolver( | ||
G.WithLearnRate(r.StepSize), | ||
G.WithEps(r.Epsilon), | ||
// G.WithEta(r.Eta), // Unsupported by Gorgonia | ||
G.WithRho(r.Rho), | ||
G.WithBatchSize(float64(r.Batch)), | ||
G.WithClip(r.Clip), | ||
) | ||
} | ||
return solver | ||
} | ||
|
||
// ValidType returns if the given Solver type is a valid type to be | ||
// created with this config. | ||
func (r RMSPropConfig) ValidType(t Type) bool { | ||
return t == RMSProp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.