HMath.MachineLearning.Internal¶
Module index · Numerical conventions
Description
Shared, deliberately small dense reference kernels for the ML estimators.
On this page¶
| API | Purpose |
|---|---|
| Dataset | Finite observations as rows with a fixed, positive feature count. |
| MLConfig | Positive iteration limittolerancerate and an explicit reproducible seed. |
| MLConfig | Declaration and type contract below. |
| mlIterations | Maximum outer iterations per fitted algorithm. |
| mlTolerance | Absolute algorithm-specific stopping residual. |
| mlRate | Positive gradient step size, where used. |
| mlSeed | Seed for initialization, projection, or stochastic updates. |
| defaultMLConfig | 500 iterations, absolute residual tolerance 1e-8, rate 0.05, PCG seed 42. |
| Fit | A finite budget is a valid stopping point, distinct from convergence. |
| Fit | Declaration and type contract below. |
| fitted | Best fitted model retained when fitting stops. |
| fitIterations | Completed fitting iterations. |
| fitResidual | Algorithm-specific finite stopping residual at the returned model. |
| fitConverged | Whether the selected stopping residual met tolerance; a budget stop may return False. |
| finite | Test whether Double is neither NaN nor infinite. |
| checked | Validate a list of finite numerical values, returning Right () or Left NonFiniteResult. |
| require | Given condition then diagnostic, return Right () or Left InvalidArgument prefixed with ML context. |
| config | Validate positive iteration count and positive finite tolerance/learning rate of MLConfig. |
| dataset | Validate a nonempty finite rectangular observation-by-feature list with positive feature count and Int-safe size. |
| responses | Given dataset then finite response list, validate dataset and equal observationresponse count. |
| queries | Given expected feature dimension then query rows, validate every row width and finite values. |
| dot | Unchecked list inner product using zipWith; unequal lengths truncate. |
| add | Unchecked coordinatewise list addition, truncating to shorter length; checked estimator callers validate dimensions. |
| sub | Unchecked coordinatewise left-minus-right list subtraction, truncating to shorter length. |
| scale | Given scalar then coordinate list, multiply each coordinate without checked finiteness validation. |
| norm | Return scaled Euclidean norm of a coordinate list, zero for empty/all-zero input. |
| dist2 | Return squared Euclidean distance using sub and dot. |
| meanV | Return per-feature means for a nonempty equal-width dataset. |
| matmul | Unchecked dense row-list matrix multiplication via row/column dot products. |
| ident | Return n-by-n Double identity rows for a nonnegative dimension; nonpositive n gives []. |
| replace | Given index,new value,then list, replace by take/drop reconstruction. |
| matrix | Validate dataset then construct row-major Matrix Double with matching dimensions. |
| rows | Convert Matrix to dense row lists, preserving explicit zero-column row count. |
| pinv | Compute a validated dataset pseudoinverse using relative singular-value tolerance 1e-12 and return dense rows. |
| solveLS | Given dataset then response list, solve least squares through the pseudoinverse. |
| inverse | Validate a square dataset, compute pseudoinverse and require inverse reconstruction residual below 1e-6*n. |
| symmetricEigen | Validate finite square approximately symmetric dataset, symmetrize and eigendecompose. |
| argmin | Return zero-based first index of a minimum in a nonempty list. |
| argmax | Return zero-based index selected by maximumBy on a nonempty list, with later equal maxima preferred. |
| iterateFit | Deterministic reference iteration; residual is supplied by each estimator. |
| foldEither | Monadic left fold: given checked step,initial accumulator,then list, stop at first Left MathError and otherwise return final accumulator. |
| firstRow | Return the first row of nested lists, or [] for an empty outer list. |
Documentation
Dataset
type Dataset = [[Double]] Source #
Finite observations as rows with a fixed, positive feature count.
MLConfig
Positive iteration limittolerancerate and an explicit reproducible seed.
Constructors
| MLConfig | |
Fields
| |
defaultMLConfig
defaultMLConfig :: MLConfig Source #
500 iterations, absolute residual tolerance 1e-8, rate 0.05, PCG seed 42.
Fit
A finite budget is a valid stopping point, distinct from convergence.
Constructors
| Fit | |
Fields
| |
checked
checked :: [Double] -> Either MathError () Source #
Validate a list of finite numerical values, returning Right () or Left NonFiniteResult.
require
require :: Bool -> String -> Either MathError () Source #
Given condition then diagnostic, return Right () or Left InvalidArgument prefixed with ML context.
config
config :: MLConfig -> Either MathError () Source #
Validate positive iteration count and positive finite tolerance/learning rate of MLConfig. Invalid settings return Left InvalidArgument.
dataset
dataset :: Dataset -> Either MathError (Int, Int) Source #
Validate a nonempty finite rectangular observation-by-feature list with positive feature count and Int-safe size. Return (observations,features) or Left MathError.
responses
responses :: Dataset -> [Double] -> Either MathError (Int, Int) Source #
Given dataset then finite response list, validate dataset and equal observationresponse count. Return dataset dimensions; mismatchnon-finite data fails.
queries
queries :: Int -> Dataset -> Either MathError () Source #
Given expected feature dimension then query rows, validate every row width and finite values. Empty queries are allowed; mismatch/non-finite values fail.
dot
dot :: [Double] -> [Double] -> Double Source #
Unchecked list inner product using zipWith; unequal lengths truncate. Estimator callers validate feature shapes first.
add
add :: [Double] -> [Double] -> [Double] Source #
Unchecked coordinatewise list addition, truncating to shorter length; checked estimator callers validate dimensions.
sub
sub :: [Double] -> [Double] -> [Double] Source #
Unchecked coordinatewise left-minus-right list subtraction, truncating to shorter length.
scale
scale :: Double -> [Double] -> [Double] Source #
Given scalar then coordinate list, multiply each coordinate without checked finiteness validation.
norm
norm :: [Double] -> Double Source #
Return scaled Euclidean norm of a coordinate list, zero for empty/all-zero input. Caller validates finite inputs/results when required.
dist2
dist2 :: [Double] -> [Double] -> Double Source #
Return squared Euclidean distance using sub and dot. Require matching dimensions externally; this unchecked helper truncates mismatched lists.
meanV
meanV :: Dataset -> [Double] Source #
Return per-feature means for a nonempty equal-width dataset. Empty outer input raises a pure foldl1 error; use dataset validation before calling.
matmul
matmul :: Dataset -> Dataset -> Dataset Source #
Unchecked dense row-list matrix multiplication via row/column dot products. Caller must validate rectangular compatible dimensions; zip-based dot otherwise truncates.
ident
ident :: Int -> Dataset Source #
Return n-by-n Double identity rows for a nonnegative dimension; nonpositive n gives []. No allocation budget is checked here.
replace
replace :: Int -> a -> [a] -> [a] Source #
Given index,new value,then list, replace by take/drop reconstruction. The checked caller must ensure an in-range index; this helper does not reject invalid bounds.
matrix
matrix :: Dataset -> Either MathError (Matrix Double) Source #
Validate dataset then construct row-major Matrix Double with matching dimensions. Emptyraggednon-finite input fails.
rows
rows :: Matrix a -> [[a]] Source #
Convert Matrix to dense row lists, preserving explicit zero-column row count.
pinv
pinv :: Dataset -> Either MathError Dataset Source #
Compute a validated dataset pseudoinverse using relative singular-value tolerance 1e-12 and return dense rows. Decomposition/backend failures propagate.
solveLS
solveLS :: Dataset -> [Double] -> Either MathError [Double] Source #
Given dataset then response list, solve least squares through the pseudoinverse. Validate countsfinite dataresult; checked failures propagate.
inverse
inverse :: Dataset -> Either MathError Dataset Source #
Validate a square dataset, compute pseudoinverse and require inverse reconstruction residual below 1e-6*n. Reject singular/invalid matrices or decomposition failures.
symmetricEigen
symmetricEigen :: Dataset -> Either MathError ([Double], Dataset) Source #
Validate finite square approximately symmetric dataset, symmetrize and eigendecompose. Return descending real eigenvalues and corresponding eigenvector columns as rows; invalid spectrum/backend failures propagate.
argmin
argmin :: Ord a => [a] -> Int Source #
Return zero-based first index of a minimum in a nonempty list. Empty list raises a pure minimum error; callers must validate nonempty input.
argmax
argmax :: Ord a => [a] -> Int Source #
Return zero-based index selected by maximumBy on a nonempty list, with later equal maxima preferred. Empty list raises a pure error.
iterateFit
iterateFit :: MLConfig -> (a -> Either MathError a) -> (a -> a -> Double) -> a -> Either MathError (Fit a) Source #
Deterministic reference iteration; residual is supplied by each estimator.