| Title: | A Unified Framework for Positive Linear Approximation Operators |
|---|---|
| Description: | Provides a unified computational framework for defining, evaluating, analyzing, comparing, and visualizing positive linear approximation operators. The package supports classical and generalized discrete operators, ordinary and central moments, numerical moment verification, approximation error analysis, convergence studies, parameter studies, and user-defined operators. The implemented framework is related to classical and generalized approximation operators described in Szász (1950) <doi:10.6028/JRES.045.024>, Sucu and Varma (2015) <doi:10.1016/j.amc.2015.08.077>, and Aliaga and Aslan (2026) <doi:10.1002/mma.70924>. |
| Authors: | Edmond Aliaga [aut, cre] |
| Maintainer: | Edmond Aliaga <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-10-16 17:39:46 UTC |
| Source: | https://github.com/cran/ApproxOp |
Computes pointwise approximation errors for an approximation operator at one or more evaluation points.
approx_error(operator, f, x)approx_error(operator, f, x)
operator |
An object of class |
f |
Function to be approximated. |
x |
Numeric vector of evaluation points. |
For an operator L_n and a function f, the signed error is
L_n(f; x) - f(x),
while the absolute and relative errors are
|L_n(f; x) - f(x)|
and
|L_n(f; x) - f(x)| / |f(x)|,
respectively. If f(x) = 0, the relative error is returned as NA.
An object of class "approx_error" and
"data.frame" containing the evaluation points, exact
function values, approximated values, signed errors, absolute
errors, and relative errors.
Creates an approximation operator object from a supported operator family and, when applicable, a supported subfamily.
approx_operator( family, n, subfamily = NULL, variant = "discrete", params = list(), control = list() )approx_operator( family, n, subfamily = NULL, variant = "discrete", params = list(), control = list() )
family |
Character string specifying the operator family. |
n |
Positive integer specifying the approximation parameter. |
subfamily |
Optional character string specifying the operator subfamily.
The default is |
variant |
Character string specifying the operator variant. |
params |
A list containing family- or subfamily-specific parameters. |
control |
A list containing numerical control parameters. |
An object of class "approx_operator".
Evaluates a positive linear approximation operator for a given function at one or more points.
approximate(operator, f, x)approximate(operator, f, x)
operator |
An object of class |
f |
Function to be approximated. |
x |
Numeric vector of evaluation points. |
A numeric vector containing the approximated values.
Creates numerical data for studying and plotting the approximation of a function by an approximation operator for one or more values of n.
approximation_data(operator, f, x, n = NULL)approximation_data(operator, f, x, n = NULL)
operator |
An object of class |
f |
Function to be approximated. |
x |
Numeric vector of evaluation points. |
n |
Optional vector of positive integers. If |
For each evaluation point x and each value of n, the function computes the exact value f(x), the approximation L_n(f; x), the signed error, the absolute error, and the relative error.
An object of class "approximation_data" and
"data.frame" containing the columns x, n,
exact, approximation, signed_error,
absolute_error, and relative_error.
Performs a collection of structural and numerical diagnostic checks for an approximation operator.
check_operator(operator, x = NULL, tolerance = 1e-10, check_positivity = TRUE)check_operator(operator, x = NULL, tolerance = 1e-10, check_positivity = TRUE)
operator |
An object of class |
x |
Optional numeric vector of diagnostic evaluation points.
If |
tolerance |
Positive numeric value used for numerical comparisons. |
check_positivity |
Logical. If |
The function checks whether the operator can be evaluated successfully on a set of points, whether the returned values are finite, whether constants are reproduced within a specified tolerance, and optionally whether the operator appears to preserve non-negativity for a collection of simple non-negative test functions.
This function is intended as a general diagnostic tool. Detailed
verification of ordinary or central moments is provided separately by
verify_moments().
An object of class "approx_operator_check" containing
a data frame of diagnostic checks and an overall status.
Compares two or more approximation operators numerically for the same function, evaluation grid, and one or more values of n.
compare_operators(operators, f, grid, n = NULL)compare_operators(operators, f, grid, n = NULL)
operators |
A list of objects of class
|
f |
Function to be approximated. |
grid |
Numeric vector of evaluation points. |
n |
Optional vector of positive integers. If |
For each operator and each value of n, the function computes the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
The comparison is performed on a common evaluation grid. Therefore,
every point in grid must belong to the domain of every
operator included in the comparison.
An object of class "approx_operator_comparison" and
"data.frame". The returned data frame contains the operator
label, family, subfamily, variant, n, maximum absolute error, MAE,
and RMSE.
Computes numerical error measures for an approximation operator over a grid of evaluation points and for one or more values of n.
convergence(operator, f, grid, n)convergence(operator, f, grid, n)
operator |
An object of class |
f |
Function to be approximated. |
grid |
Numeric vector of evaluation points. |
n |
Vector of positive integers. |
For each value of n, the function computes the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
An object of class "approx_convergence" and
"data.frame" containing the columns n,
max_absolute_error, mae, and rmse.
Creates a numerical error table for an approximation operator. The table may be computed for the operator's current value of n or for several values of n.
error_table(operator, f, x, n = NULL, digits = 6)error_table(operator, f, x, n = NULL, digits = 6)
operator |
An object of class |
f |
Function to be approximated. |
x |
Numeric vector of evaluation points. |
n |
Optional vector of positive integers. If |
digits |
Number of digits used when printing the table. |
An object of class "approx_error_table" and
"data.frame" containing pointwise absolute approximation
errors.
Computes ordinary or central moments of a positive linear approximation operator.
moments(operator, order = 8L, x, central = FALSE)moments(operator, order = 8L, x, central = FALSE)
operator |
An object of class |
order |
Non-negative integer specifying the maximum moment order. In version 0.1.0, orders from 0 to 8 are supported. |
x |
Numeric vector of evaluation points. |
central |
Logical. If |
The ordinary moment of order r is m_r(x) = L_n(t^r; x), while the central moment is mu_r(x) = L_n((t - x)^r; x).
If a registered moment engine is available for the operator,
it is used to compute the ordinary moments. Otherwise, the
ordinary moments are computed through repeated calls to
approximate().
A matrix whose rows correspond to evaluation points and whose
columns correspond to moment orders from 0 to order.
Evaluates the approximation performance of a parametric approximation operator over a sequence of values of one parameter.
parameter_scan(operator, parameter, values, f, grid, n = NULL)parameter_scan(operator, parameter, values, f, grid, n = NULL)
operator |
An object of class |
parameter |
Character string giving the name of the parameter to be varied. |
values |
Numeric vector containing the parameter values to scan. |
f |
Function to be approximated. |
grid |
Numeric vector of evaluation points. |
n |
Optional positive integer giving the operator degree.
If |
For each parameter value, the operator is reconstructed and the approximation error is evaluated on the supplied grid. The function reports the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
A data frame of class
c("approx_parameter_scan", "data.frame") containing the
parameter values and the corresponding error measures.
C <- approx_operator( family = "sheffer", subfamily = "charlier", n = 20, params = list(a = 2) ) parameter_scan( C, parameter = "a", values = c(1.5, 2, 3, 5), f = function(x) x^2, grid = seq(0, 1, length.out = 101) )C <- approx_operator( family = "sheffer", subfamily = "charlier", n = 20, params = list(a = 2) ) parameter_scan( C, parameter = "a", values = c(1.5, 2, 3, 5), f = function(x) x^2, grid = seq(0, 1, length.out = 101) )
Evaluates the approximation performance of a parametric approximation operator over all combinations of two parameter sequences.
parameter_scan_2d( operator, parameter1, values1, parameter2, values2, f, grid, n = NULL )parameter_scan_2d( operator, parameter1, values1, parameter2, values2, f, grid, n = NULL )
operator |
An object of class |
parameter1 |
Character string giving the name of the first parameter to be varied. |
values1 |
Numeric vector containing the values of the first parameter. |
parameter2 |
Character string giving the name of the second parameter to be varied. |
values2 |
Numeric vector containing the values of the second parameter. |
f |
Function to be approximated. |
grid |
Numeric vector of evaluation points. |
n |
Optional positive integer giving the operator degree.
If |
For each pair of parameter values, the operator is reconstructed and the approximation error is evaluated on the supplied grid. The function reports the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
Invalid parameter combinations do not interrupt the complete scan.
They are retained in the result with valid = FALSE,
missing error measures, and an explanatory message.
A data frame of class
c("approx_parameter_scan_2d", "data.frame") containing
all parameter combinations, validity information, and the
corresponding error measures.
M <- approx_operator( family = "sheffer", subfamily = "meixner", n = 20, params = list( alpha = 0.5, beta = 2, theta = 1, c = 0.75 ) ) parameter_scan_2d( M, parameter1 = "alpha", values1 = c(0.5, 1, 2), parameter2 = "beta", values2 = c(1, 2, 4), f = function(x) x^2, grid = seq(0, 1, length.out = 101) )M <- approx_operator( family = "sheffer", subfamily = "meixner", n = 20, params = list( alpha = 0.5, beta = 2, theta = 1, c = 0.75 ) ) parameter_scan_2d( M, parameter1 = "alpha", values1 = c(0.5, 1, 2), parameter2 = "beta", values2 = c(1, 2, 4), f = function(x) x^2, grid = seq(0, 1, length.out = 101) )
Produces a graphical representation of the numerical convergence
measures computed by convergence().
## S3 method for class 'approx_convergence' plot( x, metric = c("max_absolute_error", "mae", "rmse"), xlab = "n", ylab = NULL, main = NULL, type = "b", lwd = NULL, pch = NULL, show_n = TRUE, grid_lines = TRUE, ... )## S3 method for class 'approx_convergence' plot( x, metric = c("max_absolute_error", "mae", "rmse"), xlab = "n", ylab = NULL, main = NULL, type = "b", lwd = NULL, pch = NULL, show_n = TRUE, grid_lines = TRUE, ... )
x |
An object of class |
metric |
Error measure to be plotted. One of
|
xlab |
Label for the horizontal axis. |
ylab |
Optional label for the vertical axis. |
main |
Optional plot title. |
type |
Plot type passed to |
lwd |
Line width. |
pch |
Plotting symbol. |
show_n |
Logical. If |
grid_lines |
Logical value indicating whether light grid lines should be displayed. |
... |
Additional graphical arguments passed to
|
The horizontal axis represents the parameter n, while the vertical axis represents one of the available error measures: maximum absolute error, mean absolute error (MAE), or root mean squared error (RMSE).
The convergence object x, returned invisibly.
Produces graphical representations of the approximation of a function by an approximation operator.
## S3 method for class 'approx_operator' plot( x, f, grid, n = NULL, type = c("approximation", "error"), xlab = "x", ylab = NULL, main = NULL, lwd = NULL, legend_position = "best", legend_title = NULL, grid_lines = TRUE, ... )## S3 method for class 'approx_operator' plot( x, f, grid, n = NULL, type = c("approximation", "error"), xlab = "x", ylab = NULL, main = NULL, lwd = NULL, legend_position = "best", legend_title = NULL, grid_lines = TRUE, ... )
x |
An object of class |
f |
Function to be approximated. |
grid |
Numeric vector of evaluation points. |
n |
Optional vector of positive integers. If |
type |
Type of plot. One of |
xlab |
Label for the horizontal axis. |
ylab |
Optional label for the vertical axis. |
main |
Optional plot title. |
lwd |
Line width used for the approximation curves. |
legend_position |
Position of the legend. The default
|
legend_title |
Optional title for the legend. |
grid_lines |
Logical value indicating whether light grid lines should be displayed. |
... |
Additional graphical arguments passed to
|
Two plot types are currently supported:
"approximation" displays the exact function together
with the operator approximations for one or more values of n.
"error" displays the absolute approximation error
for one or more values of n.
The approximation data used to construct the plot, returned invisibly.
Produces a graphical comparison of approximation errors for several approximation operators and values of n.
## S3 method for class 'approx_operator_comparison' plot( x, metric = c("max_absolute_error", "mae", "rmse"), type = "b", lwd = NULL, pch = NULL, show_n = TRUE, show_legend = TRUE, legend_position = "best", legend_title = "Operator", grid_lines = TRUE, xlab = "n", ylab = NULL, main = NULL, ... )## S3 method for class 'approx_operator_comparison' plot( x, metric = c("max_absolute_error", "mae", "rmse"), type = "b", lwd = NULL, pch = NULL, show_n = TRUE, show_legend = TRUE, legend_position = "best", legend_title = "Operator", grid_lines = TRUE, xlab = "n", ylab = NULL, main = NULL, ... )
x |
An object of class |
metric |
Error metric to be plotted. One of
|
type |
Plot type passed to |
lwd |
Line width. |
pch |
Plotting symbol used for the first operator. If
|
show_n |
Logical. If |
show_legend |
Logical. If |
legend_position |
Position of the legend. The default
|
legend_title |
Optional title for the legend. |
grid_lines |
Logical value indicating whether light grid lines should be displayed. |
xlab |
Label for the horizontal axis. |
ylab |
Optional label for the vertical axis. |
main |
Optional plot title. |
... |
Additional graphical arguments passed to
|
The available error metrics are the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
The object x, invisibly.
Produces a graphical representation of approximation error as a function of a scanned operator parameter.
## S3 method for class 'approx_parameter_scan' plot( x, metric = c("max_absolute_error", "mae", "rmse"), type = "b", lwd = NULL, pch = NULL, show_values = TRUE, grid_lines = TRUE, xlab = NULL, ylab = NULL, main = NULL, ... )## S3 method for class 'approx_parameter_scan' plot( x, metric = c("max_absolute_error", "mae", "rmse"), type = "b", lwd = NULL, pch = NULL, show_values = TRUE, grid_lines = TRUE, xlab = NULL, ylab = NULL, main = NULL, ... )
x |
An object of class |
metric |
Error metric to be plotted. One of
|
type |
Plot type used to display the parameter scan. |
lwd |
Optional line width. If |
pch |
Optional plotting symbol. If |
show_values |
Logical. If |
grid_lines |
Logical. If |
xlab |
Optional label for the horizontal axis. If |
ylab |
Optional label for the vertical axis. |
main |
Optional plot title. |
... |
Additional graphical arguments passed to
|
The available error metrics are the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
The object x, invisibly.
C <- approx_operator( family = "sheffer", subfamily = "charlier", n = 20, params = list(a = 2) ) Scan <- parameter_scan( C, parameter = "a", values = c(1.5, 2, 3, 5, 10), f = function(x) x^2, grid = seq(0, 1, length.out = 101) ) plot(Scan) plot(Scan, metric = "mae")C <- approx_operator( family = "sheffer", subfamily = "charlier", n = 20, params = list(a = 2) ) Scan <- parameter_scan( C, parameter = "a", values = c(1.5, 2, 3, 5, 10), f = function(x) x^2, grid = seq(0, 1, length.out = 101) ) plot(Scan) plot(Scan, metric = "mae")
Produces a contour plot for the results obtained from
parameter_scan_2d(). The plot shows how a selected
approximation error metric changes with respect to two
operator parameters.
## S3 method for class 'approx_parameter_scan_2d' plot( x, metric = c("max_absolute_error", "mae", "rmse"), levels = 10, draw_points = TRUE, show_invalid = TRUE, pch = NULL, invalid_pch = 4, lwd = NULL, grid_lines = TRUE, xlab = NULL, ylab = NULL, main = NULL, ... )## S3 method for class 'approx_parameter_scan_2d' plot( x, metric = c("max_absolute_error", "mae", "rmse"), levels = 10, draw_points = TRUE, show_invalid = TRUE, pch = NULL, invalid_pch = 4, lwd = NULL, grid_lines = TRUE, xlab = NULL, ylab = NULL, main = NULL, ... )
x |
An object of class |
metric |
Error metric to be plotted. One of
|
levels |
Number of contour levels, or a numeric vector specifying the contour levels. |
draw_points |
Logical. If |
show_invalid |
Logical. If |
pch |
Optional plotting symbol for valid parameter
combinations. If |
invalid_pch |
Plotting symbol for invalid parameter combinations. |
lwd |
Optional contour line width. If |
grid_lines |
Logical. If |
xlab |
Optional label for the horizontal axis. |
ylab |
Optional label for the vertical axis. |
main |
Optional plot title. |
... |
Additional graphical arguments passed to
|
Invalid parameter combinations are represented by missing values and are therefore excluded from the contour surface.
The object x, invisibly.
Prints an object of class "approx_error_table" in a
structured table with horizontal and vertical separators.
## S3 method for class 'approx_error_table' print(x, ...)## S3 method for class 'approx_error_table' print(x, ...)
x |
An object of class |
... |
Additional arguments, currently unused. |
The object x, invisibly.
Prints a concise summary of an approximation operator object.
## S3 method for class 'approx_operator' print(x, ...)## S3 method for class 'approx_operator' print(x, ...)
x |
An object of class |
... |
Additional arguments, currently unused. |
The operator object, invisibly.
Prints a compact summary of the diagnostic results produced by
check_operator().
## S3 method for class 'approx_operator_check' print(x, ...)## S3 method for class 'approx_operator_check' print(x, ...)
x |
An object of class |
... |
Additional arguments, currently unused. |
The object x, invisibly.
Registers a user-defined approximation operator so that it can be
created with approx_operator() and used with the computational
tools provided by ApproxOp.
register_operator( family, domain, evaluation_engine, subfamily = NULL, variant = "discrete", moment_engine = NULL, parameter_validator = NULL, display_name = NULL, metadata = list(), overwrite = FALSE )register_operator( family, domain, evaluation_engine, subfamily = NULL, variant = "discrete", moment_engine = NULL, parameter_validator = NULL, display_name = NULL, metadata = list(), overwrite = FALSE )
family |
Character string specifying the operator family. |
domain |
Numeric vector of length two giving the operator domain. |
evaluation_engine |
Function used to evaluate the operator.
It must accept the arguments |
subfamily |
Optional character string specifying the operator
subfamily. The default is |
variant |
Character string specifying the operator variant.
The default is |
moment_engine |
Optional function for computing ordinary moments.
It must accept the arguments |
parameter_validator |
Optional function used to validate the
parameter list supplied through |
display_name |
Optional character string used as a descriptive name for the operator. |
metadata |
Optional list containing additional operator metadata. |
overwrite |
Logical. If |
A registered operator must provide an evaluation engine. A moment
engine and a parameter validator are optional. When no moment engine
is supplied, moments are computed through the general
approximate() mechanism.
Registration is atomic: if registration fails, the operator and family registries are restored to their previous state.
Invisibly returns TRUE.
Compares moments computed by the moment engine with moments obtained directly from the numerical evaluation of the operator.
verify_moments(operator, order = 8, x, central = FALSE, tolerance = 1e-10)verify_moments(operator, order = 8, x, central = FALSE, tolerance = 1e-10)
operator |
An object of class |
order |
Maximum moment order to verify. Default is 8. |
x |
Evaluation point or vector of evaluation points. |
central |
Logical. If |
tolerance |
Numerical tolerance used to determine whether the verification is successful. |
A data frame containing the moment order, computed value, numerical value, absolute error, relative error, and verification status.