Next Article in Journal
A Consensus Model for Extended Comparative Linguistic Expressions with Symbolic Translation
Next Article in Special Issue
A Path Planning Algorithm for a Dynamic Environment Based on Proper Generalized Decomposition
Previous Article in Journal
Approximate Efficient Solutions of the Vector Optimization Problem on Hadamard Manifolds via Vector Variational Inequalities
Previous Article in Special Issue
Further Properties of Quantum Spline Spaces
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Neural-Network-Based Curve Fitting Using Totally Positive Rational Bases

by
Rocio Gonzalez-Diaz
1,†,‡,
E. Mainar
2,†,§,
Eduardo Paluzo-Hidalgo
1,†,‡ and
B. Rubio
2,*,†,§
1
Department of Applied Mathematics I, University of Sevilla, 41012 Sevilla, Spain
2
Department of Applied Mathematics, University Research Institute of Mathematics and Its Applications (IUMA), University of Zaragoza, 50001 Zaragoza, Spain
*
Author to whom correspondence should be addressed.
The authors contributed equally to this work.
The authors are partially supported by MICINN, FEDER/UE under grant PID2019-107339GB-100.
§
The authors are partially supported through the Spanish research grant PGC2018-096321-B-I00 (MCIU/AEI), by Gobierno de Aragón (E41_17R ) and by Feder 2014-2020 “Construyendo Europa desde Aragón”.
Mathematics 2020, 8(12), 2197; https://doi.org/10.3390/math8122197
Submission received: 2 November 2020 / Revised: 2 December 2020 / Accepted: 8 December 2020 / Published: 10 December 2020
(This article belongs to the Special Issue Computer Aided Geometric Design)

Abstract

:
This paper proposes a method for learning the process of curve fitting through a general class of totally positive rational bases. The approximation is achieved by finding suitable weights and control points to fit the given set of data points using a neural network and a training algorithm, called AdaMax algorithm, which is a first-order gradient-based stochastic optimization. The neural network presented in this paper is novel and based on a recent generalization of rational curves which inherit geometric properties and algorithms of the traditional rational Bézier curves. The neural network has been applied to different kinds of datasets and it has been compared with the traditional least-squares method to test its performance. The obtained results show that our method can generate a satisfactory approximation.

1. Introduction

The problem of obtaining a curve that fits a given set of data points is one of the fundamental challenges of Computer Aided Geometric Design (CAGD), and it has become prevalent in several applied and industrial domains, such as Computer-Aided Design and Manufacturing (CAD/CAM) systems, Computer Graphics and Animation, Robotics Design, Medicine and many others. To face this issue, several families of bases of functions have been considered. There is a large body of literature on this topic and there are numerous methods to solve this issue, such as several least-squares techniques and different progressive iterative approximation methods (see [1,2,3] and the references therein).
Given a system ( u 0 , , u n ) of linearly independent functions defined on an interval I R and P 0 , , P n R k , we can define a parametric curve as γ ( t ) = i = 0 n P i u i ( t ) , t I . The polygon P 0 P n , formed by the ordered sequence of points P i R k , i = 0 , , n , is called the control polygon of γ and the points P i , i = 0 , , n , are named the control points of γ with respect to ( u 0 , , u n ) . A matrix is totally positive (TP) if all its minors are nonnegative (see [4]). A system of functions ( u 0 , , u n ) defined on I is TP if all its collocation matrices u j ( t i ) i , j = 0 , n with t 0 < < t n in I are TP. A TP system of functions on I is normalized (NTP) if i = 0 n u i ( t ) = 1 , for all t I . A basis provides shape-preserving representations if the shape of the curve imitates the shape of its control polygon. Normalized totally positive bases provide shape-preserving representations. The normalized B-basis of a given space is an NTP basis such that the matrix of change of basis of any NTP basis with respect to the normalized B-basis is TP and stochastic. This property implies that the control polygon of a curve with respect to the normalized B-basis can be obtained by a corner cutting algorithm from its control polygon with respect to any other NTP basis. Thus, the control polygon with respect to the normalized B-basis is closer in shape to the curve than the control polygon with respect to any other NTP basis. Furthermore, the length of the control polygon with respect to the normalized B-basis lies between the length of the curve and the length of its control polygon with respect to any other NTP basis. Similar properties hold for other geometric properties such as angular variation or number of inflections (see [5,6,7]). So, the Normalized B-basis has the optimal shape-preserving properties among all NTP bases of the space. The Bernstein bases and the B-spline bases are the normalized B-bases of their corresponding generated spaces.
It is well known that the bases obtained by rationalizing Bernstein bases are also the normalized B-bases of the generated spaces of rational functions. These spaces are made up of rational polynomial functions where the denominator is a given polynomial. Rational Bernstein bases add adjustable weights to provide closer approximations to arbitrary shapes and have become a standard tool in CAGD since they allow the exact representation of conic sections, spheres and cylinders. In [8], the generalization of rational Bernstein bases obtained when replacing the linear polynomial factors by trigonometric or hyperbolic functions or their mixtures with polynomials were analyzed. The generated rational curves inherit geometric properties and algorithms of the traditional rational Bézier curves and so, they can be considered as modeling tools in CAD/CAM systems.
As mentioned before, the weights of rational bases can be used as shape parameters. However, it is well known that the effect of changing a weight in a rational basis is different from that of moving a control point of the curve (see Figure 1). Thus, the interactive shape control of rational curves through adjusting weights is not a straightforward task and it is not easy to design algorithms to obtain the appropriate weights (see [9], Chapter 13).
Some recent papers have shown that the application of Artificial Intelligence (AI) techniques can achieve remarkable results regarding the problem of obtaining rational curves that fit a given set of data points. To face this issue, in [10], a bio-inspired algorithm was applied through the use of rational Bézier curves. Besides, in [11,12], evolutionary algorithms were applied to rational B-spline curves. As a novelty, in this paper, we define a one-hidden-layer neural network using the general class of rational bases with optimal shape-preserving properties proposed in [8]. In that work, the authors presented evaluation and subdivision algorithms. However, this is the first time that the problem of obtaining a rational fitting curve using these general class of totally positive rational bases is modeled by a neural network and its weights and control points optimized using a training algorithm. In this paper, we extend [8] for their application in curve fitting training the neural network with a recent stochastic learning process, the AdaMax algorithm [13], to find suitable weights and control points. In this approximation process, the rational basis is a hyperparameter and can be changed by substituting the linear factors by polynomial, trigonometric or hyperbolic functions, thus expanding the potential range of applications to include more difficult shapes.
The layout of the paper is as follows. In Section 2, we recall several concepts regarding CAGD and we present a general class of rational bases which are normalized B-bases. Then, in  Section 3, we present a one-hidden-layer neural network based on the rational bases presented in the previous section to approximate a given set of data points. This neural network is trained with an optimization algorithm to update the weights and control points used to construct a curve that approximates the given set of data points, while decreasing a loss function. In Section 4, several experiments are provided illustrating the use of the neural network with different normalized B-bases to test its performance giving an approximation of different kinds of sets of data points. Moreover, the proposed method has been compared with the traditional least-squares method. Finally, conclusions and future work are presented in Section 5.

2. Shape-Preserving and Rational Bases

