flare.model

-TestPModel

protocol

only for testing with models

members

fix-param!

(fix-param! this param-name value)

add-params!

(add-params! model shape & {:keys [name init]})

Add parameters of givne shape to model. Accepts some options * :name String name for parameter for inspection later * :init a map satisfying InitParamSpec for distribution of how to sample values

from-data!

(from-data! model is)

Load parameters from InputStream (e.g, File). Mutates underlying values, will throw if parameter-name doesn’t exist in model, so need to construct model same as when trained.

from-doubles!

(from-doubles! model xs)

Flatten parameters into a single vector and writes to each parameter group tensor :value

get-param-rng

multimethod

PModel

protocol

A model is effectively a paramaeter collection that holds graph nodes representing parameter groups.

By convention, any implementation should be seqable and return a sequence of [param-name, param-node] pairs for the model

members

-add-param-metadata!

(-add-param-metadata! this param-name key val)

add meta-data [key, val] pair to the node for the given param-name node. Useful for storing optimization data. Internal method due to some parameter defaulting.

-add-params!

(-add-params! this param-name shape init-spec)

add parameters to the model (mutably), returns a param graph node. Some argument defaulting happens below so this is the internal method, use add-params! as the entry point

canonical-node

(canonical-node this param-name)

returns a caonical Node for the parameter (meaning it stores the “true” value/gradient for for the parameters).

tensor-factory

(tensor-factory this)

return the underlying tensor factory (PTensorFactory) for the model

rand-params!

(rand-params! model)

using the initialziation spec for each param group, generate a fresh setting of the parameters

simple-param-collection

(simple-param-collection)(simple-param-collection factory)

Simple collection of parameters NOTE: The meta-data of the param-collection gives you access to the underlying data. Don’t use it except for an emergency!

to-data!

(to-data! model os)

Write parameters to OutputStream

to-doubles

(to-doubles model)(to-doubles model key)

Flatten parameters into a single JVM double array. Can take either parameter values or current gradient, depending on key

total-num-params

(total-num-params model)

with-metadata!

(with-metadata! model param-node-or-name key value)

add a key-value pair to the metadata on the underlying parameter node. As name implies, param-node-or-name can be either current canonical node or the Node.ref-name for the parameter group.