Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Network.RecursiveSteps() and related test cases. #55

Merged
merged 1 commit into from
Jun 21, 2022
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
6 changes: 5 additions & 1 deletion neat/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@ func (n *Network) ForwardSteps(steps int) (res bool, err error) {
}

func (n *Network) RecursiveSteps() (bool, error) {
return false, errors.New("RecursiveSteps is not implemented")
netDepth, err := n.MaxActivationDepthFast(0)
if err != nil {
return false, err
}
return n.ForwardSteps(netDepth)
}

func (n *Network) Relax(_ int, _ float64) (bool, error) {
Expand Down
20 changes: 20 additions & 0 deletions neat/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,32 @@ func TestNetwork_ForwardSteps(t *testing.T) {
assert.NoError(t, err)
assert.True(t, res)

expectedOuts := []float64{1.0, 1.0}
assert.EqualValues(t, expectedOuts, net.ReadOutputs())

// test zero steps
res, err = net.ForwardSteps(0)
assert.EqualError(t, err, ErrZeroActivationStepsRequested.Error())
assert.False(t, res)
}

func TestNetwork_RecursiveSteps(t *testing.T) {
net := buildNetwork()

data := []float64{0.5, 0.0, 1.5}
err := net.LoadSensors(data)
require.NoError(t, err, "failed to load sensors")

relaxed, err := net.RecursiveSteps()
assert.NoError(t, err)
assert.True(t, relaxed)

logNetworkActivationPath(net, t)

expectedOuts := []float64{1.0, 1.0}
assert.EqualValues(t, expectedOuts, net.ReadOutputs())
}

func TestNetwork_ForwardSteps_disconnected(t *testing.T) {
net := buildDisconnectedNetwork()

Expand Down