mnist1d

package module
v0.0.0-...-8f4c99e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Replication of the MNIST1D dataset in 100% GO.

A 100% golang implementation of the MNIST1D dataset. https://github.com/greydanus/mnist1d

the test found in data/loader_test.go : TestLoadMNISTImageFileMatches loads the orginal pickle file (converted to JSON) and compares with the go generated version. These match including supporting the random seeds.

Usage

package main

include (
    "fmt"
    "github.com/mdcfrancis/mnist1d"
)

func main() {
    m := mnist1d.NewDefault()

    ds := m.MakeDataset()
    for i, x := range m.Templates.X {
        fmt.Println("Template", i)
        fmt.Println(mnist1d.ShowAsImage(x))
    }
	
    for i := 0; i < 2; i++ {
        fmt.Println(ds.y[i])
        fmt.Println(mnist1d.ShowAsImage(ds.x[i]))
        fmt.Println(ds.x[i])
    }
}

The code attempts to follow closely the code in the original repository so at times looks less 'go like'.

References

Data converted from the original repository pickle file

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShowAsImage

func ShowAsImage(m np.NpArray) string
Example
a := np.NpArray{0.0, 0.1, 0.3, 0.3, 0.1, 0.0}

fmt.Print(ShowAsImage(a))
Output:
....................X...................
......................X.................
..........................X.............
..........................X.............
......................X.................
....................X...................

Types

type DataSet

type DataSet struct {
	X         np.NpStack `json:"x"`
	X_TEST    np.NpStack `json:"x_test"`
	Y         np.NpArray `json:"y"`
	Y_TEST    np.NpArray `json:"y_test"`
	T         np.NpArray `json:"t"`
	Templates Templates  `json:"templates"`
}

type Mnist1D

type Mnist1D struct {
	NumSamples int     `json:"num_samples"`
	TrainSplit float64 `json:"train_split"`
	Seed       uint64  `json:"seed"`
	Url        string  `json:"url"`
	Templates  Templates
	transforms.Rules
}

func NewDefault

func NewDefault() Mnist1D

func (*Mnist1D) GetTemplates

func (m *Mnist1D) GetTemplates() Templates

func (Mnist1D) MakeDataset

func (m Mnist1D) MakeDataset() DataSet

func (Mnist1D) String

