From 4144e348be2dfa2f82c0c7e2c7b5222e371c7e25 Mon Sep 17 00:00:00 2001 From: itsubaki <1759459+itsubaki@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:17:00 +0900 Subject: [PATCH] Update some files --- autograd_test.go | 6 +++--- model/mlp.go | 14 +++++--------- model/model.go | 8 ++++++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/autograd_test.go b/autograd_test.go index b79ea93..6f063bf 100644 --- a/autograd_test.go +++ b/autograd_test.go @@ -430,11 +430,11 @@ func Example_mlp() { } x := variable.Rand(100, 1, s) - y := variable.Rand(100, 1, s) + t := variable.Rand(100, 1, s) for i := 0; i < 100; i++ { - yPred := m.Forward(x) - loss := F.MeanSquaredError(y, yPred) + y := m.Forward(x) + loss := F.MeanSquaredError(y, t) m.Cleargrads() loss.Backward() diff --git a/model/mlp.go b/model/mlp.go index 54a8a9c..b7d79b8 100644 --- a/model/mlp.go +++ b/model/mlp.go @@ -9,14 +9,14 @@ import ( "github.com/itsubaki/autograd/variable" ) -type MLP struct { +type MLPOpts struct { Activation Activation - Model + Source rand.Source } -type MLPOpts struct { +type MLP struct { Activation Activation - Source rand.Source + *Model } func NewMLP(outSize []int, opts ...MLPOpts) *MLP { @@ -37,11 +37,7 @@ func NewMLP(outSize []int, opts ...MLPOpts) *MLP { return &MLP{ Activation: activation, - Model: Model{ - Layer: L.Layer{ - Layers: layers, - }, - }, + Model: NewModel(layers), } } diff --git a/model/model.go b/model/model.go index a910544..c6f69b1 100644 --- a/model/model.go +++ b/model/model.go @@ -10,6 +10,14 @@ type Model struct { L.Layer } +func NewModel(layers []*L.Layer) *Model { + return &Model{ + Layer: L.Layer{ + Layers: layers, + }, + } +} + func (m Model) graph(y *variable.Variable, opt ...dot.Opt) []string { out := make([]string, 0) for _, txt := range dot.Graph(y, opt...) {