Vector dimension
Vector dimension validation (predict)
Below is a minimal example: the predict function expects an array of 10 numbers and throws an exception if the dimension does not match.
Example of use
<?php
function vectorPredict(array $features): float {
if (count($features) !== 10) {
throw new InvalidArgumentException('Expecting a vector of dimension 10');
}
// Further calculations
return 0.75;
}
try {
$features = [0.12, 0.85, 0.33, 0.67, 0.91, 0.44, 0.58, 0.76, 0.29, 0.50];
$result = vectorPredict($features);
echo 'Model score: ' . round($result, 3) . PHP_EOL;
// Result interpretation
if ($result > 0.7) {
echo 'High probability of a positive outcome';
} elseif ($result > 0.4) {
echo 'Medium probability';
} else {
echo 'Low probability';
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
Result:
Memory: 0.001 Mb
Time running: < 0.001 sec.
Model score: 0.75
High probability of a positive outcome
The idea is straightforward: dimension is a contract between the data pipeline and the model. In production, such checks help you detect feature-generation bugs early.