func (m Mnist1D) String() string
Example
m := NewDefault()
fmt.Println(m.String())
Output:
Mnist1D{NumSamples: 5000, TrainSplit: 0.8, TemplateLen: 12, Seed: 42, Url: https://github.com/greydanus/mnist1d/raw/master/mnist1d_data.pkl, Templates: Templates{X: [[0.00000000 0.23693955 0.35540933 0.41464421 0.47387910 0.47387910 0.47387910 0.47387910 0.41464421 0.35540933 0.23693955 0.00000000 ] [0.00000000 -0.36986336 -0.36986336 -0.29589069 -0.22191802 -0.14794534 -0.07397267 0.00000000 0.07397267 0.14794534 0.00000000 0.00000000 ] [0.00000000 0.15936381 0.23904572 0.23904572 0.15936381 0.03984095 -0.03984095 -0.15936381 -0.23904572 -0.23904572 -0.15936381 0.00000000 ] [0.00000000 0.26726124 0.40089186 0.40089186 0.26726124 0.00000000 0.00000000 0.26726124 0.40089186 0.40089186 0.26726124 0.00000000 ] [0.00000000 -0.10599979 -0.21199958 -0.31799936 -0.42399915 -0.42399915 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 ] [0.00000000 -0.24771245 -0.24771245 -0.24771245 -0.24771245 0.00000000 0.12385622 0.18578434 0.18578434 0.12385622 -0.06192811 0.00000000 ] [0.00000000 -0.23693955 -0.35540933 -0.41464421 -0.47387910 -0.47387910 -0.47387910 -0.47387910 -0.41464421 -0.35540933 -0.23693955 0.00000000 ] [0.00000000 0.36986336 0.36986336 0.29589069 0.22191802 0.14794534 0.07397267 0.00000000 -0.07397267 -0.14794534 0.00000000 0.00000000 ] [0.00000000 -0.26726124 -0.40089186 -0.40089186 -0.26726124 0.00000000 0.00000000 -0.26726124 -0.40089186 -0.40089186 -0.26726124 0.00000000 ] [0.00000000 -0.28583098 -0.42874646 -0.42874646 -0.28583098 0.00000000 0.00000000 0.00000000 0.00000000 -0.08574929 -0.20008168 0.00000000 ]], T: [-0.83333333 -0.68181818 -0.53030303 -0.37878788 -0.22727273 -0.07575758 0.07575758 0.22727273 0.37878788 0.53030303 0.68181818 0.83333333 ], Y: [0.00000000 1.00000000 2.00000000 3.00000000 4.00000000 5.00000000 6.00000000 7.00000000 8.00000000 9.00000000 ]}, Rules: Rules{Padding: [36 60], TemplateLen: 12, ScaleCoeff: 0.4, MaxTranslation: 48, CorrNoiseScale: 0.25, IidNoiseScale: 0.02, ShearScale: 0.75, ShuffleSeq: false, FinalSeqLength: 40}}

type Templates

type Templates struct {
	X []np.NpArray
	T np.NpArray
	Y np.NpArray
}

func (Templates) String

func (t Templates) String() string
Example
m := NewDefault()
fmt.Println(m.Templates.String())
Output:
Templates{X: [[0.00000000 0.23693955 0.35540933 0.41464421 0.47387910 0.47387910 0.47387910 0.47387910 0.41464421 0.35540933 0.23693955 0.00000000 ] [0.00000000 -0.36986336 -0.36986336 -0.29589069 -0.22191802 -0.14794534 -0.07397267 0.00000000 0.07397267 0.14794534 0.00000000 0.00000000 ] [0.00000000 0.15936381 0.23904572 0.23904572 0.15936381 0.03984095 -0.03984095 -0.15936381 -0.23904572 -0.23904572 -0.15936381 0.00000000 ] [0.00000000 0.26726124 0.40089186 0.40089186 0.26726124 0.00000000 0.00000000 0.26726124 0.40089186 0.40089186 0.26726124 0.00000000 ] [0.00000000 -0.10599979 -0.21199958 -0.31799936 -0.42399915 -0.42399915 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 ] [0.00000000 -0.24771245 -0.24771245 -0.24771245 -0.24771245 0.00000000 0.12385622 0.18578434 0.18578434 0.12385622 -0.06192811 0.00000000 ] [0.00000000 -0.23693955 -0.35540933 -0.41464421 -0.47387910 -0.47387910 -0.47387910 -0.47387910 -0.41464421 -0.35540933 -0.23693955 0.00000000 ] [0.00000000 0.36986336 0.36986336 0.29589069 0.22191802 0.14794534 0.07397267 0.00000000 -0.07397267 -0.14794534 0.00000000 0.00000000 ] [0.00000000 -0.26726124 -0.40089186 -0.40089186 -0.26726124 0.00000000 0.00000000 -0.26726124 -0.40089186 -0.40089186 -0.26726124 0.00000000 ] [0.00000000 -0.28583098 -0.42874646 -0.42874646 -0.28583098 0.00000000 0.00000000 0.00000000 0.00000000 -0.08574929 -0.20008168 0.00000000 ]], T: [-0.83333333 -0.68181818 -0.53030303 -0.37878788 -0.22727273 -0.07575758 0.07575758 0.22727273 0.37878788 0.53030303 0.68181818 0.83333333 ], Y: [0.00000000 1.00000000 2.00000000 3.00000000 4.00000000 5.00000000 6.00000000 7.00000000 8.00000000 9.00000000 ]}

Directories

Path Synopsis
_example
examine command
transforms command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL