Contents
PolyGeniusWeightStore
A minimal in-memory per-model weight-column store
One (dict.slot, beta) pair-vector per absorbed model, indexed by model.slot -- a model's
position in PolyGeniusBackbone's own $registry, assigned in absorb order. In-memory
only, and deliberately not an out-of-core block store, since nothing today asks a weight store
to hold more than fits in RAM. It exists so PGSLibraryView's materialization has
somewhere to read a model's beta from; an out-of-core version would replace the storage
underneath, not the $get() read contract.
A backbone owns exactly one store, reached as backbone$weights. $add(dict.slot, beta)
appends a model's column and returns its model.slot; $get(model.slot) returns
list(dict.slot, beta), row-aligned.
Methods
Public methods
PolyGeniusWeightStore.class$new()PolyGeniusWeightStore.class$n.models()PolyGeniusWeightStore.class$add()PolyGeniusWeightStore.class$get()PolyGeniusWeightStore.class$set.beta()PolyGeniusWeightStore.class$remap()PolyGeniusWeightStore.class$clone()
Method new()
Create an empty store.
Usage
PolyGeniusWeightStore.class$new()
Method n.models()
Number of model columns currently stored.
Usage
PolyGeniusWeightStore.class$n.models()
Returns
An integer scalar.
Method add()
Append one model's weight column. Rows are kept in the order add() is
called with, including within-model duplicate dict.slot values, so storing a model
never changes its nrow. A duplicate is resolved when the model is built (PGS()) or
scored, never here.
add() itself promises nothing about row order. In practice its only caller,
PolyGeniusBackbone.class$absorb(), always passes rows already sorted ascending in
dict.rank, and owns that invariant; re-establishing it here would be redundant.
Usage
PolyGeniusWeightStore.class$add(dict.slot, beta)
Arguments
dict.slot — Integer vector, one dictionary row position per model row.
beta — Double vector, the same length, aligned to dict.slot.
Returns
The assigned model.slot (integer), invisibly.
Method get()
Read one model's stored column.
Usage
PolyGeniusWeightStore.class$get(model.slot)
Arguments
model.slot — Integer scalar, the 1-based position add() assigned.
Returns
list(dict.slot, beta), row-aligned.
Method set.beta()
Replace one model's stored beta vector in place, leaving its dict.slot
vector untouched. The only sanctioned write to a weight column after absorb(), and the
reason it takes no dict.slot argument: a caller cannot repoint or reorder a model's
rows through it, so the dict.rank-sorted row order established once at absorb() time
survives by construction rather than by a check.
beta is positionally aligned with the stored rows -- the order
variants.for() emits them in -- so an elementwise expression over that table lands on
the variant it was computed from. A reordering expression re-points every weight, which
is a legitimate thing to ask for and is not second-guessed here.
Does not touch the owning backbone's $fingerprint, which covers variant identity and
layout and deliberately never the weights.
Usage
PolyGeniusWeightStore.class$set.beta(model.slot, beta)
Arguments
model.slot — Integer scalar, the 1-based position add() assigned.
beta — Double vector, exactly as long as this model's stored dict.slot.
Returns
self, invisibly.
Method remap()
Remap every stored column's dict.slot values through a lookup table, in
place, and re-sort each column by its new dict.slot. Called by
PolyGeniusBackbone's rank.slots() when it renumbers the dictionary into rank
order, so a model's weight column keeps pointing at the right variant and afterwards
reads ascending in the now-identity dict.rank (the invariant the score path needs,
SCO-2). Safe unconditionally, unlike rank.slots()'s own held-guarded refusal: the
store is data the backbone owns outright, not an external reference it cannot fix up.
Hands back the row permutation it applied to each column, because a model's weight rows
are not the only thing aligned to them: $columns$model holds one row per weight row,
and re-deriving the same order() there would be a second implementation of this
ordering, free to disagree with this one.
Usage
PolyGeniusWeightStore.class$remap(old.to.new)
Arguments
old.to.new — Integer vector: old.to.new[old.slot] is that row's new position.
Returns
A list, one integer permutation per model.slot, invisibly.
Method clone()
The objects of this class are cloneable with this method.
Usage
PolyGeniusWeightStore.class$clone(deep = FALSE)
Arguments
deep — Whether to make a deep clone.
See Also
Other pgs-objects:
PGS(),
PGSLibrary(),
PGSLibraryView,
PolyGeniusBackbone()