forked from emer/emergent
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Randall C. O'Reilly
committed
Jun 2, 2021
1 parent
02ab07f
commit 6c1cf27
Showing
3 changed files
with
105 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Decoder | ||
|
||
The decoder package provides standalone decoders that can sample variables from `emer` network layers. | ||
|
||
# SoftMax | ||
|
||
The `SoftMax` decoder is the best choice for a 1-hot classification decoder. | ||
|
||
Call `Init` to initialize with number of categories and layers for input. | ||
|
||
Call `Decode` |
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,39 @@ | ||
// Copyright (c) 2021, The Emergent Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package decoder | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSoftMax(t *testing.T) { | ||
dec := SoftMax{} | ||
dec.Init(2, 2) | ||
dec.Lrate = .1 | ||
for i := 0; i < 100; i++ { | ||
trg := 0 | ||
if i%2 == 0 { | ||
dec.Inputs[0] = 1 | ||
dec.Inputs[1] = 0 | ||
} else { | ||
trg = 1 | ||
dec.Inputs[0] = 0 | ||
dec.Inputs[1] = 1 | ||
} | ||
dec.Forward() | ||
dec.Sort() | ||
// fmt.Printf("%d\t%d\t%v", i, trg, dec.Sorted) | ||
// for j := 0; j < 2; j++ { | ||
// fmt.Printf("\t%g", dec.Units[j].Act) | ||
// } | ||
// fmt.Printf("\n") | ||
if i > 2 { | ||
if dec.Sorted[0] != trg { | ||
t.Errorf("err: %d\t%d\t%v\n", i, trg, dec.Sorted) | ||
} | ||
} | ||
dec.Train(trg) | ||
} | ||
} |