Summary
Add a VectorElement<D extends Real> class to beast.base.spec.inference.parameter that presents a single element of a RealVector<D> as a RealScalar<D>.
This is a fundamental operation on the spec type system: wherever a RealScalar is required (e.g., SiteModel.mutationRate), a VectorElement can provide a scalar view into an element of a vector parameter.
Motivation
In LPhyBeast, when a vector parameter (e.g., mutation rates from WeightedDirichlet) needs to be split across multiple consumers (e.g., per-partition SiteModel), the current approach creates individual RealParameter state nodes and joins them with feast's Concatenate. This is backwards — it builds parts then reassembles them.
With VectorElement, the natural approach is:
- Create a single
RealVectorParam as the state node
- Use
VectorElement to extract scalar views where needed
This eliminates the need for Concatenate in converters and replaces the old beastlabs.core.util.Slice (which doesn't exist in beast3) with a strongly-typed equivalent.
Proposed API
package beast.base.spec.inference.parameter;
@Description("Scalar view of a single element in a RealVector")
public class VectorElement<D extends Real> extends CalculationNode implements RealScalar<D> {
Input<RealVector<?>> vectorInput; // wildcard required by BEAST's Input reflection
Input<Integer> indexInput; // index of the element
double get(); // delegates to vector.get(index)
D getDomain(); // delegates to vector.getDomain() (unchecked cast, safe via typed constructor)
}
Note: the vectorInput uses RealVector<?> rather than RealVector<D> because BEAST's Input.determineClass() cannot resolve type variables via reflection. The domain type safety is preserved through the typed constructor VectorElement(RealVector<D>, int).
Example XML
<stateNode id="r" spec="spec.inference.parameter.RealVectorParam"
domain="PositiveReal" value="0.33 0.33 0.33"/>
<mutationRate id="r_0" spec="spec.inference.parameter.VectorElement"
vector="@r" index="0"/>
<mutationRate id="r_1" spec="spec.inference.parameter.VectorElement"
vector="@r" index="1"/>
Summary
Add a
VectorElement<D extends Real>class tobeast.base.spec.inference.parameterthat presents a single element of aRealVector<D>as aRealScalar<D>.This is a fundamental operation on the spec type system: wherever a
RealScalaris required (e.g.,SiteModel.mutationRate), aVectorElementcan provide a scalar view into an element of a vector parameter.Motivation
In LPhyBeast, when a vector parameter (e.g., mutation rates from
WeightedDirichlet) needs to be split across multiple consumers (e.g., per-partitionSiteModel), the current approach creates individualRealParameterstate nodes and joins them with feast'sConcatenate. This is backwards — it builds parts then reassembles them.With
VectorElement, the natural approach is:RealVectorParamas the state nodeVectorElementto extract scalar views where neededThis eliminates the need for
Concatenatein converters and replaces the oldbeastlabs.core.util.Slice(which doesn't exist in beast3) with a strongly-typed equivalent.Proposed API
Note: the
vectorInputusesRealVector<?>rather thanRealVector<D>because BEAST'sInput.determineClass()cannot resolve type variables via reflection. The domain type safety is preserved through the typed constructorVectorElement(RealVector<D>, int).Example XML