Let us suppose that I R and f , g : I R are nonnegative continuous functions. Then, for  n N , we can define the system ( u 0 n , , u n n ) where:
u k n ( t ) = n k f k ( t ) g n k ( t ) such that t I , k = 0 , , n .
For any positive weights w i n , i = 0 , , n , let us define ω n ( t ) = i = 0 n w i n u i n ( t ) and denote by ( ρ 0 n , , ρ n n ) the rational basis described by
ρ i n ( t ) = w i n 1 ω n ( t ) u i n ( t ) , i = 0 , , n ,
where ( u 0 n , , u n n ) is defined in (1). Clearly, this system spans a space of rational functions with denominator ω n ( t ) ,
R n = span { ρ i n ( t ) i = 0 , , n } = { u ( t ) / ω n ( t ) u ( t ) U n } ,
where U n is the space generated by ( u 0 n , , u n n ) .
The following result corresponds to Corollary 4 of [8] and provides the conditions characterizing that the system given in (2) has optimal shape-preserving properties.
Proposition 1.
The system of functions given in (2) is the normalized B-basis of the space R n defined in (3) if and only if the function f / g defined on I 0 = { t I g ( t ) 0 } is increasing and satisfies
inf f ( t ) g ( t ) t I 0 = 0 , sup f ( t ) g ( t ) t I 0 = + .
Let us see several choices of functions f and g satisfying the conditions of Proposition 1. Let us consider the functions
f ( t ) = t a b a , g ( t ) = b t b a , t [ a , b ] .
It is well known that the corresponding rational basis (2), which is the rational Bernstein basis, is the normalized B-basis of its generated space (3).
We can also consider the functions
f ( t ) = t 2 , g ( t ) = 1 t 2 , t [ 0 , 1 ] .
The corresponding rational basis (2) spans the space
R n = span { u ( t ) / ω n ( t ) u ( t ) U n , ω n ( t ) = i = 0 n w i n u i n ( t ) } ,
where the system ( u 0 , , u n ) given in (1) spans the space 1 , t 2 , , t 2 n of even polynomials defined on [ 0 , 1 ] of degree less than or equal to 2 n .
Trigonometric and hyperbolic bases are attracting a lot of interest, for instance in Isogeometric Analysis (cf. [14]). Let 0 < Δ < π / 2 . Define
f ( t ) = sin ( Δ + t ) / 2   and   g ( t ) = sin ( Δ t ) / 2   for   t I = [ Δ , Δ ] .
Let us notice that the functions f and g satisfy f ( t ) > 0 and g ( t ) > 0 for all t ( Δ , Δ ) . Moreover, it can be checked that
f ( t ) g ( t ) = sin Δ + t 2 sin Δ t 2 = 1 2 sin ( Δ ) sin 2 Δ t 2 > 0 , t ( Δ , Δ ) .
Therefore, for any 0 < Δ < π / 2 , the function f / g is a strictly increasing function on ( Δ , Δ ) and f and g satisfy the conditions of Proposition 1. The corresponding rational basis (2) spans the space
R n = span { u ( t ) / ω n ( t ) u ( t ) U n , ω n ( t ) = i = 0 n w i n u i n ( t ) } ,
where, for a given n = 2 m , the system ( u 0 , , u n ) given in (1) is a basis that coincides, up to a positive scaling, with  the normalized B-basis of the space 1 , cos t , sin t , , cos m t , sin m t of trigonometric polynomials of degree less than or equal to m on I (see Section 3 of [15]).
Finally, let Δ > 0 . Define
f ( t ) = sinh ( Δ + t ) / 2 )   and   g ( t ) = sinh ( Δ t ) / 2   for   t I = [ Δ , Δ ] .
Clearly, f ( t ) > 0 and g ( t ) > 0 for all t ( Δ , Δ ) . Moreover, it can be checked that
f ( t ) g ( t ) = sinh Δ + t 2 sinh Δ t 2 = 1 2 sinh Δ sinh 2 Δ t 2 > 0 , t ( Δ , Δ ) .
Therefore, for any Δ > 0 , f / g is a strictly increasing function on ( Δ , Δ ) and f and g satisfy the conditions of Proposition 1. The corresponding rational basis (2) spans the space
R n = span { u ( t ) / ω n ( t ) u ( t ) U n , ω n ( t ) = i = 0 n w i n u i n ( t ) } ,
where, for  n = 2 m , the system ( u 0 , , u n ) given in (1) spans the space 1 , e t , e t , , e m t , e m t of hyperbolic polynomials of degree less than or equal to m on I.
In Figure 2, we illustrate two examples of the rational basis (2) of degree 3. Let us observe the effect on the shape of the functions of the basis as weights change.
Section 4 will show examples of approximations of given sets of data points using all the above mentioned normalized B-bases. Moreover, the neural network presented in the following section will be used to compute the optimal weights and control points of their corresponding fitting curves.

3. Curve Fitting with Neural Networks

It is well known that curve fitting is the process of constructing a curve, or mathematical function, that has the best fit of a given set of data points. A related topic is Regression Analysis in Machine Learning. In the literature (see [16] (Chapter 11)), a regression problem is the problem of predicting a real value for each input data. Let us consider an input space X R m and target values Y R k , and a distribution over X × Y , denoted by D . Then, a regression problem consists of a set of labeled samples S = { ( x i , y i ) } i { 0 , , } X × Y drawn according to D   where y i are the target real values we want to predict. There exists a huge variety of regression algorithms, i.e., algorithms solving regression problems, such as Linear Regression, Decision Trees, Support Vector Regression, and Neural Networks, among others. The quality of the prediction of an algorithm or model depends on the difference between the target (i.e., the true value) and the predicted one, and it is measured using a loss function. Then, given a set H (also called “hypothesis”) of function mappings X to Y, the aim of the regression algorithm is to use S to find h H such that the expected loss is small.
Specifically, the problem that we want to solve can be stated as follows. Suppose that f and g are functions defined on [ a , b ] satisfying the conditions of Proposition 1. Consider a set of parameters a t 0 < < t b and a sequence of data points s 0 , , s R k , where each parameter t i is associated with a data point s i . For some n , we want to obtain a rational curve
c ( t ) = i = 0 n w i n n i f i ( t ) g n i ( t ) i = 0 n w i n n i f i ( t ) g n i ( t ) P i , t [ a , b ] ,
to approximate the set of data points s = ( s i ) i = 0 . Therefore, the goal is to obtain the weights w 0 n , , w n n and the control points P 0 , , P n of the rational curve (11) that best fits the set of data points. In order to compute them, we have used a stochastic optimization process to train a neural network that models the rational curve c ( t ) .
The problem to be solved can be interpreted then as a regression problem where the set of labeled samples is composed of the input data, X, that is the set of parameters a t 0 < t b and the target set of data points Y = s = ( s i ) i = 0 .
Then, the expression in (11) can be represented as a hierarchical computational graph with just one hidden layer that we will denote as N w , P : R R k where the computations are organized as in Figure 3. The obtained curve N w , P ( t ) is the rational curve c ( t ) that approximates the given set of data points and we denote as the fitting curve.
The key idea is to iteratively change the input weights w = ( w i n ) i = 0 n and control points P = ( P i ) i = 0 of the active curve N w , P ( t ) , and so it deforms towards the target shape represented by the set of data points s = ( s i ) i = 0 (see Figure 4).
Then, we apply an adaptive learning rate optimization algorithm to train the neural network to find the weights and control points, which can be, for example, the Adaptive Moment Estimation (Adam) algorithm or its variant Adaptive Moment Estimation Maximum (AdaMax) algorithm based on infinity norm. These methods are used for stochastic optimization, to solve the supervised learning problem and to find the parameters where a minima is located. In this paper, we have mainly used the AdaMax variant (see Algorithm 1) because of its stability and simplicity [13]. However, the Adam method can be useful depending on the shape of the set of data points to be approximated and the choice of the loss function. The stochastic objective function, also called the loss function, measures the goodness of the fitting curve. Let us notice that there exist different loss functions such as the mean absolute error, the cross-entropy loss, the mean squared error, among others (the different loss functions implemented in Tensorflow can be consulted in the tensorflow documentation), that can be chosen depending on the problem. In our case, we have considered the mean absolute error as the loss function because of the choice of the training algorithm, given by the following expression:
E ( w , P ) = i = 0 s i N w , P ( t i ) + 1 .
The Adam and the AdaMax algorithms are stochastic gradient-based optimization algorithms and, as previously mentioned, they update the weights and the control points iteratively. The step size is a real number that measures how much the weights and the control points are updated upon each iteration. Besides, the Adam algorithm uses the first and the second moment estimate to update the weights and the control points which are updated following exponential decay rates ( β 1 and β 2 ). Finally, as AdaMax is a variation of Adam using infinity norm, the second moment estimate has a simple recursive formula which will be denoted in Algorithm 1 as exponentially weighted infinity norm. See [13] for a detailed description of the both Adam and AdaMax algorithms.    
Algorithm 1: The AdaMax algorithm [13] adapted to our context.
Mathematics 08 02197 i001
The number of units (i.e. weights and control points) is a hyperparameter and is determined based on the complexity of the shape to be approximated. Besides, the step size, α , can be changed depending on the state of the convergence of the training procedure, for example, when the loss values (i.e., the evaluation of the loss function) gets stuck or the update of the parameters is too big. Then, it is useful to increase or reduce, respectively, the step size according to the values of the loss function.

