File: softmax_test.go

package info (click to toggle)
golang-github-montanaflynn-stats 0.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 460 kB
  • sloc: makefile: 27
file content (43 lines) | stat: -rw-r--r-- 783 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package stats_test

import (
	"fmt"
	"testing"

	"github.com/montanaflynn/stats"
)

func ExampleSoftMax() {
	sm, _ := stats.SoftMax([]float64{3.0, 1.0, 0.2})
	fmt.Println(sm)
	// Output: [0.8360188027814407 0.11314284146556013 0.05083835575299916]
}

func TestSoftMaxEmptyInput(t *testing.T) {
	_, err := stats.SoftMax([]float64{})
	if err != stats.EmptyInputErr {
		t.Errorf("Should have returned empty input error")
	}
}

func TestSoftMax(t *testing.T) {
	sm, err := stats.SoftMax([]float64{3.0, 1.0, 0.2})
	if err != nil {
		t.Error(err)
	}

	a := 0.8360188027814407
	if sm[0] != a {
		t.Errorf("%v != %v", sm[0], a)
	}

	a = 0.11314284146556013
	if sm[1] != a {
		t.Errorf("%v != %v", sm[1], a)
	}

	a = 0.05083835575299916
	if sm[2] != a {
		t.Errorf("%v != %v", sm[1], a)
	}
}