mlpx

package
Version: v0.0.0-...-c486111 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package mlpx implements public API for the HeRC MLPX file format.

See MLPX(4) for the complete format specification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Layer

type Layer struct {
	// Parent is the Snapshot object which the layer belongs to.
	//
	// DANGER: modify this field with care, changing this may corrupt
	// the in-memory representation of the MLP.
	Parent *Snapshot `json:"-"`

	// ID is the layer ID
	//
	// DANGER: modify this field with care, changing this may corrupt the
	// in-memory representation of the MLP.
	ID string `json:"-"`

	// Predecessor is the preceding layer ID
	Predecessor string `json: "predecessor"`

	// Successor is the following layer ID
	Successor string `json: "successor"`

	// Neurons is the number of neurons in the layer
	Neurons int `json: "neurons"`

	// Weights is the weights list for the layers
	Weights *[]float64 `json: "weights"`

	// Outputs is the outputs list for the layer
	Outputs *[]float64 `json: "outputs"`

	// Activations is the activation value list for the layer
	Activations *[]float64 `json: "activations"`

	// Deltas is the deltas list for the layer
	Deltas *[]float64 `json: "deltas"`

	// Biases is the biases list for the layer
	Biases *[]float64 `json: "biases"`

	// ActivationFunction is the human-readable activation function used by
	// the layer
	ActivationFunction string `json: "activation_function"`
}

Layer represents a single layer definition

type MLPX

type MLPX struct {

	// Schema is used to represent the schema key
	//
	// Caveat: because of how encoding/json works, the version level
	// is usually encoded as a float64.
	Schema []interface{} `json: "schema"`

	// Snapshots is used to represent the snapshot table.
	Snapshots map[string]*Snapshot `json:"snapshots"`
}

MLPX represents an entire MLPX file

func FromJSON

func FromJSON(data []byte) (*MLPX, error)

FromJSON reads an in-memory JSON string and generates an MLPX object. It does not validate the data which is read.

func MakeMLPX

func MakeMLPX() *MLPX

MakeMLPX creates a new, empty MLPX object

func ReadJSON

func ReadJSON(path string) (*MLPX, error)

ReadJSON is a utility function which reads a file from disk, then calls FromJSON() on it. It does not validate the MLPX file.

func (*MLPX) MakeIsomorphicSnapshot

func (mlp *MLPX) MakeIsomorphicSnapshot(id, to string) error

MakeIsomorphicSnapshot will create a new snapshot which is topologically identical to the one specified. This is the preferred way of creating snapshots, once the first has been defined, to guarantee that all snapshots are isomorphic, which the spec requires.

func (*MLPX) MakeSnapshot

func (mlp *MLPX) MakeSnapshot(id string) error

MakeSnapshot creates a new, empty snapshot in the given MLPX object

func (*MLPX) MustMakeIsomorphicSnapshot

func (mlp *MLPX) MustMakeIsomorphicSnapshot(id, to string)

MustMakeIsomorphicSnapshot is a wrapper around MakeIsomorphicSnapshot that calls panic() if it errors.

func (*MLPX) MustMakeSnapshot

func (mlp *MLPX) MustMakeSnapshot(id string)

MustMakeSnapshot is a wrapper around MakeSnapshot which errors if it fails

func (*MLPX) SortedSnapshotIDs

func (mlp *MLPX) SortedSnapshotIDs() []string

SortedSnapshotIDs returns the list of snapshot IDs, sorted in the canonical order for MLPX. That is, the "initializer" snapshot sorts before everything else, and numeric snapshot IDs are sorted by numeric value, rather than by string comparison"

func (*MLPX) ToJSON

func (mlp *MLPX) ToJSON() ([]byte, error)

ToJSON converts an existing MLPX object to a JSON string and returns it.

func (*MLPX) Validate

func (mlp *MLPX) Validate() error

Validate checks the MLPX file for any errors. If none are found, it returns nil.

func (*MLPX) Version

func (mlp *MLPX) Version() (int, error)

Version retrieves the MLPX schema version of the given file. It can error if the schema has the wrong number of components, if the schema is not "mlpx", or if the schema version is not an integer.

If an error occurs, then the integer version level returned is undefined.

func (*MLPX) WriteJSON

func (mlp *MLPX) WriteJSON(path string) error

WriteJSON calls ToJSON() and then overwrites the specified path with it's return.

type Snapshot

type Snapshot struct {

	// Parent is the MLPX object which this snapshot belongs to.
	//
	// DANGER: modify this field with care, changing this may corrupt the
	// in-memory representation of the MLP.
	Parent *MLPX `json:"-"`

	// ID is the snapshot ID
	//
	// DANGER: modify this field with care, changing this may corrupt the
	// in-memory representation of the MLP.
	ID string `json:"-"`

	// Layers is the list of layers in the snapshot.
	Layers map[string]*Layer `json: "layers"`
}

Snapshot represents a single snapshot definition

func (*Snapshot) MakeLayer

func (snapshot *Snapshot) MakeLayer(id string, neurons int, pred, succ string) error

MakeLayer creates a new layer attached to the given snapshot. Where appropriate (input/output layers), pred or succ may be empty strings.

Note that referential integrity of pred and succ IS NOT VERIFIED at this stage, since either or both referenced layers may not exist yet.

func (*Snapshot) MustMakeLayer

func (snapshot *Snapshot) MustMakeLayer(id string, neurons int, pred, succ string)

MustMakeLayer is a wrapper around MakeLayer which panics if it encounters an error.

func (*Snapshot) Predecessor

func (snapshot *Snapshot) Predecessor(id string) (*Snapshot, error)

GetPredecessor returns the predecessor of a given snapshot, being the snapshot which occurs next after the specified one.

func (*Snapshot) SortedLayerIDs

func (snapshot *Snapshot) SortedLayerIDs() []string

SortedLayerIDs returns a list of layer IDs in sorted order. IDs are sorted by their topology.

If the MLPX is invalid, then the behavior of this function is undefined. In particular, cycles are not valid in MLPX, and may cause unusual behavior.

func (*Snapshot) Successor

func (snapshot *Snapshot) Successor(id string) (*Snapshot, error)

GetSuccessor returns the successor of a given snapshot, being the snapshot which occurs next after the specified one.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL