| Type: | Package |
| Title: | A Unified Framework for Positive Linear Approximation Operators |
| Version: | 0.1.0 |
| 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>. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.1.0 |
| URL: | https://github.com/edmond-aliaga/ApproxOp |
| BugReports: | https://github.com/edmond-aliaga/ApproxOp/issues |
| NeedsCompilation: | no |
| Packaged: | 2026-10-06 21:31:22 UTC; Dell |
| Author: | Edmond Aliaga [aut, cre] |
| Maintainer: | Edmond Aliaga <edmond.aliaga@uni-pr.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-16 12:50:19 UTC |
Compute Approximation Errors
Description
Computes pointwise approximation errors for an approximation operator at one or more evaluation points.
Usage
approx_error(operator, f, x)
Arguments
operator |
An object of class |
f |
Function to be approximated. |
x |
Numeric vector of evaluation points. |
Details
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.
Value
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.
Create an Approximation Operator
Description
Creates an approximation operator object from a supported operator family and, when applicable, a supported subfamily.
Usage
approx_operator(
family,
n,
subfamily = NULL,
variant = "discrete",
params = list(),
control = list()
)
Arguments
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. |
Value
An object of class "approx_operator".
Evaluate an Approximation Operator
Description
Evaluates a positive linear approximation operator for a given function at one or more points.
Usage
approximate(operator, f, x)
Arguments
operator |
An object of class |
f |
Function to be approximated. |
x |
Numeric vector of evaluation points. |
Value
A numeric vector containing the approximated values.
Create Approximation Data
Description
Creates numerical data for studying and plotting the approximation of a function by an approximation operator for one or more values of n.
Usage
approximation_data(operator, f, x, n = NULL)
Arguments
operator |
An object of class |
f |
Function to be approximated. |
x |
Numeric vector of evaluation points. |
n |
Optional vector of positive integers. If |
Details
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.
Value
An object of class "approximation_data" and
"data.frame" containing the columns x, n,
exact, approximation, signed_error,
absolute_error, and relative_error.
Check an Approximation Operator
Description
Performs a collection of structural and numerical diagnostic checks for an approximation operator.
Usage
check_operator(operator, x = NULL, tolerance = 1e-10, check_positivity = TRUE)
Arguments
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 |
Details
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().
Value
An object of class "approx_operator_check" containing
a data frame of diagnostic checks and an overall status.
Compare Approximation Operators
Description
Compares two or more approximation operators numerically for the same function, evaluation grid, and one or more values of n.
Usage
compare_operators(operators, f, grid, n = NULL)
Arguments
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 |
Details
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.
Value
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.
Study Numerical Convergence
Description
Computes numerical error measures for an approximation operator over a grid of evaluation points and for one or more values of n.
Usage
convergence(operator, f, grid, n)
Arguments
operator |
An object of class |
f |
Function to be approximated. |
grid |
Numeric vector of evaluation points. |
n |
Vector of positive integers. |
Details
For each value of n, the function computes the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
Value
An object of class "approx_convergence" and
"data.frame" containing the columns n,
max_absolute_error, mae, and rmse.
Create an Approximation Error Table
Description
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.
Usage
error_table(operator, f, x, n = NULL, digits = 6)
Arguments
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. |
Value
An object of class "approx_error_table" and
"data.frame" containing pointwise absolute approximation
errors.
Compute Moments of an Approximation Operator
Description
Computes ordinary or central moments of a positive linear approximation operator.
Usage
moments(operator, order = 8L, x, central = FALSE)
Arguments
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 |
Details
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().
Value
A matrix whose rows correspond to evaluation points and whose
columns correspond to moment orders from 0 to order.
Scan an Operator Parameter
Description
Evaluates the approximation performance of a parametric approximation operator over a sequence of values of one parameter.
Usage
parameter_scan(operator, parameter, values, f, grid, n = NULL)
Arguments
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 |
Details
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).
Value
A data frame of class
c("approx_parameter_scan", "data.frame") containing the
parameter values and the corresponding error measures.
Examples
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)
)
Scan Two Operator Parameters
Description
Evaluates the approximation performance of a parametric approximation operator over all combinations of two parameter sequences.
Usage
parameter_scan_2d(
operator,
parameter1,
values1,
parameter2,
values2,
f,
grid,
n = NULL
)
Arguments
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 |
Details
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.
Value
A data frame of class
c("approx_parameter_scan_2d", "data.frame") containing
all parameter combinations, validity information, and the
corresponding error measures.
Examples
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)
)
Plot Numerical Convergence
Description
Produces a graphical representation of the numerical convergence
measures computed by convergence().
Usage
## 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,
...
)
Arguments
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
|
Details
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).
Value
The convergence object x, returned invisibly.
Plot an Approximation Operator
Description
Produces graphical representations of the approximation of a function by an approximation operator.
Usage
## 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,
...
)
Arguments
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
|
Details
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.
Value
The approximation data used to construct the plot, returned invisibly.
Plot an Approximation Operator Comparison
Description
Produces a graphical comparison of approximation errors for several approximation operators and values of n.
Usage
## 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,
...
)
Arguments
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
|
Details
The available error metrics are the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
Value
The object x, invisibly.
Plot an Approximation Parameter Scan
Description
Produces a graphical representation of approximation error as a function of a scanned operator parameter.
Usage
## 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,
...
)
Arguments
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
|
Details
The available error metrics are the maximum absolute error, mean absolute error (MAE), and root mean squared error (RMSE).
Value
The object x, invisibly.
Examples
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")
Plot a Two-Dimensional Parameter Scan
Description
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.
Usage
## 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,
...
)
Arguments
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
|
Details
Invalid parameter combinations are represented by missing values and are therefore excluded from the contour surface.
Value
The object x, invisibly.
Print an Approximation Error Table
Description
Prints an object of class "approx_error_table" in a
structured table with horizontal and vertical separators.
Usage
## S3 method for class 'approx_error_table'
print(x, ...)
Arguments
x |
An object of class |
... |
Additional arguments, currently unused. |
Value
The object x, invisibly.
Print an Approximation Operator
Description
Prints a concise summary of an approximation operator object.
Usage
## S3 method for class 'approx_operator'
print(x, ...)
Arguments
x |
An object of class |
... |
Additional arguments, currently unused. |
Value
The operator object, invisibly.
Print an Approximation Operator Check
Description
Prints a compact summary of the diagnostic results produced by
check_operator().
Usage
## S3 method for class 'approx_operator_check'
print(x, ...)
Arguments
x |
An object of class |
... |
Additional arguments, currently unused. |
Value
The object x, invisibly.
Register a Custom Approximation Operator
Description
Registers a user-defined approximation operator so that it can be
created with approx_operator() and used with the computational
tools provided by ApproxOp.
Usage
register_operator(
family,
domain,
evaluation_engine,
subfamily = NULL,
variant = "discrete",
moment_engine = NULL,
parameter_validator = NULL,
display_name = NULL,
metadata = list(),
overwrite = FALSE
)
Arguments
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 |
Details
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.
Value
Invisibly returns TRUE.
Verify moments of an approximation operator
Description
Compares moments computed by the moment engine with moments obtained directly from the numerical evaluation of the operator.
Usage
verify_moments(operator, order = 8, x, central = FALSE, tolerance = 1e-10)
Arguments
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. |
Value
A data frame containing the moment order, computed value, numerical value, absolute error, relative error, and verification status.