Documentation ¶
Overview ¶
Package mlpx implements public API for the HeRC MLPX file format.
See MLPX(4) for the complete format specification.
Index ¶
- type Layer
- type MLPX
- func (mlp *MLPX) MakeIsomorphicSnapshot(id, to string) error
- func (mlp *MLPX) MakeSnapshot(id string) error
- func (mlp *MLPX) MustMakeIsomorphicSnapshot(id, to string)
- func (mlp *MLPX) MustMakeSnapshot(id string)
- func (mlp *MLPX) SortedSnapshotIDs() []string
- func (mlp *MLPX) ToJSON() ([]byte, error)
- func (mlp *MLPX) Validate() error
- func (mlp *MLPX) Version() (int, error)
- func (mlp *MLPX) WriteJSON(path string) error
- type Snapshot
- func (snapshot *Snapshot) MakeLayer(id string, neurons int, pred, succ string) error
- func (snapshot *Snapshot) MustMakeLayer(id string, neurons int, pred, succ string)
- func (snapshot *Snapshot) Predecessor(id string) (*Snapshot, error)
- func (snapshot *Snapshot) SortedLayerIDs() []string
- func (snapshot *Snapshot) Successor(id string) (*Snapshot, error)
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 ¶
FromJSON reads an in-memory JSON string and generates an MLPX object. It does not validate the data which is read.
func ReadJSON ¶
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 ¶
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 ¶
MakeSnapshot creates a new, empty snapshot in the given MLPX object
func (*MLPX) MustMakeIsomorphicSnapshot ¶
MustMakeIsomorphicSnapshot is a wrapper around MakeIsomorphicSnapshot that calls panic() if it errors.
func (*MLPX) MustMakeSnapshot ¶
MustMakeSnapshot is a wrapper around MakeSnapshot which errors if it fails
func (*MLPX) SortedSnapshotIDs ¶
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) Validate ¶
Validate checks the MLPX file for any errors. If none are found, it returns nil.
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 ¶
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 ¶
MustMakeLayer is a wrapper around MakeLayer which panics if it encounters an error.
func (*Snapshot) Predecessor ¶
GetPredecessor returns the predecessor of a given snapshot, being the snapshot which occurs next after the specified one.
func (*Snapshot) SortedLayerIDs ¶
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.