Model
NonArchimedeanMachineLearning.AbstractModel — Type
AbstractModel{S}A model structure that captures the underlying function and parameter/variable mapping.
Represents a model without specified parameter values. Encodes which variables in the function are data variables (inputs) versus parameters (to be optimized). This separation allows the loss and optimization machinery to work correctly.
Fields
fun::PolydiscFunction{S}: The underlying function (e.g., sum of absolute polynomials)param_info: Boolean vector whereparam_info[i] = truemeans variable $i$ is a data variable, andparam_info[i] = falsemeans variable $i$ is a parameter
Type Parameters
S: The coefficient type (typically p-adic numbers likePadicFieldElem)
Example
For a function $f(x_1, \theta_1, x_2, \theta_2)$ with data variables $x_1, x_2$ and parameters $\theta_1, \theta_2$, use param_info = [true, false, true, false].
Notes
Variables are ordered as they appear in the polynomial ring. Use var_indices and param_indices to extract the positions of data variables and parameters respectively.
NonArchimedeanMachineLearning.Model — Type
Model{FS,PS,T,N}A complete model with specified parameter values.
Combines an abstract model (function and parameter mapping) with concrete current parameter values. The structure is mutable to allow parameters to be updated during optimization.
Fields
fun::AbstractModel{FS}: The abstract model encoding the function structure and parameter layoutparam::ValuationPolydisc{PS,T,N}: The current parameter values in polydisc space
Type Parameters
FS: The scalar type expected by the underlying functionPS: The scalar type stored in the parameter polydiscT: The type for radius/valuation values (typicallyInt)N: The dimension of the parameter space
Example
# Create a model for f(x, θ) where x is data and θ is parameter
f = AbstractModel(polynomial_function, [true, false])
params = ValuationPolydisc([K(1), K(2)], [0, 0]) # θ = (1, 2)
model = Model(f, params)Notes
Models are mutable so that optimization algorithms can update param in place. Use update_weights! to modify parameter values.
NonArchimedeanMachineLearning.ModelEvaluator — Type
ModelEvaluator{FS,PS,T,N1,N2,E}Typed evaluator for AbstractModel.
Combines the model structure with a typed function evaluator for efficient computation with full compile-time type information.
Type Parameters
FS: Function coefficient typePS: Parameter coefficient type (may differ from FS due to ValuedFieldPoint wrapping)T: Radius typeN1: Dimension of data polydiscN2: Dimension of parameter polydiscE: Type of the underlying function evaluator
Fields
model::AbstractModel{FS}: The abstract modelfun_eval::E: Typed evaluator for the underlying function
NonArchimedeanMachineLearning.batch_evaluate_init — Method
batch_evaluate_init(m::AbstractModel{S})Initialize a batch evaluation function for an abstract model.
Returns a closure that evaluates the model at given data and parameter values. The returned function accepts two arguments: data and parameters (as vectors of polydiscs).
Arguments
m::AbstractModel{S}: The abstract model
Returns
Function: A closure (data::ValuationPolydisc, param::ValuationPolydisc) -> Float64 that can be applied to evaluate the model
Notes
This function creates an evaluation closure that is optimized for batch operations. It interleaves data and parameter values according to the model's variable layout.
NonArchimedeanMachineLearning.batch_evaluate_init — Method
batch_evaluate_init(m::Model{FS,PS,T,N})Initialize a batch evaluation function for a model with stored parameters.
Returns a closure that evaluates the model at given data values using the model's stored parameter values. The returned function accepts a single argument: data (polydisc).
Arguments
m::Model{FS,PS,T,N}: The model (containing stored parameters)
Returns
Function: A closure (data::ValuationPolydisc) -> Float64 that evaluates the model at the given data using the stored parameters
Notes
This is a convenience wrapper around batch_evaluate_init(::AbstractModel) that captures the model's current parameters in the closure.
NonArchimedeanMachineLearning.batch_evaluate_init — Method
batch_evaluate_init(m::AbstractModel{S}, ::Type{ValuationPolydisc{ValuedFieldPoint{P,Prec,S},T,N}}) where {S,P,Prec,T,N}Lifting evaluator: when the model uses type S but data uses ValuedFieldPoint{P,Prec,S}, eagerly lift the function to ValuedFieldPoint at evaluator creation time.
This avoids runtime type conversion on every evaluation call. The function-level batch_evaluate_init methods handle the coefficient lifting (e.g. converting LinearPolynomial{S} coefficients to ValuedFieldPoint{P,Prec,S}).
NonArchimedeanMachineLearning.batch_evaluate_init — Method
batch_evaluate_init(m::AbstractModel{S}, ::Type{ValuationPolydisc{S,T,N}}) where {S,T,N}Create a typed evaluator for an AbstractModel.
NEW TYPED INTERFACE: Returns a ModelEvaluator struct instead of a closure.
Arguments
m::AbstractModel{S}: The abstract model::Type{ValuationPolydisc{S,T,N}}: The full variable polydisc type (data + parameters combined)
Returns
ModelEvaluator: A typed evaluator callable as eval(data_polydisc, param_polydisc)
Example
model = AbstractModel(fun, param_info)
# Determine full dimension (data_dim + param_dim)
eval = batch_evaluate_init(model, ValuationPolydisc{S,T,FullDim})
result = eval(data_polydisc, param_polydisc)NonArchimedeanMachineLearning.evaluate — Method
evaluate(m::AbstractModel, val, param)Evaluate an abstract model at given data and parameter values.
Constructs the full variable point by interleaving data and parameters, then evaluates the underlying function.
Arguments
m::AbstractModel: The abstract modelval: Data variable values (typically aValuationPolydisc)param: Parameter values (typically aValuationPolydisc)
Returns
The evaluated function value (typically a Float64 for absolute polynomial sums)
Notes
Current implementation is specific to absolute polynomial sums. Will need updates for more general polydisc functions.
NonArchimedeanMachineLearning.evaluate — Method
evaluate(m::Model, val)Evaluate a model at given data using the model's stored parameters.
Convenience wrapper that uses the model's current parameter values.
Arguments
m::Model: The model (containing stored parameters)val: Data variable values (typically aValuationPolydisc)
Returns
The evaluated function value (typically a Float64 for absolute polynomial sums)
See Also
evaluate(::AbstractModel, val, param): The underlying function with explicit parameters
NonArchimedeanMachineLearning.getkeys — Method
getkeys(m::AbstractModel)Map each model variable to its position within data variables or parameters.
For each variable in the model, returns its index within either the data variables or the parameters, depending on its type.
Arguments
m::AbstractModel: The abstract model
Returns
Vector{Int}: Array $[a_1, \ldots, a_n]$ where $a_i$ is the index of the $i$-th variable within its category (data or parameter)
Example
For $f(x, \theta, y, z, \phi)$ with parameters $\theta, \phi$, returns [1, 1, 2, 3, 2] since $x$ is the 1st data variable, $\theta$ is the 1st parameter, $y$ is the 2nd data variable, $z$ is the 3rd data variable, and $\phi$ is the 2nd parameter.
NonArchimedeanMachineLearning.param_indices — Method
param_indices(m::AbstractModel)Get the indices of parameters in an abstract model.
Arguments
m::AbstractModel: The abstract model
Returns
Vector{Int}: Indices where param_info is false (parameters)
Example
For param_info = [true, true, false, false], returns [3, 4]
NonArchimedeanMachineLearning.set_abstract_model_variable — Method
set_abstract_model_variable(m::AbstractModel{S}, val::ValuationPolydisc{S,T,N1}, param::ValuationPolydisc{S,T,N2}) where {S,T,N1,N2}Construct a polydisc by interleaving data and parameter values according to the model layout.
Given data variable values and parameter values, constructs a polydisc point in the full model variable space that can be evaluated using polynomial evaluation mechanisms.
Arguments
m::AbstractModel{S}: The abstract model defining the variable layout viaparam_infoval::ValuationPolydisc{S,T,N1}: The data variable values (polydisc in data space)param::ValuationPolydisc{S,T,N2}: The parameter values (polydisc in parameter space)
Returns
ValuationPolydisc{S,T,N}: A polydisc point with all variables interleaved in model order
Example
For model $f(x, \theta, y, \phi)$ with param_info = [true, false, true, false]:
- Data inputs:
(x, y) = (1, 2)→val = ValuationPolydisc([K(1), K(2)], [r_x, r_y]) - Parameters:
(\theta, \phi) = (3, 4)→param = ValuationPolydisc([K(3), K(4)], [r_θ, r_φ]) - Returns:
ValuationPolydisc([K(1), K(3), K(2), K(4)], [r_x, r_θ, r_y, r_φ])
Notes
The returned polydisc has the same dimension as the original polynomial ring and can be directly passed to polynomial evaluation functions.
NonArchimedeanMachineLearning.set_model_variable — Method
set_model_variable(m::Model{FS,PS,T,N}, val::ValuationPolydisc{S,T,M}) where {FS,PS,S,T,N,M}Construct an evaluation point using a model's stored parameter values and given data.
Convenience wrapper around set_abstract_model_variable that uses the model's current parameter values rather than requiring them as an argument.
Arguments
m::Model{FS,PS,T,N}: The model (containing stored parameters)val::ValuationPolydisc{S,T,M}: The data variable values
Returns
A polydisc point with all variables interleaved in model order
See Also
set_abstract_model_variable: The underlying function with explicit parameters
NonArchimedeanMachineLearning.specialise — Method
specialise(f::AbsolutePolynomialSum{S}, param_info, val::Vector{S})::AbsolutePolynomialSum{S} where SSpecialize an AbsolutePolynomialSum by substituting data variable values.
Creates a new polynomial ring with only parameter variables and applies polynomial ring homomorphisms to substitute data values into each polynomial.
Arguments
f::AbsolutePolynomialSum{S}: The polynomial sum to specializeparam_info: Boolean vector indicating variable typesval::Vector{S}: Values to substitute for data variables
Returns
AbsolutePolynomialSum{S}: A polynomial sum depending only on parameters
Implementation Details
Uses ring homomorphisms to correctly substitute values while maintaining the polynomial structure in the new parameter-only ring.
NonArchimedeanMachineLearning.specialise — Method
specialise(m::AbstractModel{S}, data::Vector{Vector{S}})::PolydiscFunction{S} where SSpecialize a model at multiple data points and combine the results.
Specializes the model at each data point separately, then combines all specialized polynomials into a single function. This is useful for constructing batch loss functions.
Arguments
m::AbstractModel{S}: The abstract modeldata::Vector{Vector{S}}: Data points at which to specialize the model
Returns
PolydiscFunction{S}: A combined polydisc function with all specializations
Implementation Notes
Concatenates polynomial vectors from each specialization. Supports AbsolutePolynomialSum and LinearAbsolutePolynomialSum types.
NonArchimedeanMachineLearning.specialise — Method
specialise(m::AbstractModel{S}, val::Vector{S})::PolydiscFunction{S} where SSpecialize a model by substituting data variable values.
Removes data variables from the model by substituting given values, returning a function that depends only on parameters. This is used for computational efficiency when the data is fixed.
Arguments
m::AbstractModel{S}: The abstract modelval::Vector{S}: Values to substitute for data variables (length = number of data variables)
Returns
PolydiscFunction{S}: A specialized polydisc function depending only on parameters
Implementation Notes
Dispatches to type-specific implementations based on the function type (AbsolutePolynomialSum or LinearAbsolutePolynomialSum).
Errors
Raises an error if the model function type is not supported.
Example
For a model with data variables x, y and parameters θ, φ:
- Original: $f(x, \theta, y, \phi)$
- After specialization with
val = [x_0, y_0]: $f_specialized(\theta, \phi)$
NonArchimedeanMachineLearning.specialise — Method
specialise(f::LinearAbsolutePolynomialSum{S}, param_info, val::Vector{S})::LinearAbsolutePolynomialSum{S} where SSpecialize a LinearAbsolutePolynomialSum by substituting data variable values.
Applies specialization to each linear polynomial in the sum.
Arguments
f::LinearAbsolutePolynomialSum{S}: The linear polynomial sum to specializeparam_info: Boolean vector indicating variable typesval::Vector{S}: Values to substitute for data variables
Returns
LinearAbsolutePolynomialSum{S}: A linear polynomial sum depending only on parameters
NonArchimedeanMachineLearning.specialise — Method
specialise(poly::LinearPolynomial{S}, param_info, val::Vector{S})::LinearPolynomial{S} where SSpecialize a single LinearPolynomial by substituting data variable values.
For a linear polynomial $a_1 T_1 + \cdots + a_n T_n + b$, removes data variables by:
- Computing their contribution to the constant term
- Keeping only the coefficients for parameters
Arguments
poly::LinearPolynomial{S}: The linear polynomial to specializeparam_info: Boolean vector indicating variable typesval::Vector{S}: Values to substitute for data variables
Returns
LinearPolynomial{S}: A linear polynomial depending only on parameters
Example
For $3x + 2\theta + 5y + 1$ with x, y as data and \theta as parameter:
- Substitute
x=1, y=2: $3(1) + 2\theta + 5(2) + 1 = 2\theta + 14$ - Returns:
LinearPolynomial([2], 14)
NonArchimedeanMachineLearning.update_weights! — Method
update_weights!(m::Model, param)Update the parameter values of a model in place.
Arguments
m::Model: The model to updateparam: New parameter values
Notes
Mutates the model structure directly since Model is mutable.
NonArchimedeanMachineLearning.var_indices — Method
var_indices(m::AbstractModel)Get the indices of data variables in an abstract model.
Arguments
m::AbstractModel: The abstract model
Returns
Vector{Int}: Indices where param_info is true (data variables)
Example
For param_info = [true, true, false, false], returns [1, 2]