Math Engine Reference: Numerical
문서 탐색
개요
Scalar differentiation, quadrature and linear-regression C API.
All algorithms use synchronous borrowed callbacks, caller-owned storage and the common computation context. No exception, allocation or consumer state crosses the C ABI.
- 실행 원본:
include/math_engine/math_engine_numerical.h - 분류: 일반 수학·수치 알고리즘
관련 public header
공개 API
Header 사용 시작
이 module의 public declaration을 사용하려면 installed SDK의 다음 header를 include한다.
#include <math_engine/math_engine_numerical.h>
Type과 callback
math_engine_differentiation_scheme_f64_t
Finite-difference schemes. Values are append-only ABI identifiers.
typedef enum math_engine_differentiation_scheme_f64 {
MATH_ENGINE_DIFFERENTIATION_FORWARD_F64 = 1, /**< One-sided forward first derivative. */
MATH_ENGINE_DIFFERENTIATION_BACKWARD_F64 = 2, /**< One-sided backward first derivative. */
MATH_ENGINE_DIFFERENTIATION_CENTRAL_F64 = 3, /**< Symmetric two-point central derivative. */
MATH_ENGINE_DIFFERENTIATION_CENTRAL_5_POINT_F64 = 4 /**< Symmetric fourth-order five-point derivative. */
} math_engine_differentiation_scheme_f64_t;
math_engine_differentiation_scheme_f64_t.MATH_ENGINE_DIFFERENTIATION_FORWARD_F64
One-sided forward first derivative.
MATH_ENGINE_DIFFERENTIATION_FORWARD_F64 = 1,
math_engine_differentiation_scheme_f64_t.MATH_ENGINE_DIFFERENTIATION_BACKWARD_F64
One-sided backward first derivative.
MATH_ENGINE_DIFFERENTIATION_BACKWARD_F64 = 2,
math_engine_differentiation_scheme_f64_t.MATH_ENGINE_DIFFERENTIATION_CENTRAL_F64
Symmetric two-point central derivative.
MATH_ENGINE_DIFFERENTIATION_CENTRAL_F64 = 3,
math_engine_differentiation_scheme_f64_t.MATH_ENGINE_DIFFERENTIATION_CENTRAL_5_POINT_F64
Symmetric fourth-order five-point derivative.
MATH_ENGINE_DIFFERENTIATION_CENTRAL_5_POINT_F64 = 4,
math_engine_quadrature_method_f64_t
Quadrature methods. Values are append-only ABI identifiers.
typedef enum math_engine_quadrature_method_f64 {
MATH_ENGINE_QUADRATURE_ADAPTIVE_SIMPSON_F64 = 1 /**< Iterative adaptive Simpson subdivision. */
} math_engine_quadrature_method_f64_t;
math_engine_scalar_evaluator_f64_fn
하나의 finite argument에서 scalar 함수를 평가하는 borrowed callback이다.
- 매개변수
argument: caller가 정한 독립변수 단위의 평가점이다. - 매개변수
user_data: caller가 호출 동안 유효하게 유지하는 opaque pointer다. - 매개변수
out_value: 성공 시 함수값을 기록할 caller-provided storage다. - 반환: 성공 시
MATH_ENGINE_STATUS_OK, 평가 실패 시 정의된 음수 상태 code다.
호출 thread에서 동기적으로 실행되고 저장되지 않는다. out_value 를 보관하거나 C++
exception을 ABI 밖으로 전달하면 안 되며 성공 시 finite 값을 기록해야 한다.
- Math Engine ownership:
user_data=borrowed out_value=caller - Math Engine nullable:
user_data=true out_value=false - Math Engine thread_safety:
conditional - Math Engine callback:
invocation=synchronous thread=caller retention=none exception=forbidden
typedef math_engine_status_t (*math_engine_scalar_evaluator_f64_fn)(
double argument,
void* user_data,
double* out_value);
math_engine_differentiation_options_f64_t
Versioned finite-difference policy. A zero step selects a scale-aware step.
typedef struct math_engine_differentiation_options_f64 {
uint32_t struct_size; /**< Exact byte size of this option POD. */
uint32_t version; /**< =MATH_ENGINE_DIFFERENTIATION_OPTIONS_F64_VERSION_1=. */
uint32_t scheme; /**< One =math_engine_differentiation_scheme_f64_t=. */
uint32_t reserved; /**< Reserved for ABI growth; must be 0. */
double step; /**< Finite nonnegative stencil step in argument units; 0 selects automatic. */
uint64_t reserved_u64[5]; /**< Reserved words; all five elements must be 0. */
} math_engine_differentiation_options_f64_t;
math_engine_differentiation_options_f64_t.struct_size
Exact byte size of this option POD.
uint32_t struct_size;
math_engine_differentiation_options_f64_t.version
MATH_ENGINE_DIFFERENTIATION_OPTIONS_F64_VERSION_1.uint32_t version;
math_engine_differentiation_options_f64_t.scheme
One
math_engine_differentiation_scheme_f64_t.uint32_t scheme;
math_engine_differentiation_options_f64_t.reserved
Reserved for ABI growth; must be 0.
uint32_t reserved;
math_engine_differentiation_options_f64_t.step
Finite nonnegative stencil step in argument units; 0 selects automatic.
double step;
math_engine_differentiation_options_f64_t.reserved_u64
Reserved words; all five elements must be 0.
uint64_t reserved_u64[5];
math_engine_differentiation_result_f64_t
Derivative value, Richardson estimate and consumed callback budget.
typedef struct math_engine_differentiation_result_f64 {
uint32_t struct_size; /**< Exact byte size written for this result. */
uint32_t version; /**< =MATH_ENGINE_DIFFERENTIATION_RESULT_F64_VERSION_1=. */
uint32_t scheme; /**< Finite-difference scheme that produced the derivative. */
uint32_t flags; /**< Bitwise =MATH_ENGINE_NUMERICAL_FLAG_*= diagnostics. */
uint64_t evaluation_count; /**< Number of successful or failed callback invocations consumed. */
double derivative; /**< First derivative in function-value units per argument unit. */
double absolute_error; /**< Nonnegative Richardson difference in derivative units. */
double step; /**< Final refined stencil step in argument units. */
uint64_t evaluation_fingerprint; /**< Ordered FNV fingerprint of argument/value pairs. */
uint64_t reserved_u64; /**< Reserved for ABI growth; written as 0. */
} math_engine_differentiation_result_f64_t;
math_engine_differentiation_result_f64_t.struct_size
Exact byte size written for this result.
uint32_t struct_size;
math_engine_differentiation_result_f64_t.version
MATH_ENGINE_DIFFERENTIATION_RESULT_F64_VERSION_1.uint32_t version;
math_engine_differentiation_result_f64_t.scheme
Finite-difference scheme that produced the derivative.
uint32_t scheme;
math_engine_differentiation_result_f64_t.flags
Bitwise
MATH_ENGINE_NUMERICAL_FLAG_*diagnostics.uint32_t flags;
math_engine_differentiation_result_f64_t.evaluation_count
Number of successful or failed callback invocations consumed.
uint64_t evaluation_count;
math_engine_differentiation_result_f64_t.derivative
First derivative in function-value units per argument unit.
double derivative;
math_engine_differentiation_result_f64_t.absolute_error
Nonnegative Richardson difference in derivative units.
double absolute_error;
math_engine_differentiation_result_f64_t.step
Final refined stencil step in argument units.
double step;
math_engine_differentiation_result_f64_t.evaluation_fingerprint
Ordered FNV fingerprint of argument/value pairs.
uint64_t evaluation_fingerprint;
math_engine_differentiation_result_f64_t.reserved_u64
Reserved for ABI growth; written as 0.
uint64_t reserved_u64;
math_engine_quadrature_options_f64_t
Versioned adaptive-Simpson policy.
typedef struct math_engine_quadrature_options_f64 {
uint32_t struct_size; /**< Exact byte size of this option POD. */
uint32_t version; /**< =MATH_ENGINE_QUADRATURE_OPTIONS_F64_VERSION_1=. */
uint32_t method; /**< Must be =MATH_ENGINE_QUADRATURE_ADAPTIVE_SIMPSON_F64=. */
uint32_t maximum_depth; /**< Inclusive subdivision depth limit in [1, 60]. */
uint64_t reserved_u64[2]; /**< Reserved words; both elements must be 0. */
} math_engine_quadrature_options_f64_t;
math_engine_quadrature_options_f64_t.struct_size
Exact byte size of this option POD.
uint32_t struct_size;
math_engine_quadrature_options_f64_t.version
MATH_ENGINE_QUADRATURE_OPTIONS_F64_VERSION_1.uint32_t version;
math_engine_quadrature_options_f64_t.method
Must be
MATH_ENGINE_QUADRATURE_ADAPTIVE_SIMPSON_F64.uint32_t method;
math_engine_quadrature_options_f64_t.maximum_depth
Inclusive subdivision depth limit in [1, 60].
uint32_t maximum_depth;
math_engine_quadrature_options_f64_t.reserved_u64
Reserved words; both elements must be 0.
uint64_t reserved_u64[2];
math_engine_quadrature_interval_f64_t
One explicit adaptive-Simpson stack entry in caller-owned workspace.
typedef struct math_engine_quadrature_interval_f64 {
double lower; /**< Finite interval lower argument in caller units. */
double upper; /**< Finite interval upper argument, strictly above =lower=. */
double lower_value; /**< Finite callback value at =lower=. */
double middle_value; /**< Finite callback value at the interval midpoint. */
double upper_value; /**< Finite callback value at =upper=. */
double estimate; /**< Simpson integral estimate in value-times-argument units. */
double absolute_tolerance; /**< Positive error allocation for this interval. */
uint32_t depth; /**< Zero-based adaptive subdivision depth. */
uint32_t reserved; /**< Reserved stack-entry field; written as 0. */
} math_engine_quadrature_interval_f64_t;
math_engine_quadrature_interval_f64_t.lower
Finite interval lower argument in caller units.
double lower;
math_engine_quadrature_interval_f64_t.upper
Finite interval upper argument, strictly above
lower.double upper;
math_engine_quadrature_interval_f64_t.lower_value
Finite callback value at
lower.double lower_value;
math_engine_quadrature_interval_f64_t.middle_value
Finite callback value at the interval midpoint.
double middle_value;
math_engine_quadrature_interval_f64_t.upper_value
Finite callback value at
upper.double upper_value;
math_engine_quadrature_interval_f64_t.estimate
Simpson integral estimate in value-times-argument units.
double estimate;
math_engine_quadrature_interval_f64_t.absolute_tolerance
Positive error allocation for this interval.
double absolute_tolerance;
math_engine_quadrature_interval_f64_t.depth
Zero-based adaptive subdivision depth.
uint32_t depth;
math_engine_quadrature_interval_f64_t.reserved
Reserved stack-entry field; written as 0.
uint32_t reserved;
math_engine_quadrature_result_f64_t
Integral, accumulated error estimate and adaptive-work statistics.
typedef struct math_engine_quadrature_result_f64 {
uint32_t struct_size; /**< Exact byte size written for this result. */
uint32_t version; /**< =MATH_ENGINE_QUADRATURE_RESULT_F64_VERSION_1=. */
uint32_t method; /**< Quadrature method used for all intervals. */
uint32_t flags; /**< Reversed-interval/refinement diagnostic bits. */
uint64_t interval_count; /**< Total interval stack entries processed. */
uint64_t evaluation_count; /**< Total synchronous callback invocations consumed. */
uint64_t accepted_interval_count; /**< Leaf intervals accepted within tolerance. */
uint64_t refined_interval_count; /**< Intervals split into two children. */
double value; /**< Signed integral in function-value times argument units. */
double absolute_error; /**< Nonnegative accumulated Simpson error estimate. */
double lower_bound; /**< Original finite lower argument supplied by the caller. */
double upper_bound; /**< Original finite upper argument supplied by the caller. */
uint64_t evaluation_fingerprint; /**< Ordered FNV fingerprint of argument/value pairs. */
uint64_t reserved_u64; /**< Reserved for ABI growth; written as 0. */
} math_engine_quadrature_result_f64_t;
math_engine_quadrature_result_f64_t.struct_size
Exact byte size written for this result.
uint32_t struct_size;
math_engine_quadrature_result_f64_t.version
MATH_ENGINE_QUADRATURE_RESULT_F64_VERSION_1.uint32_t version;
math_engine_quadrature_result_f64_t.method
Quadrature method used for all intervals.
uint32_t method;
math_engine_quadrature_result_f64_t.flags
Reversed-interval/refinement diagnostic bits.
uint32_t flags;
math_engine_quadrature_result_f64_t.interval_count
Total interval stack entries processed.
uint64_t interval_count;
math_engine_quadrature_result_f64_t.evaluation_count
Total synchronous callback invocations consumed.
uint64_t evaluation_count;
math_engine_quadrature_result_f64_t.accepted_interval_count
Leaf intervals accepted within tolerance.
uint64_t accepted_interval_count;
math_engine_quadrature_result_f64_t.refined_interval_count
Intervals split into two children.
uint64_t refined_interval_count;
math_engine_quadrature_result_f64_t.value
Signed integral in function-value times argument units.
double value;
math_engine_quadrature_result_f64_t.absolute_error
Nonnegative accumulated Simpson error estimate.
double absolute_error;
math_engine_quadrature_result_f64_t.lower_bound
Original finite lower argument supplied by the caller.
double lower_bound;
math_engine_quadrature_result_f64_t.upper_bound
Original finite upper argument supplied by the caller.
double upper_bound;
math_engine_quadrature_result_f64_t.evaluation_fingerprint
Ordered FNV fingerprint of argument/value pairs.
uint64_t evaluation_fingerprint;
math_engine_quadrature_result_f64_t.reserved_u64
Reserved for ABI growth; written as 0.
uint64_t reserved_u64;
math_engine_linear_regression_result_f64_t
Stable weighted or unweighted line fit and fit-quality diagnostics.
typedef struct math_engine_linear_regression_result_f64 {
uint32_t struct_size; /**< Exact byte size written for this result. */
uint32_t version; /**< =MATH_ENGINE_LINEAR_REGRESSION_RESULT_F64_VERSION_1=. */
uint32_t flags; /**< Includes WEIGHTED when a weight array was supplied. */
uint32_t reserved; /**< Reserved for ABI growth; written as 0. */
uint64_t sample_count; /**< Total x/y samples supplied, including zero-weight samples. */
uint64_t effective_sample_count; /**< Samples with strictly positive weight. */
uint64_t sample_visit_count; /**< Deterministic three-pass visit count, =3*sample_count=. */
double slope; /**< Best-fit line slope in y units per x unit. */
double intercept; /**< Best-fit y value at x=0, in y units. */
double residual_sum_squares; /**< Weighted sum of squared y residuals. */
double root_mean_square_error; /**< Square root of weighted residual mean, in y units. */
double coefficient_of_determination; /**< Finite R-squared fit statistic. */
double condition_estimate; /**< Nonnegative scale/dispersion sensitivity estimate. */
double mean_x; /**< Weighted x mean in x units. */
double mean_y; /**< Weighted y mean in y units. */
uint64_t data_fingerprint; /**< Ordered FNV fingerprint of x, y and effective weights. */
uint64_t reserved_u64; /**< Reserved for ABI growth; written as 0. */
} math_engine_linear_regression_result_f64_t;
math_engine_linear_regression_result_f64_t.struct_size
Exact byte size written for this result.
uint32_t struct_size;
math_engine_linear_regression_result_f64_t.version
MATH_ENGINE_LINEAR_REGRESSION_RESULT_F64_VERSION_1.uint32_t version;
math_engine_linear_regression_result_f64_t.flags
Includes WEIGHTED when a weight array was supplied.
uint32_t flags;
math_engine_linear_regression_result_f64_t.reserved
Reserved for ABI growth; written as 0.
uint32_t reserved;
math_engine_linear_regression_result_f64_t.sample_count
Total x/y samples supplied, including zero-weight samples.
uint64_t sample_count;
math_engine_linear_regression_result_f64_t.effective_sample_count
Samples with strictly positive weight.
uint64_t effective_sample_count;
math_engine_linear_regression_result_f64_t.sample_visit_count
Deterministic three-pass visit count,
3*sample_count.uint64_t sample_visit_count;
math_engine_linear_regression_result_f64_t.slope
Best-fit line slope in y units per x unit.
double slope;
math_engine_linear_regression_result_f64_t.intercept
Best-fit y value at x=0, in y units.
double intercept;
math_engine_linear_regression_result_f64_t.residual_sum_squares
Weighted sum of squared y residuals.
double residual_sum_squares;
math_engine_linear_regression_result_f64_t.root_mean_square_error
Square root of weighted residual mean, in y units.
double root_mean_square_error;
math_engine_linear_regression_result_f64_t.coefficient_of_determination
Finite R-squared fit statistic.
double coefficient_of_determination;
math_engine_linear_regression_result_f64_t.condition_estimate
Nonnegative scale/dispersion sensitivity estimate.
double condition_estimate;
math_engine_linear_regression_result_f64_t.mean_x
Weighted x mean in x units.
double mean_x;
math_engine_linear_regression_result_f64_t.mean_y
Weighted y mean in y units.
double mean_y;
math_engine_linear_regression_result_f64_t.data_fingerprint
Ordered FNV fingerprint of x, y and effective weights.
uint64_t data_fingerprint;
math_engine_linear_regression_result_f64_t.reserved_u64
Reserved for ABI growth; written as 0.
uint64_t reserved_u64;
Anonymous enum
anonymous_enum_at_line_59
Result flags shared by the numerical-analysis scalar kernels.
enum {
MATH_ENGINE_NUMERICAL_FLAG_AUTO_STEP = 1u << 0, /**< Differentiation selected a scale-aware step. */
MATH_ENGINE_NUMERICAL_FLAG_REVERSED_INTERVAL = 1u << 1, /**< Quadrature bounds were supplied in descending order. */
MATH_ENGINE_NUMERICAL_FLAG_REFINED = 1u << 2, /**< Richardson or interval refinement was applied. */
MATH_ENGINE_NUMERICAL_FLAG_WEIGHTED = 1u << 3 /**< Regression consumed caller-provided sample weights. */
};
MATH_ENGINE_NUMERICAL_FLAG_AUTO_STEP
Differentiation selected a scale-aware step.
MATH_ENGINE_NUMERICAL_FLAG_AUTO_STEP = 1u << 0,
MATH_ENGINE_NUMERICAL_FLAG_REVERSED_INTERVAL
Quadrature bounds were supplied in descending order.
MATH_ENGINE_NUMERICAL_FLAG_REVERSED_INTERVAL = 1u << 1,
MATH_ENGINE_NUMERICAL_FLAG_REFINED
Richardson or interval refinement was applied.
MATH_ENGINE_NUMERICAL_FLAG_REFINED = 1u << 2,
MATH_ENGINE_NUMERICAL_FLAG_WEIGHTED
Regression consumed caller-provided sample weights.
MATH_ENGINE_NUMERICAL_FLAG_WEIGHTED = 1u << 3,
Macro와 constant
MATH_ENGINE_DIFFERENTIATION_OPTIONS_F64_VERSION_1
Initial layout version for math_engine_differentiation_options_f64_t.
#define MATH_ENGINE_DIFFERENTIATION_OPTIONS_F64_VERSION_1 1u
MATH_ENGINE_DIFFERENTIATION_RESULT_F64_VERSION_1
Initial layout version for math_engine_differentiation_result_f64_t.
#define MATH_ENGINE_DIFFERENTIATION_RESULT_F64_VERSION_1 1u
MATH_ENGINE_LINEAR_REGRESSION_RESULT_F64_VERSION_1
Initial layout version for math_engine_linear_regression_result_f64_t.
#define MATH_ENGINE_LINEAR_REGRESSION_RESULT_F64_VERSION_1 1u
MATH_ENGINE_QUADRATURE_OPTIONS_F64_VERSION_1
Initial layout version for math_engine_quadrature_options_f64_t.
#define MATH_ENGINE_QUADRATURE_OPTIONS_F64_VERSION_1 1u
MATH_ENGINE_QUADRATURE_RESULT_F64_VERSION_1
Initial layout version for math_engine_quadrature_result_f64_t.
#define MATH_ENGINE_QUADRATURE_RESULT_F64_VERSION_1 1u
Function
math_engine_differentiation_options_f64_init
5-point central difference와 scale-aware automatic step 기본 정책을 초기화한다.
- 매개변수
out_options: 성공 시 기본 정책을 받는 caller-owned storage다. - 반환: 성공 시
MATH_ENGINE_STATUS_OK, NULL이면MATH_ENGINE_STATUS_INVALID_ARGUMENT다.
성공 시에만 전체 POD를 commit하고 실패 시 기존 값을 보존한다. 전역 상태를 사용하지 않으므로 같은 output storage를 동시에 공유하지 않는 호출은 thread-safe하다.
- Math Engine ownership:
out_options=caller - Math Engine nullable:
out_options=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_differentiation_options_f64_init(
math_engine_differentiation_options_f64_t* out_options);
math_engine_differentiate_f64
Richardson refinement를 사용해 scalar 함수의 1차 derivative를 계산한다.
- 매개변수
function: 동기 borrowed scalar evaluator다. - 매개변수
user_data: callback에 그대로 전달하는 borrowed pointer며 NULL일 수 있다. - 매개변수
argument: finite 평가점이며 step과 같은 독립변수 단위다. - 매개변수
options: scheme과 step을 정하는 validated borrowed 정책이다. - 매개변수
context: evaluation budget와 cancellation을 제공하는 borrowed context다. - 매개변수
out_result: 성공 시 derivative, error estimate와 fingerprint를 받는 caller storage다. - 반환: 성공 시
MATH_ENGINE_STATUS_OK. 잘못된 인자/정책, non-finite, 구별되지 않는 stencil, callback 오류, budget 소진 또는 취소에 해당하는 음수 상태 code다.
step==0=이면 argument scale과 binary64 epsilon으로 step을 정한다. Forward/backward/
central은 네 번, 5-point central은 여섯 번 callback을 고정 순서로 평가한다. Derivative와
=absolute_error 단위는 function-value/argument 이며 error는 coarse/refined 식의 차이로
계산한 추정치이지 엄밀한 상계가 아니다. Context tolerance는 이 함수의 acceptance 기준에
사용되지 않는다. Stencil point가 argument와 구별되지 않으면 OUT_OF_RANGE 다.
Callback과 cancellation은 호출 thread에서 동기 실행되고 저장되지 않는다. 같은 input과
callback 결과에는 평가 순서와 fingerprint가 deterministic하다. out_result 는 options,
context 및 callback이 접근하는 storage와 겹치지 않아야 하며 모든 실패에서 보존된다.
- Math Engine ownership:
function=borrowed user_data=borrowed options=borrowed - Math Engine ownership:
context=borrowed out_result=caller - Math Engine nullable:
function=false user_data=true options=false context=false - Math Engine nullable:
out_result=false - Math Engine thread_safety:
conditional
MATH_ENGINE_API math_engine_status_t math_engine_differentiate_f64(
math_engine_scalar_evaluator_f64_fn function,
void* user_data,
double argument,
const math_engine_differentiation_options_f64_t* options,
const math_engine_context_t* context,
math_engine_differentiation_result_f64_t* out_result);
math_engine_quadrature_options_f64_init
최대 depth 48인 adaptive Simpson 기본 정책을 초기화한다.
- 매개변수
out_options: 성공 시 기본 quadrature 정책을 받는 caller-owned storage다. - 반환: 성공 시
MATH_ENGINE_STATUS_OK, NULL이면MATH_ENGINE_STATUS_INVALID_ARGUMENT다.
성공 시에만 전체 POD를 commit하고 실패 시 기존 값을 보존한다.
- Math Engine ownership:
out_options=caller - Math Engine nullable:
out_options=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_quadrature_options_f64_init(
math_engine_quadrature_options_f64_t* out_options);
math_engine_integrate_adaptive_f64
Caller-owned adaptive stack을 사용해 finite 구간을 Simpson quadrature한다.
- 매개변수
function: 동기 borrowed scalar evaluator다. - 매개변수
user_data: callback에 그대로 전달하는 borrowed pointer며 NULL일 수 있다. - 매개변수
lower_bound: 적분 구간의 첫 끝점이다. - 매개변수
upper_bound: 적분 구간의 둘째 끝점이며 더 작으면 부호를 뒤집어 적분한다. - 매개변수
options: method와 maximum depth를 정하는 validated borrowed 정책이다. - 매개변수
context: tolerance, iteration/evaluation budget와 cancellation을 제공한다. - 매개변수
workspace: 최소 두 원소인 caller-owned adaptive interval stack이다. - 매개변수
workspace_count:workspace의 interval 원소 수다. - 매개변수
out_result: 성공 시 적분값·error estimate·통계를 받는 caller storage다. - 반환: 성공 시
MATH_ENGINE_STATUS_OK. 잘못된 인자/정책, non-finite, workspace 부족, callback 오류, budget 소진, 취소 또는 tolerance 미확증에는 해당 음수 code다.
Bounds 단위가 x 이고 callback 값 단위가 y 이면 결과와 absolute_error 단위는
x*y 다. 각 interval은 abs(delta)<=15*(absolute+relative*|estimate|)=를 만족할 때
accept하며 error field는 Richardson 추정치다. Equal bounds는 callback 없이 정확한 0을
반환한다. Maximum depth에서 tolerance를 확증하지 못하면 =UNCERTAIN 다.
Callback/cancellation은 호출 thread에서 동기 실행되고 저장되지 않는다. Workspace는
input/output과 겹치지 않아야 하며 실패해도 scratch 내용은 변경될 수 있다. 평가 순서와
fingerprint는 같은 input/callback에서 deterministic하고, 모든 실패에서 partial integral을
commit하지 않으며 out_result 를 보존한다.
- Math Engine ownership:
function=borrowed user_data=borrowed options=borrowed - Math Engine ownership:
context=borrowed workspace=caller out_result=caller - Math Engine nullable:
function=false user_data=true options=false context=false - Math Engine nullable:
workspace=false out_result=false - Math Engine thread_safety:
conditional
MATH_ENGINE_API math_engine_status_t math_engine_integrate_adaptive_f64(
math_engine_scalar_evaluator_f64_fn function,
void* user_data,
double lower_bound,
double upper_bound,
const math_engine_quadrature_options_f64_t* options,
const math_engine_context_t* context,
math_engine_quadrature_interval_f64_t* workspace,
size_t workspace_count,
math_engine_quadrature_result_f64_t* out_result);
math_engine_linear_regression_f64
Centered accumulation으로 y=intercept+slope*x 선형 회귀를 계산한다.
- 매개변수
x_values:sample_count개의 finite 독립변수 값 배열이다. - 매개변수
y_values:sample_count개의 finite 종속변수 값 배열이다. - 매개변수
weights: NULL이면 unweighted, 아니면 dimensionless non-negative weight 배열이다. - 매개변수
sample_count: 각 배열의 원소 수이며 2 이상이어야 한다. - 매개변수
context: 세 번의 sample 방문 budget과 cancellation을 제공하는 borrowed context다. - 매개변수
out_result: 성공 시 계수와 fit diagnostics를 받는 caller-owned storage다. - 반환: 성공 시
MATH_ENGINE_STATUS_OK. 잘못된 크기/weight, non-finite, x 분산이 없는 degenerate 자료, overflow, budget 소진 또는 취소에는 해당 음수 상태 code다.
x 와 y 단위를 각각 X/Y라 하면 slope는 Y/X, intercept·RMSE는 Y,
residual sum of squares는 weight*Y^2 단위다. Weight가 있으면 최소 두 개가 양수여야
한다. Context tolerance는 regression 판정에 사용하지 않는다. 입력 배열은 모두 read-only라
서로 alias할 수 있지만 out_result 와 context에는 겹치면 안 된다. 세 번의 고정 순서
pass를 3*sample_count evaluation으로 charge하고 같은 bit pattern에는 같은 fingerprint를
반환한다. 모든 실패에서 partial fit을 commit하지 않고 output을 보존한다.
- Math Engine ownership:
x_values=borrowed y_values=borrowed weights=borrowed - Math Engine ownership:
context=borrowed out_result=caller - Math Engine nullable:
x_values=false y_values=false weights=true context=false - Math Engine nullable:
out_result=false - Math Engine thread_safety:
conditional
MATH_ENGINE_API math_engine_status_t math_engine_linear_regression_f64(
const double* x_values,
const double* y_values,
const double* weights,
size_t sample_count,
const math_engine_context_t* context,
math_engine_linear_regression_result_f64_t* out_result);