4. Experiments Results

In order to show the performance of the neural network N w , P , we have taken different sets of data points s = ( s i ) i = 0 . They have been chosen to reflect the variety of situations where the proposed neural network can be applied. The first set of data points belongs to a closed conic curve, the second one belongs to a transcendental curve, the third one is a curve with a twisted shape and, finally, the fourth one is a noisy set of data points from a baroque image.
In all cases, we have taken different functions f and g satisfying the conditions of Proposition 1 and allowing that the corresponding rational bases (2) have the optimal shape-preserving properties.
Remark 1.
One of the requirements for a rational basis to be the normalized B-basis of its generated space is the positivity of the weights. This makes it necessary to apply the absolute value to the weights in the weight update step of Algorithm 1. However, in the experiments shown, we opted to avoid this choice because we have observed that, although in the intermediate steps the weights could be negative, at the end of the training, the weights were positive and the convergence was faster. Nevertheless, we can add the restriction depending on the needs.
Let us notice that we have used an uniform distribution of the parameters t i , i = 0 , , , in all the examples. This choice of parameters does not have to be the optimal but we have preferred it because of its simplicity. Besides, a normalization of the data points, s = ( s i ) i = 0 , between 0 and 1, was applied in order to facilitate the training procedure following the formula:
s ^ i = s i min S max S min S , for i { 0 , , } .
The AdaMax algorithm was applied to solve the minimization problem with the mean absolute error loss function (12) with the following choice of hyperparameters: α = 0.0001 , β 1 = 0.9 , β 2 = 0.999 , and ε = 10 7 . Then, the number of iterations of the algorithm depends on the desired accuracy of the fitting curve to the set of data points. In this case, we have used between 3000 to 5000 iterations of the algorithm but, with more iterations and a better tuning of the parameters, the results provided here may be improved. Finally, in order to reach a better approximation, the first and the last control point of the fitting curve were fixed to be the same as the first and the last point of the set of data points, thus the obtained fitting curve is always exactly at those points. We can see in Table 1, a summary of the loss values from different fitting curves. Let us observe that the value n is the degree of the fitting curve and it depends on the complexity of the shape to be approximated. Moreover, let us notice that the proposed neural network is able to obtain a suitable accuracy with low degrees and, as a generalization of other methods, we can choose, depending on the shape of the set of data points, the basis that best fits. Note that, in CAGD, it is important to properly address the problem of curve fitting, finding a balance between accuracy and degree of the curve since high-degree curves are computationally expensive to evaluate. The AdaMax algorithm has been selected because it is computationally efficient with little memory requirements, suited for problems with large data or parameters. In Table 2, the time of execution of the Algorithm 1 using different numbers of units (i.e., weights and control points) and numbers of iterations is provided.
The implementation (the code of the experimentation can be found in https://github.com/Cimagroup/Curve-approximation-NN) was developed using TensorFlow 2.0 [17] allowing developers to easily use it to build and deploy Machine Learning powered applications. All experiments were ran on a Quad-Core Intel Core i7 CPU, 2.8 GHz with 16 GB RAM. Let us see a detailed description of the experiments.

4.1. Circle Curve

Circles and conic sections play a relevant role in curve design and have been approximated in several works (see [18,19]). Let us show different approximations to the circle given by the parametric equations
x c ( t ) = cos ( t ) , y c ( t ) = sin ( t ) ,
t [ 0 , 2 π ] . First, let us see an approximation obtained performing the neural network N w , P using polynomial functions.
We have taken the following sequence of points s = s i i = 0 99 on the circle (14):
s i = ( x c ( 2 π t i ) , y c ( 2 π t i ) ) , i = 0 , , 99 ,
being the parameters t i = i / 99 , i = 0 , , 99 .
For n = 5 , we have approximated the set s by the fitting curve ( N w , P x ( t ) , N w , P y ( t ) ) considering the functions f ( t ) = t and g ( t ) = 1 t at the vector nodes t = ( t i ) i = 0 99 with t i as above. After training the neural network N w , P , performing the Algorithm 1 for 3000 iterations, we have obtained the following weights:
w 0 5 = 1.253390550613403320 , w 1 5 = 0.6930422186851501465 , w 2 5 = 0.7461462020874023438 , w 3 5 = 0.7428795099258422852 , w 4 5 = 0.7499830722808837891 , w 5 5 = 1.511020541191101074 ,
and the following control points:
P 0 = ( 1 , 0 ) , P 1 = ( 0.9514569678202488 , 2.265164366524486 ) , P 2 = ( 2.041393043066488 , 1.823594836649781 ) , P 3 = ( 2.573274681480492 , 1.594942712567735 ) , P 4 = ( 0.9104298578262079 , 2.558222347419337 ) , P 5 = ( 1 , 0 ) .
We can see in Figure 5 the obtained fitting curve of degree 5 and its corresponding control polygon.
In order to analyze the performance of the obtained approximation to the circle, we depict some geometric approximations of the approximation error. In Figure 6, we plot the radial and curvature errors given, respectively, by
ϵ r ( t ) = r ( t ) 1 , ϵ k = k ( t ) 1 ,
where r ( t ) = N w , P x 2 ( t ) + N w , P y 2 ( t ) and k ( t ) = ( N w , P x ( t ) N w , P y ( t ) N w , P x ( t ) N w , P y ( t ) ) / ( N w , P x ( t ) ) 2 + ( N w , P y ( t ) ) 2 3 .
We can observe that the radial error vanishes at t = Δ , Δ because the approximation is exact for the initial and the last points of the curve.
Let us see another approximation example of the unit circle performing the neural network N w , P using trigonometric functions. We have the following set of data points s = s i i = 0 99 on circle (14):
s i = ( x c ( ( t i / Δ + 1 ) π ) , y c ( ( t i / Δ + 1 ) π ) , i = 0 , , 99 ,
being the parameters t i = Δ + 2 Δ i / 99 , i = 0 , , 99 , with  0 < Δ < π / 2 . For  n = 5 , we have approximated the set s by the fitting curve ( N w , P x ( t ) , N w , P y ( t ) ) using the functions f ( t ) = sin ( Δ + t ) / 2 and g ( t ) = sin ( Δ t ) / 2 at the vector nodes t = ( t i ) i = 0 99 with t i as above. After training the neural network N w , P , performing Algorithm 1 for 3000 iterations, and with α = 0.001 , β 1 = 0.9 , β 2 = 0.999 , a n d ε = 10 7 , we have obtained the following weights:
w 0 5 = 2.193439722061157227 , w 1 5 = 0.6315788030624389648 , w 2 5 = 0.4818322956562042236 , w 3 5 = 0.4559116661548614502 , w 4 5 = 0.6407876610755920410 , w 5 5 = 2.386862277984619141 ,
and the following control points:
P 0 = ( 1 , 0 ) , P 1 = ( 1.094536581177390 , 2.759880482316126 ) , P 2 = ( 3.104044853918599 , 2.85189370210171 ) , P 3 = ( 3.702726956127786 , 2.817369554402328 ) , P 4 = ( 1.085284693582619 , 3.000573791799708 ) , P 5 = ( 1 , 0 ) .
We can see in Figure 7 the fitting curve of degree 5 obtained and its control polygon.
Figure 8 shows its corresponding radial and curvature errors. We can observe that the radial error vanishes at t = Δ , Δ because the approximation is exact for the initial and the last points of the curve.
Finally, for different values of n, Figure 9 shows the history of the loss function given in (12) through the training process on 3000 iterations of the neural network N w , P using the polynomial functions and the trigonometric functions. We can observe, in both cases, that the convergence to the circle of the fitting curves is faster as n increases.

4.2. Cycloid Curve

Cycloids are commonly used in manufacturing applications (e.g. gear tooth geometry). The cycloid is a transcendental curve and thus, it cannot be expressed by polynomials exactly. Creating a complex curve in a CAD/CAM system is not always straightforward. In [20], it is shown the need to new methods for approximating this curve. Let us show different approximations to the cycloid by several fitting curves obtained by training the neural network N w , P using polynomial, trigonometric and hyperbolic functions f and g that satisfy the conditions of Proposition 1.
The cycloid is given by the parametric equations
x c c ( t ) = t sin t , y c c ( t ) = 1 cos t ,
t [ 0 , 2 π ] . We have taken the following sequence of points s = s i i = 0 99 on the cycloid (15):
s i = ( x c c ( 2 π t i ) , y c c ( 2 π t i ) ) , i = 0 , , 99 ,
being the parameters t i = i / 99 , i = 0 , , 99 .
For n = 10 , we have approximated the set s by two fitting curves at the vector nodes t = ( t i ) i = 0 99 with t i as above. One of the fitting curves is obtained using the functions f ( t ) = t and g ( t ) = 1 t , and the other fitting curve is obtained using the functions f ( t ) = t 2 and g ( t ) = 1 t 2 .
We can see in Figure 10, the fitting curves and their corresponding fitting error. The fitting error is given by the Euclidean norm between the approximated curve—in this case, the cycloid curve—and the obtained fitting curve. Observe that the cycloid curve is better approximated by the fitting curve obtained using the functions f ( t ) = t 2 and g ( t ) = 1 t 2 than by the fitting curve obtained using the functions f ( t ) = t and g ( t ) = 1 t .
Let us see two more approximations of the cycloid. We have taken the following sequence of points s = s i i = 0 99 on the cycloid (15):
s i = ( x c c ( ( t i / Δ + 1 ) π ) , y c c ( ( t i / Δ + 1 ) π ) , i = 0 , , 99 ,
being the parameters t i = Δ + 2 Δ i / 99 , i = 0 , , 99 , with  0 < Δ < π / 2 .
For n = 10 , we have approximated the set s by two fitting curves at the vector nodes t = ( t i ) i = 0 99 with t i as above. One of the fitting curves is obtained by training the neural network N w , P using the trigonometric functions f ( t ) = sin ( Δ + t ) / 2 and g ( t ) = sin ( Δ t ) / 2 and the other one using the hyperbolic functions f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 .
We can see in Figure 11, the fitting curves and their corresponding fitting error. Let us observe that the cycloid is better approximated by the fitting curve obtained using the hyperbolic functions than the fitting curve obtained using the trigonometric functions.

4.3. Archimedean Spiral Curve

Finally, let us show different approximations of the Archimedean spiral given by the parametric equations
x s a ( t ) = t cos ( t ) , y s a ( t ) = t sin ( t ) ,
t [ 0 , 4 π ] . First, let us see an approximation obtained training the neural network N w , P using polynomial functions. We have taken the following sequence of points s = s i i = 0 99 on the Archimedean spiral (16):
s i = ( x s a ( 4 π t i ) , y s a ( 4 π t i ) ) , i = 0 , , 99 ,
being the parameters t i = i / 99 , i = 0 , , 99 .
For n = 11 , we have approximated the set s by the fitting curve using the functions f ( t ) = t and g ( t ) = 1 t at the vector nodes t = ( t i ) i = 0 99 with t i as above. Figure 12 shows the fitting curve of degree 11 and its corresponding fitting error.
Let us see other examples in which the Archimedean spiral is approximated by the neural network using hyperbolic functions. We have taken the following sequence of points s = s i i = 0 99 on the Archimedean spiral (16):
s i = ( x s a ( ( t i + Δ ) 2 π / Δ ) , y s a ( ( t i + Δ ) 2 π / Δ ) , i = 0 , , 99 ,
being the parameters t i = Δ + 2 Δ i / 99 , i = 0 , , 99 . For  n = 11 , we have approximated the set s by the fitting curve using the functions f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 at the vector nodes t = ( t i ) i = 0 99 with t i as above.
Figure 13 shows the fitting curve of degree 11 and its corresponding fitting error.
We can see in Figure 14, the convergence of the two above fitting curves. Let us observe that the fitting curve corresponding to the hyperbolic rational basis has a faster convergence. Therefore, once again, it seems that the choice of the functions f and g, hence the choice of the rational basis, is relevant to the approximation.

4.4. Comparison of Least-Squares Fitting and the Neural Network N w , P

In this section, the proposed neural network is compared with the least-squares method and the regularized least-squares method. It is well known that least-squares fitting is a common procedure to find the best fitting curve to a given set of data points by minimizing the sum of the squares of the data points from the curve ([9,21,22]). The least-squares method is sensitive to small perturbations in data and, in those cases, regularization methods can be applied such as the regularized least-squares method (see [23]). Therefore, two experiments have been developed. The set of data points used in the first experiment is a non-noisy parametrization of known curves, so the least-squares method has been applied. In the second experiment, we used an image to obtain a noisy set of data points and applied the regularized least-squares method.
The problem that we want to solve is stated as follows. Suppose that f and g are functions defined on [ a , b ] satisfying the conditions of Proposition 1. Consider a set of parameters a t 0 < t b and a sequence of data points s 0 , , s R k , where each parameter t i is associated with a data point s i . For some n , we want to compute a rational curve
c ( t ) = i = 0 n w i n n i f i ( t ) g n i ( t ) i = 0 n w i n n i f i ( t ) g n i ( t ) P i , t [ a , b ] ,
minimizing the sum of the squares of the deviations from the set of data points s = ( s i ) i = 0 , that is, i = 0 ( s i c ( t i ) ) 2 . In order to compute the control points P = ( P i ) i = 0 n of the fitting curve, we have to solve, in the least-squares sense, the overdeterminated linear system A P = s , where the matrix A is
A = w i n n i f i ( t j ) g n i ( t j ) i = 0 n w i n n i f i ( t j ) g n i ( t j ) 0 i n ; 0 j .
In this fourth experiment, let us see two examples comparing the fitting curves obtained applying this traditional method and the fitting curves obtained by training the neural network N w , P . We have seen previously an approximation of the circle (14) obtained with the neural network N w , P for n = 5 using the polynomial functions f = t and g = 1 t , t [ 0 , 1 ] . Besides, we have seen an approximation of the Archimedean spiral (16) obtained with the neural network N w , P for n = 11 using the polynomial functions f = t and g = 1 t , t [ 0 , 1 ] . Using the same parameters and sets of data points, we solved the corresponding overdeterminated linear systems A P = s to obtain the control points of the curve that best fits the given data points in the least-squares sense. For this purpose, following the steps shown in Section 6.4 of [1], we have obtained the solutions of A P = s , firstly, by using the Matlab command SVD and, secondly, by using the Matlab command mldivide.
Since the weights are unknown and are necessary for solving the linear system A P = s in the least-squares sense, these have been randomly chosen within a positive range. Let us observe that one of the advantages of the neural network N w , P with respect to the least-squares method is that the neural network N w , P not only finds suitable control points, but it also finds suitable weights to fit the given set of data points.
In Table 3, the execution time of the least-squares method using a different number of weights and control points is provided. We can see that, although for low-degree fitting curves, the least-squares method is faster than the method proposed in this paper, for the fitting curves of degree greater than n = 18 , the proposed method is faster than the least-squares method.
We can see in Figure 15 and Figure 16 that the fitting curves obtained by training the neural network are more accurate than the fitting curves obtained by applying the traditional least-squares method.
In the last experiment, we have taken 31 points from a baroque image as a set of data points (see Figure 17). We have approximated them by two fitting curves of degree 8 with hyperbolic functions f ( t ) = sin ( Δ + t ) / 2 at the vector nodes t = ( t i ) i = 0 30 , such that t i = Δ + 2 Δ ( i 1 ) / 30 , 0 < Δ < π / 2 . The first fitting curve was obtained by training the neural network N w , P during 1000, reaching a final mean absolute error on the set of data points of 9 × 10 3 . Besides, this example shows the robustness of the proposed method to noisy data points. The second fitting curve was obtained with random vector weights and the regularized least-squares method by using an adaptation of the Matlab library available in [24]. This last fitting curve reached a mean absolute error of 1.95 × 10 2 . Visually, in Figure 17, it is appreciated that the fitting curve obtained by training the neural network N w , P achieves better curvature than the regularized least-squares method (which is more evident at the beginning and at the end of the curve). Finally, we would like to highlight that we have observed in all the executed experiments a good performance of the neural network for small values of n, in spite of the complexity of the set of data points.

5. Conlusions and Future Work

In this work, we have tackled the problem of finding a rational curve to fit a given set of data points. To solve this issue, we have proposed a one-hidden-layer neural network based on a general class of totally positive rational bases belonging to spaces mixing algebraic, trigonometric and hyperbolic polynomials, thus expanding the potential range of applications to include more difficult shapes. In order to obtain the weights and control points of the rational curve to fit the data points, the neural network is trained with an optimization algorithm to update the weights and control points while decreasing a loss function. The fitting curves of the numerical experiments show that for certain curves, the use of particular rational bases provides better results.
In future work, we wish to extend the neural network to obtain a suitable parametrization of the data points. The choice of the parameters can help to improve the approximation. Additionally, we plan to apply our method to curves, surfaces and high-dimensional data, and analyze, as in [25] for Bezier curves, its application to industrial software, CAD/CAM systems (such as Blender (https://www.blender.org/), Maya (https://www.autodesk.es/products/maya/overview) or Solid Edge (https://solidedge.siemens.com/en/)), and other real-world problems. Finally, we plan to explore the applicability of our approach to the resolution of linear differential equations (cf. [26,27]).

Author Contributions

Conceptualization, R.G.-D., E.M., E.P.-H. and B.R.; Investigation, R.G.-D., E.M., E.P.-H. and B.R.; Methodology, R.G.-D., E.M., E.P.-H. and B.R.; Software, R.G.-D., E.M., E.P.-H. and B.R.; Supervision, R.G.-D., E.M., E.P.-H. and B.R.; Validation, R.G.-D., E.M., E.P.-H. and B.R.; Writing—original draft, R.G.-D., E.M., E.P.-H. and B.R.; Writing—review and editing, R.G.-D., E.M., E.P.-H. and B.R. All authors have read and agreed to the published version of the manuscript.

Funding

MICINN, FEDER/UE under grant PID2019-107339GB-100,PGC2018-096321-B-I00 (MCIU/AEI), Gobierno de Aragón (E41_17R ) and Feder 2014–2020 “Construyendo Europa desde Aragón”.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Iglesias, A.; Gálvez, A.; Avila, A. Discrete Bézier Curve Fitting with Artificial Immune Systems. In Intelligent Computer Graphics 2012; Springer: Berlin/Heidelberg, Germany, 2013; pp. 59–75. [Google Scholar] [CrossRef]
  2. Hoffmann, M.; Várady, L. Free-form Surfaces for scattered data by neural networks. J. Geom. Graph. 1998, 2, 1–6. [Google Scholar]
  3. Delgado, J.; Peña, J.M. A Comparison of Different Progressive Iteration Approximation Methods. In Mathematical Methods for Curves and Surfaces; Dæhlen, M., Floater, M., Lyche, T., Merrien, J.L., Mørken, K., Schumaker, L.L., Eds.; Springer: Berlin/Heidelberg, Germany, 2010; pp. 136–152. [Google Scholar]
  4. Ando, T. Totally positive matrices. Linear Algebra Appl. 1987, 90, 165–219. [Google Scholar] [CrossRef] [Green Version]
  5. Peña, J. Shape preserving representations for trigonometric polynomial curves. Comput. Aided Geom. Des. 1997, 14, 5–11. [Google Scholar] [CrossRef]
  6. Carnicer, J.; Peña, J. Totally positive bases for shape preserving curve design and optimality of B-splines. Comput. Aided Geom. Des. 1994, 11, 633–654. [Google Scholar] [CrossRef]
  7. Carnicer, J.; Peña, J. Shape preserving representations and optimality of the Bernstein basis. Adv. Comput. Math 1993, 1, 173–196. [Google Scholar] [CrossRef]
  8. Mainar, E.; Peña, J.; Rubio, B. Evaluation and subdivision algorithms for general classes of totally positive rational bases. Comput. Aided Geom. Des. 2020, 81, 101900. [Google Scholar] [CrossRef]
  9. Farin, G. Curves and Surfaces for Computer Aided Geometric Design (Fifth Ed.): A Practical Guide; Academic Press Professional Inc.: Cambridge, MA, USA, 2002. [Google Scholar]
  10. Iglesias, A.; Gálvez, A.; Collantes, M. Global-support rational curve method for data approximation with bat algorithm. In Proceedings of the IFIP International Conference on Artificial Intelligence Applications and Innovations, Bayonne, France, 14–17 September 2015; Springer: Berlin/Heidelberg, Germany, 2015; pp. 191–205. [Google Scholar]
  11. Mehnen, J.; Weinert, K. Discrete NURBS-Surface Approximation using an Evolutionary Strategy. Reihe Comput. Intell. 2001, 87. [Google Scholar] [CrossRef]
  12. Van To, T.; Kositviwat, T. Using Rational B-Spline Neural Networks for Curve Approximation. In Proceedings of the 7th WSEAS International Conference on Mathematical Methods and Computational Techniques in Electrical Engineering, World Scientific and Engineering Academy and Society (WSEAS), Stevens Point, WI, USA, 7–9 November 2009; MMACTE’05. pp. 42–50. [Google Scholar]
  13. Kingma, D.P.; Ba, J. Adam: A Method for Stochastic Optimization. arXiv 2014, arXiv:cs.LG/1412.6980. [Google Scholar]
  14. Manni, C.; Pelosi, F.; Lucia Sampoli, M. Generalized B-splines as a tool in isogeometric analysis. Comput. Methods Appl. Mech. Eng. 2011, 200, 867–881. [Google Scholar] [CrossRef]
  15. Sánchez-Reyes, J. Harmonic rational Bézier curves, p-Bézier curves and trigonometric polynomials. Comput. Aided Geom. Des. 1998, 15, 909–923. [Google Scholar] [CrossRef]
  16. Mohri, M.; Rostamizadeh, A.; Talwalkar, A. Foundations of Machine Learning; The MIT Press: Cambridge, MA, USA, 2012. [Google Scholar]
  17. Abadi, M.; Agarwal, A.; Barham, P.; Brevdo, E.; Chen, Z.; Citro, C.; Corrado, G.S.; Davis, A.; Dean, J.; Devin, M.; et al. TensorFlow: Large-Scale Machine Learning on Heterogeneous Systems. arXiv 2015, arXiv:cs.DC/1603.04467. [Google Scholar]
  18. Carnicer, J.; Mainar, E.; Peña, J. Representing circles with five control points. Comput. Aided Geom. Des. 2003, 20, 501–511. [Google Scholar] [CrossRef]
  19. Carnicer, J.; Mainar, E.; Peña, J. A totally positive basis for circle approximations. Rev. Real Acad. Cienc. Exactas Fis. Nat. Ser. A Mat. 2019, 113. [Google Scholar] [CrossRef]
  20. Díaz Pérez, L.; Rubio Serrano, B.; Albajez García, J.; Yague Fabra, J.; Mainar Maza, E.; Torralba Gracia, M. Trajectory Definition with High Relative Accuracy (HRA) by Parametric Representation of Curves in Nano-Positioning Systems. Micromachines 2019, 10, 597. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  21. Marco, A.; Martínez, J.J. Polynomial least squares fitting in the Bernstein basis. Linear Algebra Its Appl. 2010, 433, 1254–1264. [Google Scholar] [CrossRef] [Green Version]
  22. Mainar, E.; Peña, J.; Rubio, B. Accurate least squares fitting with a general class of shape preserving bases. In Proceedings of the Fifteenth International Conference Zaragoza-Pau on Mathematics and its Applications, Jaca, Spain, 10–12 September 2019; pp. 183–192. [Google Scholar]
  23. Volkov, V.V.; Erokhin, V.I.; Kakaev, V.V.; Onufrei, A.Y. Generalizations of Tikhonov’s regularized method of least squares to non-Euclidean vector norms. Comput. Math. Math. Phys. 2017, 57, 1416–1426. [Google Scholar] [CrossRef]
  24. Rao, S. Regularized Least Square: Tikhonov Regularization Test for Hilbert Matrix. MATLAB Central File Exchange. 2020. Available online: https://es.mathworks.com/matlabcentral/fileexchange/58736-regularized-least-square-tikhonov-regularization-test-for-hilbert-matrix (accessed on 25 November 2020).
  25. Fitter, H.N.; Pandey, A.B.; Patel, D.D.; Mistry, J.M. A Review on Approaches for Handling Bezier Curves in CAD for Manufacturing. Procedia Eng. 2014, 97, 1155–1166. [Google Scholar] [CrossRef] [Green Version]
  26. Calin, I.; Öchsner, A.; Vlase, S.; Marin, M. Improved rigidity of composite circular plates through radial ribs. Proc. Inst. Mech. Eng. Part L J. Mater. Des. Appl. 2018, 233. [Google Scholar] [CrossRef]
  27. Groza, G.; Pop, N. Approximate solution of multipoint boundary value problems for linear differential equations by polynomial functions. J. Differ. Equations Appl. 2008, 14, 1289–1309. [Google Scholar] [CrossRef]
Figure 1. Initial curve (line) and curve obtained (dotted line) after changing the weights and/or control points. Left: changing the fourth weight; center: changing the fourth control point; and right: changing the fourth weight and the fourth control point.
Figure 1. Initial curve (line) and curve obtained (dotted line) after changing the weights and/or control points. Left: changing the fourth weight; center: changing the fourth control point; and right: changing the fourth weight and the fourth control point.
Mathematics 08 02197 g001
Figure 2. (Left): Rational basis (2) using f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] . Weights w = [ 1 , 2 , 3 , 2 ] (black line) and weights w = [ 1 , 2 , 3 , 8 ] (blue dotted line). (Right): Rational basis (2) using f ( t ) = sin ( Δ + t ) / 2 , g ( t ) = sin ( Δ t ) / 2 , t I = [ Δ , Δ ] , 0 < Δ < π / 2 . Weights w = [ 1 , 2 , 3 , 2 ] (black line) and weights w = [ 1 , 8 , 3 , 2 ] (blue dotted line).
Figure 2. (Left): Rational basis (2) using f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] . Weights w = [ 1 , 2 , 3 , 2 ] (black line) and weights w = [ 1 , 2 , 3 , 8 ] (blue dotted line). (Right): Rational basis (2) using f ( t ) = sin ( Δ + t ) / 2 , g ( t ) = sin ( Δ t ) / 2 , t I = [ Δ , Δ ] , 0 < Δ < π / 2 . Weights w = [ 1 , 2 , 3 , 2 ] (black line) and weights w = [ 1 , 8 , 3 , 2 ] (blue dotted line).
Mathematics 08 02197 g002
Figure 3. From top to bottom. The input layer has the parameter t R as input. The hidden layer is of width n + 1 and its parameters are the weights. Then, the output layer computes the approximation of the target curve and its parameters are the control points.
Figure 3. From top to bottom. The input layer has the parameter t R as input. The hidden layer is of width n + 1 and its parameters are the weights. Then, the output layer computes the approximation of the target curve and its parameters are the control points.
Mathematics 08 02197 g003
Figure 4. Evolution of the fitting curve N w , P ( t ) . Set of data points from the target curve (dotted) and the fitting curve (line). From top to bottom and left to right: Increment d = 0 , d = 250 , d = 500 , d = 1000 , d = 1500 , d = 2000 and d = 3000 .
Figure 4. Evolution of the fitting curve N w , P ( t ) . Set of data points from the target curve (dotted) and the fitting curve (line). From top to bottom and left to right: Increment d = 0 , d = 250 , d = 500 , d = 1000 , d = 1500 , d = 2000 and d = 3000 .
Mathematics 08 02197 g004
Figure 5. Fitting curve of degree 5 obtained using the functions f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] , and its corresponding control polygon.
Figure 5. Fitting curve of degree 5 obtained using the functions f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] , and its corresponding control polygon.
Mathematics 08 02197 g005
Figure 6. (Left): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the radial error value of the fitting curve obtained using the functions f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] . (Right): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the curvature error value of fitting curve obtained using the functions f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] .
Figure 6. (Left): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the radial error value of the fitting curve obtained using the functions f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] . (Right): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the curvature error value of fitting curve obtained using the functions f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] .
Mathematics 08 02197 g006
Figure 7. Fitting curve of degree 5 using f ( t ) = sin ( Δ + t ) / 2 and g ( t ) = sin ( Δ t ) / 2 , t [ Δ , Δ ] , and its control polygon.
Figure 7. Fitting curve of degree 5 using f ( t ) = sin ( Δ + t ) / 2 and g ( t ) = sin ( Δ t ) / 2 , t [ Δ , Δ ] , and its control polygon.
Mathematics 08 02197 g007
Figure 8. (Left): The x-axis represents the parameters t in [ Δ , Δ ] and the y-axis represents the radial error value of the fitting curve obtained using the trigonometric basis. (Right): The x-axis represents the parameters t in [ Δ , Δ ] and the y-axis represents the curvature error value of the fitting curves obtained using the trigonometric basis.
Figure 8. (Left): The x-axis represents the parameters t in [ Δ , Δ ] and the y-axis represents the radial error value of the fitting curve obtained using the trigonometric basis. (Right): The x-axis represents the parameters t in [ Δ , Δ ] and the y-axis represents the curvature error value of the fitting curves obtained using the trigonometric basis.
Mathematics 08 02197 g008
Figure 9. For different values of n, the history of the loss function, i.e., the mean absolute error values, through the training process on 3000 iterations while the fitting curves converges. (Left): Loss values of the fitting curve using f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] . (Right): Loss values of the fitting curve using f ( t ) = sin ( Δ + t ) / 2 , g ( t ) = sin ( Δ t ) / 2 , t [ Δ , Δ ] . The x-axis represents the iteration of the training algorithm and the y-axis represents the mean absolute error value.
Figure 9. For different values of n, the history of the loss function, i.e., the mean absolute error values, through the training process on 3000 iterations while the fitting curves converges. (Left): Loss values of the fitting curve using f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] . (Right): Loss values of the fitting curve using f ( t ) = sin ( Δ + t ) / 2 , g ( t ) = sin ( Δ t ) / 2 , t [ Δ , Δ ] . The x-axis represents the iteration of the training algorithm and the y-axis represents the mean absolute error value.
Mathematics 08 02197 g009
Figure 10. (Left): Set of data points on the cycloid (dotted), fitting curve obtained using the functions f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] (blue) and fitting curve obtained using the functions f ( t ) = t 2 , g ( t ) = 1 t 2 , t [ 0 , 1 ] (green). (Right): Fitting error comparison.The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the fitting error value of the fitting curves obtained using the functions f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] (green) and the functions f ( t ) = t 2 , g ( t ) = 1 t 2 , t [ 0 , 1 ] (blue).
Figure 10. (Left): Set of data points on the cycloid (dotted), fitting curve obtained using the functions f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] (blue) and fitting curve obtained using the functions f ( t ) = t 2 , g ( t ) = 1 t 2 , t [ 0 , 1 ] (green). (Right): Fitting error comparison.The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the fitting error value of the fitting curves obtained using the functions f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] (green) and the functions f ( t ) = t 2 , g ( t ) = 1 t 2 , t [ 0 , 1 ] (blue).
Mathematics 08 02197 g010
Figure 11. (Left): Set of data points on the cycloid (dotted), fitting curve obtained using the trigonometric functions f ( t ) = sin ( Δ + t ) / 2 and g ( t ) = sin ( Δ t ) / 2 and fitting curve obtained using the hyperbolic functions f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 . (Right): Fitting error comparison. The x-axis represents the parameters t in [ Δ , Δ ] and the y-axis represents the curvature error value of the fitting curve obtained using the trigonometric and hyperbolic bases.
Figure 11. (Left): Set of data points on the cycloid (dotted), fitting curve obtained using the trigonometric functions f ( t ) = sin ( Δ + t ) / 2 and g ( t ) = sin ( Δ t ) / 2 and fitting curve obtained using the hyperbolic functions f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 . (Right): Fitting error comparison. The x-axis represents the parameters t in [ Δ , Δ ] and the y-axis represents the curvature error value of the fitting curve obtained using the trigonometric and hyperbolic bases.
Mathematics 08 02197 g011
Figure 12. (Left): Set of data points on the Archimedean spiral (dotted) and the fitting curve of degree 11 obtained using the functions f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] . (Right): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the fitting error value of the fitting curve obtained using the functions f ( t ) = t and g ( t ) = 1 t .
Figure 12. (Left): Set of data points on the Archimedean spiral (dotted) and the fitting curve of degree 11 obtained using the functions f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] . (Right): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the fitting error value of the fitting curve obtained using the functions f ( t ) = t and g ( t ) = 1 t .
Mathematics 08 02197 g012
Figure 13. (Left): Set of data points on the Archimedean spiral (dotted) and the fitting curve of degree 11 with the functions f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 . (Right): The x-axis represents the parameters t in [ Δ , Δ ] and the y-axis represents the fitting error value of the fitting curve obtained using the hyperbolic basis.
Figure 13. (Left): Set of data points on the Archimedean spiral (dotted) and the fitting curve of degree 11 with the functions f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 . (Right): The x-axis represents the parameters t in [ Δ , Δ ] and the y-axis represents the fitting error value of the fitting curve obtained using the hyperbolic basis.
Mathematics 08 02197 g013
Figure 14. The history of the loss values, i.e., the mean absolute error values, through 3000 iterations of the training algorithm while the fitting curves converge is pictured. The blue line corresponds to the fitting curve of degree 11 obtained using f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] , and the orange line corresponds to the fitting curve of degree 11 obtained using f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 . The x-axis represents the iteration of the training algorithm and the y-axis represents the mean absolute error value. The values are the mean of 50 repetitions.
Figure 14. The history of the loss values, i.e., the mean absolute error values, through 3000 iterations of the training algorithm while the fitting curves converge is pictured. The blue line corresponds to the fitting curve of degree 11 obtained using f ( t ) = t and g ( t ) = 1 t , t [ 0 , 1 ] , and the orange line corresponds to the fitting curve of degree 11 obtained using f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 . The x-axis represents the iteration of the training algorithm and the y-axis represents the mean absolute error value. The values are the mean of 50 repetitions.
Mathematics 08 02197 g014
Figure 15. (Left): Set of data points on circle (dotted), fitting curve of degree 5 obtained with the neural network, fitting curve of degree 5 obtained with the least-squares method by using the Matlab commmand mldivide (LS1), fitting curve of degree 5 obtained with the least-squares method by using the Matlab command SVD (LS2). (Right): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the radial error value of the fitting curves obtained with the different methods.
Figure 15. (Left): Set of data points on circle (dotted), fitting curve of degree 5 obtained with the neural network, fitting curve of degree 5 obtained with the least-squares method by using the Matlab commmand mldivide (LS1), fitting curve of degree 5 obtained with the least-squares method by using the Matlab command SVD (LS2). (Right): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the radial error value of the fitting curves obtained with the different methods.
Mathematics 08 02197 g015
Figure 16. (Left): Set of points on the Archimedean spiral curve, fitting curve of degree 11 obtained with the neural network, fitting curve of degree 11 obtained with the least-squares method by using the Matlab command mldivide (LS1) and fitting curve of degree 11 obtained with the least-squares method using the Matlab command SVD (LS2). (Right): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the fitting error value of the fitting curves obtained with the different methods.
Figure 16. (Left): Set of points on the Archimedean spiral curve, fitting curve of degree 11 obtained with the neural network, fitting curve of degree 11 obtained with the least-squares method by using the Matlab command mldivide (LS1) and fitting curve of degree 11 obtained with the least-squares method using the Matlab command SVD (LS2). (Right): The x-axis represents the parameters t in [ 0 , 1 ] and the y-axis represents the fitting error value of the fitting curves obtained with the different methods.
Mathematics 08 02197 g016
Figure 17. Noisy set of data points obtained from the baroque image (points in blue), fitting curve obtained by training the proposed neural network (points in green) and fitting curve obtained using the regularized least-squares method (pink). Baroque motif image source: Freepik.com.
Figure 17. Noisy set of data points obtained from the baroque image (points in blue), fitting curve obtained by training the proposed neural network (points in green) and fitting curve obtained using the regularized least-squares method (pink). Baroque motif image source: Freepik.com.
Mathematics 08 02197 g017
Table 1. Loss values of the mean absolute error (12) for different fitting curves of degree n with f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] (Basis 1), f ( t ) = t 2 and g ( t ) = 1 t 2 , t [ 0 , 1 ] , (Basis 2), f ( t ) = sin ( Δ + t ) / 2 and g ( t ) = sin ( Δ t ) / 2 , Δ < π / 2 , Δ < π / 2 , t [ Δ , Δ ] , (Basis 3) and finally f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 , Δ < π / 2 , t [ Δ , Δ ] , (Basis 4). They were all trained with 4000 iterations, α = 0.0001 , β 1 = 0.9 , β 2 = 0.999 , ε = 10 7 . The process was repeated 5 times, with the loss values provided being the best values reached.
Table 1. Loss values of the mean absolute error (12) for different fitting curves of degree n with f ( t ) = t , g ( t ) = 1 t , t [ 0 , 1 ] (Basis 1), f ( t ) = t 2 and g ( t ) = 1 t 2 , t [ 0 , 1 ] , (Basis 2), f ( t ) = sin ( Δ + t ) / 2 and g ( t ) = sin ( Δ t ) / 2 , Δ < π / 2 , Δ < π / 2 , t [ Δ , Δ ] , (Basis 3) and finally f ( t ) = sinh ( Δ + t ) / 2 and g ( t ) = sinh ( Δ t ) / 2 , Δ < π / 2 , t [ Δ , Δ ] , (Basis 4). They were all trained with 4000 iterations, α = 0.0001 , β 1 = 0.9 , β 2 = 0.999 , ε = 10 7 . The process was repeated 5 times, with the loss values provided being the best values reached.
nBasis 1Basis 2Basis 3Basis 4
Circle
33.3946 × 10 2 3.7129 × 10 2 7.0468 × 10 2 3.6438 × 10 2
42.1757 × 10 3 1.5338 × 10 2 3.1678 × 10 3 2.5582 × 10 3
51.7333 × 10 4 9.2269 × 10 3 2.8083 × 10 4 2.2488 × 10 3
Cycloid
81.0849 × 10 3 3.6855 × 10 4 3.6017 × 10 4 3.1674 × 10 4
94.6163 × 10 4 3.6855 × 10 4 3.6017 × 10 4 2.4914 × 10 4
103.3944 × 10 4 3.6855 × 10 4 3.6017 × 10 4 2.4914 × 10 4
Archimedean spiral
111.5982 × 10 3 1.0474 × 10 2 2.2349 × 10 2 7.8109 × 10 4
121.5982 × 10 3 7.8916 × 10 3 5.7801 × 10 3 7.8109 × 10 4
131.4106 × 10 3 5.2853 × 10 3 5.7801 × 10 3 7.8109 × 10 4
Table 2. Time of execution of the proposed algorithm measured in seconds for different numbers of units and iterations. The values provided are the mean of 5 repetitions with a set of data points of size 100.
Table 2. Time of execution of the proposed algorithm measured in seconds for different numbers of units and iterations. The values provided are the mean of 5 repetitions with a set of data points of size 100.
n + 1 Number of Iterations
125501003000
50.12591.42842.83815.7259189.5386
100.09892.07814.132510.2672268.8726
150.12442.71425.378110.9886347.6139
500.64798.258913.357627.4398850.6713
1001.162414.399932.657665.32981521.3971
Table 3. For different number of weights and control points, the time of execution of the least-squares method using the Matlab commands mldivide and SVD, and the time of execution of the Algorithm 1 for 3000 iterations are provided. The values have been measured in seconds with a set of data points of size 100 and they are the mean of 5 repetitions.
Table 3. For different number of weights and control points, the time of execution of the least-squares method using the Matlab commands mldivide and SVD, and the time of execution of the Algorithm 1 for 3000 iterations are provided. The values have been measured in seconds with a set of data points of size 100 and they are the mean of 5 repetitions.
n + 1 Least-Squares MethodAlgorithm 1
mldivideSVD3000 Iterations
563.301465.6015189.5386
10167.0402237.0386268.8726
15309.5811457.8987347.6139
20478.1141774.3472429.2819
30961.2860978.6830568.5647
502552.40644097.9278850.6713
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Gonzalez-Diaz, R.; Mainar, E.; Paluzo-Hidalgo, E.; Rubio, B. Neural-Network-Based Curve Fitting Using Totally Positive Rational Bases. Mathematics 2020, 8, 2197. https://doi.org/10.3390/math8122197

AMA Style

Gonzalez-Diaz R, Mainar E, Paluzo-Hidalgo E, Rubio B. Neural-Network-Based Curve Fitting Using Totally Positive Rational Bases. Mathematics. 2020; 8(12):2197. https://doi.org/10.3390/math8122197

Chicago/Turabian Style

Gonzalez-Diaz, Rocio, E. Mainar, Eduardo Paluzo-Hidalgo, and B. Rubio. 2020. "Neural-Network-Based Curve Fitting Using Totally Positive Rational Bases" Mathematics 8, no. 12: 2197. https://doi.org/10.3390/math8122197

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop