alglibinternal.h   alglibinternal.h 
skipping to change at line 172 skipping to change at line 172
ae_state *_state); ae_state *_state);
void taskgenint1dcheb2(double a, void taskgenint1dcheb2(double a,
double b, double b,
ae_int_t n, ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
ae_state *_state); ae_state *_state);
ae_bool aredistinct(/* Real */ ae_vector* x, ae_bool aredistinct(/* Real */ ae_vector* x,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
void bvectorsetlengthatleast(/* Boolean */ ae_vector* x,
ae_int_t n,
ae_state *_state);
void rvectorsetlengthatleast(/* Real */ ae_vector* x,
ae_int_t n,
ae_state *_state);
void rmatrixsetlengthatleast(/* Real */ ae_matrix* x,
ae_int_t m,
ae_int_t n,
ae_state *_state);
ae_bool isfinitevector(/* Real */ ae_vector* x, ae_bool isfinitevector(/* Real */ ae_vector* x,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
ae_bool isfinitecvector(/* Complex */ ae_vector* z, ae_bool isfinitecvector(/* Complex */ ae_vector* z,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
ae_bool apservisfinitematrix(/* Real */ ae_matrix* x, ae_bool apservisfinitematrix(/* Real */ ae_matrix* x,
ae_int_t m, ae_int_t m,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
skipping to change at line 201 skipping to change at line 211
ae_int_t n, ae_int_t n,
ae_bool isupper, ae_bool isupper,
ae_state *_state); ae_state *_state);
ae_bool apservisfiniteornanmatrix(/* Real */ ae_matrix* x, ae_bool apservisfiniteornanmatrix(/* Real */ ae_matrix* x,
ae_int_t m, ae_int_t m,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
double safepythag2(double x, double y, ae_state *_state); double safepythag2(double x, double y, ae_state *_state);
double safepythag3(double x, double y, double z, ae_state *_state); double safepythag3(double x, double y, double z, ae_state *_state);
ae_int_t saferdiv(double x, double y, double* r, ae_state *_state); ae_int_t saferdiv(double x, double y, double* r, ae_state *_state);
double safeminposrv(double x, double y, double v, ae_state *_state);
void apperiodicmap(double* x, void apperiodicmap(double* x,
double a, double a,
double b, double b,
double* k, double* k,
ae_state *_state); ae_state *_state);
double boundval(double x, double b1, double b2, ae_state *_state); double boundval(double x, double b1, double b2, ae_state *_state);
ae_bool _apbuffers_init(apbuffers* p, ae_state *_state, ae_bool make_automa tic); ae_bool _apbuffers_init(apbuffers* p, ae_state *_state, ae_bool make_automa tic);
ae_bool _apbuffers_init_copy(apbuffers* dst, apbuffers* src, ae_state *_sta te, ae_bool make_automatic); ae_bool _apbuffers_init_copy(apbuffers* dst, apbuffers* src, ae_state *_sta te, ae_bool make_automatic);
void _apbuffers_clear(apbuffers* p); void _apbuffers_clear(apbuffers* p);
void rankx(/* Real */ ae_vector* x, void rankx(/* Real */ ae_vector* x,
 End of changes. 2 change blocks. 
0 lines changed or deleted 11 lines changed or added


 ap.h   ap.h 
skipping to change at line 24 skipping to change at line 24
A copy of the GNU General Public License is available at A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>> >>> END OF LICENSE >>>
*************************************************************************/ *************************************************************************/
#ifndef _ap_h #ifndef _ap_h
#define _ap_h #define _ap_h
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <setjmp.h> #include <stddef.h>
#include <string> #include <string>
#include <cstring> #include <cstring>
#include <math.h> #include <math.h>
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#include <list.h> #include <list.h>
#include <vector.h> #include <vector.h>
#else #else
#include <list> #include <list>
#include <vector> #include <vector>
skipping to change at line 49 skipping to change at line 49
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS DECLARATIONS FOR BASIC FUNCTIONALITY // THIS SECTION CONTAINS DECLARATIONS FOR BASIC FUNCTIONALITY
// LIKE MEMORY MANAGEMENT FOR VECTORS/MATRICES WHICH IS SHARED // LIKE MEMORY MANAGEMENT FOR VECTORS/MATRICES WHICH IS SHARED
// BETWEEN C++ AND PURE C LIBRARIES // BETWEEN C++ AND PURE C LIBRARIES
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
/* /*
* automatically determine compiler * definitions
*/ */
#define AE_UNKNOWN 0 #define AE_UNKNOWN 0
#define AE_MSVC 1 #define AE_MSVC 1
#define AE_GNUC 2 #define AE_GNUC 2
#define AE_SUNC 3 #define AE_SUNC 3
#define AE_INTEL 1
#define AE_SPARC 2
/*
* automatically determine compiler
*/
#define AE_COMPILER AE_UNKNOWN #define AE_COMPILER AE_UNKNOWN
#ifdef __GNUC__ #ifdef __GNUC__
#undef AE_COMPILER #undef AE_COMPILER
#define AE_COMPILER AE_GNUC #define AE_COMPILER AE_GNUC
#endif #endif
#ifdef __SUNPRO_C #ifdef __SUNPRO_C
#undef AE_COMPILER #undef AE_COMPILER
#define AE_COMPILER AE_SUNC #define AE_COMPILER AE_SUNC
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
skipping to change at line 115 skipping to change at line 121
#if !defined(AE_HAVE_STDINT) && !defined(AE_INT64_T) #if !defined(AE_HAVE_STDINT) && !defined(AE_INT64_T)
#if AE_COMPILER==AE_MSVC #if AE_COMPILER==AE_MSVC
typedef _int64 ae_int64_t; typedef _int64 ae_int64_t;
#endif #endif
#if (AE_COMPILER==AE_GNUC) || (AE_COMPILER==AE_SUNC) || (AE_COMPILER==AE_UN KNOWN) #if (AE_COMPILER==AE_GNUC) || (AE_COMPILER==AE_SUNC) || (AE_COMPILER==AE_UN KNOWN)
typedef signed long long ae_int64_t; typedef signed long long ae_int64_t;
#endif #endif
#endif #endif
#if !defined(AE_INT_T) #if !defined(AE_INT_T)
#include <stddef.h>
typedef ptrdiff_t ae_int_t; typedef ptrdiff_t ae_int_t;
#endif #endif
#if !defined(AE_USE_CPP_BOOL) #if !defined(AE_USE_CPP_BOOL)
#define ae_bool char #define ae_bool char
#define ae_true 1 #define ae_true 1
#define ae_false 0 #define ae_false 0
#else #else
#define ae_bool bool #define ae_bool bool
#define ae_true true #define ae_true true
#define ae_false false #define ae_false false
#endif #endif
/*
* SSE2 intrinsics
*
* Preprocessor directives below:
* - include headers for SSE2 intrinsics
* - define AE_HAS_SSE2_INTRINSICS definition
*
* These actions are performed when we have:
* - x86 architecture definition (AE_CPU==AE_INTEL)
* - compiler which supports intrinsics
*
* Presence of AE_HAS_SSE2_INTRINSICS does NOT mean that our CPU
* actually supports SSE2 - such things should be determined at runtime
* with ae_cpuid() call. It means that we are working under Intel and
* out compiler can issue SSE2-capable code.
*
*/
#if defined(AE_CPU)
#if AE_CPU==AE_INTEL
#ifdef AE_USE_CPP
} // end of namespace declaration, subsequent includes must be out of names
pace
#endif
#if AE_COMPILER==AE_MSVC
#include <emmintrin.h>
#define AE_HAS_SSE2_INTRINSICS
#endif
#if (AE_COMPILER==AE_GNUC)||(AE_COMPILER==AE_SUNC)
#include <xmmintrin.h>
#define AE_HAS_SSE2_INTRINSICS
#endif
#ifdef AE_USE_CPP
namespace alglib_impl { // namespace declaration continued
#endif
#endif
#endif
typedef struct { double x, y; } ae_complex; typedef struct { double x, y; } ae_complex;
typedef enum typedef enum
{ {
ERR_OK = 0, ERR_OK = 0,
ERR_OUT_OF_MEMORY = 1, ERR_OUT_OF_MEMORY = 1,
ERR_XARRAY_TOO_LARGE = 2, ERR_XARRAY_TOO_LARGE = 2,
ERR_ASSERTION_FAILED = 3 ERR_ASSERTION_FAILED = 3
} ae_error_type; } ae_error_type;
typedef ae_int_t ae_datatype; typedef ae_int_t ae_datatype;
/* /*
* other definitions * other definitions
*/ */
enum { OWN_CALLER=1, OWN_AE=2 }; enum { OWN_CALLER=1, OWN_AE=2 };
enum { ACT_UNCHANGED=1, ACT_SAME_LOCATION=2, ACT_NEW_LOCATION=3 }; enum { ACT_UNCHANGED=1, ACT_SAME_LOCATION=2, ACT_NEW_LOCATION=3 };
enum { DT_BOOL=1, DT_INT=2, DT_REAL=3, DT_COMPLEX=4 }; enum { DT_BOOL=1, DT_INT=2, DT_REAL=3, DT_COMPLEX=4 };
enum { CPU_SSE2=1 };
/************************************************************************ /************************************************************************
x-string (zero-terminated): x-string (zero-terminated):
owner OWN_CALLER or OWN_AE. Determines what to do on realloc(). owner OWN_CALLER or OWN_AE. Determines what to do on realloc().
If vector is owned by caller, X-interface will just set If vector is owned by caller, X-interface will just set
ptr to NULL before realloc(). If it is owned by X, it ptr to NULL before realloc(). If it is owned by X, it
will call ae_free/x_free/aligned_free family functions. will call ae_free/x_free/aligned_free family functions.
last_action ACT_UNCHANGED, ACT_SAME_LOCATION, ACT_NEW_LOCATION last_action ACT_UNCHANGED, ACT_SAME_LOCATION, ACT_NEW_LOCATION
contents is either: unchanged, stored at the same location, contents is either: unchanged, stored at the same location,
skipping to change at line 278 skipping to change at line 325
typedef struct typedef struct
{ {
ae_int_t endianness; ae_int_t endianness;
double v_nan; double v_nan;
double v_posinf; double v_posinf;
double v_neginf; double v_neginf;
ae_dyn_block * volatile p_top_block; ae_dyn_block * volatile p_top_block;
ae_dyn_block last_block; ae_dyn_block last_block;
#ifndef AE_USE_CPP_ERROR_HANDLING
jmp_buf * volatile break_jump; jmp_buf * volatile break_jump;
#endif
ae_error_type volatile last_error; ae_error_type volatile last_error;
const char* volatile error_msg; const char* volatile error_msg;
} ae_state; } ae_state;
typedef void(*ae_deallocator)(void*); typedef void(*ae_deallocator)(void*);
typedef struct ae_vector typedef struct ae_vector
{ {
ae_int_t cnt; ae_int_t cnt;
ae_datatype datatype; ae_datatype datatype;
skipping to change at line 318 skipping to change at line 367
{ {
void *p_ptr; void *p_ptr;
void **pp_void; void **pp_void;
ae_bool **pp_bool; ae_bool **pp_bool;
ae_int_t **pp_int; ae_int_t **pp_int;
double **pp_double; double **pp_double;
ae_complex **pp_complex; ae_complex **pp_complex;
} ptr; } ptr;
} ae_matrix; } ae_matrix;
ae_int_t ae_misalignment(const void *ptr, size_t alignment);
void* ae_align(void *ptr, size_t alignment); void* ae_align(void *ptr, size_t alignment);
void* aligned_malloc(size_t size, size_t alignment); void* aligned_malloc(size_t size, size_t alignment);
void aligned_free(void *block); void aligned_free(void *block);
void* ae_malloc(size_t size, ae_state *state); void* ae_malloc(size_t size, ae_state *state);
void ae_free(void *p); void ae_free(void *p);
ae_int_t ae_sizeof(ae_datatype datatype); ae_int_t ae_sizeof(ae_datatype datatype);
void ae_state_init(ae_state *state); void ae_state_init(ae_state *state);
void ae_state_clear(ae_state *state); void ae_state_clear(ae_state *state);
#ifndef AE_USE_CPP_ERROR_HANDLING
void ae_state_set_break_jump(ae_state *state, jmp_buf *buf); void ae_state_set_break_jump(ae_state *state, jmp_buf *buf);
#endif
void ae_break(ae_state *state, ae_error_type error_type, const char *msg); void ae_break(ae_state *state, ae_error_type error_type, const char *msg);
void ae_frame_make(ae_state *state, ae_frame *tmp); void ae_frame_make(ae_state *state, ae_frame *tmp);
void ae_frame_leave(ae_state *state); void ae_frame_leave(ae_state *state);
void ae_db_attach(ae_dyn_block *block, ae_state *state); void ae_db_attach(ae_dyn_block *block, ae_state *state);
ae_bool ae_db_malloc(ae_dyn_block *block, ae_int_t size, ae_state *state, a e_bool make_automatic); ae_bool ae_db_malloc(ae_dyn_block *block, ae_int_t size, ae_state *state, a e_bool make_automatic);
ae_bool ae_db_realloc(ae_dyn_block *block, ae_int_t size, ae_state *state); ae_bool ae_db_realloc(ae_dyn_block *block, ae_int_t size, ae_state *state);
void ae_db_free(ae_dyn_block *block); void ae_db_free(ae_dyn_block *block);
void ae_db_swap(ae_dyn_block *block1, ae_dyn_block *block2); void ae_db_swap(ae_dyn_block *block1, ae_dyn_block *block2);
skipping to change at line 374 skipping to change at line 426
ae_bool x_force_hermitian(x_matrix *a); ae_bool x_force_hermitian(x_matrix *a);
ae_bool ae_is_symmetric(ae_matrix *a); ae_bool ae_is_symmetric(ae_matrix *a);
ae_bool ae_is_hermitian(ae_matrix *a); ae_bool ae_is_hermitian(ae_matrix *a);
ae_bool ae_force_symmetric(ae_matrix *a); ae_bool ae_force_symmetric(ae_matrix *a);
ae_bool ae_force_hermitian(ae_matrix *a); ae_bool ae_force_hermitian(ae_matrix *a);
/************************************************************************ /************************************************************************
Service functions Service functions
************************************************************************/ ************************************************************************/
void ae_assert(ae_bool cond, const char *msg, ae_state *state); void ae_assert(ae_bool cond, const char *msg, ae_state *state);
ae_int_t ae_cpuid();
/************************************************************************ /************************************************************************
Real math functions: Real math functions:
* IEEE-compliant floating point comparisons * IEEE-compliant floating point comparisons
* standard functions * standard functions
************************************************************************/ ************************************************************************/
ae_bool ae_fp_eq(double v1, double v2); ae_bool ae_fp_eq(double v1, double v2);
ae_bool ae_fp_neq(double v1, double v2); ae_bool ae_fp_neq(double v1, double v2);
ae_bool ae_fp_less(double v1, double v2); ae_bool ae_fp_less(double v1, double v2);
ae_bool ae_fp_less_eq(double v1, double v2); ae_bool ae_fp_less_eq(double v1, double v2);
skipping to change at line 526 skipping to change at line 579
ae_vector ca; ae_vector ca;
} rcommstate; } rcommstate;
ae_bool _rcommstate_init(rcommstate* p, ae_state *_state, ae_bool make_auto matic); ae_bool _rcommstate_init(rcommstate* p, ae_state *_state, ae_bool make_auto matic);
ae_bool _rcommstate_init_copy(rcommstate* dst, rcommstate* src, ae_state *_ state, ae_bool make_automatic); ae_bool _rcommstate_init_copy(rcommstate* dst, rcommstate* src, ae_state *_ state, ae_bool make_automatic);
void _rcommstate_clear(rcommstate* p); void _rcommstate_clear(rcommstate* p);
#ifdef AE_USE_ALLOC_COUNTER #ifdef AE_USE_ALLOC_COUNTER
extern ae_int64_t _alloc_counter; extern ae_int64_t _alloc_counter;
#endif #endif
/************************************************************************
debug functions (must be turned on by preprocessor definitions:
* tickcount(), which is wrapper around GetTickCount()
************************************************************************/
#ifdef AE_DEBUG4WINDOWS
#include <windows.h>
#include <stdio.h>
#define tickcount(s) GetTickCount()
#define flushconsole(s) fflush(stdout)
#endif
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS DECLARATIONS FOR C++ RELATED FUNCTIONALITY // THIS SECTION CONTAINS DECLARATIONS FOR C++ RELATED FUNCTIONALITY
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib namespace alglib
{ {
skipping to change at line 991 skipping to change at line 1055
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTIONS CONTAINS DECLARATIONS FOR OPTIMIZED LINEAR ALGEBRA CODES // THIS SECTIONS CONTAINS DECLARATIONS FOR OPTIMIZED LINEAR ALGEBRA CODES
// IT IS SHARED BETWEEN C++ AND PURE C LIBRARIES // IT IS SHARED BETWEEN C++ AND PURE C LIBRARIES
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
#define ALGLIB_INTERCEPTS_ABLAS #define ALGLIB_INTERCEPTS_ABLAS
void _ialglib_mv_32(const double *a, const double *x, double *y, ae_int_t s
tride, double alpha, double beta);
void _ialglib_mv(ae_int_t m, ae_int_t n, const double *a, const double *x,
double *y, ae_int_t stride, double alpha, double beta);
void _ialglib_mv_generic(ae_int_t m, ae_int_t n, const double *a, const dou
ble *x, double *y, ae_int_t stride, double alpha, double beta);
void _ialglib_mv_complex(ae_int_t m, ae_int_t n, const double *a, const dou
ble *x, ae_complex *cy, double *dy, ae_int_t stride, ae_complex alpha, ae_c
omplex beta);
void _ialglib_mv_complex_generic(ae_int_t m, ae_int_t n, const double *a, c
onst double *x, ae_complex *cy, double *dy, ae_int_t stride, ae_complex alp
ha, ae_complex beta);
void _ialglib_vzero(ae_int_t n, double *p, ae_int_t stride); void _ialglib_vzero(ae_int_t n, double *p, ae_int_t stride);
void _ialglib_vzero_complex(ae_int_t n, ae_complex *p, ae_int_t stride); void _ialglib_vzero_complex(ae_int_t n, ae_complex *p, ae_int_t stride);
void _ialglib_vcopy(ae_int_t n, const double *a, ae_int_t stridea, double * b, ae_int_t strideb); void _ialglib_vcopy(ae_int_t n, const double *a, ae_int_t stridea, double * b, ae_int_t strideb);
void _ialglib_vcopy_complex(ae_int_t n, const ae_complex *a, ae_int_t strid void _ialglib_vcopy_complex(ae_int_t n, const ae_complex *a, ae_int_t strid
ea, double *b, ae_int_t strideb, char *conj); ea, double *b, ae_int_t strideb, const char *conj);
void _ialglib_vcopy_complex(ae_int_t n, const double *a, ae_int_t stridea, void _ialglib_vcopy_dcomplex(ae_int_t n, const double *a, ae_int_t stridea,
double *b, ae_int_t strideb, char *conj); double *b, ae_int_t strideb, const char *conj);
void _ialglib_mcopyblock(ae_int_t m, ae_int_t n, const double *a, ae_int_t op, ae_int_t stride, double *b); void _ialglib_mcopyblock(ae_int_t m, ae_int_t n, const double *a, ae_int_t op, ae_int_t stride, double *b);
void _ialglib_mcopyunblock(ae_int_t m, ae_int_t n, const double *a, ae_int_ t op, double *b, ae_int_t stride); void _ialglib_mcopyunblock(ae_int_t m, ae_int_t n, const double *a, ae_int_ t op, double *b, ae_int_t stride);
void _ialglib_mcopyblock_complex(ae_int_t m, ae_int_t n, const ae_complex * a, ae_int_t op, ae_int_t stride, double *b); void _ialglib_mcopyblock_complex(ae_int_t m, ae_int_t n, const ae_complex * a, ae_int_t op, ae_int_t stride, double *b);
void _ialglib_mcopyunblock_complex(ae_int_t m, ae_int_t n, const double *a, ae_int_t op, ae_complex* b, ae_int_t stride); void _ialglib_mcopyunblock_complex(ae_int_t m, ae_int_t n, const double *a, ae_int_t op, ae_complex* b, ae_int_t stride);
bool _ialglib_i_rmatrixgemmf(ae_int_t m, ae_bool _ialglib_i_rmatrixgemmf(ae_int_t m,
ae_int_t n, ae_int_t n,
ae_int_t k, ae_int_t k,
double alpha, double alpha,
ae_matrix *a, ae_matrix *a,
ae_int_t ia, ae_int_t ia,
ae_int_t ja, ae_int_t ja,
ae_int_t optypea, ae_int_t optypea,
ae_matrix *b, ae_matrix *b,
ae_int_t ib, ae_int_t ib,
ae_int_t jb, ae_int_t jb,
ae_int_t optypeb, ae_int_t optypeb,
double beta, double beta,
ae_matrix *c, ae_matrix *c,
ae_int_t ic, ae_int_t ic,
ae_int_t jc); ae_int_t jc);
bool _ialglib_i_cmatrixgemmf(ae_int_t m, ae_bool _ialglib_i_cmatrixgemmf(ae_int_t m,
ae_int_t n, ae_int_t n,
ae_int_t k, ae_int_t k,
ae_complex alpha, ae_complex alpha,
ae_matrix *a, ae_matrix *a,
ae_int_t ia, ae_int_t ia,
ae_int_t ja, ae_int_t ja,
ae_int_t optypea, ae_int_t optypea,
ae_matrix *b, ae_matrix *b,
ae_int_t ib, ae_int_t ib,
ae_int_t jb, ae_int_t jb,
ae_int_t optypeb, ae_int_t optypeb,
ae_complex beta, ae_complex beta,
ae_matrix *c, ae_matrix *c,
ae_int_t ic, ae_int_t ic,
ae_int_t jc); ae_int_t jc);
bool _ialglib_i_cmatrixrighttrsmf(ae_int_t m, ae_bool _ialglib_i_cmatrixrighttrsmf(ae_int_t m,
ae_int_t n, ae_int_t n,
ae_matrix *a, ae_matrix *a,
ae_int_t i1, ae_int_t i1,
ae_int_t j1, ae_int_t j1,
bool isupper, ae_bool isupper,
bool isunit, ae_bool isunit,
ae_int_t optype, ae_int_t optype,
ae_matrix *x, ae_matrix *x,
ae_int_t i2, ae_int_t i2,
ae_int_t j2); ae_int_t j2);
bool _ialglib_i_rmatrixrighttrsmf(ae_int_t m, ae_bool _ialglib_i_rmatrixrighttrsmf(ae_int_t m,
ae_int_t n, ae_int_t n,
ae_matrix *a, ae_matrix *a,
ae_int_t i1, ae_int_t i1,
ae_int_t j1, ae_int_t j1,
bool isupper, ae_bool isupper,
bool isunit, ae_bool isunit,
ae_int_t optype, ae_int_t optype,
ae_matrix *x, ae_matrix *x,
ae_int_t i2, ae_int_t i2,
ae_int_t j2); ae_int_t j2);
bool _ialglib_i_cmatrixlefttrsmf(ae_int_t m, ae_bool _ialglib_i_cmatrixlefttrsmf(ae_int_t m,
ae_int_t n, ae_int_t n,
ae_matrix *a, ae_matrix *a,
ae_int_t i1, ae_int_t i1,
ae_int_t j1, ae_int_t j1,
bool isupper, ae_bool isupper,
bool isunit, ae_bool isunit,
ae_int_t optype, ae_int_t optype,
ae_matrix *x, ae_matrix *x,
ae_int_t i2, ae_int_t i2,
ae_int_t j2); ae_int_t j2);
bool _ialglib_i_rmatrixlefttrsmf(ae_int_t m, ae_bool _ialglib_i_rmatrixlefttrsmf(ae_int_t m,
ae_int_t n, ae_int_t n,
ae_matrix *a, ae_matrix *a,
ae_int_t i1, ae_int_t i1,
ae_int_t j1, ae_int_t j1,
bool isupper, ae_bool isupper,
bool isunit, ae_bool isunit,
ae_int_t optype, ae_int_t optype,
ae_matrix *x, ae_matrix *x,
ae_int_t i2, ae_int_t i2,
ae_int_t j2); ae_int_t j2);
bool _ialglib_i_cmatrixsyrkf(ae_int_t n, ae_bool _ialglib_i_cmatrixsyrkf(ae_int_t n,
ae_int_t k, ae_int_t k,
double alpha, double alpha,
ae_matrix *a, ae_matrix *a,
ae_int_t ia, ae_int_t ia,
ae_int_t ja, ae_int_t ja,
ae_int_t optypea, ae_int_t optypea,
double beta, double beta,
ae_matrix *c, ae_matrix *c,
ae_int_t ic, ae_int_t ic,
ae_int_t jc, ae_int_t jc,
bool isupper); ae_bool isupper);
bool _ialglib_i_rmatrixsyrkf(ae_int_t n, ae_bool _ialglib_i_rmatrixsyrkf(ae_int_t n,
ae_int_t k, ae_int_t k,
double alpha, double alpha,
ae_matrix *a, ae_matrix *a,
ae_int_t ia, ae_int_t ia,
ae_int_t ja, ae_int_t ja,
ae_int_t optypea, ae_int_t optypea,
double beta, double beta,
ae_matrix *c, ae_matrix *c,
ae_int_t ic, ae_int_t ic,
ae_int_t jc, ae_int_t jc,
bool isupper); ae_bool isupper);
bool _ialglib_i_cmatrixrank1f(ae_int_t m, ae_bool _ialglib_i_cmatrixrank1f(ae_int_t m,
ae_int_t n, ae_int_t n,
ae_matrix *a, ae_matrix *a,
ae_int_t ia, ae_int_t ia,
ae_int_t ja, ae_int_t ja,
ae_vector *u, ae_vector *u,
ae_int_t uoffs, ae_int_t uoffs,
ae_vector *v, ae_vector *v,
ae_int_t voffs); ae_int_t voffs);
bool _ialglib_i_rmatrixrank1f(ae_int_t m, ae_bool _ialglib_i_rmatrixrank1f(ae_int_t m,
ae_int_t n, ae_int_t n,
ae_matrix *a, ae_matrix *a,
ae_int_t ia, ae_int_t ia,
ae_int_t ja, ae_int_t ja,
ae_vector *u, ae_vector *u,
ae_int_t uoffs, ae_int_t uoffs,
ae_vector *v, ae_vector *v,
ae_int_t voffs); ae_int_t voffs);
} }
 End of changes. 29 change blocks. 
40 lines changed or deleted 92 lines changed or added


 dataanalysis.h   dataanalysis.h 
skipping to change at line 39 skipping to change at line 39
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
typedef struct typedef struct
{ {
double relclserror;
double avgce;
double rmserror;
double avgerror;
double avgrelerror;
} cvreport;
typedef struct
{
ae_int_t nvars; ae_int_t nvars;
ae_int_t nclasses; ae_int_t nclasses;
ae_int_t ntrees; ae_int_t ntrees;
ae_int_t bufsize; ae_int_t bufsize;
ae_vector trees; ae_vector trees;
} decisionforest; } decisionforest;
typedef struct typedef struct
{ {
double relclserror; double relclserror;
double avgce; double avgce;
skipping to change at line 75 skipping to change at line 83
ae_vector classibuf; ae_vector classibuf;
ae_vector sortrbuf; ae_vector sortrbuf;
ae_vector sortrbuf2; ae_vector sortrbuf2;
ae_vector sortibuf; ae_vector sortibuf;
ae_vector varpool; ae_vector varpool;
ae_vector evsbin; ae_vector evsbin;
ae_vector evssplits; ae_vector evssplits;
} dfinternalbuffers; } dfinternalbuffers;
typedef struct typedef struct
{ {
double relclserror;
double avgce;
double rmserror;
double avgerror;
double avgrelerror;
} cvreport;
typedef struct
{
ae_vector w; ae_vector w;
} linearmodel; } linearmodel;
typedef struct typedef struct
{ {
ae_matrix c; ae_matrix c;
double rmserror; double rmserror;
double avgerror; double avgerror;
double avgrelerror; double avgrelerror;
double cvrmserror; double cvrmserror;
double cvavgerror; double cvavgerror;
double cvavgrelerror; double cvavgrelerror;
ae_int_t ncvdefects; ae_int_t ncvdefects;
ae_vector cvdefects; ae_vector cvdefects;
} lrreport; } lrreport;
typedef struct typedef struct
{ {
ae_vector structinfo;
ae_vector weights;
ae_vector columnmeans;
ae_vector columnsigmas;
ae_vector neurons;
ae_vector dfdnet;
ae_vector derror;
ae_vector x;
ae_vector y;
ae_matrix chunks;
ae_vector nwbuf;
} multilayerperceptron;
typedef struct
{
ae_vector w; ae_vector w;
} logitmodel; } logitmodel;
typedef struct typedef struct
{ {
ae_bool brackt; ae_bool brackt;
ae_bool stage1; ae_bool stage1;
ae_int_t infoc; ae_int_t infoc;
double dg; double dg;
double dgm; double dgm;
double dginit; double dginit;
skipping to change at line 136 skipping to change at line 150
double width1; double width1;
double xtrapf; double xtrapf;
} logitmcstate; } logitmcstate;
typedef struct typedef struct
{ {
ae_int_t ngrad; ae_int_t ngrad;
ae_int_t nhess; ae_int_t nhess;
} mnlreport; } mnlreport;
typedef struct typedef struct
{ {
ae_vector structinfo; ae_int_t ngrad;
ae_vector weights; ae_int_t nhess;
ae_vector columnmeans; ae_int_t ncholesky;
ae_vector columnsigmas; } mlpreport;
ae_vector neurons; typedef struct
ae_vector dfdnet; {
ae_vector derror; double relclserror;
ae_vector x; double avgce;
ae_vector y; double rmserror;
ae_matrix chunks; double avgerror;
ae_vector nwbuf; double avgrelerror;
} multilayerperceptron; } mlpcvreport;
typedef struct typedef struct
{ {
ae_vector structinfo; ae_vector structinfo;
ae_int_t ensemblesize; ae_int_t ensemblesize;
ae_int_t nin; ae_int_t nin;
ae_int_t nout; ae_int_t nout;
ae_int_t wcount; ae_int_t wcount;
ae_bool issoftmax; ae_bool issoftmax;
ae_bool postprocessing; ae_bool postprocessing;
ae_vector weights; ae_vector weights;
skipping to change at line 169 skipping to change at line 183
ae_vector columnsigmas; ae_vector columnsigmas;
ae_int_t serializedlen; ae_int_t serializedlen;
ae_vector serializedmlp; ae_vector serializedmlp;
ae_vector tmpweights; ae_vector tmpweights;
ae_vector tmpmeans; ae_vector tmpmeans;
ae_vector tmpsigmas; ae_vector tmpsigmas;
ae_vector neurons; ae_vector neurons;
ae_vector dfdnet; ae_vector dfdnet;
ae_vector y; ae_vector y;
} mlpensemble; } mlpensemble;
typedef struct
{
ae_int_t ngrad;
ae_int_t nhess;
ae_int_t ncholesky;
} mlpreport;
typedef struct
{
double relclserror;
double avgce;
double rmserror;
double avgerror;
double avgrelerror;
} mlpcvreport;
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS C++ INTERFACE // THIS SECTION CONTAINS C++ INTERFACE
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib namespace alglib
{ {
skipping to change at line 330 skipping to change at line 330
double &cvavgerror; double &cvavgerror;
double &cvavgrelerror; double &cvavgrelerror;
ae_int_t &ncvdefects; ae_int_t &ncvdefects;
integer_1d_array cvdefects; integer_1d_array cvdefects;
}; };
/************************************************************************* /*************************************************************************
*************************************************************************/ *************************************************************************/
class _multilayerperceptron_owner
{
public:
_multilayerperceptron_owner();
_multilayerperceptron_owner(const _multilayerperceptron_owner &rhs);
_multilayerperceptron_owner& operator=(const _multilayerperceptron_owne
r &rhs);
virtual ~_multilayerperceptron_owner();
alglib_impl::multilayerperceptron* c_ptr();
alglib_impl::multilayerperceptron* c_ptr() const;
protected:
alglib_impl::multilayerperceptron *p_struct;
};
class multilayerperceptron : public _multilayerperceptron_owner
{
public:
multilayerperceptron();
multilayerperceptron(const multilayerperceptron &rhs);
multilayerperceptron& operator=(const multilayerperceptron &rhs);
virtual ~multilayerperceptron();
};
/*************************************************************************
*************************************************************************/
class _logitmodel_owner class _logitmodel_owner
{ {
public: public:
_logitmodel_owner(); _logitmodel_owner();
_logitmodel_owner(const _logitmodel_owner &rhs); _logitmodel_owner(const _logitmodel_owner &rhs);
_logitmodel_owner& operator=(const _logitmodel_owner &rhs); _logitmodel_owner& operator=(const _logitmodel_owner &rhs);
virtual ~_logitmodel_owner(); virtual ~_logitmodel_owner();
alglib_impl::logitmodel* c_ptr(); alglib_impl::logitmodel* c_ptr();
alglib_impl::logitmodel* c_ptr() const; alglib_impl::logitmodel* c_ptr() const;
protected: protected:
skipping to change at line 382 skipping to change at line 407
mnlreport(); mnlreport();
mnlreport(const mnlreport &rhs); mnlreport(const mnlreport &rhs);
mnlreport& operator=(const mnlreport &rhs); mnlreport& operator=(const mnlreport &rhs);
virtual ~mnlreport(); virtual ~mnlreport();
ae_int_t &ngrad; ae_int_t &ngrad;
ae_int_t &nhess; ae_int_t &nhess;
}; };
/************************************************************************* /*************************************************************************
*************************************************************************/
class _multilayerperceptron_owner
{
public:
_multilayerperceptron_owner();
_multilayerperceptron_owner(const _multilayerperceptron_owner &rhs);
_multilayerperceptron_owner& operator=(const _multilayerperceptron_owne
r &rhs);
virtual ~_multilayerperceptron_owner();
alglib_impl::multilayerperceptron* c_ptr();
alglib_impl::multilayerperceptron* c_ptr() const;
protected:
alglib_impl::multilayerperceptron *p_struct;
};
class multilayerperceptron : public _multilayerperceptron_owner
{
public:
multilayerperceptron();
multilayerperceptron(const multilayerperceptron &rhs);
multilayerperceptron& operator=(const multilayerperceptron &rhs);
virtual ~multilayerperceptron();
};
/*************************************************************************
Neural networks ensemble
*************************************************************************/
class _mlpensemble_owner
{
public:
_mlpensemble_owner();
_mlpensemble_owner(const _mlpensemble_owner &rhs);
_mlpensemble_owner& operator=(const _mlpensemble_owner &rhs);
virtual ~_mlpensemble_owner();
alglib_impl::mlpensemble* c_ptr();
alglib_impl::mlpensemble* c_ptr() const;
protected:
alglib_impl::mlpensemble *p_struct;
};
class mlpensemble : public _mlpensemble_owner
{
public:
mlpensemble();
mlpensemble(const mlpensemble &rhs);
mlpensemble& operator=(const mlpensemble &rhs);
virtual ~mlpensemble();
};
/*************************************************************************
Training report: Training report:
* NGrad - number of gradient calculations * NGrad - number of gradient calculations
* NHess - number of Hessian calculations * NHess - number of Hessian calculations
* NCholesky - number of Cholesky decompositions * NCholesky - number of Cholesky decompositions
*************************************************************************/ *************************************************************************/
class _mlpreport_owner class _mlpreport_owner
{ {
public: public:
_mlpreport_owner(); _mlpreport_owner();
_mlpreport_owner(const _mlpreport_owner &rhs); _mlpreport_owner(const _mlpreport_owner &rhs);
skipping to change at line 493 skipping to change at line 468
virtual ~mlpcvreport(); virtual ~mlpcvreport();
double &relclserror; double &relclserror;
double &avgce; double &avgce;
double &rmserror; double &rmserror;
double &avgerror; double &avgerror;
double &avgrelerror; double &avgrelerror;
}; };
/************************************************************************* /*************************************************************************
Neural networks ensemble
*************************************************************************/
class _mlpensemble_owner
{
public:
_mlpensemble_owner();
_mlpensemble_owner(const _mlpensemble_owner &rhs);
_mlpensemble_owner& operator=(const _mlpensemble_owner &rhs);
virtual ~_mlpensemble_owner();
alglib_impl::mlpensemble* c_ptr();
alglib_impl::mlpensemble* c_ptr() const;
protected:
alglib_impl::mlpensemble *p_struct;
};
class mlpensemble : public _mlpensemble_owner
{
public:
mlpensemble();
mlpensemble(const mlpensemble &rhs);
mlpensemble& operator=(const mlpensemble &rhs);
virtual ~mlpensemble();
};
/*************************************************************************
Optimal binary classification
Algorithms finds optimal (=with minimal cross-entropy) binary partition.
Internal subroutine.
INPUT PARAMETERS:
A - array[0..N-1], variable
C - array[0..N-1], class numbers (0 or 1).
N - array size
OUTPUT PARAMETERS:
Info - completetion code:
* -3, all values of A[] are same (partition is impossible)
* -2, one of C[] is incorrect (<0, >1)
* -1, incorrect pararemets were passed (N<=0).
* 1, OK
Threshold- partiton boundary. Left part contains values which are
strictly less than Threshold. Right part contains values
which are greater than or equal to Threshold.
PAL, PBL- probabilities P(0|v<Threshold) and P(1|v<Threshold)
PAR, PBR- probabilities P(0|v>=Threshold) and P(1|v>=Threshold)
CVE - cross-validation estimate of cross-entropy
-- ALGLIB --
Copyright 22.05.2008 by Bochkanov Sergey
*************************************************************************/
void dsoptimalsplit2(const real_1d_array &a, const integer_1d_array &c, con
st ae_int_t n, ae_int_t &info, double &threshold, double &pal, double &pbl,
double &par, double &pbr, double &cve);
/*************************************************************************
Optimal partition, internal subroutine. Fast version.
Accepts:
A array[0..N-1] array of attributes array[0..N-1]
C array[0..N-1] array of class labels
TiesBuf array[0..N] temporaries (ties)
CntBuf array[0..2*NC-1] temporaries (counts)
Alpha centering factor (0<=alpha<=1, recommended
value - 0.05)
BufR array[0..N-1] temporaries
BufI array[0..N-1] temporaries
Output:
Info error code (">0"=OK, "<0"=bad)
RMS training set RMS error
CVRMS leave-one-out RMS error
Note:
content of all arrays is changed by subroutine;
it doesn't allocate temporaries.
-- ALGLIB --
Copyright 11.12.2008 by Bochkanov Sergey
*************************************************************************/
void dsoptimalsplit2fast(real_1d_array &a, integer_1d_array &c, integer_1d_
array &tiesbuf, integer_1d_array &cntbuf, real_1d_array &bufr, integer_1d_a
rray &bufi, const ae_int_t n, const ae_int_t nc, const double alpha, ae_int
_t &info, double &threshold, double &rms, double &cvrms);
/*************************************************************************
This subroutine builds random decision forest. This subroutine builds random decision forest.
INPUT PARAMETERS: INPUT PARAMETERS:
XY - training set XY - training set
NPoints - training set size, NPoints>=1 NPoints - training set size, NPoints>=1
NVars - number of independent variables, NVars>=1 NVars - number of independent variables, NVars>=1
NClasses - task type: NClasses - task type:
* NClasses=1 - regression task with one * NClasses=1 - regression task with one
dependent variable dependent variable
* NClasses>1 - classification task with * NClasses>1 - classification task with
skipping to change at line 648 skipping to change at line 703
Its meaning for regression task is obvious. As for Its meaning for regression task is obvious. As for
classification task, it means average relative error when estimating classification task, it means average relative error when estimating
posterior probability of belonging to the correct class. posterior probability of belonging to the correct class.
-- ALGLIB -- -- ALGLIB --
Copyright 16.02.2009 by Bochkanov Sergey Copyright 16.02.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
double dfavgrelerror(const decisionforest &df, const real_2d_array &xy, con st ae_int_t npoints); double dfavgrelerror(const decisionforest &df, const real_2d_array &xy, con st ae_int_t npoints);
/************************************************************************* /*************************************************************************
Optimal binary classification k-means++ clusterization
Algorithms finds optimal (=with minimal cross-entropy) binary partition.
Internal subroutine.
INPUT PARAMETERS: INPUT PARAMETERS:
A - array[0..N-1], variable XY - dataset, array [0..NPoints-1,0..NVars-1].
C - array[0..N-1], class numbers (0 or 1). NPoints - dataset size, NPoints>=K
N - array size NVars - number of variables, NVars>=1
K - desired number of clusters, K>=1
Restarts - number of restarts, Restarts>=1
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info - completetion code: Info - return code:
* -3, all values of A[] are same (partition is impossible) * -3, if task is degenerate (number of distinct points
* -2, one of C[] is incorrect (<0, >1) is
* -1, incorrect pararemets were passed (N<=0). less than K)
* 1, OK * -1, if incorrect NPoints/NFeatures/K/Restarts was pas
Threshold- partiton boundary. Left part contains values which are sed
strictly less than Threshold. Right part contains values * 1, if subroutine finished successfully
which are greater than or equal to Threshold. C - array[0..NVars-1,0..K-1].matrix whose columns store
PAL, PBL- probabilities P(0|v<Threshold) and P(1|v<Threshold) cluster's centers
PAR, PBR- probabilities P(0|v>=Threshold) and P(1|v>=Threshold) XYC - array which contains number of clusters dataset points
CVE - cross-validation estimate of cross-entropy belong to.
-- ALGLIB --
Copyright 22.05.2008 by Bochkanov Sergey
*************************************************************************/
void dsoptimalsplit2(const real_1d_array &a, const integer_1d_array &c, con
st ae_int_t n, ae_int_t &info, double &threshold, double &pal, double &pbl,
double &par, double &pbr, double &cve);
/*************************************************************************
Optimal partition, internal subroutine. Fast version.
Accepts:
A array[0..N-1] array of attributes array[0..N-1]
C array[0..N-1] array of class labels
TiesBuf array[0..N] temporaries (ties)
CntBuf array[0..2*NC-1] temporaries (counts)
Alpha centering factor (0<=alpha<=1, recommended
value - 0.05)
BufR array[0..N-1] temporaries
BufI array[0..N-1] temporaries
Output:
Info error code (">0"=OK, "<0"=bad)
RMS training set RMS error
CVRMS leave-one-out RMS error
Note:
content of all arrays is changed by subroutine;
it doesn't allocate temporaries.
-- ALGLIB --
Copyright 11.12.2008 by Bochkanov Sergey
*************************************************************************/
void dsoptimalsplit2fast(real_1d_array &a, integer_1d_array &c, integer_1d_
array &tiesbuf, integer_1d_array &cntbuf, real_1d_array &bufr, integer_1d_a
rray &bufi, const ae_int_t n, const ae_int_t nc, const double alpha, ae_int
_t &info, double &threshold, double &rms, double &cvrms);
/*************************************************************************
k-means++ clusterization
INPUT PARAMETERS:
XY - dataset, array [0..NPoints-1,0..NVars-1].
NPoints - dataset size, NPoints>=K
NVars - number of variables, NVars>=1
K - desired number of clusters, K>=1
Restarts - number of restarts, Restarts>=1
OUTPUT PARAMETERS:
Info - return code:
* -3, if task is degenerate (number of distinct points
is
less than K)
* -1, if incorrect NPoints/NFeatures/K/Restarts was pas
sed
* 1, if subroutine finished successfully
C - array[0..NVars-1,0..K-1].matrix whose columns store
cluster's centers
XYC - array which contains number of clusters dataset points
belong to.
-- ALGLIB -- -- ALGLIB --
Copyright 21.03.2009 by Bochkanov Sergey Copyright 21.03.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void kmeansgenerate(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nvars, const ae_int_t k, const ae_int_t restarts, ae_int_t &info, real_2d_array &c, integer_1d_array &xyc); void kmeansgenerate(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nvars, const ae_int_t k, const ae_int_t restarts, ae_int_t &info, real_2d_array &c, integer_1d_array &xyc);
/************************************************************************* /*************************************************************************
Multiclass Fisher LDA Multiclass Fisher LDA
Subroutine finds coefficients of linear combination which optimally separat es Subroutine finds coefficients of linear combination which optimally separat es
skipping to change at line 985 skipping to change at line 985
RESULT: RESULT:
average relative error. average relative error.
-- ALGLIB -- -- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
double lravgrelerror(const linearmodel &lm, const real_2d_array &xy, const ae_int_t npoints); double lravgrelerror(const linearmodel &lm, const real_2d_array &xy, const ae_int_t npoints);
/************************************************************************* /*************************************************************************
This subroutine trains logit model.
INPUT PARAMETERS:
XY - training set, array[0..NPoints-1,0..NVars]
First NVars columns store values of independent
variables, next column stores number of class (from 0
to NClasses-1) which dataset element belongs to. Fracti
onal
values are rounded to nearest integer.
NPoints - training set size, NPoints>=1
NVars - number of independent variables, NVars>=1
NClasses - number of classes, NClasses>=2
OUTPUT PARAMETERS:
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<NVars+2, NVars<1, NClasses<2).
* 1, if task has been solved
LM - model built
Rep - training report
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnltrainh(const real_2d_array &xy, const ae_int_t npoints, const ae_in
t_t nvars, const ae_int_t nclasses, ae_int_t &info, logitmodel &lm, mnlrepo
rt &rep);
/*************************************************************************
Procesing
INPUT PARAMETERS:
LM - logit model, passed by non-constant reference
(some fields of structure are used as temporaries
when calculating model output).
X - input vector, array[0..NVars-1].
Y - (possibly) preallocated buffer; if size of Y is less than
NClasses, it will be reallocated.If it is large enough, it
is NOT reallocated, so we can save some time on reallocatio
n.
OUTPUT PARAMETERS:
Y - result, array[0..NClasses-1]
Vector of posterior probabilities for classification task.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnlprocess(const logitmodel &lm, const real_1d_array &x, real_1d_array
&y);
/*************************************************************************
'interactive' variant of MNLProcess for languages like Python which
support constructs like "Y = MNLProcess(LM,X)" and interactive mode of the
interpreter
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnlprocessi(const logitmodel &lm, const real_1d_array &x, real_1d_arra
y &y);
/*************************************************************************
Unpacks coefficients of logit model. Logit model have form:
P(class=i) = S(i) / (S(0) + S(1) + ... +S(M-1))
S(i) = Exp(A[i,0]*X[0] + ... + A[i,N-1]*X[N-1] + A[i,N]), when i<
M-1
S(M-1) = 1
INPUT PARAMETERS:
LM - logit model in ALGLIB format
OUTPUT PARAMETERS:
V - coefficients, array[0..NClasses-2,0..NVars]
NVars - number of independent variables
NClasses - number of classes
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnlunpack(const logitmodel &lm, real_2d_array &a, ae_int_t &nvars, ae_
int_t &nclasses);
/*************************************************************************
"Packs" coefficients and creates logit model in ALGLIB format (MNLUnpack
reversed).
INPUT PARAMETERS:
A - model (see MNLUnpack)
NVars - number of independent variables
NClasses - number of classes
OUTPUT PARAMETERS:
LM - logit model.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnlpack(const real_2d_array &a, const ae_int_t nvars, const ae_int_t n
classes, logitmodel &lm);
/*************************************************************************
Average cross-entropy (in bits per element) on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
CrossEntropy/(NPoints*ln(2)).
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
double mnlavgce(const logitmodel &lm, const real_2d_array &xy, const ae_int
_t npoints);
/*************************************************************************
Relative classification error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
percent of incorrectly classified cases.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
double mnlrelclserror(const logitmodel &lm, const real_2d_array &xy, const
ae_int_t npoints);
/*************************************************************************
RMS error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
root mean square error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
double mnlrmserror(const logitmodel &lm, const real_2d_array &xy, const ae_
int_t npoints);
/*************************************************************************
Average error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
average error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
double mnlavgerror(const logitmodel &lm, const real_2d_array &xy, const ae_
int_t npoints);
/*************************************************************************
Average relative error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
average relative error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
double mnlavgrelerror(const logitmodel &lm, const real_2d_array &xy, const
ae_int_t ssize);
/*************************************************************************
Classification error on test set = MNLRelClsError*NPoints
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
ae_int_t mnlclserror(const logitmodel &lm, const real_2d_array &xy, const a
e_int_t npoints);
/*************************************************************************
Creates neural network with NIn inputs, NOut outputs, without hidden Creates neural network with NIn inputs, NOut outputs, without hidden
layers, with linear output layer. Network weights are filled with small layers, with linear output layer. Network weights are filled with small
random values. random values.
-- ALGLIB -- -- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mlpcreate0(const ae_int_t nin, const ae_int_t nout, multilayerperceptr on &network); void mlpcreate0(const ae_int_t nin, const ae_int_t nout, multilayerperceptr on &network);
/************************************************************************* /*************************************************************************
skipping to change at line 1587 skipping to change at line 1399
Copyright 26.01.2008 by Bochkanov Sergey. Copyright 26.01.2008 by Bochkanov Sergey.
Hessian calculation based on R-algorithm described in Hessian calculation based on R-algorithm described in
"Fast Exact Multiplication by the Hessian", "Fast Exact Multiplication by the Hessian",
B. A. Pearlmutter, B. A. Pearlmutter,
Neural Computation, 1994. Neural Computation, 1994.
*************************************************************************/ *************************************************************************/
void mlphessianbatch(const multilayerperceptron &network, const real_2d_arr ay &xy, const ae_int_t ssize, double &e, real_1d_array &grad, real_2d_array &h); void mlphessianbatch(const multilayerperceptron &network, const real_2d_arr ay &xy, const ae_int_t ssize, double &e, real_1d_array &grad, real_2d_array &h);
/************************************************************************* /*************************************************************************
Like MLPCreate0, but for ensembles. This subroutine trains logit model.
-- ALGLIB -- INPUT PARAMETERS:
Copyright 18.02.2009 by Bochkanov Sergey XY - training set, array[0..NPoints-1,0..NVars]
*************************************************************************/ First NVars columns store values of independent
void mlpecreate0(const ae_int_t nin, const ae_int_t nout, const ae_int_t en variables, next column stores number of class (from 0
semblesize, mlpensemble &ensemble); to NClasses-1) which dataset element belongs to. Fracti
onal
values are rounded to nearest integer.
NPoints - training set size, NPoints>=1
NVars - number of independent variables, NVars>=1
NClasses - number of classes, NClasses>=2
/************************************************************************* OUTPUT PARAMETERS:
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<NVars+2, NVars<1, NClasses<2).
* 1, if task has been solved
LM - model built
Rep - training report
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnltrainh(const real_2d_array &xy, const ae_int_t npoints, const ae_in
t_t nvars, const ae_int_t nclasses, ae_int_t &info, logitmodel &lm, mnlrepo
rt &rep);
/*************************************************************************
Procesing
INPUT PARAMETERS:
LM - logit model, passed by non-constant reference
(some fields of structure are used as temporaries
when calculating model output).
X - input vector, array[0..NVars-1].
Y - (possibly) preallocated buffer; if size of Y is less than
NClasses, it will be reallocated.If it is large enough, it
is NOT reallocated, so we can save some time on reallocatio
n.
OUTPUT PARAMETERS:
Y - result, array[0..NClasses-1]
Vector of posterior probabilities for classification task.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnlprocess(const logitmodel &lm, const real_1d_array &x, real_1d_array
&y);
/*************************************************************************
'interactive' variant of MNLProcess for languages like Python which
support constructs like "Y = MNLProcess(LM,X)" and interactive mode of the
interpreter
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnlprocessi(const logitmodel &lm, const real_1d_array &x, real_1d_arra
y &y);
/*************************************************************************
Unpacks coefficients of logit model. Logit model have form:
P(class=i) = S(i) / (S(0) + S(1) + ... +S(M-1))
S(i) = Exp(A[i,0]*X[0] + ... + A[i,N-1]*X[N-1] + A[i,N]), when i<
M-1
S(M-1) = 1
INPUT PARAMETERS:
LM - logit model in ALGLIB format
OUTPUT PARAMETERS:
V - coefficients, array[0..NClasses-2,0..NVars]
NVars - number of independent variables
NClasses - number of classes
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnlunpack(const logitmodel &lm, real_2d_array &a, ae_int_t &nvars, ae_
int_t &nclasses);
/*************************************************************************
"Packs" coefficients and creates logit model in ALGLIB format (MNLUnpack
reversed).
INPUT PARAMETERS:
A - model (see MNLUnpack)
NVars - number of independent variables
NClasses - number of classes
OUTPUT PARAMETERS:
LM - logit model.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
void mnlpack(const real_2d_array &a, const ae_int_t nvars, const ae_int_t n
classes, logitmodel &lm);
/*************************************************************************
Average cross-entropy (in bits per element) on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
CrossEntropy/(NPoints*ln(2)).
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
double mnlavgce(const logitmodel &lm, const real_2d_array &xy, const ae_int
_t npoints);
/*************************************************************************
Relative classification error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
percent of incorrectly classified cases.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
double mnlrelclserror(const logitmodel &lm, const real_2d_array &xy, const
ae_int_t npoints);
/*************************************************************************
RMS error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
root mean square error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
double mnlrmserror(const logitmodel &lm, const real_2d_array &xy, const ae_
int_t npoints);
/*************************************************************************
Average error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
average error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
double mnlavgerror(const logitmodel &lm, const real_2d_array &xy, const ae_
int_t npoints);
/*************************************************************************
Average relative error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
average relative error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
double mnlavgrelerror(const logitmodel &lm, const real_2d_array &xy, const
ae_int_t ssize);
/*************************************************************************
Classification error on test set = MNLRelClsError*NPoints
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
ae_int_t mnlclserror(const logitmodel &lm, const real_2d_array &xy, const a
e_int_t npoints);
/*************************************************************************
Neural network training using modified Levenberg-Marquardt with exact
Hessian calculation and regularization. Subroutine trains neural network
with restarts from random positions. Algorithm is well suited for small
and medium scale problems (hundreds of weights).
INPUT PARAMETERS:
Network - neural network with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts from random position, >0.
If you don't know what Restarts to choose, use 2.
OUTPUT PARAMETERS:
Network - trained neural network.
Info - return code:
* -9, if internal matrix inverse subroutine failed
* -2, if there is a point with class number
outside of [0..NOut-1].
* -1, if wrong parameters specified
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
void mlptrainlm(const multilayerperceptron &network, const real_2d_array &x
y, const ae_int_t npoints, const double decay, const ae_int_t restarts, ae_
int_t &info, mlpreport &rep);
/*************************************************************************
Neural network training using L-BFGS algorithm with regularization.
Subroutine trains neural network with restarts from random positions.
Algorithm is well suited for problems of any dimensionality (memory
requirements and step complexity are linear by weights number).
INPUT PARAMETERS:
Network - neural network with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts from random position, >0.
If you don't know what Restarts to choose, use 2.
WStep - stopping criterion. Algorithm stops if step size is
less than WStep. Recommended value - 0.01. Zero step
size means stopping after MaxIts iterations.
MaxIts - stopping criterion. Algorithm stops after MaxIts
iterations (NOT gradient calculations). Zero MaxIts
means stopping when step is sufficiently small.
OUTPUT PARAMETERS:
Network - trained neural network.
Info - return code:
* -8, if both WStep=0 and MaxIts=0
* -2, if there is a point with class number
outside of [0..NOut-1].
* -1, if wrong parameters specified
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report
-- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey
*************************************************************************/
void mlptrainlbfgs(const multilayerperceptron &network, const real_2d_array
&xy, const ae_int_t npoints, const double decay, const ae_int_t restarts,
const double wstep, const ae_int_t maxits, ae_int_t &info, mlpreport &rep);
/*************************************************************************
Neural network training using early stopping (base algorithm - L-BFGS with
regularization).
INPUT PARAMETERS:
Network - neural network with initialized geometry
TrnXY - training set
TrnSize - training set size
ValXY - validation set
ValSize - validation set size
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts from random position, >0.
If you don't know what Restarts to choose, use 2.
OUTPUT PARAMETERS:
Network - trained neural network.
Info - return code:
* -2, if there is a point with class number
outside of [0..NOut-1].
* -1, if wrong parameters specified
(NPoints<0, Restarts<1, ...).
* 2, task has been solved, stopping criterion met -
sufficiently small step size. Not expected (we
use EARLY stopping) but possible and not an
error.
* 6, task has been solved, stopping criterion met -
increasing of validation set error.
Rep - training report
NOTE:
Algorithm stops if validation set error increases for a long enough or
step size is small enought (there are task where validation set may
decrease for eternity). In any case solution returned corresponds to the
minimum of validation set error.
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
void mlptraines(const multilayerperceptron &network, const real_2d_array &t
rnxy, const ae_int_t trnsize, const real_2d_array &valxy, const ae_int_t va
lsize, const double decay, const ae_int_t restarts, ae_int_t &info, mlprepo
rt &rep);
/*************************************************************************
Cross-validation estimate of generalization error.
Base algorithm - L-BFGS.
INPUT PARAMETERS:
Network - neural network with initialized geometry. Network is
not changed during cross-validation - it is used only
as a representative of its architecture.
XY - training set.
SSize - training set size
Decay - weight decay, same as in MLPTrainLBFGS
Restarts - number of restarts, >0.
restarts are counted for each partition separately, so
total number of restarts will be Restarts*FoldsCount.
WStep - stopping criterion, same as in MLPTrainLBFGS
MaxIts - stopping criterion, same as in MLPTrainLBFGS
FoldsCount - number of folds in k-fold cross-validation,
2<=FoldsCount<=SSize.
recommended value: 10.
OUTPUT PARAMETERS:
Info - return code, same as in MLPTrainLBFGS
Rep - report, same as in MLPTrainLM/MLPTrainLBFGS
CVRep - generalization error estimates
-- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey
*************************************************************************/
void mlpkfoldcvlbfgs(const multilayerperceptron &network, const real_2d_arr
ay &xy, const ae_int_t npoints, const double decay, const ae_int_t restarts
, const double wstep, const ae_int_t maxits, const ae_int_t foldscount, ae_
int_t &info, mlpreport &rep, mlpcvreport &cvrep);
/*************************************************************************
Cross-validation estimate of generalization error.
Base algorithm - Levenberg-Marquardt.
INPUT PARAMETERS:
Network - neural network with initialized geometry. Network is
not changed during cross-validation - it is used only
as a representative of its architecture.
XY - training set.
SSize - training set size
Decay - weight decay, same as in MLPTrainLBFGS
Restarts - number of restarts, >0.
restarts are counted for each partition separately, so
total number of restarts will be Restarts*FoldsCount.
FoldsCount - number of folds in k-fold cross-validation,
2<=FoldsCount<=SSize.
recommended value: 10.
OUTPUT PARAMETERS:
Info - return code, same as in MLPTrainLBFGS
Rep - report, same as in MLPTrainLM/MLPTrainLBFGS
CVRep - generalization error estimates
-- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey
*************************************************************************/
void mlpkfoldcvlm(const multilayerperceptron &network, const real_2d_array
&xy, const ae_int_t npoints, const double decay, const ae_int_t restarts, c
onst ae_int_t foldscount, ae_int_t &info, mlpreport &rep, mlpcvreport &cvre
p);
/*************************************************************************
Like MLPCreate0, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
void mlpecreate0(const ae_int_t nin, const ae_int_t nout, const ae_int_t en
semblesize, mlpensemble &ensemble);
/*************************************************************************
Like MLPCreate1, but for ensembles. Like MLPCreate1, but for ensembles.
-- ALGLIB -- -- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mlpecreate1(const ae_int_t nin, const ae_int_t nhid, const ae_int_t no ut, const ae_int_t ensemblesize, mlpensemble &ensemble); void mlpecreate1(const ae_int_t nin, const ae_int_t nhid, const ae_int_t no ut, const ae_int_t ensemblesize, mlpensemble &ensemble);
/************************************************************************* /*************************************************************************
Like MLPCreate2, but for ensembles. Like MLPCreate2, but for ensembles.
skipping to change at line 1812 skipping to change at line 1988
INPUT PARAMETERS: INPUT PARAMETERS:
Ensemble- ensemble Ensemble- ensemble
XY - test set XY - test set
NPoints - test set size NPoints - test set size
RESULT: RESULT:
Its meaning for regression task is obvious. As for classification task Its meaning for regression task is obvious. As for classification task
it means average error when estimating posterior probabilities. it means average error when estimating posterior probabilities.
-- ALGLIB -- -- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
double mlpeavgerror(const mlpensemble &ensemble, const real_2d_array &xy, c double mlpeavgerror(const mlpensemble &ensemble, const real_2d_array &xy, c
onst ae_int_t npoints); onst ae_int_t npoints);
/*************************************************************************
Average relative error on the test set
INPUT PARAMETERS:
Ensemble- ensemble
XY - test set
NPoints - test set size
RESULT:
Its meaning for regression task is obvious. As for classification task
it means average relative error when estimating posterior probabilities.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
double mlpeavgrelerror(const mlpensemble &ensemble, const real_2d_array &xy
, const ae_int_t npoints);
/*************************************************************************
Training neural networks ensemble using bootstrap aggregating (bagging).
Modified Levenberg-Marquardt algorithm is used as base training method.
INPUT PARAMETERS:
Ensemble - model with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay coefficient, >=0.001
Restarts - restarts, >0.
OUTPUT PARAMETERS:
Ensemble - trained model
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report.
OOBErrors - out-of-bag generalization error estimate
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
void mlpebagginglm(const mlpensemble &ensemble, const real_2d_array &xy, co
nst ae_int_t npoints, const double decay, const ae_int_t restarts, ae_int_t
&info, mlpreport &rep, mlpcvreport &ooberrors);
/*************************************************************************
Training neural networks ensemble using bootstrap aggregating (bagging).
L-BFGS algorithm is used as base training method.
INPUT PARAMETERS:
Ensemble - model with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay coefficient, >=0.001
Restarts - restarts, >0.
WStep - stopping criterion, same as in MLPTrainLBFGS
MaxIts - stopping criterion, same as in MLPTrainLBFGS
OUTPUT PARAMETERS:
Ensemble - trained model
Info - return code:
* -8, if both WStep=0 and MaxIts=0
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report.
OOBErrors - out-of-bag generalization error estimate
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
void mlpebagginglbfgs(const mlpensemble &ensemble, const real_2d_array &xy,
const ae_int_t npoints, const double decay, const ae_int_t restarts, const
double wstep, const ae_int_t maxits, ae_int_t &info, mlpreport &rep, mlpcv
report &ooberrors);
/*************************************************************************
Training neural networks ensemble using early stopping.
INPUT PARAMETERS:
Ensemble - model with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay coefficient, >=0.001
Restarts - restarts, >0.
OUTPUT PARAMETERS:
Ensemble - trained model
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<0, Restarts<1).
* 6, if task has been solved.
Rep - training report.
OOBErrors - out-of-bag generalization error estimate
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
void mlpetraines(const mlpensemble &ensemble, const real_2d_array &xy, cons
t ae_int_t npoints, const double decay, const ae_int_t restarts, ae_int_t &
info, mlpreport &rep);
/*************************************************************************
Neural network training using modified Levenberg-Marquardt with exact
Hessian calculation and regularization. Subroutine trains neural network
with restarts from random positions. Algorithm is well suited for small
and medium scale problems (hundreds of weights).
INPUT PARAMETERS:
Network - neural network with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts from random position, >0.
If you don't know what Restarts to choose, use 2.
OUTPUT PARAMETERS:
Network - trained neural network.
Info - return code:
* -9, if internal matrix inverse subroutine failed
* -2, if there is a point with class number
outside of [0..NOut-1].
* -1, if wrong parameters specified
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
void mlptrainlm(const multilayerperceptron &network, const real_2d_array &x
y, const ae_int_t npoints, const double decay, const ae_int_t restarts, ae_
int_t &info, mlpreport &rep);
/*************************************************************************
Neural network training using L-BFGS algorithm with regularization.
Subroutine trains neural network with restarts from random positions.
Algorithm is well suited for problems of any dimensionality (memory
requirements and step complexity are linear by weights number).
INPUT PARAMETERS:
Network - neural network with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts from random position, >0.
If you don't know what Restarts to choose, use 2.
WStep - stopping criterion. Algorithm stops if step size is
less than WStep. Recommended value - 0.01. Zero step
size means stopping after MaxIts iterations.
MaxIts - stopping criterion. Algorithm stops after MaxIts
iterations (NOT gradient calculations). Zero MaxIts
means stopping when step is sufficiently small.
OUTPUT PARAMETERS: /*************************************************************************
Network - trained neural network. Average relative error on the test set
Info - return code:
* -8, if both WStep=0 and MaxIts=0 INPUT PARAMETERS:
* -2, if there is a point with class number Ensemble- ensemble
outside of [0..NOut-1]. XY - test set
* -1, if wrong parameters specified NPoints - test set size
(NPoints<0, Restarts<1).
* 2, if task has been solved. RESULT:
Rep - training report Its meaning for regression task is obvious. As for classification task
it means average relative error when estimating posterior probabilities.
-- ALGLIB -- -- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mlptrainlbfgs(const multilayerperceptron &network, const real_2d_array &xy, const ae_int_t npoints, const double decay, const ae_int_t restarts, const double wstep, const ae_int_t maxits, ae_int_t &info, mlpreport &rep); double mlpeavgrelerror(const mlpensemble &ensemble, const real_2d_array &xy , const ae_int_t npoints);
/************************************************************************* /*************************************************************************
Neural network training using early stopping (base algorithm - L-BFGS with Training neural networks ensemble using bootstrap aggregating (bagging).
regularization). Modified Levenberg-Marquardt algorithm is used as base training method.
INPUT PARAMETERS: INPUT PARAMETERS:
Network - neural network with initialized geometry Ensemble - model with initialized geometry
TrnXY - training set XY - training set
TrnSize - training set size NPoints - training set size
ValXY - validation set Decay - weight decay coefficient, >=0.001
ValSize - validation set size Restarts - restarts, >0.
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts from random position, >0.
If you don't know what Restarts to choose, use 2.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Network - trained neural network. Ensemble - trained model
Info - return code: Info - return code:
* -2, if there is a point with class number * -2, if there is a point with class number
outside of [0..NOut-1]. outside of [0..NClasses-1].
* -1, if wrong parameters specified * -1, if incorrect parameters was passed
(NPoints<0, Restarts<1, ...). (NPoints<0, Restarts<1).
* 2, task has been solved, stopping criterion met - * 2, if task has been solved.
sufficiently small step size. Not expected (we Rep - training report.
use EARLY stopping) but possible and not an OOBErrors - out-of-bag generalization error estimate
error.
* 6, task has been solved, stopping criterion met -
increasing of validation set error.
Rep - training report
NOTE:
Algorithm stops if validation set error increases for a long enough or
step size is small enought (there are task where validation set may
decrease for eternity). In any case solution returned corresponds to the
minimum of validation set error.
-- ALGLIB -- -- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mlptraines(const multilayerperceptron &network, const real_2d_array &t rnxy, const ae_int_t trnsize, const real_2d_array &valxy, const ae_int_t va lsize, const double decay, const ae_int_t restarts, ae_int_t &info, mlprepo rt &rep); void mlpebagginglm(const mlpensemble &ensemble, const real_2d_array &xy, co nst ae_int_t npoints, const double decay, const ae_int_t restarts, ae_int_t &info, mlpreport &rep, mlpcvreport &ooberrors);
/************************************************************************* /*************************************************************************
Cross-validation estimate of generalization error. Training neural networks ensemble using bootstrap aggregating (bagging).
L-BFGS algorithm is used as base training method.
Base algorithm - L-BFGS.
INPUT PARAMETERS: INPUT PARAMETERS:
Network - neural network with initialized geometry. Network is Ensemble - model with initialized geometry
not changed during cross-validation - it is used only XY - training set
as a representative of its architecture. NPoints - training set size
XY - training set. Decay - weight decay coefficient, >=0.001
SSize - training set size Restarts - restarts, >0.
Decay - weight decay, same as in MLPTrainLBFGS
Restarts - number of restarts, >0.
restarts are counted for each partition separately, so
total number of restarts will be Restarts*FoldsCount.
WStep - stopping criterion, same as in MLPTrainLBFGS WStep - stopping criterion, same as in MLPTrainLBFGS
MaxIts - stopping criterion, same as in MLPTrainLBFGS MaxIts - stopping criterion, same as in MLPTrainLBFGS
FoldsCount - number of folds in k-fold cross-validation,
2<=FoldsCount<=SSize.
recommended value: 10.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info - return code, same as in MLPTrainLBFGS Ensemble - trained model
Rep - report, same as in MLPTrainLM/MLPTrainLBFGS Info - return code:
CVRep - generalization error estimates * -8, if both WStep=0 and MaxIts=0
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report.
OOBErrors - out-of-bag generalization error estimate
-- ALGLIB -- -- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mlpkfoldcvlbfgs(const multilayerperceptron &network, const real_2d_arr ay &xy, const ae_int_t npoints, const double decay, const ae_int_t restarts , const double wstep, const ae_int_t maxits, const ae_int_t foldscount, ae_ int_t &info, mlpreport &rep, mlpcvreport &cvrep); void mlpebagginglbfgs(const mlpensemble &ensemble, const real_2d_array &xy, const ae_int_t npoints, const double decay, const ae_int_t restarts, const double wstep, const ae_int_t maxits, ae_int_t &info, mlpreport &rep, mlpcv report &ooberrors);
/************************************************************************* /*************************************************************************
Cross-validation estimate of generalization error. Training neural networks ensemble using early stopping.
Base algorithm - Levenberg-Marquardt.
INPUT PARAMETERS: INPUT PARAMETERS:
Network - neural network with initialized geometry. Network is Ensemble - model with initialized geometry
not changed during cross-validation - it is used only XY - training set
as a representative of its architecture. NPoints - training set size
XY - training set. Decay - weight decay coefficient, >=0.001
SSize - training set size Restarts - restarts, >0.
Decay - weight decay, same as in MLPTrainLBFGS
Restarts - number of restarts, >0.
restarts are counted for each partition separately, so
total number of restarts will be Restarts*FoldsCount.
FoldsCount - number of folds in k-fold cross-validation,
2<=FoldsCount<=SSize.
recommended value: 10.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info - return code, same as in MLPTrainLBFGS Ensemble - trained model
Rep - report, same as in MLPTrainLM/MLPTrainLBFGS Info - return code:
CVRep - generalization error estimates * -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<0, Restarts<1).
* 6, if task has been solved.
Rep - training report.
OOBErrors - out-of-bag generalization error estimate
-- ALGLIB -- -- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mlpkfoldcvlm(const multilayerperceptron &network, const real_2d_array &xy, const ae_int_t npoints, const double decay, const ae_int_t restarts, c onst ae_int_t foldscount, ae_int_t &info, mlpreport &rep, mlpcvreport &cvre p); void mlpetraines(const mlpensemble &ensemble, const real_2d_array &xy, cons t ae_int_t npoints, const double decay, const ae_int_t restarts, ae_int_t & info, mlpreport &rep);
/************************************************************************* /*************************************************************************
Principal components analysis Principal components analysis
Subroutine builds orthogonal basis where first axis corresponds to Subroutine builds orthogonal basis where first axis corresponds to
direction with maximum variance, second axis maximizes variance in subspace direction with maximum variance, second axis maximizes variance in subspace
orthogonal to first axis and so on. orthogonal to first axis and so on.
It should be noted that, unlike LDA, PCA does not use class labels. It should be noted that, unlike LDA, PCA does not use class labels.
skipping to change at line 2132 skipping to change at line 2132
void pcabuildbasis(const real_2d_array &x, const ae_int_t npoints, const ae _int_t nvars, ae_int_t &info, real_1d_array &s2, real_2d_array &v); void pcabuildbasis(const real_2d_array &x, const ae_int_t npoints, const ae _int_t nvars, ae_int_t &info, real_1d_array &s2, real_2d_array &v);
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
void dfbuildrandomdecisionforest(/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t ntrees,
double r,
ae_int_t* info,
decisionforest* df,
dfreport* rep,
ae_state *_state);
void dfbuildinternal(/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t ntrees,
ae_int_t samplesize,
ae_int_t nfeatures,
ae_int_t flags,
ae_int_t* info,
decisionforest* df,
dfreport* rep,
ae_state *_state);
void dfprocess(decisionforest* df,
/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_state *_state);
void dfprocessi(decisionforest* df,
/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_state *_state);
double dfrelclserror(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double dfavgce(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double dfrmserror(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double dfavgerror(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double dfavgrelerror(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
void dfcopy(decisionforest* df1, decisionforest* df2, ae_state *_state);
ae_bool _decisionforest_init(decisionforest* p, ae_state *_state, ae_bool m
ake_automatic);
ae_bool _decisionforest_init_copy(decisionforest* dst, decisionforest* src,
ae_state *_state, ae_bool make_automatic);
void _decisionforest_clear(decisionforest* p);
ae_bool _dfreport_init(dfreport* p, ae_state *_state, ae_bool make_automati
c);
ae_bool _dfreport_init_copy(dfreport* dst, dfreport* src, ae_state *_state,
ae_bool make_automatic);
void _dfreport_clear(dfreport* p);
ae_bool _dfinternalbuffers_init(dfinternalbuffers* p, ae_state *_state, ae_
bool make_automatic);
ae_bool _dfinternalbuffers_init_copy(dfinternalbuffers* dst, dfinternalbuff
ers* src, ae_state *_state, ae_bool make_automatic);
void _dfinternalbuffers_clear(dfinternalbuffers* p);
void dserrallocate(ae_int_t nclasses, void dserrallocate(ae_int_t nclasses,
/* Real */ ae_vector* buf, /* Real */ ae_vector* buf,
ae_state *_state); ae_state *_state);
void dserraccumulate(/* Real */ ae_vector* buf, void dserraccumulate(/* Real */ ae_vector* buf,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
/* Real */ ae_vector* desiredy, /* Real */ ae_vector* desiredy,
ae_state *_state); ae_state *_state);
void dserrfinish(/* Real */ ae_vector* buf, ae_state *_state); void dserrfinish(/* Real */ ae_vector* buf, ae_state *_state);
void dsnormalize(/* Real */ ae_matrix* xy, void dsnormalize(/* Real */ ae_matrix* xy,
ae_int_t npoints, ae_int_t npoints,
skipping to change at line 2278 skipping to change at line 2218
void dsoptimalsplitk(/* Real */ ae_vector* a, void dsoptimalsplitk(/* Real */ ae_vector* a,
/* Integer */ ae_vector* c, /* Integer */ ae_vector* c,
ae_int_t n, ae_int_t n,
ae_int_t nc, ae_int_t nc,
ae_int_t kmax, ae_int_t kmax,
ae_int_t* info, ae_int_t* info,
/* Real */ ae_vector* thresholds, /* Real */ ae_vector* thresholds,
ae_int_t* ni, ae_int_t* ni,
double* cve, double* cve,
ae_state *_state); ae_state *_state);
ae_bool _cvreport_init(cvreport* p, ae_state *_state, ae_bool make_automati ae_bool _cvreport_init(cvreport* p, ae_state *_state, ae_bool make_automati
c); c);
ae_bool _cvreport_init_copy(cvreport* dst, cvreport* src, ae_state *_state, ae_bool _cvreport_init_copy(cvreport* dst, cvreport* src, ae_state *_state,
ae_bool make_automatic); ae_bool make_automatic);
void _cvreport_clear(cvreport* p); void _cvreport_clear(cvreport* p);
void dfbuildrandomdecisionforest(/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t ntrees,
double r,
ae_int_t* info,
decisionforest* df,
dfreport* rep,
ae_state *_state);
void dfbuildinternal(/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t ntrees,
ae_int_t samplesize,
ae_int_t nfeatures,
ae_int_t flags,
ae_int_t* info,
decisionforest* df,
dfreport* rep,
ae_state *_state);
void dfprocess(decisionforest* df,
/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_state *_state);
void dfprocessi(decisionforest* df,
/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_state *_state);
double dfrelclserror(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double dfavgce(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double dfrmserror(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double dfavgerror(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double dfavgrelerror(decisionforest* df,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
void dfcopy(decisionforest* df1, decisionforest* df2, ae_state *_state);
ae_bool _decisionforest_init(decisionforest* p, ae_state *_state, ae_bool m
ake_automatic);
ae_bool _decisionforest_init_copy(decisionforest* dst, decisionforest* src,
ae_state *_state, ae_bool make_automatic);
void _decisionforest_clear(decisionforest* p);
ae_bool _dfreport_init(dfreport* p, ae_state *_state, ae_bool make_automati
c);
ae_bool _dfreport_init_copy(dfreport* dst, dfreport* src, ae_state *_state,
ae_bool make_automatic);
void _dfreport_clear(dfreport* p);
ae_bool _dfinternalbuffers_init(dfinternalbuffers* p, ae_state *_state, ae_
bool make_automatic);
ae_bool _dfinternalbuffers_init_copy(dfinternalbuffers* dst, dfinternalbuff
ers* src, ae_state *_state, ae_bool make_automatic);
void _dfinternalbuffers_clear(dfinternalbuffers* p);
void kmeansgenerate(/* Real */ ae_matrix* xy, void kmeansgenerate(/* Real */ ae_matrix* xy,
ae_int_t npoints, ae_int_t npoints,
ae_int_t nvars, ae_int_t nvars,
ae_int_t k, ae_int_t k,
ae_int_t restarts, ae_int_t restarts,
ae_int_t* info, ae_int_t* info,
/* Real */ ae_matrix* c, /* Real */ ae_matrix* c,
/* Integer */ ae_vector* xyc, /* Integer */ ae_vector* xyc,
ae_state *_state); ae_state *_state);
void fisherlda(/* Real */ ae_matrix* xy, void fisherlda(/* Real */ ae_matrix* xy,
skipping to change at line 2382 skipping to change at line 2382
ae_int_t* info, ae_int_t* info,
double* a, double* a,
double* b, double* b,
ae_state *_state); ae_state *_state);
ae_bool _linearmodel_init(linearmodel* p, ae_state *_state, ae_bool make_au tomatic); ae_bool _linearmodel_init(linearmodel* p, ae_state *_state, ae_bool make_au tomatic);
ae_bool _linearmodel_init_copy(linearmodel* dst, linearmodel* src, ae_state *_state, ae_bool make_automatic); ae_bool _linearmodel_init_copy(linearmodel* dst, linearmodel* src, ae_state *_state, ae_bool make_automatic);
void _linearmodel_clear(linearmodel* p); void _linearmodel_clear(linearmodel* p);
ae_bool _lrreport_init(lrreport* p, ae_state *_state, ae_bool make_automati c); ae_bool _lrreport_init(lrreport* p, ae_state *_state, ae_bool make_automati c);
ae_bool _lrreport_init_copy(lrreport* dst, lrreport* src, ae_state *_state, ae_bool make_automatic); ae_bool _lrreport_init_copy(lrreport* dst, lrreport* src, ae_state *_state, ae_bool make_automatic);
void _lrreport_clear(lrreport* p); void _lrreport_clear(lrreport* p);
void mnltrainh(/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t* info,
logitmodel* lm,
mnlreport* rep,
ae_state *_state);
void mnlprocess(logitmodel* lm,
/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_state *_state);
void mnlprocessi(logitmodel* lm,
/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_state *_state);
void mnlunpack(logitmodel* lm,
/* Real */ ae_matrix* a,
ae_int_t* nvars,
ae_int_t* nclasses,
ae_state *_state);
void mnlpack(/* Real */ ae_matrix* a,
ae_int_t nvars,
ae_int_t nclasses,
logitmodel* lm,
ae_state *_state);
void mnlcopy(logitmodel* lm1, logitmodel* lm2, ae_state *_state);
double mnlavgce(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double mnlrelclserror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double mnlrmserror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double mnlavgerror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double mnlavgrelerror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t ssize,
ae_state *_state);
ae_int_t mnlclserror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
ae_bool _logitmodel_init(logitmodel* p, ae_state *_state, ae_bool make_auto
matic);
ae_bool _logitmodel_init_copy(logitmodel* dst, logitmodel* src, ae_state *_
state, ae_bool make_automatic);
void _logitmodel_clear(logitmodel* p);
ae_bool _logitmcstate_init(logitmcstate* p, ae_state *_state, ae_bool make_
automatic);
ae_bool _logitmcstate_init_copy(logitmcstate* dst, logitmcstate* src, ae_st
ate *_state, ae_bool make_automatic);
void _logitmcstate_clear(logitmcstate* p);
ae_bool _mnlreport_init(mnlreport* p, ae_state *_state, ae_bool make_automa
tic);
ae_bool _mnlreport_init_copy(mnlreport* dst, mnlreport* src, ae_state *_sta
te, ae_bool make_automatic);
void _mnlreport_clear(mnlreport* p);
void mlpcreate0(ae_int_t nin, void mlpcreate0(ae_int_t nin,
ae_int_t nout, ae_int_t nout,
multilayerperceptron* network, multilayerperceptron* network,
ae_state *_state); ae_state *_state);
void mlpcreate1(ae_int_t nin, void mlpcreate1(ae_int_t nin,
ae_int_t nhid, ae_int_t nhid,
ae_int_t nout, ae_int_t nout,
multilayerperceptron* network, multilayerperceptron* network,
ae_state *_state); ae_state *_state);
void mlpcreate2(ae_int_t nin, void mlpcreate2(ae_int_t nin,
skipping to change at line 2626 skipping to change at line 2566
/* Real */ ae_vector* columnmeans, /* Real */ ae_vector* columnmeans,
/* Real */ ae_vector* columnsigmas, /* Real */ ae_vector* columnsigmas,
/* Real */ ae_vector* neurons, /* Real */ ae_vector* neurons,
/* Real */ ae_vector* dfdnet, /* Real */ ae_vector* dfdnet,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
ae_state *_state); ae_state *_state);
ae_bool _multilayerperceptron_init(multilayerperceptron* p, ae_state *_stat e, ae_bool make_automatic); ae_bool _multilayerperceptron_init(multilayerperceptron* p, ae_state *_stat e, ae_bool make_automatic);
ae_bool _multilayerperceptron_init_copy(multilayerperceptron* dst, multilay erperceptron* src, ae_state *_state, ae_bool make_automatic); ae_bool _multilayerperceptron_init_copy(multilayerperceptron* dst, multilay erperceptron* src, ae_state *_state, ae_bool make_automatic);
void _multilayerperceptron_clear(multilayerperceptron* p); void _multilayerperceptron_clear(multilayerperceptron* p);
void mnltrainh(/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t* info,
logitmodel* lm,
mnlreport* rep,
ae_state *_state);
void mnlprocess(logitmodel* lm,
/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_state *_state);
void mnlprocessi(logitmodel* lm,
/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_state *_state);
void mnlunpack(logitmodel* lm,
/* Real */ ae_matrix* a,
ae_int_t* nvars,
ae_int_t* nclasses,
ae_state *_state);
void mnlpack(/* Real */ ae_matrix* a,
ae_int_t nvars,
ae_int_t nclasses,
logitmodel* lm,
ae_state *_state);
void mnlcopy(logitmodel* lm1, logitmodel* lm2, ae_state *_state);
double mnlavgce(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double mnlrelclserror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double mnlrmserror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double mnlavgerror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
double mnlavgrelerror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t ssize,
ae_state *_state);
ae_int_t mnlclserror(logitmodel* lm,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
ae_state *_state);
ae_bool _logitmodel_init(logitmodel* p, ae_state *_state, ae_bool make_auto
matic);
ae_bool _logitmodel_init_copy(logitmodel* dst, logitmodel* src, ae_state *_
state, ae_bool make_automatic);
void _logitmodel_clear(logitmodel* p);
ae_bool _logitmcstate_init(logitmcstate* p, ae_state *_state, ae_bool make_
automatic);
ae_bool _logitmcstate_init_copy(logitmcstate* dst, logitmcstate* src, ae_st
ate *_state, ae_bool make_automatic);
void _logitmcstate_clear(logitmcstate* p);
ae_bool _mnlreport_init(mnlreport* p, ae_state *_state, ae_bool make_automa
tic);
ae_bool _mnlreport_init_copy(mnlreport* dst, mnlreport* src, ae_state *_sta
te, ae_bool make_automatic);
void _mnlreport_clear(mnlreport* p);
void mlptrainlm(multilayerperceptron* network,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
double decay,
ae_int_t restarts,
ae_int_t* info,
mlpreport* rep,
ae_state *_state);
void mlptrainlbfgs(multilayerperceptron* network,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
double decay,
ae_int_t restarts,
double wstep,
ae_int_t maxits,
ae_int_t* info,
mlpreport* rep,
ae_state *_state);
void mlptraines(multilayerperceptron* network,
/* Real */ ae_matrix* trnxy,
ae_int_t trnsize,
/* Real */ ae_matrix* valxy,
ae_int_t valsize,
double decay,
ae_int_t restarts,
ae_int_t* info,
mlpreport* rep,
ae_state *_state);
void mlpkfoldcvlbfgs(multilayerperceptron* network,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
double decay,
ae_int_t restarts,
double wstep,
ae_int_t maxits,
ae_int_t foldscount,
ae_int_t* info,
mlpreport* rep,
mlpcvreport* cvrep,
ae_state *_state);
void mlpkfoldcvlm(multilayerperceptron* network,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
double decay,
ae_int_t restarts,
ae_int_t foldscount,
ae_int_t* info,
mlpreport* rep,
mlpcvreport* cvrep,
ae_state *_state);
ae_bool _mlpreport_init(mlpreport* p, ae_state *_state, ae_bool make_automa
tic);
ae_bool _mlpreport_init_copy(mlpreport* dst, mlpreport* src, ae_state *_sta
te, ae_bool make_automatic);
void _mlpreport_clear(mlpreport* p);
ae_bool _mlpcvreport_init(mlpcvreport* p, ae_state *_state, ae_bool make_au
tomatic);
ae_bool _mlpcvreport_init_copy(mlpcvreport* dst, mlpcvreport* src, ae_state
*_state, ae_bool make_automatic);
void _mlpcvreport_clear(mlpcvreport* p);
void mlpecreate0(ae_int_t nin, void mlpecreate0(ae_int_t nin,
ae_int_t nout, ae_int_t nout,
ae_int_t ensemblesize, ae_int_t ensemblesize,
mlpensemble* ensemble, mlpensemble* ensemble,
ae_state *_state); ae_state *_state);
void mlpecreate1(ae_int_t nin, void mlpecreate1(ae_int_t nin,
ae_int_t nhid, ae_int_t nhid,
ae_int_t nout, ae_int_t nout,
ae_int_t ensemblesize, ae_int_t ensemblesize,
mlpensemble* ensemble, mlpensemble* ensemble,
skipping to change at line 2789 skipping to change at line 2845
/* Real */ ae_matrix* xy, /* Real */ ae_matrix* xy,
ae_int_t npoints, ae_int_t npoints,
double decay, double decay,
ae_int_t restarts, ae_int_t restarts,
ae_int_t* info, ae_int_t* info,
mlpreport* rep, mlpreport* rep,
ae_state *_state); ae_state *_state);
ae_bool _mlpensemble_init(mlpensemble* p, ae_state *_state, ae_bool make_au tomatic); ae_bool _mlpensemble_init(mlpensemble* p, ae_state *_state, ae_bool make_au tomatic);
ae_bool _mlpensemble_init_copy(mlpensemble* dst, mlpensemble* src, ae_state *_state, ae_bool make_automatic); ae_bool _mlpensemble_init_copy(mlpensemble* dst, mlpensemble* src, ae_state *_state, ae_bool make_automatic);
void _mlpensemble_clear(mlpensemble* p); void _mlpensemble_clear(mlpensemble* p);
void mlptrainlm(multilayerperceptron* network,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
double decay,
ae_int_t restarts,
ae_int_t* info,
mlpreport* rep,
ae_state *_state);
void mlptrainlbfgs(multilayerperceptron* network,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
double decay,
ae_int_t restarts,
double wstep,
ae_int_t maxits,
ae_int_t* info,
mlpreport* rep,
ae_state *_state);
void mlptraines(multilayerperceptron* network,
/* Real */ ae_matrix* trnxy,
ae_int_t trnsize,
/* Real */ ae_matrix* valxy,
ae_int_t valsize,
double decay,
ae_int_t restarts,
ae_int_t* info,
mlpreport* rep,
ae_state *_state);
void mlpkfoldcvlbfgs(multilayerperceptron* network,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
double decay,
ae_int_t restarts,
double wstep,
ae_int_t maxits,
ae_int_t foldscount,
ae_int_t* info,
mlpreport* rep,
mlpcvreport* cvrep,
ae_state *_state);
void mlpkfoldcvlm(multilayerperceptron* network,
/* Real */ ae_matrix* xy,
ae_int_t npoints,
double decay,
ae_int_t restarts,
ae_int_t foldscount,
ae_int_t* info,
mlpreport* rep,
mlpcvreport* cvrep,
ae_state *_state);
ae_bool _mlpreport_init(mlpreport* p, ae_state *_state, ae_bool make_automa
tic);
ae_bool _mlpreport_init_copy(mlpreport* dst, mlpreport* src, ae_state *_sta
te, ae_bool make_automatic);
void _mlpreport_clear(mlpreport* p);
ae_bool _mlpcvreport_init(mlpcvreport* p, ae_state *_state, ae_bool make_au
tomatic);
ae_bool _mlpcvreport_init_copy(mlpcvreport* dst, mlpcvreport* src, ae_state
*_state, ae_bool make_automatic);
void _mlpcvreport_clear(mlpcvreport* p);
void pcabuildbasis(/* Real */ ae_matrix* x, void pcabuildbasis(/* Real */ ae_matrix* x,
ae_int_t npoints, ae_int_t npoints,
ae_int_t nvars, ae_int_t nvars,
ae_int_t* info, ae_int_t* info,
/* Real */ ae_vector* s2, /* Real */ ae_vector* s2,
/* Real */ ae_matrix* v, /* Real */ ae_matrix* v,
ae_state *_state); ae_state *_state);
} }
#endif #endif
 End of changes. 41 change blocks. 
826 lines changed or deleted 829 lines changed or added


 diffequations.h   diffequations.h 
skipping to change at line 194 skipping to change at line 194
*************************************************************************/ *************************************************************************/
bool odesolveriteration(const odesolverstate &state); bool odesolveriteration(const odesolverstate &state);
/************************************************************************* /*************************************************************************
This function is used to launcn iterations of ODE solver This function is used to launcn iterations of ODE solver
It accepts following parameters: It accepts following parameters:
diff - callback which calculates dy/dx for given y and x diff - callback which calculates dy/dx for given y and x
ptr - optional pointer which is passed to diff; can be NULL ptr - optional pointer which is passed to diff; can be NULL
One iteration of ODE solver.
Called after inialization of State structure with OdeSolverXXX subroutine.
See HTML docs for examples.
INPUT PARAMETERS:
State - structure which stores algorithm state between subsequent
calls and which is used for reverse communication. Must be
initialized with OdeSolverXXX() call first.
If subroutine returned False, algorithm have finished its work.
If subroutine returned True, then user should:
* calculate F(State.X, State.Y)
* store it in State.DY
Here State.X is real, State.Y and State.DY are arrays[0..N-1] of reals.
-- ALGLIB -- -- ALGLIB --
Copyright 01.09.2009 by Bochkanov Sergey Copyright 01.09.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void odesolversolve(odesolverstate &state, void odesolversolve(odesolverstate &state,
void (*diff)(const real_1d_array &y, double x, real_1d_array &dy, void *ptr), void (*diff)(const real_1d_array &y, double x, real_1d_array &dy, void *ptr),
void *ptr = NULL); void *ptr = NULL);
/************************************************************************* /*************************************************************************
ODE solver results ODE solver results
 End of changes. 1 change blocks. 
16 lines changed or deleted 0 lines changed or added


 fasttransforms.h   fasttransforms.h 
skipping to change at line 43 skipping to change at line 43
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS C++ INTERFACE // THIS SECTION CONTAINS C++ INTERFACE
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib namespace alglib
{ {
/************************************************************************* /*************************************************************************
1-dimensional complex FFT.
Array size N may be arbitrary number (composite or prime). Composite N's
are handled with cache-oblivious variation of a Cooley-Tukey algorithm.
Small prime-factors are transformed using hard coded codelets (similar to
FFTW codelets, but without low-level optimization), large prime-factors
are handled with Bluestein's algorithm.
Fastests transforms are for smooth N's (prime factors are 2, 3, 5 only),
most fast for powers of 2. When N have prime factors larger than these,
but orders of magnitude smaller than N, computations will be about 4 times
slower than for nearby highly composite N's. When N itself is prime, speed
will be 6 times lower.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - complex function to be transformed
N - problem size
OUTPUT PARAMETERS
A - DFT of a input array, array[0..N-1]
A_out[j] = SUM(A_in[k]*exp(-2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
-- ALGLIB --
Copyright 29.05.2009 by Bochkanov Sergey
*************************************************************************/
void fftc1d(complex_1d_array &a, const ae_int_t n);
void fftc1d(complex_1d_array &a);
/*************************************************************************
1-dimensional complex inverse FFT.
Array size N may be arbitrary number (composite or prime). Algorithm has
O(N*logN) complexity for any N (composite or prime).
See FFTC1D() description for more information about algorithm performance.
INPUT PARAMETERS
A - array[0..N-1] - complex array to be transformed
N - problem size
OUTPUT PARAMETERS
A - inverse DFT of a input array, array[0..N-1]
A_out[j] = SUM(A_in[k]/N*exp(+2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
-- ALGLIB --
Copyright 29.05.2009 by Bochkanov Sergey
*************************************************************************/
void fftc1dinv(complex_1d_array &a, const ae_int_t n);
void fftc1dinv(complex_1d_array &a);
/*************************************************************************
1-dimensional real FFT.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - real function to be transformed
N - problem size
OUTPUT PARAMETERS
F - DFT of a input array, array[0..N-1]
F[j] = SUM(A[k]*exp(-2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
NOTE:
F[] satisfies symmetry property F[k] = conj(F[N-k]), so just one half
of array is usually needed. But for convinience subroutine returns full
complex array (with frequencies above N/2), so its result may be used by
other FFT-related subroutines.
-- ALGLIB --
Copyright 01.06.2009 by Bochkanov Sergey
*************************************************************************/
void fftr1d(const real_1d_array &a, const ae_int_t n, complex_1d_array &f);
void fftr1d(const real_1d_array &a, complex_1d_array &f);
/*************************************************************************
1-dimensional real inverse FFT.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
F - array[0..floor(N/2)] - frequencies from forward real FFT
N - problem size
OUTPUT PARAMETERS
A - inverse DFT of a input array, array[0..N-1]
NOTE:
F[] should satisfy symmetry property F[k] = conj(F[N-k]), so just one
half of frequencies array is needed - elements from 0 to floor(N/2). F[0]
is ALWAYS real. If N is even F[floor(N/2)] is real too. If N is odd, then
F[floor(N/2)] has no special properties.
Relying on properties noted above, FFTR1DInv subroutine uses only elements
from 0th to floor(N/2)-th. It ignores imaginary part of F[0], and in case
N is even it ignores imaginary part of F[floor(N/2)] too.
When you call this function using full arguments list - "FFTR1DInv(F,N,A)"
- you can pass either either frequencies array with N elements or reduced
array with roughly N/2 elements - subroutine will successfully transform
both.
If you call this function using reduced arguments list - "FFTR1DInv(F,A)"
- you must pass FULL array with N elements (although higher N/2 are still
not used) because array size is used to automatically determine FFT length
-- ALGLIB --
Copyright 01.06.2009 by Bochkanov Sergey
*************************************************************************/
void fftr1dinv(const complex_1d_array &f, const ae_int_t n, real_1d_array &
a);
void fftr1dinv(const complex_1d_array &f, real_1d_array &a);
/*************************************************************************
1-dimensional complex convolution. 1-dimensional complex convolution.
For given A/B returns conv(A,B) (non-circular). Subroutine can automaticall y For given A/B returns conv(A,B) (non-circular). Subroutine can automaticall y
choose between three implementations: straightforward O(M*N) formula for choose between three implementations: straightforward O(M*N) formula for
very small N (or M), overlap-add algorithm for cases where max(M,N) is very small N (or M), overlap-add algorithm for cases where max(M,N) is
significantly larger than min(M,N), but O(M*N) algorithm is too slow, and significantly larger than min(M,N), but O(M*N) algorithm is too slow, and
general FFT-based formula for cases where two previois algorithms are too general FFT-based formula for cases where two previois algorithms are too
slow. slow.
Algorithm has max(M,N)*log(max(M,N)) complexity for any M/N. Algorithm has max(M,N)*log(max(M,N)) complexity for any M/N.
skipping to change at line 264 skipping to change at line 379
It is assumed that B is zero at T<0. If it has non-zero values at It is assumed that B is zero at T<0. If it has non-zero values at
negative T's, you can still use this subroutine - just shift its result negative T's, you can still use this subroutine - just shift its result
correspondingly. correspondingly.
-- ALGLIB -- -- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void convr1dcircularinv(const real_1d_array &a, const ae_int_t m, const rea l_1d_array &b, const ae_int_t n, real_1d_array &r); void convr1dcircularinv(const real_1d_array &a, const ae_int_t m, const rea l_1d_array &b, const ae_int_t n, real_1d_array &r);
/************************************************************************* /*************************************************************************
1-dimensional complex FFT.
Array size N may be arbitrary number (composite or prime). Composite N's
are handled with cache-oblivious variation of a Cooley-Tukey algorithm.
Small prime-factors are transformed using hard coded codelets (similar to
FFTW codelets, but without low-level optimization), large prime-factors
are handled with Bluestein's algorithm.
Fastests transforms are for smooth N's (prime factors are 2, 3, 5 only),
most fast for powers of 2. When N have prime factors larger than these,
but orders of magnitude smaller than N, computations will be about 4 times
slower than for nearby highly composite N's. When N itself is prime, speed
will be 6 times lower.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - complex function to be transformed
N - problem size
OUTPUT PARAMETERS
A - DFT of a input array, array[0..N-1]
A_out[j] = SUM(A_in[k]*exp(-2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
-- ALGLIB --
Copyright 29.05.2009 by Bochkanov Sergey
*************************************************************************/
void fftc1d(complex_1d_array &a, const ae_int_t n);
void fftc1d(complex_1d_array &a);
/*************************************************************************
1-dimensional complex inverse FFT.
Array size N may be arbitrary number (composite or prime). Algorithm has
O(N*logN) complexity for any N (composite or prime).
See FFTC1D() description for more information about algorithm performance.
INPUT PARAMETERS
A - array[0..N-1] - complex array to be transformed
N - problem size
OUTPUT PARAMETERS
A - inverse DFT of a input array, array[0..N-1]
A_out[j] = SUM(A_in[k]/N*exp(+2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
-- ALGLIB --
Copyright 29.05.2009 by Bochkanov Sergey
*************************************************************************/
void fftc1dinv(complex_1d_array &a, const ae_int_t n);
void fftc1dinv(complex_1d_array &a);
/*************************************************************************
1-dimensional real FFT.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - real function to be transformed
N - problem size
OUTPUT PARAMETERS
F - DFT of a input array, array[0..N-1]
F[j] = SUM(A[k]*exp(-2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
NOTE:
F[] satisfies symmetry property F[k] = conj(F[N-k]), so just one half
of array is usually needed. But for convinience subroutine returns full
complex array (with frequencies above N/2), so its result may be used by
other FFT-related subroutines.
-- ALGLIB --
Copyright 01.06.2009 by Bochkanov Sergey
*************************************************************************/
void fftr1d(const real_1d_array &a, const ae_int_t n, complex_1d_array &f);
void fftr1d(const real_1d_array &a, complex_1d_array &f);
/*************************************************************************
1-dimensional real inverse FFT.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
F - array[0..floor(N/2)] - frequencies from forward real FFT
N - problem size
OUTPUT PARAMETERS
A - inverse DFT of a input array, array[0..N-1]
NOTE:
F[] should satisfy symmetry property F[k] = conj(F[N-k]), so just one
half of frequencies array is needed - elements from 0 to floor(N/2). F[0]
is ALWAYS real. If N is even F[floor(N/2)] is real too. If N is odd, then
F[floor(N/2)] has no special properties.
Relying on properties noted above, FFTR1DInv subroutine uses only elements
from 0th to floor(N/2)-th. It ignores imaginary part of F[0], and in case
N is even it ignores imaginary part of F[floor(N/2)] too.
When you call this function using full arguments list - "FFTR1DInv(F,N,A)"
- you can pass either either frequencies array with N elements or reduced
array with roughly N/2 elements - subroutine will successfully transform
both.
If you call this function using reduced arguments list - "FFTR1DInv(F,A)"
- you must pass FULL array with N elements (although higher N/2 are still
not used) because array size is used to automatically determine FFT length
-- ALGLIB --
Copyright 01.06.2009 by Bochkanov Sergey
*************************************************************************/
void fftr1dinv(const complex_1d_array &f, const ae_int_t n, real_1d_array &
a);
void fftr1dinv(const complex_1d_array &f, real_1d_array &a);
/*************************************************************************
1-dimensional complex cross-correlation. 1-dimensional complex cross-correlation.
For given Pattern/Signal returns corr(Pattern,Signal) (non-circular). For given Pattern/Signal returns corr(Pattern,Signal) (non-circular).
Correlation is calculated using reduction to convolution. Algorithm with Correlation is calculated using reduction to convolution. Algorithm with
max(N,N)*log(max(N,N)) complexity is used (see ConvC1D() for more info max(N,N)*log(max(N,N)) complexity is used (see ConvC1D() for more info
about performance). about performance).
IMPORTANT: IMPORTANT:
for historical reasons subroutine accepts its parameters in reversed for historical reasons subroutine accepts its parameters in reversed
skipping to change at line 553 skipping to change at line 553
void fhtr1dinv(real_1d_array &a, const ae_int_t n); void fhtr1dinv(real_1d_array &a, const ae_int_t n);
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
void fftc1d(/* Complex */ ae_vector* a, ae_int_t n, ae_state *_state);
void fftc1dinv(/* Complex */ ae_vector* a, ae_int_t n, ae_state *_state);
void fftr1d(/* Real */ ae_vector* a,
ae_int_t n,
/* Complex */ ae_vector* f,
ae_state *_state);
void fftr1dinv(/* Complex */ ae_vector* f,
ae_int_t n,
/* Real */ ae_vector* a,
ae_state *_state);
void fftr1dinternaleven(/* Real */ ae_vector* a,
ae_int_t n,
/* Real */ ae_vector* buf,
ftplan* plan,
ae_state *_state);
void fftr1dinvinternaleven(/* Real */ ae_vector* a,
ae_int_t n,
/* Real */ ae_vector* buf,
ftplan* plan,
ae_state *_state);
void convc1d(/* Complex */ ae_vector* a, void convc1d(/* Complex */ ae_vector* a,
ae_int_t m, ae_int_t m,
/* Complex */ ae_vector* b, /* Complex */ ae_vector* b,
ae_int_t n, ae_int_t n,
/* Complex */ ae_vector* r, /* Complex */ ae_vector* r,
ae_state *_state); ae_state *_state);
void convc1dinv(/* Complex */ ae_vector* a, void convc1dinv(/* Complex */ ae_vector* a,
ae_int_t m, ae_int_t m,
/* Complex */ ae_vector* b, /* Complex */ ae_vector* b,
ae_int_t n, ae_int_t n,
skipping to change at line 619 skipping to change at line 639
ae_state *_state); ae_state *_state);
void convr1dx(/* Real */ ae_vector* a, void convr1dx(/* Real */ ae_vector* a,
ae_int_t m, ae_int_t m,
/* Real */ ae_vector* b, /* Real */ ae_vector* b,
ae_int_t n, ae_int_t n,
ae_bool circular, ae_bool circular,
ae_int_t alg, ae_int_t alg,
ae_int_t q, ae_int_t q,
/* Real */ ae_vector* r, /* Real */ ae_vector* r,
ae_state *_state); ae_state *_state);
void fftc1d(/* Complex */ ae_vector* a, ae_int_t n, ae_state *_state);
void fftc1dinv(/* Complex */ ae_vector* a, ae_int_t n, ae_state *_state);
void fftr1d(/* Real */ ae_vector* a,
ae_int_t n,
/* Complex */ ae_vector* f,
ae_state *_state);
void fftr1dinv(/* Complex */ ae_vector* f,
ae_int_t n,
/* Real */ ae_vector* a,
ae_state *_state);
void fftr1dinternaleven(/* Real */ ae_vector* a,
ae_int_t n,
/* Real */ ae_vector* buf,
ftplan* plan,
ae_state *_state);
void fftr1dinvinternaleven(/* Real */ ae_vector* a,
ae_int_t n,
/* Real */ ae_vector* buf,
ftplan* plan,
ae_state *_state);
void corrc1d(/* Complex */ ae_vector* signal, void corrc1d(/* Complex */ ae_vector* signal,
ae_int_t n, ae_int_t n,
/* Complex */ ae_vector* pattern, /* Complex */ ae_vector* pattern,
ae_int_t m, ae_int_t m,
/* Complex */ ae_vector* r, /* Complex */ ae_vector* r,
ae_state *_state); ae_state *_state);
void corrc1dcircular(/* Complex */ ae_vector* signal, void corrc1dcircular(/* Complex */ ae_vector* signal,
ae_int_t m, ae_int_t m,
/* Complex */ ae_vector* pattern, /* Complex */ ae_vector* pattern,
ae_int_t n, ae_int_t n,
 End of changes. 4 change blocks. 
136 lines changed or deleted 136 lines changed or added


 integration.h   integration.h 
skipping to change at line 166 skipping to change at line 166
virtual ~autogkstate(); virtual ~autogkstate();
ae_bool &needf; ae_bool &needf;
double &x; double &x;
double &xminusa; double &xminusa;
double &bminusx; double &bminusx;
double &f; double &f;
}; };
/************************************************************************* /*************************************************************************
Integration of a smooth function F(x) on a finite interval [a,b].
Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
is calculated with accuracy close to the machine precision.
Algorithm works well only with smooth integrands. It may be used with
continuous non-smooth integrands, but with less performance.
It should never be used with integrands which have integrable singularities
at lower or upper limits - algorithm may crash. Use AutoGKSingular in such
cases.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmoothW, AutoGKSingular, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
void autogksmooth(const double a, const double b, autogkstate &state);
/*************************************************************************
Integration of a smooth function F(x) on a finite interval [a,b].
This subroutine is same as AutoGKSmooth(), but it guarantees that interval
[a,b] is partitioned into subintervals which have width at most XWidth.
Subroutine can be used when integrating nearly-constant function with
narrow "bumps" (about XWidth wide). If "bumps" are too narrow, AutoGKSmooth
subroutine can overlook them.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmooth, AutoGKSingular, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
void autogksmoothw(const double a, const double b, const double xwidth, aut
ogkstate &state);
/*************************************************************************
Integration on a finite interval [A,B].
Integrand have integrable singularities at A/B.
F(X) must diverge as "(x-A)^alpha" at A, as "(B-x)^beta" at B, with known
alpha/beta (alpha>-1, beta>-1). If alpha/beta are not known, estimates
from below can be used (but these estimates should be greater than -1 too).
One of alpha/beta variables (or even both alpha/beta) may be equal to 0,
which means than function F(x) is non-singular at A/B. Anyway (singular at
bounds or not), function F(x) is supposed to be continuous on (A,B).
Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
is calculated with accuracy close to the machine precision.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
Alpha - power-law coefficient of the F(x) at A,
Alpha>-1
Beta - power-law coefficient of the F(x) at B,
Beta>-1
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmooth, AutoGKSmoothW, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
void autogksingular(const double a, const double b, const double alpha, con
st double beta, autogkstate &state);
/*************************************************************************
This function provides reverse communication interface
Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API
*************************************************************************/
bool autogkiteration(const autogkstate &state);
/*************************************************************************
This function is used to launcn iterations of the 1-dimensional integrator
It accepts following parameters:
func - callback which calculates f(x) for given x
ptr - optional pointer which is passed to func; can be NULL
-- ALGLIB --
Copyright 07.05.2009 by Bochkanov Sergey
*************************************************************************/
void autogkintegrate(autogkstate &state,
void (*func)(double x, double xminusa, double bminusx, double &y, void
*ptr),
void *ptr = NULL);
/*************************************************************************
Adaptive integration results
Called after AutoGKIteration returned False.
Input parameters:
State - algorithm state (used by AutoGKIteration).
Output parameters:
V - integral(f(x)dx,a,b)
Rep - optimization report (see AutoGKReport description)
-- ALGLIB --
Copyright 14.11.2007 by Bochkanov Sergey
*************************************************************************/
void autogkresults(const autogkstate &state, double &v, autogkreport &rep);
/*************************************************************************
Computation of nodes and weights for a Gauss quadrature formula Computation of nodes and weights for a Gauss quadrature formula
The algorithm generates the N-point Gauss quadrature formula with weight The algorithm generates the N-point Gauss quadrature formula with weight
function given by coefficients alpha and beta of a recurrence relation function given by coefficients alpha and beta of a recurrence relation
which generates a system of orthogonal polynomials: which generates a system of orthogonal polynomials:
P-1(x) = 0 P-1(x) = 0
P0(x) = 1 P0(x) = 1
Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x) Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x)
skipping to change at line 675 skipping to change at line 552
X - array[0..N-1] - array of quadrature nodes, ordered in X - array[0..N-1] - array of quadrature nodes, ordered in
ascending order. ascending order.
WKronrod - array[0..N-1] - Kronrod weights WKronrod - array[0..N-1] - Kronrod weights
WGauss - array[0..N-1] - Gauss weights (interleaved with zeros WGauss - array[0..N-1] - Gauss weights (interleaved with zeros
corresponding to extended Kronrod nodes). corresponding to extended Kronrod nodes).
-- ALGLIB -- -- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void gkqlegendretbl(const ae_int_t n, real_1d_array &x, real_1d_array &wkro nrod, real_1d_array &wgauss, double &eps); void gkqlegendretbl(const ae_int_t n, real_1d_array &x, real_1d_array &wkro nrod, real_1d_array &wgauss, double &eps);
/*************************************************************************
Integration of a smooth function F(x) on a finite interval [a,b].
Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
is calculated with accuracy close to the machine precision.
Algorithm works well only with smooth integrands. It may be used with
continuous non-smooth integrands, but with less performance.
It should never be used with integrands which have integrable singularities
at lower or upper limits - algorithm may crash. Use AutoGKSingular in such
cases.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmoothW, AutoGKSingular, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
void autogksmooth(const double a, const double b, autogkstate &state);
/*************************************************************************
Integration of a smooth function F(x) on a finite interval [a,b].
This subroutine is same as AutoGKSmooth(), but it guarantees that interval
[a,b] is partitioned into subintervals which have width at most XWidth.
Subroutine can be used when integrating nearly-constant function with
narrow "bumps" (about XWidth wide). If "bumps" are too narrow, AutoGKSmooth
subroutine can overlook them.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmooth, AutoGKSingular, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
void autogksmoothw(const double a, const double b, const double xwidth, aut
ogkstate &state);
/*************************************************************************
Integration on a finite interval [A,B].
Integrand have integrable singularities at A/B.
F(X) must diverge as "(x-A)^alpha" at A, as "(B-x)^beta" at B, with known
alpha/beta (alpha>-1, beta>-1). If alpha/beta are not known, estimates
from below can be used (but these estimates should be greater than -1 too).
One of alpha/beta variables (or even both alpha/beta) may be equal to 0,
which means than function F(x) is non-singular at A/B. Anyway (singular at
bounds or not), function F(x) is supposed to be continuous on (A,B).
Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
is calculated with accuracy close to the machine precision.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
Alpha - power-law coefficient of the F(x) at A,
Alpha>-1
Beta - power-law coefficient of the F(x) at B,
Beta>-1
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmooth, AutoGKSmoothW, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
void autogksingular(const double a, const double b, const double alpha, con
st double beta, autogkstate &state);
/*************************************************************************
This function provides reverse communication interface
Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API
*************************************************************************/
bool autogkiteration(const autogkstate &state);
/*************************************************************************
This function is used to launcn iterations of the 1-dimensional integrator
It accepts following parameters:
func - callback which calculates f(x) for given x
ptr - optional pointer which is passed to func; can be NULL
-- ALGLIB --
Copyright 07.05.2009 by Bochkanov Sergey
*************************************************************************/
void autogkintegrate(autogkstate &state,
void (*func)(double x, double xminusa, double bminusx, double &y, void
*ptr),
void *ptr = NULL);
/*************************************************************************
Adaptive integration results
Called after AutoGKIteration returned False.
Input parameters:
State - algorithm state (used by AutoGKIteration).
Output parameters:
V - integral(f(x)dx,a,b)
Rep - optimization report (see AutoGKReport description)
-- ALGLIB --
Copyright 14.11.2007 by Bochkanov Sergey
*************************************************************************/
void autogkresults(const autogkstate &state, double &v, autogkreport &rep);
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
void autogksmooth(double a,
double b,
autogkstate* state,
ae_state *_state);
void autogksmoothw(double a,
double b,
double xwidth,
autogkstate* state,
ae_state *_state);
void autogksingular(double a,
double b,
double alpha,
double beta,
autogkstate* state,
ae_state *_state);
ae_bool autogkiteration(autogkstate* state, ae_state *_state);
void autogkresults(autogkstate* state,
double* v,
autogkreport* rep,
ae_state *_state);
ae_bool _autogkreport_init(autogkreport* p, ae_state *_state, ae_bool make_
automatic);
ae_bool _autogkreport_init_copy(autogkreport* dst, autogkreport* src, ae_st
ate *_state, ae_bool make_automatic);
void _autogkreport_clear(autogkreport* p);
ae_bool _autogkinternalstate_init(autogkinternalstate* p, ae_state *_state,
ae_bool make_automatic);
ae_bool _autogkinternalstate_init_copy(autogkinternalstate* dst, autogkinte
rnalstate* src, ae_state *_state, ae_bool make_automatic);
void _autogkinternalstate_clear(autogkinternalstate* p);
ae_bool _autogkstate_init(autogkstate* p, ae_state *_state, ae_bool make_au
tomatic);
ae_bool _autogkstate_init_copy(autogkstate* dst, autogkstate* src, ae_state
*_state, ae_bool make_automatic);
void _autogkstate_clear(autogkstate* p);
void gqgeneraterec(/* Real */ ae_vector* alpha, void gqgeneraterec(/* Real */ ae_vector* alpha,
/* Real */ ae_vector* beta, /* Real */ ae_vector* beta,
double mu0, double mu0,
ae_int_t n, ae_int_t n,
ae_int_t* info, ae_int_t* info,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* w, /* Real */ ae_vector* w,
ae_state *_state); ae_state *_state);
void gqgenerategausslobattorec(/* Real */ ae_vector* alpha, void gqgenerategausslobattorec(/* Real */ ae_vector* alpha,
/* Real */ ae_vector* beta, /* Real */ ae_vector* beta,
skipping to change at line 798 skipping to change at line 769
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* wkronrod, /* Real */ ae_vector* wkronrod,
/* Real */ ae_vector* wgauss, /* Real */ ae_vector* wgauss,
ae_state *_state); ae_state *_state);
void gkqlegendretbl(ae_int_t n, void gkqlegendretbl(ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* wkronrod, /* Real */ ae_vector* wkronrod,
/* Real */ ae_vector* wgauss, /* Real */ ae_vector* wgauss,
double* eps, double* eps,
ae_state *_state); ae_state *_state);
void autogksmooth(double a,
double b,
autogkstate* state,
ae_state *_state);
void autogksmoothw(double a,
double b,
double xwidth,
autogkstate* state,
ae_state *_state);
void autogksingular(double a,
double b,
double alpha,
double beta,
autogkstate* state,
ae_state *_state);
ae_bool autogkiteration(autogkstate* state, ae_state *_state);
void autogkresults(autogkstate* state,
double* v,
autogkreport* rep,
ae_state *_state);
ae_bool _autogkreport_init(autogkreport* p, ae_state *_state, ae_bool make_
automatic);
ae_bool _autogkreport_init_copy(autogkreport* dst, autogkreport* src, ae_st
ate *_state, ae_bool make_automatic);
void _autogkreport_clear(autogkreport* p);
ae_bool _autogkinternalstate_init(autogkinternalstate* p, ae_state *_state,
ae_bool make_automatic);
ae_bool _autogkinternalstate_init_copy(autogkinternalstate* dst, autogkinte
rnalstate* src, ae_state *_state, ae_bool make_automatic);
void _autogkinternalstate_clear(autogkinternalstate* p);
ae_bool _autogkstate_init(autogkstate* p, ae_state *_state, ae_bool make_au
tomatic);
ae_bool _autogkstate_init_copy(autogkstate* dst, autogkstate* src, ae_state
*_state, ae_bool make_automatic);
void _autogkstate_clear(autogkstate* p);
} }
#endif #endif
 End of changes. 4 change blocks. 
161 lines changed or deleted 161 lines changed or added


 interpolation.h   interpolation.h 
skipping to change at line 25 skipping to change at line 25
A copy of the GNU General Public License is available at A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>> >>> END OF LICENSE >>>
*************************************************************************/ *************************************************************************/
#ifndef _interpolation_pkg_h #ifndef _interpolation_pkg_h
#define _interpolation_pkg_h #define _interpolation_pkg_h
#include "ap.h" #include "ap.h"
#include "alglibinternal.h" #include "alglibinternal.h"
#include "alglibmisc.h" #include "alglibmisc.h"
#include "linalg.h" #include "linalg.h"
#include "optimization.h"
#include "solvers.h" #include "solvers.h"
#include "optimization.h"
#include "specialfunctions.h" #include "specialfunctions.h"
#include "integration.h" #include "integration.h"
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
typedef struct typedef struct
{ {
ae_int_t n;
ae_int_t nx;
ae_int_t d;
double r;
ae_int_t nw;
kdtree tree;
ae_int_t modeltype;
ae_matrix q;
ae_vector xbuf;
ae_vector tbuf;
ae_vector rbuf;
ae_matrix xybuf;
ae_int_t debugsolverfailures;
double debugworstrcond;
double debugbestrcond;
} idwinterpolant;
typedef struct
{
ae_int_t n;
double sy;
ae_vector x;
ae_vector y;
ae_vector w;
} barycentricinterpolant;
typedef struct
{
ae_bool periodic;
ae_int_t n;
ae_int_t k;
ae_vector x;
ae_vector c;
} spline1dinterpolant;
typedef struct
{
double taskrcond; double taskrcond;
double rmserror; double rmserror;
double avgerror; double avgerror;
double avgrelerror; double avgrelerror;
double maxerror; double maxerror;
} polynomialfitreport; } polynomialfitreport;
typedef struct typedef struct
{ {
double taskrcond; double taskrcond;
ae_int_t dbest; ae_int_t dbest;
skipping to change at line 105 skipping to change at line 139
double repavgerror; double repavgerror;
double repavgrelerror; double repavgrelerror;
double repmaxerror; double repmaxerror;
minlmstate optstate; minlmstate optstate;
minlmreport optrep; minlmreport optrep;
rcommstate rstate; rcommstate rstate;
} lsfitstate; } lsfitstate;
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t n;
double sy;
ae_vector x;
ae_vector y;
ae_vector w;
} barycentricinterpolant;
typedef struct
{
ae_bool periodic;
ae_int_t n;
ae_int_t k;
ae_vector x;
ae_vector c;
} spline1dinterpolant;
typedef struct
{
ae_int_t k;
ae_vector c;
} spline2dinterpolant;
typedef struct
{
ae_int_t n;
ae_int_t nx;
ae_int_t d;
double r;
ae_int_t nw;
kdtree tree;
ae_int_t modeltype;
ae_matrix q;
ae_vector xbuf;
ae_vector tbuf;
ae_vector rbuf;
ae_matrix xybuf;
ae_int_t debugsolverfailures;
double debugworstrcond;
double debugbestrcond;
} idwinterpolant;
typedef struct
{
ae_int_t n;
ae_bool periodic; ae_bool periodic;
ae_vector p; ae_vector p;
spline1dinterpolant x; spline1dinterpolant x;
spline1dinterpolant y; spline1dinterpolant y;
} pspline2interpolant; } pspline2interpolant;
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t n;
ae_bool periodic; ae_bool periodic;
ae_vector p; ae_vector p;
spline1dinterpolant x; spline1dinterpolant x;
spline1dinterpolant y; spline1dinterpolant y;
spline1dinterpolant z; spline1dinterpolant z;
} pspline3interpolant; } pspline3interpolant;
typedef struct
{
ae_int_t k;
ae_vector c;
} spline2dinterpolant;
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS C++ INTERFACE // THIS SECTION CONTAINS C++ INTERFACE
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib namespace alglib
{ {
/************************************************************************* /*************************************************************************
IDW interpolant.
*************************************************************************/
class _idwinterpolant_owner
{
public:
_idwinterpolant_owner();
_idwinterpolant_owner(const _idwinterpolant_owner &rhs);
_idwinterpolant_owner& operator=(const _idwinterpolant_owner &rhs);
virtual ~_idwinterpolant_owner();
alglib_impl::idwinterpolant* c_ptr();
alglib_impl::idwinterpolant* c_ptr() const;
protected:
alglib_impl::idwinterpolant *p_struct;
};
class idwinterpolant : public _idwinterpolant_owner
{
public:
idwinterpolant();
idwinterpolant(const idwinterpolant &rhs);
idwinterpolant& operator=(const idwinterpolant &rhs);
virtual ~idwinterpolant();
};
/*************************************************************************
Barycentric interpolant.
*************************************************************************/
class _barycentricinterpolant_owner
{
public:
_barycentricinterpolant_owner();
_barycentricinterpolant_owner(const _barycentricinterpolant_owner &rhs)
;
_barycentricinterpolant_owner& operator=(const _barycentricinterpolant_
owner &rhs);
virtual ~_barycentricinterpolant_owner();
alglib_impl::barycentricinterpolant* c_ptr();
alglib_impl::barycentricinterpolant* c_ptr() const;
protected:
alglib_impl::barycentricinterpolant *p_struct;
};
class barycentricinterpolant : public _barycentricinterpolant_owner
{
public:
barycentricinterpolant();
barycentricinterpolant(const barycentricinterpolant &rhs);
barycentricinterpolant& operator=(const barycentricinterpolant &rhs);
virtual ~barycentricinterpolant();
};
/*************************************************************************
1-dimensional spline inteprolant
*************************************************************************/
class _spline1dinterpolant_owner
{
public:
_spline1dinterpolant_owner();
_spline1dinterpolant_owner(const _spline1dinterpolant_owner &rhs);
_spline1dinterpolant_owner& operator=(const _spline1dinterpolant_owner
&rhs);
virtual ~_spline1dinterpolant_owner();
alglib_impl::spline1dinterpolant* c_ptr();
alglib_impl::spline1dinterpolant* c_ptr() const;
protected:
alglib_impl::spline1dinterpolant *p_struct;
};
class spline1dinterpolant : public _spline1dinterpolant_owner
{
public:
spline1dinterpolant();
spline1dinterpolant(const spline1dinterpolant &rhs);
spline1dinterpolant& operator=(const spline1dinterpolant &rhs);
virtual ~spline1dinterpolant();
};
/*************************************************************************
Polynomial fitting report: Polynomial fitting report:
TaskRCond reciprocal of task's condition number TaskRCond reciprocal of task's condition number
RMSError RMS error RMSError RMS error
AvgError average error AvgError average error
AvgRelError average relative error (for non-zero Y[I]) AvgRelError average relative error (for non-zero Y[I])
MaxError maximum error MaxError maximum error
*************************************************************************/ *************************************************************************/
class _polynomialfitreport_owner class _polynomialfitreport_owner
{ {
public: public:
skipping to change at line 351 skipping to change at line 426
ae_bool &xupdated; ae_bool &xupdated;
real_1d_array c; real_1d_array c;
double &f; double &f;
real_1d_array g; real_1d_array g;
real_2d_array h; real_2d_array h;
real_1d_array x; real_1d_array x;
}; };
/************************************************************************* /*************************************************************************
Barycentric interpolant.
*************************************************************************/
class _barycentricinterpolant_owner
{
public:
_barycentricinterpolant_owner();
_barycentricinterpolant_owner(const _barycentricinterpolant_owner &rhs)
;
_barycentricinterpolant_owner& operator=(const _barycentricinterpolant_
owner &rhs);
virtual ~_barycentricinterpolant_owner();
alglib_impl::barycentricinterpolant* c_ptr();
alglib_impl::barycentricinterpolant* c_ptr() const;
protected:
alglib_impl::barycentricinterpolant *p_struct;
};
class barycentricinterpolant : public _barycentricinterpolant_owner
{
public:
barycentricinterpolant();
barycentricinterpolant(const barycentricinterpolant &rhs);
barycentricinterpolant& operator=(const barycentricinterpolant &rhs);
virtual ~barycentricinterpolant();
};
/*************************************************************************
1-dimensional spline inteprolant
*************************************************************************/
class _spline1dinterpolant_owner
{
public:
_spline1dinterpolant_owner();
_spline1dinterpolant_owner(const _spline1dinterpolant_owner &rhs);
_spline1dinterpolant_owner& operator=(const _spline1dinterpolant_owner
&rhs);
virtual ~_spline1dinterpolant_owner();
alglib_impl::spline1dinterpolant* c_ptr();
alglib_impl::spline1dinterpolant* c_ptr() const;
protected:
alglib_impl::spline1dinterpolant *p_struct;
};
class spline1dinterpolant : public _spline1dinterpolant_owner
{
public:
spline1dinterpolant();
spline1dinterpolant(const spline1dinterpolant &rhs);
spline1dinterpolant& operator=(const spline1dinterpolant &rhs);
virtual ~spline1dinterpolant();
};
/*************************************************************************
2-dimensional spline inteprolant
*************************************************************************/
class _spline2dinterpolant_owner
{
public:
_spline2dinterpolant_owner();
_spline2dinterpolant_owner(const _spline2dinterpolant_owner &rhs);
_spline2dinterpolant_owner& operator=(const _spline2dinterpolant_owner
&rhs);
virtual ~_spline2dinterpolant_owner();
alglib_impl::spline2dinterpolant* c_ptr();
alglib_impl::spline2dinterpolant* c_ptr() const;
protected:
alglib_impl::spline2dinterpolant *p_struct;
};
class spline2dinterpolant : public _spline2dinterpolant_owner
{
public:
spline2dinterpolant();
spline2dinterpolant(const spline2dinterpolant &rhs);
spline2dinterpolant& operator=(const spline2dinterpolant &rhs);
virtual ~spline2dinterpolant();
};
/*************************************************************************
IDW interpolant.
*************************************************************************/
class _idwinterpolant_owner
{
public:
_idwinterpolant_owner();
_idwinterpolant_owner(const _idwinterpolant_owner &rhs);
_idwinterpolant_owner& operator=(const _idwinterpolant_owner &rhs);
virtual ~_idwinterpolant_owner();
alglib_impl::idwinterpolant* c_ptr();
alglib_impl::idwinterpolant* c_ptr() const;
protected:
alglib_impl::idwinterpolant *p_struct;
};
class idwinterpolant : public _idwinterpolant_owner
{
public:
idwinterpolant();
idwinterpolant(const idwinterpolant &rhs);
idwinterpolant& operator=(const idwinterpolant &rhs);
virtual ~idwinterpolant();
};
/*************************************************************************
Parametric spline inteprolant: 2-dimensional curve. Parametric spline inteprolant: 2-dimensional curve.
You should not try to access its members directly - use PSpline2XXXXXXXX() You should not try to access its members directly - use PSpline2XXXXXXXX()
functions instead. functions instead.
*************************************************************************/ *************************************************************************/
class _pspline2interpolant_owner class _pspline2interpolant_owner
{ {
public: public:
_pspline2interpolant_owner(); _pspline2interpolant_owner();
_pspline2interpolant_owner(const _pspline2interpolant_owner &rhs); _pspline2interpolant_owner(const _pspline2interpolant_owner &rhs);
skipping to change at line 507 skipping to change at line 482
{ {
public: public:
pspline3interpolant(); pspline3interpolant();
pspline3interpolant(const pspline3interpolant &rhs); pspline3interpolant(const pspline3interpolant &rhs);
pspline3interpolant& operator=(const pspline3interpolant &rhs); pspline3interpolant& operator=(const pspline3interpolant &rhs);
virtual ~pspline3interpolant(); virtual ~pspline3interpolant();
}; };
/************************************************************************* /*************************************************************************
Fitting by polynomials in barycentric form. This function provides simple 2-dimensional spline inteprolant
unterface for unconstrained unweighted fitting. See PolynomialFitWC() if *************************************************************************/
you need constrained fitting. class _spline2dinterpolant_owner
{
public:
_spline2dinterpolant_owner();
_spline2dinterpolant_owner(const _spline2dinterpolant_owner &rhs);
_spline2dinterpolant_owner& operator=(const _spline2dinterpolant_owner
&rhs);
virtual ~_spline2dinterpolant_owner();
alglib_impl::spline2dinterpolant* c_ptr();
alglib_impl::spline2dinterpolant* c_ptr() const;
protected:
alglib_impl::spline2dinterpolant *p_struct;
};
class spline2dinterpolant : public _spline2dinterpolant_owner
{
public:
spline2dinterpolant();
spline2dinterpolant(const spline2dinterpolant &rhs);
spline2dinterpolant& operator=(const spline2dinterpolant &rhs);
virtual ~spline2dinterpolant();
Task is linear, so linear least squares solver is used. Complexity of this };
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO: /*************************************************************************
PolynomialFitWC() IDW interpolation
INPUT PARAMETERS: INPUT PARAMETERS:
X - points, array[0..N-1]. Z - IDW interpolant built with one of model building
Y - function values, array[0..N-1]. subroutines.
N - number of points, N>0 X - array[0..NX-1], interpolation point
* if given, only leading N elements of X/Y are used
* if not given, automatically determined from sizes of X/Y Result:
M - number of basis functions (= polynomial_degree + 1), M>=1 IDW interpolant Z(X)
-- ALGLIB --
Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/
double idwcalc(const idwinterpolant &z, const real_1d_array &x);
/*************************************************************************
IDW interpolant using modified Shepard method for uniform point
distributions.
INPUT PARAMETERS:
XY - X and Y values, array[0..N-1,0..NX].
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
D - nodal function type, either:
* 0 constant model. Just for demonstration only, worst
model ever.
* 1 linear model, least squares fitting. Simpe model for
datasets too small for quadratic models
* 2 quadratic model, least squares fitting. Best model
available (if your dataset is large enough).
* -1 "fast" linear model, use with caution!!! It is
significantly faster than linear/quadratic and better
than constant model. But it is less robust (especially
in the presence of noise).
NQ - number of points used to calculate nodal functions (ignored
for constant models). NQ should be LARGER than:
* max(1.5*(1+NX),2^NX+1) for linear model,
* max(3/4*(NX+2)*(NX+1),2^NX+1) for quadratic model.
Values less than this threshold will be silently increased.
NW - number of points used to calculate weights and to interpolate.
Required: >=2^NX+1, values less than this threshold will be
silently increased.
Recommended value: about 2*NQ
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine: Z - IDW interpolant.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
P - interpolant in barycentric form.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
NOTES: NOTES:
you can convert P from barycentric form to the power or Chebyshev * best results are obtained with quadratic models, worst - with constant
basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from models
POLINT subpackage. * when N is large, NQ and NW must be significantly smaller than N both
to obtain optimal performance and to obtain optimal accuracy. In 2 or
3-dimensional tasks NQ=15 and NW=25 are good values to start with.
* NQ and NW may be greater than N. In such cases they will be
automatically decreased.
* this subroutine is always succeeds (as long as correct parameters are
passed).
* see 'Multivariate Interpolation of Large Sets of Scattered Data' by
Robert J. Renka for more information on this algorithm.
* this subroutine assumes that point distribution is uniform at the small
scales. If it isn't - for example, points are concentrated along
"lines", but "lines" distribution is uniform at the larger scale - then
you should use IDWBuildModifiedShepardR()
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 10.12.2009 by Bochkanov Sergey Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae void idwbuildmodifiedshepard(const real_2d_array &xy, const ae_int_t n, con
_int_t n, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, poly st ae_int_t nx, const ae_int_t d, const ae_int_t nq, const ae_int_t nw, idw
nomialfitreport &rep); interpolant &z);
void polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae
_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &r
ep);
/************************************************************************* /*************************************************************************
Weighted fitting by polynomials in barycentric form, with constraints on IDW interpolant using modified Shepard method for non-uniform datasets.
function values or first derivatives.
Small regularizing term is used when solving constrained tasks (to improve
stability).
Task is linear, so linear least squares solver is used. Complexity of this
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO: This type of model uses constant nodal functions and interpolates using
PolynomialFit() all nodes which are closer than user-specified radius R. It may be used
when points distribution is non-uniform at the small scale, but it is at
the distances as large as R.
INPUT PARAMETERS: INPUT PARAMETERS:
X - points, array[0..N-1]. XY - X and Y values, array[0..N-1,0..NX].
Y - function values, array[0..N-1]. First NX columns contain X-values, last column contain
W - weights, array[0..N-1] Y-values.
Each summand in square sum of approximation deviations from N - number of nodes, N>0.
given values is multiplied by the square of corresponding NX - space dimension, NX>=1.
weight. Fill it by 1's if you don't want to solve weighted R - radius, R>0
task.
N - number of points, N>0.
* if given, only leading N elements of X/Y/W are used
* if not given, automatically determined from sizes of X/Y/W
XC - points where polynomial values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that P(XC[i])=YC[i]
* DC[i]=1 means that P'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints, 0<=K<M.
K=0 means no constraints (XC/YC/DC are not used in such cases)
M - number of basis functions (= polynomial_degree + 1), M>=1
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine: Z - IDW interpolant.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
P - interpolant in barycentric form.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
NOTES: NOTES:
you can convert P from barycentric form to the power or Chebyshev * if there is less than IDWKMin points within R-ball, algorithm selects
basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from IDWKMin closest ones, so that continuity properties of interpolant are
POLINT subpackage. preserved even far from points.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* even simple constraints can be inconsistent, see Wikipedia article on
this subject: http://en.wikipedia.org/wiki/Birkhoff_interpolation
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints is NOT GUARANTEED.
* in the one special cases, however, we can guarantee consistency. This
case is: M>1 and constraints on the function values (NOT DERIVATIVES)
Our final recommendation is to use constraints WHEN AND ONLY when you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 10.12.2009 by Bochkanov Sergey Copyright 11.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const void idwbuildmodifiedshepardr(const real_2d_array &xy, const ae_int_t n, co
real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_ nst ae_int_t nx, const double r, idwinterpolant &z);
array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m,
ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
void polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const
real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, const i
nteger_1d_array &dc, const ae_int_t m, ae_int_t &info, barycentricinterpola
nt &p, polynomialfitreport &rep);
/************************************************************************* /*************************************************************************
Weghted rational least squares fitting using Floater-Hormann rational IDW model for noisy data.
functions with optimal D chosen from [0,9], with constraints and
individual weights.
Equidistant grid with M node on [min(x),max(x)] is used to build basis This subroutine may be used to handle noisy data, i.e. data with noise in
functions. Different values of D are tried, optimal D (least WEIGHTED root OUTPUT values. It differs from IDWBuildModifiedShepard() in the following
mean square error) is chosen. Task is linear, so linear least squares aspects:
solver is used. Complexity of this computational scheme is O(N*M^2) * nodal functions are not constrained to pass through nodes: Qi(xi)<>yi,
(mostly dominated by the least squares solver). i.e. we have fitting instead of interpolation.
* weights which are used during least squares fitting stage are all equal
to 1.0 (independently of distance)
* "fast"-linear or constant nodal functions are not supported (either not
robust enough or too rigid)
SEE ALSO This problem require far more complex tuning than interpolation problems.
* BarycentricFitFloaterHormann(), "lightweight" fitting without invididual Below you can find some recommendations regarding this problem:
weights and constraints. * focus on tuning NQ; it controls noise reduction. As for NW, you can just
make it equal to 2*NQ.
* you can use cross-validation to determine optimal NQ.
* optimal NQ is a result of complex tradeoff between noise level (more
noise = larger NQ required) and underlying function complexity (given
fixed N, larger NQ means smoothing of compex features in the data). For
example, NQ=N will reduce noise to the minimum level possible, but you
will end up with just constant/linear/quadratic (depending on D) least
squares model for the whole dataset.
INPUT PARAMETERS: INPUT PARAMETERS:
X - points, array[0..N-1]. XY - X and Y values, array[0..N-1,0..NX].
Y - function values, array[0..N-1]. First NX columns contain X-values, last column contain
W - weights, array[0..N-1] Y-values.
Each summand in square sum of approximation deviations from N - number of nodes, N>0.
given values is multiplied by the square of corresponding NX - space dimension, NX>=1.
weight. Fill it by 1's if you don't want to solve weighted D - nodal function degree, either:
task. * 1 linear model, least squares fitting. Simpe model for
N - number of points, N>0. datasets too small for quadratic models (or for very
XC - points where function values/derivatives are constrained, noisy problems).
array[0..K-1]. * 2 quadratic model, least squares fitting. Best model
YC - values of constraints, array[0..K-1] available (if your dataset is large enough).
DC - array[0..K-1], types of constraints: NQ - number of points used to calculate nodal functions. NQ should
* DC[i]=0 means that S(XC[i])=YC[i] be significantly larger than 1.5 times the number of
* DC[i]=1 means that S'(XC[i])=YC[i] coefficients in a nodal function to overcome effects of noise:
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS * larger than 1.5*(1+NX) for linear model,
K - number of constraints, 0<=K<M. * larger than 3/4*(NX+2)*(NX+1) for quadratic model.
K=0 means no constraints (XC/YC/DC are not used in such cases) Values less than this threshold will be silently increased.
M - number of basis functions ( = number_of_nodes), M>=2. NW - number of points used to calculate weights and to interpolate.
Required: >=2^NX+1, values less than this threshold will be
OUTPUT PARAMETERS: silently increased.
Info- same format as in LSFitLinearWC() subroutine. Recommended value: about 2*NQ or larger
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
-1 means another errors in parameters passed
(N<=0, for example)
B - barycentric interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* DBest best value of the D parameter
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroutine doesn't calculate task's condition number for K<>0.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned OUTPUT PARAMETERS:
behavior, or inconsistency being detected. From the other side, it allows Z - IDW interpolant.
us to improve quality of the fit. Here we summarize our experience with
constrained barycentric interpolants:
* excessive constraints can be inconsistent. Floater-Hormann basis
functions aren't as flexible as splines (although they are very smooth).
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints IS NOT GUARANTEED.
* in the several special cases, however, we CAN guarantee consistency.
* one of this cases is constraints on the function VALUES at the interval
boundaries. Note that consustency of the constraints on the function
DERIVATIVES is NOT guaranteed (you can use in such cases cubic splines
which are more flexible).
* another special case is ONE constraint on the function value (OR, but
not AND, derivative) anywhere in the interval
Our final recommendation is to use constraints WHEN AND ONLY WHEN you NOTES:
can't solve your task without them. Anything beyond special cases given * best results are obtained with quadratic models, linear models are not
above is not guaranteed and may result in inconsistency. recommended to use unless you are pretty sure that it is what you want
* this subroutine is always succeeds (as long as correct parameters are
passed).
* see 'Multivariate Interpolation of Large Sets of Scattered Data' by
Robert J. Renka for more information on this algorithm.
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void barycentricfitfloaterhormannwc(const real_1d_array &x, const real_1d_a rray &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, con st ae_int_t m, ae_int_t &info, barycentricinterpolant &b, barycentricfitrep ort &rep); void idwbuildnoisy(const real_2d_array &xy, const ae_int_t n, const ae_int_ t nx, const ae_int_t d, const ae_int_t nq, const ae_int_t nw, idwinterpolan t &z);
/************************************************************************* /*************************************************************************
Rational least squares fitting using Floater-Hormann rational functions Rational interpolation using barycentric formula
with optimal D chosen from [0,9].
Equidistant grid with M node on [min(x),max(x)] is used to build basis F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i]))
functions. Different values of D are tried, optimal D (least root mean
square error) is chosen. Task is linear, so linear least squares solver
is used. Complexity of this computational scheme is O(N*M^2) (mostly
dominated by the least squares solver).
INPUT PARAMETERS: Input parameters:
X - points, array[0..N-1]. B - barycentric interpolant built with one of model building
Y - function values, array[0..N-1]. subroutines.
N - number of points, N>0. T - interpolation point
M - number of basis functions ( = number_of_nodes), M>=2.
OUTPUT PARAMETERS: Result:
Info- same format as in LSFitLinearWC() subroutine. barycentric interpolant F(t)
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
B - barycentric interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* DBest best value of the D parameter
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 18.08.2009 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void barycentricfitfloaterhormann(const real_1d_array &x, const real_1d_arr ay &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, barycentricinter polant &b, barycentricfitreport &rep); double barycentriccalc(const barycentricinterpolant &b, const double t);
/************************************************************************* /*************************************************************************
Rational least squares fitting using Floater-Hormann rational functions Differentiation of barycentric interpolant: first derivative.
with optimal D chosen from [0,9].
Equidistant grid with M node on [min(x),max(x)] is used to build basis Algorithm used in this subroutine is very robust and should not fail until
functions. Different values of D are tried, optimal D (least root mean provided with values too close to MaxRealNumber (usually MaxRealNumber/N
square error) is chosen. Task is linear, so linear least squares solver or greater will overflow).
is used. Complexity of this computational scheme is O(N*M^2) (mostly
dominated by the least squares solver).
INPUT PARAMETERS: INPUT PARAMETERS:
X - points, array[0..N-1]. B - barycentric interpolant built with one of model building
Y - function values, array[0..N-1]. subroutines.
N - number of points, N>0. T - interpolation point
M - number of basis functions ( = number_of_nodes), M>=2.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine. F - barycentric interpolant at T
* Info>0 task is solved DF - first derivative
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
B - barycentric interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* DBest best value of the D parameter
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB PROJECT -- NOTE
Copyright 18.08.2009 by Bochkanov Sergey
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, c void barycentricdiff1(const barycentricinterpolant &b, const double t, doub
onst ae_int_t n, const ae_int_t m, const double rho, ae_int_t &info, spline le &f, double &df);
1dinterpolant &s, spline1dfitreport &rep);
void spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, c
onst ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s,
spline1dfitreport &rep);
/************************************************************************* /*************************************************************************
Weighted fitting by penalized cubic spline. Differentiation of barycentric interpolant: first/second derivatives.
Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are cubic splines with natural boundary
conditions. Problem is regularized by adding non-linearity penalty to the
usual least squares penalty function:
S(x) = arg min { LS + P }, where
LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty
P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty
rho - tunable constant given by user
C - automatically determined scale parameter,
makes penalty invariant with respect to scaling of X, Y, W.
INPUT PARAMETERS: INPUT PARAMETERS:
X - points, array[0..N-1]. B - barycentric interpolant built with one of model building
Y - function values, array[0..N-1]. subroutines.
W - weights, array[0..N-1] T - interpolation point
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
problem.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
M - number of basis functions ( = number_of_nodes), M>=4.
Rho - regularization constant passed by user. It penalizes
nonlinearity in the regression spline. It is logarithmically
scaled, i.e. actual value of regularization constant is
calculated as 10^Rho. It is automatically scaled so that:
* Rho=2.0 corresponds to moderate amount of nonlinearity
* generally, it should be somewhere in the [-8.0,+8.0]
If you do not want to penalize nonlineary,
pass small Rho. Values as low as -15 should work.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine. F - barycentric interpolant at T
* Info>0 task is solved DF - first derivative
* Info<=0 an error occured: D2F - second derivative
-4 means inconvergence of internal SVD or
Cholesky decomposition; problem may be
too ill-conditioned (very rare)
S - spline interpolant.
Rep - Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT: NOTE: this algorithm may fail due to overflow/underflor if used on data
this subroitine doesn't calculate task's condition number for K<>0. whose values are close to MaxRealNumber or MinRealNumber. Use more robust
BarycentricDiff1() subroutine in such cases.
NOTE 1: additional nodes are added to the spline outside of the fitting -- ALGLIB --
interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done Copyright 17.08.2009 by Bochkanov Sergey
for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so *************************************************************************/
it is natural to force linearity outside of this interval. void barycentricdiff2(const barycentricinterpolant &b, const double t, doub
le &f, double &df, double &d2f);
NOTE 2: function automatically sorts points, so caller may pass unsorted /*************************************************************************
array. This subroutine performs linear transformation of the argument.
INPUT PARAMETERS:
B - rational interpolant in barycentric form
CA, CB - transformation coefficients: x = CA*t + CB
OUTPUT PARAMETERS:
B - transformed interpolant with X replaced by T
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 19.10.2010 by Bochkanov Sergey Copyright 19.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y, void barycentriclintransx(const barycentricinterpolant &b, const double ca,
const real_1d_array &w, const ae_int_t n, const ae_int_t m, const double rh const double cb);
o, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
void spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y,
const real_1d_array &w, const ae_int_t m, const double rho, ae_int_t &info,
spline1dinterpolant &s, spline1dfitreport &rep);
/************************************************************************* /*************************************************************************
Weighted fitting by cubic spline, with constraints on function values or This subroutine performs linear transformation of the barycentric
derivatives. interpolant.
Equidistant grid with M-2 nodes on [min(x,xc),max(x,xc)] is used to build INPUT PARAMETERS:
basis functions. Basis functions are cubic splines with continuous second B - rational interpolant in barycentric form
derivatives and non-fixed first derivatives at interval ends. Small CA, CB - transformation coefficients: B2(x) = CA*B(x) + CB
regularizing term is used when solving constrained tasks (to improve
stability).
Task is linear, so linear least squares solver is used. Complexity of this OUTPUT PARAMETERS:
computational scheme is O(N*M^2), mostly dominated by least squares solver B - transformed interpolant
SEE ALSO -- ALGLIB PROJECT --
Spline1DFitHermiteWC() - fitting by Hermite splines (more flexible, Copyright 19.08.2009 by Bochkanov Sergey
less smooth) *************************************************************************/
Spline1DFitCubic() - "lightweight" fitting by cubic splines, void barycentriclintransy(const barycentricinterpolant &b, const double ca,
without invididual weights and constraints const double cb);
/*************************************************************************
Extracts X/Y/W arrays from rational interpolant
INPUT PARAMETERS: INPUT PARAMETERS:
X - points, array[0..N-1]. B - barycentric interpolant
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
XC - points where spline values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints (optional):
* 0<=K<M.
* K=0 means no constraints (XC/YC/DC are not used)
* if given, only first K elements of XC/YC/DC are used
* if not given, automatically determined from XC/YC/DC
M - number of basis functions ( = number_of_nodes+2), M>=4.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine. N - nodes count, N>0
* Info>0 task is solved X - interpolation nodes, array[0..N-1]
* Info<=0 an error occured: F - function values, array[0..N-1]
-4 means inconvergence of internal SVD W - barycentric weights, array[0..N-1]
-3 means inconsistent constraints
S - spline interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* excessive constraints can be inconsistent. Splines are piecewise cubic
functions, and it is easy to create an example, where large number of
constraints concentrated in small area will result in inconsistency.
Just because spline is not flexible enough to satisfy all of them. And
same constraints spread across the [min(x),max(x)] will be perfectly
consistent.
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints IS NOT GUARANTEED.
* in the several special cases, however, we CAN guarantee consistency.
* one of this cases is constraints on the function values AND/OR its
derivatives at the interval boundaries.
* another special case is ONE constraint on the function value (OR, but
not AND, derivative) anywhere in the interval
Our final recommendation is to use constraints WHEN AND ONLY WHEN you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 18.08.2009 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, con void barycentricunpack(const barycentricinterpolant &b, ae_int_t &n, real_1
st real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_ d_array &x, real_1d_array &y, real_1d_array &w);
1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t
m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
void spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, con
st real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, cons
t integer_1d_array &dc, const ae_int_t m, ae_int_t &info, spline1dinterpola
nt &s, spline1dfitreport &rep);
/************************************************************************* /*************************************************************************
Weighted fitting by Hermite spline, with constraints on function values Rational interpolant from X/Y/W arrays
or first derivatives.
Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are Hermite splines. Small regularizing
term is used when solving constrained tasks (to improve stability).
Task is linear, so linear least squares solver is used. Complexity of this
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i]))
Spline1DFitCubicWC() - fitting by Cubic splines (less flexible,
more smooth)
Spline1DFitHermite() - "lightweight" Hermite fitting, without
invididual weights and constraints
INPUT PARAMETERS: INPUT PARAMETERS:
X - points, array[0..N-1]. X - interpolation nodes, array[0..N-1]
Y - function values, array[0..N-1]. F - function values, array[0..N-1]
W - weights, array[0..N-1] W - barycentric weights, array[0..N-1]
Each summand in square sum of approximation deviations from N - nodes count, N>0
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
XC - points where spline values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints (optional):
* 0<=K<M.
* K=0 means no constraints (XC/YC/DC are not used)
* if given, only first K elements of XC/YC/DC are used
* if not given, automatically determined from XC/YC/DC
M - number of basis functions (= 2 * number of nodes),
M>=4,
M IS EVEN!
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine: B - barycentric interpolant built from (X, Y, W)
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
-2 means odd M was passed (which is not supported)
-1 means another errors in parameters passed
(N<=0, for example)
S - spline interpolant.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
IMPORTANT: -- ALGLIB --
this subroitine supports only even M's Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
void barycentricbuildxyw(const real_1d_array &x, const real_1d_array &y, co
nst real_1d_array &w, const ae_int_t n, barycentricinterpolant &b);
ORDER OF POINTS /*************************************************************************
Rational interpolant without poles
Subroutine automatically sorts points, so caller may pass unsorted array. The subroutine constructs the rational interpolating function without real
poles (see 'Barycentric rational interpolation with no poles and high
rates of approximation', Michael S. Floater. and Kai Hormann, for more
information on this subject).
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES: Input parameters:
X - interpolation nodes, array[0..N-1].
Y - function values, array[0..N-1].
N - number of nodes, N>0.
D - order of the interpolation scheme, 0 <= D <= N-1.
D<0 will cause an error.
D>=N it will be replaced with D=N-1.
if you don't know what D to choose, use small value about 3-5.
Setting constraints can lead to undesired results, like ill-conditioned Output parameters:
behavior, or inconsistency being detected. From the other side, it allows B - barycentric interpolant.
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* excessive constraints can be inconsistent. Splines are piecewise cubic
functions, and it is easy to create an example, where large number of
constraints concentrated in small area will result in inconsistency.
Just because spline is not flexible enough to satisfy all of them. And
same constraints spread across the [min(x),max(x)] will be perfectly
consistent.
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints is NOT GUARANTEED.
* in the several special cases, however, we can guarantee consistency.
* one of this cases is M>=4 and constraints on the function value
(AND/OR its derivative) at the interval boundaries.
* another special case is M>=4 and ONE constraint on the function value
(OR, BUT NOT AND, derivative) anywhere in [min(x),max(x)]
Our final recommendation is to use constraints WHEN AND ONLY when you Note:
can't solve your task without them. Anything beyond special cases given this algorithm always succeeds and calculates the weights with close
above is not guaranteed and may result in inconsistency. to machine precision.
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey Copyright 17.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, c void barycentricbuildfloaterhormann(const real_1d_array &x, const real_1d_a
onst real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const rea rray &y, const ae_int_t n, const ae_int_t d, barycentricinterpolant &b);
l_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_
t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
void spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, c
onst real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, co
nst integer_1d_array &dc, const ae_int_t m, ae_int_t &info, spline1dinterpo
lant &s, spline1dfitreport &rep);
/************************************************************************* /*************************************************************************
Least squares fitting by cubic spline. Conversion from barycentric representation to Chebyshev basis.
This function has O(N^2) complexity.
This subroutine is "lightweight" alternative for more complex and feature-
rich Spline1DFitCubicWC(). See Spline1DFitCubicWC() for more information
about subroutine parameters (we don't duplicate it here because of length)
-- ALGLIB PROJECT -- INPUT PARAMETERS:
Copyright 18.08.2009 by Bochkanov Sergey P - polynomial in barycentric form
*************************************************************************/ A,B - base interval for Chebyshev polynomials (see below)
void spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const A<>B
ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spli
ne1dfitreport &rep);
void spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const
ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep
);
/************************************************************************* OUTPUT PARAMETERS
Least squares fitting by Hermite spline. T - coefficients of Chebyshev representation;
P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N-1 },
where Ti - I-th Chebyshev polynomial.
This subroutine is "lightweight" alternative for more complex and feature- NOTES:
rich Spline1DFitHermiteWC(). See Spline1DFitHermiteWC() description for barycentric interpolant passed as P may be either polynomial obtained
more information about subroutine parameters (we don't duplicate it here from polynomial interpolation/ fitting or rational function which is
because of length). NOT polynomial. We can't distinguish between these two cases, and this
algorithm just tries to work assuming that P IS a polynomial. If not,
algorithm will return results, but they won't have any meaning.
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 18.08.2009 by Bochkanov Sergey Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dfithermite(const real_1d_array &x, const real_1d_array &y, con void polynomialbar2cheb(const barycentricinterpolant &p, const double a, co
st ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, sp nst double b, real_1d_array &t);
line1dfitreport &rep);
void spline1dfithermite(const real_1d_array &x, const real_1d_array &y, con
st ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &r
ep);
/************************************************************************* /*************************************************************************
Weighted linear least squares fitting. Conversion from Chebyshev basis to barycentric representation.
This function has O(N^2) complexity.
QR decomposition is used to reduce task to MxM, then triangular solver or
SVD-based solver is used depending on condition number of the system. It
allows to maximize speed and retain decent accuracy.
INPUT PARAMETERS: INPUT PARAMETERS:
Y - array[0..N-1] Function values in N points. T - coefficients of Chebyshev representation;
W - array[0..N-1] Weights corresponding to function values. P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N },
Each summand in square sum of approximation deviations where Ti - I-th Chebyshev polynomial.
from given values is multiplied by the square of N - number of coefficients:
corresponding weight. * if given, only leading N elements of T are used
FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. * if not given, automatically determined from size of T
FMatrix[I, J] - value of J-th basis function in I-th point. A,B - base interval for Chebyshev polynomials (see above)
N - number of points used. N>=1. A<B
M - number of basis functions, M>=1.
OUTPUT PARAMETERS: OUTPUT PARAMETERS
Info - error code: P - polynomial in barycentric form
* -4 internal SVD decomposition subroutine failed (very
rare and for degenerate systems only)
* -1 incorrect N/M were specified
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* Rep.TaskRCond reciprocal of condition number
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB -- -- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const rea void polynomialcheb2bar(const real_1d_array &t, const ae_int_t n, const dou
l_2d_array &fmatrix, const ae_int_t n, const ae_int_t m, ae_int_t &info, re ble a, const double b, barycentricinterpolant &p);
al_1d_array &c, lsfitreport &rep); void polynomialcheb2bar(const real_1d_array &t, const double a, const doubl
void lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const rea e b, barycentricinterpolant &p);
l_2d_array &fmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
/************************************************************************* /*************************************************************************
Weighted constained linear least squares fitting. Conversion from barycentric representation to power basis.
This function has O(N^2) complexity.
This is variation of LSFitLinearW(), which searchs for min|A*x=b| given
that K additional constaints C*x=bc are satisfied. It reduces original
task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinearW()
is called.
INPUT PARAMETERS: INPUT PARAMETERS:
Y - array[0..N-1] Function values in N points. P - polynomial in barycentric form
W - array[0..N-1] Weights corresponding to function values. C - offset (see below); 0.0 is used as default value.
Each summand in square sum of approximation deviations S - scale (see below); 1.0 is used as default value. S<>0.
from given values is multiplied by the square of
corresponding weight.
FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
FMatrix[I,J] - value of J-th basis function in I-th point.
CMatrix - a table of constaints, array[0..K-1,0..M].
I-th row of CMatrix corresponds to I-th linear constraint:
CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I
,M]
N - number of points used. N>=1.
M - number of basis functions, M>=1.
K - number of constraints, 0 <= K < M
K=0 corresponds to absence of constraints.
OUTPUT PARAMETERS: OUTPUT PARAMETERS
Info - error code: A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 }
* -4 internal SVD decomposition subroutine failed (very N - number of coefficients (polynomial degree plus 1)
rare and for degenerate systems only)
* -3 either too many constraints (M or more),
degenerate constraints (some constraints are
repetead twice) or inconsistent constraints were
specified.
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT: NOTES:
this subroitine doesn't calculate task's condition number for K<>0. 1. this function accepts offset and scale, which can be set to improve
numerical properties of polynomial. For example, if P was obtained as
result of interpolation on [-1,+1], you can set C=0 and S=1 and
represent P as sum of 1, x, x^2, x^3 and so on. In most cases you it
is exactly what you need.
However, if your interpolation model was built on [999,1001], you will
see significant growth of numerical errors when using {1, x, x^2, x^3}
as basis. Representing P as sum of 1, (x-1000), (x-1000)^2, (x-1000)^3
will be better option. Such representation can be obtained by using
1000.0 as offset C and 1.0 as scale S.
2. power basis is ill-conditioned and tricks described above can't solve
this problem completely. This function will return coefficients in
any case, but for N>8 they will become unreliable. However, N's
less than 5 are pretty safe.
3. barycentric interpolant passed as P may be either polynomial obtained
from polynomial interpolation/ fitting or rational function which is
NOT polynomial. We can't distinguish between these two cases, and this
algorithm just tries to work assuming that P IS a polynomial. If not,
algorithm will return results, but they won't have any meaning.
-- ALGLIB -- -- ALGLIB --
Copyright 07.09.2009 by Bochkanov Sergey Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const re void polynomialbar2pow(const barycentricinterpolant &p, const double c, con
al_2d_array &fmatrix, const real_2d_array &cmatrix, const ae_int_t n, const st double s, real_1d_array &a);
ae_int_t m, const ae_int_t k, ae_int_t &info, real_1d_array &c, lsfitrepor void polynomialbar2pow(const barycentricinterpolant &p, real_1d_array &a);
t &rep);
void lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const re
al_2d_array &fmatrix, const real_2d_array &cmatrix, ae_int_t &info, real_1d
_array &c, lsfitreport &rep);
/************************************************************************* /*************************************************************************
Linear least squares fitting. Conversion from power basis to barycentric representation.
This function has O(N^2) complexity.
QR decomposition is used to reduce task to MxM, then triangular solver or
SVD-based solver is used depending on condition number of the system. It
allows to maximize speed and retain decent accuracy.
INPUT PARAMETERS: INPUT PARAMETERS:
Y - array[0..N-1] Function values in N points. A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 }
FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. N - number of coefficients (polynomial degree plus 1)
FMatrix[I, J] - value of J-th basis function in I-th point. * if given, only leading N elements of A are used
N - number of points used. N>=1. * if not given, automatically determined from size of A
M - number of basis functions, M>=1. C - offset (see below); 0.0 is used as default value.
S - scale (see below); 1.0 is used as default value. S<>0.
OUTPUT PARAMETERS: OUTPUT PARAMETERS
Info - error code: P - polynomial in barycentric form
* -4 internal SVD decomposition subroutine failed (very
rare and for degenerate systems only) NOTES:
* 1 task is solved 1. this function accepts offset and scale, which can be set to improve
C - decomposition coefficients, array[0..M-1] numerical properties of polynomial. For example, if you interpolate on
Rep - fitting report. Following fields are set: [-1,+1], you can set C=0 and S=1 and convert from sum of 1, x, x^2,
* Rep.TaskRCond reciprocal of condition number x^3 and so on. In most cases you it is exactly what you need.
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y). However, if your interpolation model was built on [999,1001], you will
* AvgRelError average relative error on the non-zero see significant growth of numerical errors when using {1, x, x^2, x^3}
Y as input basis. Converting from sum of 1, (x-1000), (x-1000)^2,
* MaxError maximum error (x-1000)^3 will be better option (you have to specify 1000.0 as offset
NON-WEIGHTED ERRORS ARE CALCULATED C and 1.0 as scale S).
2. power basis is ill-conditioned and tricks described above can't solve
this problem completely. This function will return barycentric model
in any case, but for N>8 accuracy well degrade. However, N's less than
5 are pretty safe.
-- ALGLIB -- -- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, cons void polynomialpow2bar(const real_1d_array &a, const ae_int_t n, const doub
t ae_int_t n, const ae_int_t m, ae_int_t &info, real_1d_array &c, lsfitrepo le c, const double s, barycentricinterpolant &p);
rt &rep); void polynomialpow2bar(const real_1d_array &a, barycentricinterpolant &p);
void lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, ae_i
nt_t &info, real_1d_array &c, lsfitreport &rep);
/************************************************************************* /*************************************************************************
Constained linear least squares fitting. Lagrange intepolant: generation of the model on the general grid.
This function has O(N^2) complexity.
This is variation of LSFitLinear(), which searchs for min|A*x=b| given
that K additional constaints C*x=bc are satisfied. It reduces original
task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinear()
is called.
INPUT PARAMETERS: INPUT PARAMETERS:
Y - array[0..N-1] Function values in N points. X - abscissas, array[0..N-1]
FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. Y - function values, array[0..N-1]
FMatrix[I,J] - value of J-th basis function in I-th point. N - number of points, N>=1
CMatrix - a table of constaints, array[0..K-1,0..M].
I-th row of CMatrix corresponds to I-th linear constraint:
CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I
,M]
N - number of points used. N>=1.
M - number of basis functions, M>=1.
K - number of constraints, 0 <= K < M
K=0 corresponds to absence of constraints.
OUTPUT PARAMETERS:
Info - error code:
* -4 internal SVD decomposition subroutine failed (very
rare and for degenerate systems only)
* -3 either too many constraints (M or more),
degenerate constraints (some constraints are
repetead twice) or inconsistent constraints were
specified.
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT: OUTPUT PARAMETERS
this subroitine doesn't calculate task's condition number for K<>0. P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB -- -- ALGLIB --
Copyright 07.09.2009 by Bochkanov Sergey Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, con void polynomialbuild(const real_1d_array &x, const real_1d_array &y, const
st real_2d_array &cmatrix, const ae_int_t n, const ae_int_t m, const ae_int ae_int_t n, barycentricinterpolant &p);
_t k, ae_int_t &info, real_1d_array &c, lsfitreport &rep); void polynomialbuild(const real_1d_array &x, const real_1d_array &y, baryce
void lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, con ntricinterpolant &p);
st real_2d_array &cmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &r
ep);
/************************************************************************* /*************************************************************************
Weighted nonlinear least squares fitting using function values only. Lagrange intepolant: generation of the model on equidistant grid.
This function has O(N) complexity.
Combination of numerical differentiation and secant updates is used to
obtain function Jacobian.
Nonlinear task min(F(c)) is solved, where INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
Y - function values at the nodes, array[0..N-1]
N - number of points, N>=1
for N=1 a constant model is constructed.
F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^ OUTPUT PARAMETERS
2, P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
* N is a number of points, -- ALGLIB --
* M is a dimension of a space points belong to, Copyright 03.12.2009 by Bochkanov Sergey
* K is a dimension of a space of parameters being fitted, *************************************************************************/
* w is an N-dimensional vector of weight coefficients, void polynomialbuildeqdist(const double a, const double b, const real_1d_ar
* x is a set of N points, each of them is an M-dimensional vector, ray &y, const ae_int_t n, barycentricinterpolant &p);
* c is a K-dimensional vector of parameters being fitted void polynomialbuildeqdist(const double a, const double b, const real_1d_ar
ray &y, barycentricinterpolant &p);
This subroutine uses only f(c,x[i]). /*************************************************************************
Lagrange intepolant on Chebyshev grid (first kind).
This function has O(N) complexity.
INPUT PARAMETERS: INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point) A - left boundary of [A,B]
Y - array[0..N-1], function values. B - right boundary of [A,B]
W - weights, array[0..N-1] Y - function values at the nodes, array[0..N-1],
C - array[0..K-1], initial approximation to the solution, Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n)))
N - number of points, N>1 N - number of points, N>=1
M - dimension of space for N=1 a constant model is constructed.
K - number of parameters being fitted
DiffStep- numerical differentiation step;
should not be very small or large;
large = loss of accuracy
small = growth of round-off errors
OUTPUT PARAMETERS: OUTPUT PARAMETERS
State - structure which stores algorithm state P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB -- -- ALGLIB --
Copyright 18.10.2008 by Bochkanov Sergey Copyright 03.12.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitcreatewf(const real_2d_array &x, const real_1d_array &y, const re void polynomialbuildcheb1(const double a, const double b, const real_1d_arr
al_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m, ay &y, const ae_int_t n, barycentricinterpolant &p);
const ae_int_t k, const double diffstep, lsfitstate &state); void polynomialbuildcheb1(const double a, const double b, const real_1d_arr
void lsfitcreatewf(const real_2d_array &x, const real_1d_array &y, const re ay &y, barycentricinterpolant &p);
al_1d_array &w, const real_1d_array &c, const double diffstep, lsfitstate &
state);
/************************************************************************* /*************************************************************************
Nonlinear least squares fitting using function values only. Lagrange intepolant on Chebyshev grid (second kind).
This function has O(N) complexity.
Combination of numerical differentiation and secant updates is used to
obtain function Jacobian.
Nonlinear task min(F(c)) is solved, where
F(c) = (f(c,x[0])-y[0])^2 + ... + (f(c,x[n-1])-y[n-1])^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* w is an N-dimensional vector of weight coefficients,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]).
INPUT PARAMETERS: INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point) A - left boundary of [A,B]
Y - array[0..N-1], function values. B - right boundary of [A,B]
C - array[0..K-1], initial approximation to the solution, Y - function values at the nodes, array[0..N-1],
N - number of points, N>1 Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1)))
M - dimension of space N - number of points, N>=1
K - number of parameters being fitted for N=1 a constant model is constructed.
DiffStep- numerical differentiation step;
should not be very small or large;
large = loss of accuracy
small = growth of round-off errors
OUTPUT PARAMETERS: OUTPUT PARAMETERS
State - structure which stores algorithm state P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB -- -- ALGLIB --
Copyright 18.10.2008 by Bochkanov Sergey Copyright 03.12.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const rea void polynomialbuildcheb2(const double a, const double b, const real_1d_arr
l_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const ay &y, const ae_int_t n, barycentricinterpolant &p);
double diffstep, lsfitstate &state); void polynomialbuildcheb2(const double a, const double b, const real_1d_arr
void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const rea ay &y, barycentricinterpolant &p);
l_1d_array &c, const double diffstep, lsfitstate &state);
/************************************************************************* /*************************************************************************
Weighted nonlinear least squares fitting using gradient only. Fast equidistant polynomial interpolation function with O(N) complexity
Nonlinear task min(F(c)) is solved, where
F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^
2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* w is an N-dimensional vector of weight coefficients,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]) and its gradient.
INPUT PARAMETERS: INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point) A - left boundary of [A,B]
Y - array[0..N-1], function values. B - right boundary of [A,B]
W - weights, array[0..N-1] F - function values, array[0..N-1]
C - array[0..K-1], initial approximation to the solution, N - number of points on equidistant grid, N>=1
N - number of points, N>1 for N=1 a constant model is constructed.
M - dimension of space T - position where P(x) is calculated
K - number of parameters being fitted
CheapFG - boolean flag, which is:
* True if both function and gradient calculation complexit
y
are less than O(M^2). An improved algorithm can
be used which corresponds to FGJ scheme from
MINLM unit.
* False otherwise.
Standard Jacibian-bases Levenberg-Marquardt algo
will be used (FJ scheme).
OUTPUT PARAMETERS: RESULT
State - structure which stores algorithm state value of the Lagrange interpolant at T
See also: IMPORTANT
LSFitResults this function provides fast interface which is not overflow-safe
LSFitCreateFG (fitting without weights) nor it is very precise.
LSFitCreateWFGH (fitting using Hessian) the best option is to use PolynomialBuildEqDist()/BarycentricCalc()
LSFitCreateFGH (fitting using Hessian, without weights) subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB -- -- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitcreatewfg(const real_2d_array &x, const real_1d_array &y, const r double polynomialcalceqdist(const double a, const double b, const real_1d_a
eal_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m rray &f, const ae_int_t n, const double t);
, const ae_int_t k, const bool cheapfg, lsfitstate &state); double polynomialcalceqdist(const double a, const double b, const real_1d_a
void lsfitcreatewfg(const real_2d_array &x, const real_1d_array &y, const r rray &f, const double t);
eal_1d_array &w, const real_1d_array &c, const bool cheapfg, lsfitstate &st
ate);
/************************************************************************* /*************************************************************************
Nonlinear least squares fitting using gradient only, without individual Fast polynomial interpolation function on Chebyshev points (first kind)
weights. with O(N) complexity.
Nonlinear task min(F(c)) is solved, where
F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]) and its gradient.
INPUT PARAMETERS: INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point) A - left boundary of [A,B]
Y - array[0..N-1], function values. B - right boundary of [A,B]
C - array[0..K-1], initial approximation to the solution, F - function values, array[0..N-1]
N - number of points, N>1 N - number of points on Chebyshev grid (first kind),
M - dimension of space X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n))
K - number of parameters being fitted for N=1 a constant model is constructed.
CheapFG - boolean flag, which is: T - position where P(x) is calculated
* True if both function and gradient calculation complexit
y
are less than O(M^2). An improved algorithm can
be used which corresponds to FGJ scheme from
MINLM unit.
* False otherwise.
Standard Jacibian-bases Levenberg-Marquardt algo
will be used (FJ scheme).
OUTPUT PARAMETERS: RESULT
State - structure which stores algorithm state value of the Lagrange interpolant at T
IMPORTANT
this function provides fast interface which is not overflow-safe
nor it is very precise.
the best option is to use PolIntBuildCheb1()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB -- -- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitcreatefg(const real_2d_array &x, const real_1d_array &y, const re double polynomialcalccheb1(const double a, const double b, const real_1d_ar
al_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const ray &f, const ae_int_t n, const double t);
bool cheapfg, lsfitstate &state); double polynomialcalccheb1(const double a, const double b, const real_1d_ar
void lsfitcreatefg(const real_2d_array &x, const real_1d_array &y, const re ray &f, const double t);
al_1d_array &c, const bool cheapfg, lsfitstate &state);
/************************************************************************* /*************************************************************************
Weighted nonlinear least squares fitting using gradient/Hessian. Fast polynomial interpolation function on Chebyshev points (second kind)
with O(N) complexity.
Nonlinear task min(F(c)) is solved, where INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
F - function values, array[0..N-1]
N - number of points on Chebyshev grid (second kind),
X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1))
for N=1 a constant model is constructed.
T - position where P(x) is calculated
F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^ RESULT
2, value of the Lagrange interpolant at T
* N is a number of points, IMPORTANT
* M is a dimension of a space points belong to, this function provides fast interface which is not overflow-safe
* K is a dimension of a space of parameters being fitted, nor it is very precise.
* w is an N-dimensional vector of weight coefficients, the best option is to use PolIntBuildCheb2()/BarycentricCalc()
* x is a set of N points, each of them is an M-dimensional vector, subroutines unless you are pretty sure that your data will not result
* c is a K-dimensional vector of parameters being fitted in overflow.
This subroutine uses f(c,x[i]), its gradient and its Hessian. -- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
double polynomialcalccheb2(const double a, const double b, const real_1d_ar
ray &f, const ae_int_t n, const double t);
double polynomialcalccheb2(const double a, const double b, const real_1d_ar
ray &f, const double t);
/*************************************************************************
This subroutine builds linear spline interpolant
INPUT PARAMETERS: INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point) X - spline nodes, array[0..N-1]
Y - array[0..N-1], function values. Y - function values, array[0..N-1]
W - weights, array[0..N-1] N - points count (optional):
C - array[0..K-1], initial approximation to the solution, * N>=2
N - number of points, N>1 * if given, only first N points are used to build spline
M - dimension of space * if not given, automatically detected from X/Y sizes
K - number of parameters being fitted (len(X) must be equal to len(Y))
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
State - structure which stores algorithm state C - spline interpolant
-- ALGLIB -- ORDER OF POINTS
Copyright 17.08.2009 by Bochkanov Sergey
Subroutine automatically sorts points, so caller may pass unsorted array.
-- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitcreatewfgh(const real_2d_array &x, const real_1d_array &y, const void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, co
real_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t nst ae_int_t n, spline1dinterpolant &c);
m, const ae_int_t k, lsfitstate &state); void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, sp
void lsfitcreatewfgh(const real_2d_array &x, const real_1d_array &y, const line1dinterpolant &c);
real_1d_array &w, const real_1d_array &c, lsfitstate &state);
/************************************************************************* /*************************************************************************
Nonlinear least squares fitting using gradient/Hessian, without individial This subroutine builds cubic spline interpolant.
weights.
Nonlinear task min(F(c)) is solved, where
F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses f(c,x[i]), its gradient and its Hessian.
INPUT PARAMETERS: INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point) X - spline nodes, array[0..N-1].
Y - array[0..N-1], function values. Y - function values, array[0..N-1].
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1 OPTIONAL PARAMETERS:
M - dimension of space N - points count:
K - number of parameters being fitted * N>=2
* if given, only first N points are used to build splin
e
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
State - structure which stores algorithm state C - spline interpolant
-- ALGLIB -- ORDER OF POINTS
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const r
eal_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, lsfi
tstate &state);
void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const r
eal_1d_array &c, lsfitstate &state);
/************************************************************************* Subroutine automatically sorts points, so caller may pass unsorted array.
Stopping conditions for nonlinear least squares fitting.
INPUT PARAMETERS: SETTING BOUNDARY VALUES:
State - structure which stores algorithm state
EpsF - stopping criterion. Algorithm stops if
|F(k+1)-F(k)| <= EpsF*max{|F(k)|, |F(k+1)|, 1}
EpsX - stopping criterion. Algorithm stops if
|X(k+1)-X(k)| <= EpsX*(1+|X(k)|)
MaxIts - stopping criterion. Algorithm stops after MaxIts iterations
.
MaxIts=0 means no stopping criterion.
NOTE The BoundLType/BoundRType parameters can have the following values:
* -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
Passing EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
stopping criterion selection (according to the scheme used by MINLM unit).
-- ALGLIB -- Problems with periodic boundary conditions have Y[first_point]=Y[last_point
Copyright 17.08.2009 by Bochkanov Sergey ].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitsetcond(const lsfitstate &state, const double epsf, const double void spline1dbuildcubic(const real_1d_array &x, const real_1d_array &y, con
epsx, const ae_int_t maxits); st ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int
_t boundrtype, const double boundr, spline1dinterpolant &c);
void spline1dbuildcubic(const real_1d_array &x, const real_1d_array &y, spl
ine1dinterpolant &c);
/************************************************************************* /*************************************************************************
This function sets maximum step length This function solves following problem: given table y[] of function values
at nodes x[], it calculates and returns table of function derivatives d[]
(calculated at the same nodes x[]).
This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state X - spline nodes
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't Y - function values
want to limit step length.
Use this subroutine when you optimize target function which contains exp() OPTIONAL PARAMETERS:
or other fast growing functions, and optimization algorithm makes too N - points count:
large steps which leads to overflow. This function allows us to reject * N>=2
steps that are too large (and therefore expose us to the possible * if given, only first N points are used
overflow) without actually calculating function value at the x+stp*d. * if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
NOTE: non-zero StpMax leads to moderate performance degradation because OUTPUT PARAMETERS:
intermediate step of preconditioned L-BFGS optimization is incompatible D - derivative values at X[]
with limits on step size.
-- ALGLIB -- ORDER OF POINTS
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
void lsfitsetstpmax(const lsfitstate &state, const double stpmax);
/************************************************************************* Subroutine automatically sorts points, so caller may pass unsorted array.
This function turns on/off reporting. Derivative values are correctly reordered on return, so D[I] is always
equal to S'(X[I]) independently of points order.
INPUT PARAMETERS: SETTING BOUNDARY VALUES:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
When reports are needed, State.C (current parameters) and State.F (current The BoundLType/BoundRType parameters can have the following values:
value of fitting function) are reported. * -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
-- ALGLIB -- PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Copyright 15.08.2010 by Bochkanov Sergey
*************************************************************************/
void lsfitsetxrep(const lsfitstate &state, const bool needxrep);
/************************************************************************* Problems with periodic boundary conditions have Y[first_point]=Y[last_point
This function provides reverse communication interface ].
Reverse communication interface is not documented or recommended to use. However, this subroutine doesn't require you to specify equal values for
See below for functions which provide better documented API the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
bool lsfititeration(const lsfitstate &state); void spline1dgriddiffcubic(const real_1d_array &x, const real_1d_array &y,
const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_
int_t boundrtype, const double boundr, real_1d_array &d);
void spline1dgriddiffcubic(const real_1d_array &x, const real_1d_array &y,
real_1d_array &d);
/************************************************************************* /*************************************************************************
This family of functions is used to launcn iterations of nonlinear fitter This function solves following problem: given table y[] of function values
at nodes x[], it calculates and returns tables of first and second
These functions accept following parameters: function derivatives d1[] and d2[] (calculated at the same nodes x[]).
state - algorithm state
func - callback which calculates function (or merit function)
value func at given point x
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
hess - callback which calculates function (or merit function)
value func, gradient grad and Hessian hess at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES:
1. this algorithm is somewhat unusual because it works with parameterized This function yields same result as Spline1DBuildCubic() call followed by
function f(C,X), where X is a function argument (we have many points sequence of Spline1DDiff() calls, but it can be several times faster when
which are characterized by different argument values), and C is a called for ordered X[] and X2[].
parameter to fit.
For example, if we want to do linear fit by f(c0,c1,x) = c0*x+c1, then INPUT PARAMETERS:
x will be argument, and {c0,c1} will be parameters. X - spline nodes
Y - function values
It is important to understand that this algorithm finds minimum in the OPTIONAL PARAMETERS:
space of function PARAMETERS (not arguments), so it needs derivatives N - points count:
of f() with respect to C, not X. * N>=2
* if given, only first N points are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
In the example above it will need f=c0*x+c1 and {df/dc0,df/dc1} = {x,1} OUTPUT PARAMETERS:
instead of {df/dx} = {c0}. D1 - S' values at X[]
D2 - S'' values at X[]
2. Callback functions accept C as the first parameter, and X as the second ORDER OF POINTS
3. If state was created with LSFitCreateFG(), algorithm needs just Subroutine automatically sorts points, so caller may pass unsorted array.
function and its gradient, but if state was created with Derivative values are correctly reordered on return, so D[I] is always
LSFitCreateFGH(), algorithm will need function, gradient and Hessian. equal to S'(X[I]) independently of points order.
According to the said above, there ase several versions of this SETTING BOUNDARY VALUES:
function, which accept different sets of callbacks.
This flexibility opens way to subtle errors - you may create state with The BoundLType/BoundRType parameters can have the following values:
LSFitCreateFGH() (optimization using Hessian), but call function which * -1, which corresonds to the periodic (cyclic) boundary conditions.
does not accept Hessian. So when algorithm will request Hessian, there In this case:
will be no callback to call. In this case exception will be thrown. * both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
Be careful to avoid such errors because there is no way to find them at PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
compile time - you can see them at runtime only.
-- ALGLIB -- Problems with periodic boundary conditions have Y[first_point]=Y[last_point
Copyright 17.08.2009 by Bochkanov Sergey ].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitfit(lsfitstate &state, void spline1dgriddiff2cubic(const real_1d_array &x, const real_1d_array &y,
void (*func)(const real_1d_array &c, const real_1d_array &x, double &fu const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae
nc, void *ptr), _int_t boundrtype, const double boundr, real_1d_array &d1, real_1d_array &d
void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL, 2);
void *ptr = NULL); void spline1dgriddiff2cubic(const real_1d_array &x, const real_1d_array &y,
void lsfitfit(lsfitstate &state, real_1d_array &d1, real_1d_array &d2);
void (*func)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, void *ptr),
void (*grad)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, real_1d_array &grad, void *ptr),
void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL,
void *ptr = NULL);
void lsfitfit(lsfitstate &state,
void (*func)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, void *ptr),
void (*grad)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, real_1d_array &grad, void *ptr),
void (*hess)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, real_1d_array &grad, real_2d_array &hess, void *ptr),
void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL,
void *ptr = NULL);
/************************************************************************* /*************************************************************************
Nonlinear least squares fitting results. This function solves following problem: given table y[] of function values
at old nodes x[] and new nodes x2[], it calculates and returns table of
function values y2[] (calculated at x2[]).
Called after return from LSFitFit(). This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS: INPUT PARAMETERS:
State - algorithm state X - old spline nodes
Y - function values
X2 - new spline nodes
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points from X/Y are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
N2 - new points count:
* N2>=2
* if given, only first N2 points from X2 are used
* if not given, automatically detected from X2 size
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Info - completetion code: F2 - function values at X2[]
* 1 relative function improvement is no more than
EpsF.
* 2 relative step is no more than EpsX.
* 4 gradient norm is no more than EpsG
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible
C - array[0..K-1], solution
Rep - optimization report. Following fields are set:
* Rep.TerminationType completetion code:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB -- ORDER OF POINTS
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
void lsfitresults(const lsfitstate &state, ae_int_t &info, real_1d_array &c
, lsfitreport &rep);
/************************************************************************* Subroutine automatically sorts points, so caller may pass unsorted array.
Rational interpolation using barycentric formula Function values are correctly reordered on return, so F2[I] is always
equal to S(X2[I]) independently of points order.
F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i])) SETTING BOUNDARY VALUES:
Input parameters: The BoundLType/BoundRType parameters can have the following values:
B - barycentric interpolant built with one of model building * -1, which corresonds to the periodic (cyclic) boundary conditions.
subroutines. In this case:
T - interpolation point * both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
Result: PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
barycentric interpolant F(t)
-- ALGLIB -- Problems with periodic boundary conditions have Y[first_point]=Y[last_point
Copyright 17.08.2009 by Bochkanov Sergey ].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
double barycentriccalc(const barycentricinterpolant &b, const double t); void spline1dconvcubic(const real_1d_array &x, const real_1d_array &y, cons
t ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_
t boundrtype, const double boundr, const real_1d_array &x2, const ae_int_t
n2, real_1d_array &y2);
void spline1dconvcubic(const real_1d_array &x, const real_1d_array &y, cons
t real_1d_array &x2, real_1d_array &y2);
/************************************************************************* /*************************************************************************
Differentiation of barycentric interpolant: first derivative. This function solves following problem: given table y[] of function values
at old nodes x[] and new nodes x2[], it calculates and returns table of
function values y2[] and derivatives d2[] (calculated at x2[]).
Algorithm used in this subroutine is very robust and should not fail until This function yields same result as Spline1DBuildCubic() call followed by
provided with values too close to MaxRealNumber (usually MaxRealNumber/N sequence of Spline1DDiff() calls, but it can be several times faster when
or greater will overflow). called for ordered X[] and X2[].
INPUT PARAMETERS: INPUT PARAMETERS:
B - barycentric interpolant built with one of model building X - old spline nodes
subroutines. Y - function values
T - interpolation point X2 - new spline nodes
OUTPUT PARAMETERS:
F - barycentric interpolant at T
DF - first derivative
NOTE
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
void barycentricdiff1(const barycentricinterpolant &b, const double t, doub
le &f, double &df);
/*************************************************************************
Differentiation of barycentric interpolant: first/second derivatives.
INPUT PARAMETERS: OPTIONAL PARAMETERS:
B - barycentric interpolant built with one of model building N - points count:
subroutines. * N>=2
T - interpolation point * if given, only first N points from X/Y are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
N2 - new points count:
* N2>=2
* if given, only first N2 points from X2 are used
* if not given, automatically detected from X2 size
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
F - barycentric interpolant at T F2 - function values at X2[]
DF - first derivative D2 - first derivatives at X2[]
D2F - second derivative
NOTE: this algorithm may fail due to overflow/underflor if used on data ORDER OF POINTS
whose values are close to MaxRealNumber or MinRealNumber. Use more robust
BarycentricDiff1() subroutine in such cases.
-- ALGLIB -- Subroutine automatically sorts points, so caller may pass unsorted array.
Copyright 17.08.2009 by Bochkanov Sergey Function values are correctly reordered on return, so F2[I] is always
*************************************************************************/ equal to S(X2[I]) independently of points order.
void barycentricdiff2(const barycentricinterpolant &b, const double t, doub
le &f, double &df, double &d2f);
/************************************************************************* SETTING BOUNDARY VALUES:
This subroutine performs linear transformation of the argument.
INPUT PARAMETERS: The BoundLType/BoundRType parameters can have the following values:
B - rational interpolant in barycentric form * -1, which corresonds to the periodic (cyclic) boundary conditions.
CA, CB - transformation coefficients: x = CA*t + CB In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
OUTPUT PARAMETERS: PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
B - transformed interpolant with X replaced by T
Problems with periodic boundary conditions have Y[first_point]=Y[last_point
].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 19.08.2009 by Bochkanov Sergey Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void barycentriclintransx(const barycentricinterpolant &b, const double ca, void spline1dconvdiffcubic(const real_1d_array &x, const real_1d_array &y,
const double cb); const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_
int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_in
t_t n2, real_1d_array &y2, real_1d_array &d2);
void spline1dconvdiffcubic(const real_1d_array &x, const real_1d_array &y,
const real_1d_array &x2, real_1d_array &y2, real_1d_array &d2);
/************************************************************************* /*************************************************************************
This subroutine performs linear transformation of the barycentric This function solves following problem: given table y[] of function values
interpolant. at old nodes x[] and new nodes x2[], it calculates and returns table of
function values y2[], first and second derivatives d2[] and dd2[]
(calculated at x2[]).
This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS: INPUT PARAMETERS:
B - rational interpolant in barycentric form X - old spline nodes
CA, CB - transformation coefficients: B2(x) = CA*B(x) + CB Y - function values
X2 - new spline nodes
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points from X/Y are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
N2 - new points count:
* N2>=2
* if given, only first N2 points from X2 are used
* if not given, automatically detected from X2 size
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
B - transformed interpolant F2 - function values at X2[]
D2 - first derivatives at X2[]
DD2 - second derivatives at X2[]
-- ALGLIB PROJECT -- ORDER OF POINTS
Copyright 19.08.2009 by Bochkanov Sergey
*************************************************************************/
void barycentriclintransy(const barycentricinterpolant &b, const double ca,
const double cb);
/************************************************************************* Subroutine automatically sorts points, so caller may pass unsorted array.
Extracts X/Y/W arrays from rational interpolant Function values are correctly reordered on return, so F2[I] is always
equal to S(X2[I]) independently of points order.
INPUT PARAMETERS: SETTING BOUNDARY VALUES:
B - barycentric interpolant
OUTPUT PARAMETERS: The BoundLType/BoundRType parameters can have the following values:
N - nodes count, N>0 * -1, which corresonds to the periodic (cyclic) boundary conditions.
X - interpolation nodes, array[0..N-1] In this case:
F - function values, array[0..N-1] * both BoundLType and BoundRType must be equal to -1.
W - barycentric weights, array[0..N-1] * BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
-- ALGLIB -- PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Copyright 17.08.2009 by Bochkanov Sergey
Problems with periodic boundary conditions have Y[first_point]=Y[last_point
].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void barycentricunpack(const barycentricinterpolant &b, ae_int_t &n, real_1 void spline1dconvdiff2cubic(const real_1d_array &x, const real_1d_array &y,
d_array &x, real_1d_array &y, real_1d_array &w); const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae
_int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_i
nt_t n2, real_1d_array &y2, real_1d_array &d2, real_1d_array &dd2);
void spline1dconvdiff2cubic(const real_1d_array &x, const real_1d_array &y,
const real_1d_array &x2, real_1d_array &y2, real_1d_array &d2, real_1d_arr
ay &dd2);
/************************************************************************* /*************************************************************************
Rational interpolant from X/Y/W arrays This subroutine builds Catmull-Rom spline interpolant.
F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i]))
INPUT PARAMETERS: INPUT PARAMETERS:
X - interpolation nodes, array[0..N-1] X - spline nodes, array[0..N-1].
F - function values, array[0..N-1] Y - function values, array[0..N-1].
W - barycentric weights, array[0..N-1]
N - nodes count, N>0 OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points are used to build splin
e
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundType - boundary condition type:
* -1 for periodic boundary condition
* 0 for parabolically terminated spline (default)
Tension - tension parameter:
* tension=0 corresponds to classic Catmull-Rom spline
(default)
* 0<tension<1 corresponds to more general form - cardin
al spline
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
B - barycentric interpolant built from (X, Y, W) C - spline interpolant
-- ALGLIB -- ORDER OF POINTS
Copyright 17.08.2009 by Bochkanov Sergey
Subroutine automatically sorts points, so caller may pass unsorted array.
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point
].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void barycentricbuildxyw(const real_1d_array &x, const real_1d_array &y, co void spline1dbuildcatmullrom(const real_1d_array &x, const real_1d_array &y
nst real_1d_array &w, const ae_int_t n, barycentricinterpolant &b); , const ae_int_t n, const ae_int_t boundtype, const double tension, spline1
dinterpolant &c);
void spline1dbuildcatmullrom(const real_1d_array &x, const real_1d_array &y
, spline1dinterpolant &c);
/************************************************************************* /*************************************************************************
Rational interpolant without poles This subroutine builds Hermite spline interpolant.
The subroutine constructs the rational interpolating function without real INPUT PARAMETERS:
poles (see 'Barycentric rational interpolation with no poles and high X - spline nodes, array[0..N-1]
rates of approximation', Michael S. Floater. and Kai Hormann, for more Y - function values, array[0..N-1]
information on this subject). D - derivatives, array[0..N-1]
N - points count (optional):
* N>=2
* if given, only first N points are used to build splin
e
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
Input parameters: OUTPUT PARAMETERS:
X - interpolation nodes, array[0..N-1]. C - spline interpolant.
Y - function values, array[0..N-1].
N - number of nodes, N>0.
D - order of the interpolation scheme, 0 <= D <= N-1.
D<0 will cause an error.
D>=N it will be replaced with D=N-1.
if you don't know what D to choose, use small value about 3-5.
Output parameters: ORDER OF POINTS
B - barycentric interpolant.
Note: Subroutine automatically sorts points, so caller may pass unsorted array.
this algorithm always succeeds and calculates the weights with close
to machine precision.
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 17.06.2007 by Bochkanov Sergey Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void barycentricbuildfloaterhormann(const real_1d_array &x, const real_1d_a void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, c
rray &y, const ae_int_t n, const ae_int_t d, barycentricinterpolant &b); onst real_1d_array &d, const ae_int_t n, spline1dinterpolant &c);
void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, c
onst real_1d_array &d, spline1dinterpolant &c);
/************************************************************************* /*************************************************************************
Conversion from barycentric representation to Chebyshev basis. This subroutine builds Akima spline interpolant
This function has O(N^2) complexity.
INPUT PARAMETERS: INPUT PARAMETERS:
P - polynomial in barycentric form X - spline nodes, array[0..N-1]
A,B - base interval for Chebyshev polynomials (see below) Y - function values, array[0..N-1]
A<>B N - points count (optional):
* N>=5
* if given, only first N points are used to build splin
e
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
OUTPUT PARAMETERS OUTPUT PARAMETERS:
T - coefficients of Chebyshev representation; C - spline interpolant
P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N-1 },
where Ti - I-th Chebyshev polynomial.
NOTES: ORDER OF POINTS
barycentric interpolant passed as P may be either polynomial obtained
from polynomial interpolation/ fitting or rational function which is
NOT polynomial. We can't distinguish between these two cases, and this
algorithm just tries to work assuming that P IS a polynomial. If not,
algorithm will return results, but they won't have any meaning.
-- ALGLIB -- Subroutine automatically sorts points, so caller may pass unsorted array.
Copyright 30.09.2010 by Bochkanov Sergey
-- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void polynomialbar2cheb(const barycentricinterpolant &p, const double a, co void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, con
nst double b, real_1d_array &t); st ae_int_t n, spline1dinterpolant &c);
void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, spl
ine1dinterpolant &c);
/************************************************************************* /*************************************************************************
Conversion from Chebyshev basis to barycentric representation. This subroutine calculates the value of the spline at the given point X.
This function has O(N^2) complexity.
INPUT PARAMETERS: INPUT PARAMETERS:
T - coefficients of Chebyshev representation; C - spline interpolant
P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N }, X - point
where Ti - I-th Chebyshev polynomial.
N - number of coefficients:
* if given, only leading N elements of T are used
* if not given, automatically determined from size of T
A,B - base interval for Chebyshev polynomials (see above)
A<B
OUTPUT PARAMETERS Result:
P - polynomial in barycentric form S(x)
-- ALGLIB -- -- ALGLIB PROJECT --
Copyright 30.09.2010 by Bochkanov Sergey Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void polynomialcheb2bar(const real_1d_array &t, const ae_int_t n, const dou double spline1dcalc(const spline1dinterpolant &c, const double x);
ble a, const double b, barycentricinterpolant &p);
void polynomialcheb2bar(const real_1d_array &t, const double a, const doubl
e b, barycentricinterpolant &p);
/************************************************************************* /*************************************************************************
Conversion from barycentric representation to power basis. This subroutine differentiates the spline.
This function has O(N^2) complexity.
INPUT PARAMETERS: INPUT PARAMETERS:
P - polynomial in barycentric form C - spline interpolant.
C - offset (see below); 0.0 is used as default value. X - point
S - scale (see below); 1.0 is used as default value. S<>0.
OUTPUT PARAMETERS Result:
A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 } S - S(x)
N - number of coefficients (polynomial degree plus 1) DS - S'(x)
D2S - S''(x)
NOTES: -- ALGLIB PROJECT --
1. this function accepts offset and scale, which can be set to improve Copyright 24.06.2007 by Bochkanov Sergey
numerical properties of polynomial. For example, if P was obtained as *************************************************************************/
result of interpolation on [-1,+1], you can set C=0 and S=1 and void spline1ddiff(const spline1dinterpolant &c, const double x, double &s,
represent P as sum of 1, x, x^2, x^3 and so on. In most cases you it double &ds, double &d2s);
is exactly what you need.
However, if your interpolation model was built on [999,1001], you will /*************************************************************************
see significant growth of numerical errors when using {1, x, x^2, x^3} This subroutine unpacks the spline into the coefficients table.
as basis. Representing P as sum of 1, (x-1000), (x-1000)^2, (x-1000)^3
will be better option. Such representation can be obtained by using
1000.0 as offset C and 1.0 as scale S.
2. power basis is ill-conditioned and tricks described above can't solve INPUT PARAMETERS:
this problem completely. This function will return coefficients in C - spline interpolant.
any case, but for N>8 they will become unreliable. However, N's X - point
less than 5 are pretty safe.
3. barycentric interpolant passed as P may be either polynomial obtained Result:
from polynomial interpolation/ fitting or rational function which is Tbl - coefficients table, unpacked format, array[0..N-2, 0..5].
NOT polynomial. We can't distinguish between these two cases, and this For I = 0...N-2:
algorithm just tries to work assuming that P IS a polynomial. If not, Tbl[I,0] = X[i]
algorithm will return results, but they won't have any meaning. Tbl[I,1] = X[i+1]
Tbl[I,2] = C0
Tbl[I,3] = C1
Tbl[I,4] = C2
Tbl[I,5] = C3
On [x[i], x[i+1]] spline is equals to:
S(x) = C0 + C1*t + C2*t^2 + C3*t^3
t = x-x[i]
-- ALGLIB -- -- ALGLIB PROJECT --
Copyright 30.09.2010 by Bochkanov Sergey Copyright 29.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void polynomialbar2pow(const barycentricinterpolant &p, const double c, con void spline1dunpack(const spline1dinterpolant &c, ae_int_t &n, real_2d_arra
st double s, real_1d_array &a); y &tbl);
void polynomialbar2pow(const barycentricinterpolant &p, real_1d_array &a);
/************************************************************************* /*************************************************************************
Conversion from power basis to barycentric representation. This subroutine performs linear transformation of the spline argument.
This function has O(N^2) complexity.
INPUT PARAMETERS: INPUT PARAMETERS:
A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 } C - spline interpolant.
N - number of coefficients (polynomial degree plus 1) A, B- transformation coefficients: x = A*t + B
* if given, only leading N elements of A are used Result:
* if not given, automatically determined from size of A C - transformed spline
C - offset (see below); 0.0 is used as default value.
S - scale (see below); 1.0 is used as default value. S<>0.
OUTPUT PARAMETERS -- ALGLIB PROJECT --
P - polynomial in barycentric form Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/
NOTES: void spline1dlintransx(const spline1dinterpolant &c, const double a, const
1. this function accepts offset and scale, which can be set to improve double b);
numerical properties of polynomial. For example, if you interpolate on
[-1,+1], you can set C=0 and S=1 and convert from sum of 1, x, x^2,
x^3 and so on. In most cases you it is exactly what you need.
However, if your interpolation model was built on [999,1001], you will
see significant growth of numerical errors when using {1, x, x^2, x^3}
as input basis. Converting from sum of 1, (x-1000), (x-1000)^2,
(x-1000)^3 will be better option (you have to specify 1000.0 as offset
C and 1.0 as scale S).
2. power basis is ill-conditioned and tricks described above can't solve
this problem completely. This function will return barycentric model
in any case, but for N>8 accuracy well degrade. However, N's less than
5 are pretty safe.
-- ALGLIB --
Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/
void polynomialpow2bar(const real_1d_array &a, const ae_int_t n, const doub
le c, const double s, barycentricinterpolant &p);
void polynomialpow2bar(const real_1d_array &a, barycentricinterpolant &p);
/************************************************************************* /*************************************************************************
Lagrange intepolant: generation of the model on the general grid. This subroutine performs linear transformation of the spline.
This function has O(N^2) complexity.
INPUT PARAMETERS: INPUT PARAMETERS:
X - abscissas, array[0..N-1] C - spline interpolant.
Y - function values, array[0..N-1] A, B- transformation coefficients: S2(x) = A*S(x) + B
N - number of points, N>=1 Result:
C - transformed spline
OUTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB -- -- ALGLIB PROJECT --
Copyright 02.12.2009 by Bochkanov Sergey Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void polynomialbuild(const real_1d_array &x, const real_1d_array &y, const void spline1dlintransy(const spline1dinterpolant &c, const double a, const
ae_int_t n, barycentricinterpolant &p); double b);
void polynomialbuild(const real_1d_array &x, const real_1d_array &y, baryce
ntricinterpolant &p);
/************************************************************************* /*************************************************************************
Lagrange intepolant: generation of the model on equidistant grid. This subroutine integrates the spline.
This function has O(N) complexity.
INPUT PARAMETERS: INPUT PARAMETERS:
A - left boundary of [A,B] C - spline interpolant.
B - right boundary of [A,B] X - right bound of the integration interval [a, x],
Y - function values at the nodes, array[0..N-1] here 'a' denotes min(x[])
N - number of points, N>=1 Result:
for N=1 a constant model is constructed. integral(S(t)dt,a,x)
OUTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB -- -- ALGLIB PROJECT --
Copyright 03.12.2009 by Bochkanov Sergey Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void polynomialbuildeqdist(const double a, const double b, const real_1d_ar double spline1dintegrate(const spline1dinterpolant &c, const double x);
ray &y, const ae_int_t n, barycentricinterpolant &p);
void polynomialbuildeqdist(const double a, const double b, const real_1d_ar
ray &y, barycentricinterpolant &p);
/************************************************************************* /*************************************************************************
Lagrange intepolant on Chebyshev grid (first kind). Fitting by polynomials in barycentric form. This function provides simple
This function has O(N) complexity. unterface for unconstrained unweighted fitting. See PolynomialFitWC() if
you need constrained fitting.
Task is linear, so linear least squares solver is used. Complexity of this
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO:
PolynomialFitWC()
INPUT PARAMETERS: INPUT PARAMETERS:
A - left boundary of [A,B] X - points, array[0..N-1].
B - right boundary of [A,B] Y - function values, array[0..N-1].
Y - function values at the nodes, array[0..N-1], N - number of points, N>0
Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n))) * if given, only leading N elements of X/Y are used
N - number of points, N>=1 * if not given, automatically determined from sizes of X/Y
for N=1 a constant model is constructed. M - number of basis functions (= polynomial_degree + 1), M>=1
OUTPUT PARAMETERS OUTPUT PARAMETERS:
P - barycentric model which represents Lagrange interpolant Info- same format as in LSFitLinearW() subroutine:
(see ratint unit info and BarycentricCalc() description for * Info>0 task is solved
more information). * Info<=0 an error occured:
-4 means inconvergence of internal SVD
P - interpolant in barycentric form.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB -- NOTES:
Copyright 03.12.2009 by Bochkanov Sergey you can convert P from barycentric form to the power or Chebyshev
basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from
POLINT subpackage.
-- ALGLIB PROJECT --
Copyright 10.12.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void polynomialbuildcheb1(const double a, const double b, const real_1d_arr void polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae
ay &y, const ae_int_t n, barycentricinterpolant &p); _int_t n, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, poly
void polynomialbuildcheb1(const double a, const double b, const real_1d_arr nomialfitreport &rep);
ay &y, barycentricinterpolant &p); void polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae
_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &r
ep);
/************************************************************************* /*************************************************************************
Lagrange intepolant on Chebyshev grid (second kind). Weighted fitting by polynomials in barycentric form, with constraints on
This function has O(N) complexity. function values or first derivatives.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
Y - function values at the nodes, array[0..N-1],
Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1)))
N - number of points, N>=1
for N=1 a constant model is constructed.
OUTPUT PARAMETERS Small regularizing term is used when solving constrained tasks (to improve
P - barycentric model which represents Lagrange interpolant stability).
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB -- Task is linear, so linear least squares solver is used. Complexity of this
Copyright 03.12.2009 by Bochkanov Sergey computational scheme is O(N*M^2), mostly dominated by least squares solver
*************************************************************************/
void polynomialbuildcheb2(const double a, const double b, const real_1d_arr
ay &y, const ae_int_t n, barycentricinterpolant &p);
void polynomialbuildcheb2(const double a, const double b, const real_1d_arr
ay &y, barycentricinterpolant &p);
/************************************************************************* SEE ALSO:
Fast equidistant polynomial interpolation function with O(N) complexity PolynomialFit()
INPUT PARAMETERS: INPUT PARAMETERS:
A - left boundary of [A,B] X - points, array[0..N-1].
B - right boundary of [A,B] Y - function values, array[0..N-1].
F - function values, array[0..N-1] W - weights, array[0..N-1]
N - number of points on equidistant grid, N>=1 Each summand in square sum of approximation deviations from
for N=1 a constant model is constructed. given values is multiplied by the square of corresponding
T - position where P(x) is calculated weight. Fill it by 1's if you don't want to solve weighted
task.
RESULT N - number of points, N>0.
value of the Lagrange interpolant at T * if given, only leading N elements of X/Y/W are used
* if not given, automatically determined from sizes of X/Y/W
XC - points where polynomial values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that P(XC[i])=YC[i]
* DC[i]=1 means that P'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints, 0<=K<M.
K=0 means no constraints (XC/YC/DC are not used in such cases)
M - number of basis functions (= polynomial_degree + 1), M>=1
IMPORTANT OUTPUT PARAMETERS:
this function provides fast interface which is not overflow-safe Info- same format as in LSFitLinearW() subroutine:
nor it is very precise. * Info>0 task is solved
the best option is to use PolynomialBuildEqDist()/BarycentricCalc() * Info<=0 an error occured:
subroutines unless you are pretty sure that your data will not result -4 means inconvergence of internal SVD
in overflow. -3 means inconsistent constraints
P - interpolant in barycentric form.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB -- IMPORTANT:
Copyright 02.12.2009 by Bochkanov Sergey this subroitine doesn't calculate task's condition number for K<>0.
*************************************************************************/
double polynomialcalceqdist(const double a, const double b, const real_1d_a
rray &f, const ae_int_t n, const double t);
double polynomialcalceqdist(const double a, const double b, const real_1d_a
rray &f, const double t);
/************************************************************************* NOTES:
Fast polynomial interpolation function on Chebyshev points (first kind) you can convert P from barycentric form to the power or Chebyshev
with O(N) complexity. basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from
POLINT subpackage.
INPUT PARAMETERS: SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
A - left boundary of [A,B]
B - right boundary of [A,B]
F - function values, array[0..N-1]
N - number of points on Chebyshev grid (first kind),
X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n))
for N=1 a constant model is constructed.
T - position where P(x) is calculated
RESULT Setting constraints can lead to undesired results, like ill-conditioned
value of the Lagrange interpolant at T behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* even simple constraints can be inconsistent, see Wikipedia article on
this subject: http://en.wikipedia.org/wiki/Birkhoff_interpolation
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints is NOT GUARANTEED.
* in the one special cases, however, we can guarantee consistency. This
case is: M>1 and constraints on the function values (NOT DERIVATIVES)
IMPORTANT Our final recommendation is to use constraints WHEN AND ONLY when you
this function provides fast interface which is not overflow-safe can't solve your task without them. Anything beyond special cases given
nor it is very precise. above is not guaranteed and may result in inconsistency.
the best option is to use PolIntBuildCheb1()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB -- -- ALGLIB PROJECT --
Copyright 02.12.2009 by Bochkanov Sergey Copyright 10.12.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
double polynomialcalccheb1(const double a, const double b, const real_1d_ar void polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const
ray &f, const ae_int_t n, const double t); real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_
double polynomialcalccheb1(const double a, const double b, const real_1d_ar array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m,
ray &f, const double t); ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
void polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const
real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, const i
nteger_1d_array &dc, const ae_int_t m, ae_int_t &info, barycentricinterpola
nt &p, polynomialfitreport &rep);
/************************************************************************* /*************************************************************************
Fast polynomial interpolation function on Chebyshev points (second kind) Weghted rational least squares fitting using Floater-Hormann rational
with O(N) complexity. functions with optimal D chosen from [0,9], with constraints and
individual weights.
INPUT PARAMETERS: Equidistant grid with M node on [min(x),max(x)] is used to build basis
A - left boundary of [A,B] functions. Different values of D are tried, optimal D (least WEIGHTED root
B - right boundary of [A,B] mean square error) is chosen. Task is linear, so linear least squares
F - function values, array[0..N-1] solver is used. Complexity of this computational scheme is O(N*M^2)
N - number of points on Chebyshev grid (second kind), (mostly dominated by the least squares solver).
X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1))
for N=1 a constant model is constructed.
T - position where P(x) is calculated
RESULT
value of the Lagrange interpolant at T
IMPORTANT
this function provides fast interface which is not overflow-safe
nor it is very precise.
the best option is to use PolIntBuildCheb2()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
double polynomialcalccheb2(const double a, const double b, const real_1d_ar
ray &f, const ae_int_t n, const double t);
double polynomialcalccheb2(const double a, const double b, const real_1d_ar
ray &f, const double t);
/************************************************************************* SEE ALSO
This subroutine builds linear spline interpolant * BarycentricFitFloaterHormann(), "lightweight" fitting without invididual
weights and constraints.
INPUT PARAMETERS: INPUT PARAMETERS:
X - spline nodes, array[0..N-1] X - points, array[0..N-1].
Y - function values, array[0..N-1] Y - function values, array[0..N-1].
N - points count (optional): W - weights, array[0..N-1]
* N>=2 Each summand in square sum of approximation deviations from
* if given, only first N points are used to build spline given values is multiplied by the square of corresponding
* if not given, automatically detected from X/Y sizes weight. Fill it by 1's if you don't want to solve weighted
(len(X) must be equal to len(Y)) task.
N - number of points, N>0.
XC - points where function values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints, 0<=K<M.
K=0 means no constraints (XC/YC/DC are not used in such cases)
M - number of basis functions ( = number_of_nodes), M>=2.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
C - spline interpolant Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
-1 means another errors in parameters passed
(N<=0, for example)
B - barycentric interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* DBest best value of the D parameter
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
ORDER OF POINTS IMPORTANT:
this subroutine doesn't calculate task's condition number for K<>0.
Subroutine automatically sorts points, so caller may pass unsorted array. SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained barycentric interpolants:
* excessive constraints can be inconsistent. Floater-Hormann basis
functions aren't as flexible as splines (although they are very smooth).
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints IS NOT GUARANTEED.
* in the several special cases, however, we CAN guarantee consistency.
* one of this cases is constraints on the function VALUES at the interval
boundaries. Note that consustency of the constraints on the function
DERIVATIVES is NOT guaranteed (you can use in such cases cubic splines
which are more flexible).
* another special case is ONE constraint on the function value (OR, but
not AND, derivative) anywhere in the interval
Our final recommendation is to use constraints WHEN AND ONLY WHEN you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, co void barycentricfitfloaterhormannwc(const real_1d_array &x, const real_1d_a
nst ae_int_t n, spline1dinterpolant &c); rray &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc,
void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, sp const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, con
line1dinterpolant &c); st ae_int_t m, ae_int_t &info, barycentricinterpolant &b, barycentricfitrep
ort &rep);
/************************************************************************* /*************************************************************************
This subroutine builds cubic spline interpolant. Rational least squares fitting using Floater-Hormann rational functions
with optimal D chosen from [0,9].
INPUT PARAMETERS: Equidistant grid with M node on [min(x),max(x)] is used to build basis
X - spline nodes, array[0..N-1]. functions. Different values of D are tried, optimal D (least root mean
Y - function values, array[0..N-1]. square error) is chosen. Task is linear, so linear least squares solver
is used. Complexity of this computational scheme is O(N*M^2) (mostly
dominated by the least squares solver).
OPTIONAL PARAMETERS: INPUT PARAMETERS:
N - points count: X - points, array[0..N-1].
* N>=2 Y - function values, array[0..N-1].
* if given, only first N points are used to build splin N - number of points, N>0.
e M - number of basis functions ( = number_of_nodes), M>=2.
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
C - spline interpolant Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
ORDER OF POINTS * Info<=0 an error occured:
-4 means inconvergence of internal SVD
Subroutine automatically sorts points, so caller may pass unsorted array. -3 means inconsistent constraints
B - barycentric interpolant.
SETTING BOUNDARY VALUES: Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
The BoundLType/BoundRType parameters can have the following values: * DBest best value of the D parameter
* -1, which corresonds to the periodic (cyclic) boundary conditions. * RMSError rms error on the (X,Y).
In this case: * AvgError average error on the (X,Y).
* both BoundLType and BoundRType must be equal to -1. * AvgRelError average relative error on the non-zero Y
* BoundL/BoundR are ignored * MaxError maximum error
* Y[last] is ignored (it is assumed to be equal to Y[first]). NON-WEIGHTED ERRORS ARE CALCULATED
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point
].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dbuildcubic(const real_1d_array &x, const real_1d_array &y, con void barycentricfitfloaterhormann(const real_1d_array &x, const real_1d_arr
st ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int ay &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, barycentricinter
_t boundrtype, const double boundr, spline1dinterpolant &c); polant &b, barycentricfitreport &rep);
void spline1dbuildcubic(const real_1d_array &x, const real_1d_array &y, spl
ine1dinterpolant &c);
/************************************************************************* /*************************************************************************
This function solves following problem: given table y[] of function values Rational least squares fitting using Floater-Hormann rational functions
at nodes x[], it calculates and returns table of function derivatives d[] with optimal D chosen from [0,9].
(calculated at the same nodes x[]).
This function yields same result as Spline1DBuildCubic() call followed by Equidistant grid with M node on [min(x),max(x)] is used to build basis
sequence of Spline1DDiff() calls, but it can be several times faster when functions. Different values of D are tried, optimal D (least root mean
called for ordered X[] and X2[]. square error) is chosen. Task is linear, so linear least squares solver
is used. Complexity of this computational scheme is O(N*M^2) (mostly
dominated by the least squares solver).
INPUT PARAMETERS: INPUT PARAMETERS:
X - spline nodes X - points, array[0..N-1].
Y - function values Y - function values, array[0..N-1].
N - number of points, N>0.
OPTIONAL PARAMETERS: M - number of basis functions ( = number_of_nodes), M>=2.
N - points count:
* N>=2
* if given, only first N points are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
D - derivative values at X[] Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
B - barycentric interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* DBest best value of the D parameter
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
ORDER OF POINTS -- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
void spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, c
onst ae_int_t n, const ae_int_t m, const double rho, ae_int_t &info, spline
1dinterpolant &s, spline1dfitreport &rep);
void spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, c
onst ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s,
spline1dfitreport &rep);
Subroutine automatically sorts points, so caller may pass unsorted array. /*************************************************************************
Derivative values are correctly reordered on return, so D[I] is always Weighted fitting by penalized cubic spline.
equal to S'(X[I]) independently of points order.
SETTING BOUNDARY VALUES: Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are cubic splines with natural boundary
conditions. Problem is regularized by adding non-linearity penalty to the
usual least squares penalty function:
The BoundLType/BoundRType parameters can have the following values: S(x) = arg min { LS + P }, where
* -1, which corresonds to the periodic (cyclic) boundary conditions. LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty
In this case: P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty
* both BoundLType and BoundRType must be equal to -1. rho - tunable constant given by user
* BoundL/BoundR are ignored C - automatically determined scale parameter,
* Y[last] is ignored (it is assumed to be equal to Y[first]). makes penalty invariant with respect to scaling of X, Y, W.
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
problem.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
M - number of basis functions ( = number_of_nodes), M>=4.
Rho - regularization constant passed by user. It penalizes
nonlinearity in the regression spline. It is logarithmically
scaled, i.e. actual value of regularization constant is
calculated as 10^Rho. It is automatically scaled so that:
* Rho=2.0 corresponds to moderate amount of nonlinearity
* generally, it should be somewhere in the [-8.0,+8.0]
If you do not want to penalize nonlineary,
pass small Rho. Values as low as -15 should work.
Problems with periodic boundary conditions have Y[first_point]=Y[last_point OUTPUT PARAMETERS:
]. Info- same format as in LSFitLinearWC() subroutine.
However, this subroutine doesn't require you to specify equal values for * Info>0 task is solved
the first and last points - it automatically forces them to be equal by * Info<=0 an error occured:
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to -4 means inconvergence of internal SVD or
Y[last_point]. However it is recommended to pass consistent values of Y[], Cholesky decomposition; problem may be
i.e. to make Y[first_point]=Y[last_point]. too ill-conditioned (very rare)
S - spline interpolant.
Rep - Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
NOTE 1: additional nodes are added to the spline outside of the fitting
interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done
for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so
it is natural to force linearity outside of this interval.
NOTE 2: function automatically sorts points, so caller may pass unsorted
array.
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey Copyright 19.10.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dgriddiffcubic(const real_1d_array &x, const real_1d_array &y, void spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y,
const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_ const real_1d_array &w, const ae_int_t n, const ae_int_t m, const double rh
int_t boundrtype, const double boundr, real_1d_array &d); o, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
void spline1dgriddiffcubic(const real_1d_array &x, const real_1d_array &y, void spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y,
real_1d_array &d); const real_1d_array &w, const ae_int_t m, const double rho, ae_int_t &info,
spline1dinterpolant &s, spline1dfitreport &rep);
/************************************************************************* /*************************************************************************
This function solves following problem: given table y[] of function values Weighted fitting by cubic spline, with constraints on function values or
at nodes x[], it calculates and returns tables of first and second derivatives.
function derivatives d1[] and d2[] (calculated at the same nodes x[]).
This function yields same result as Spline1DBuildCubic() call followed by Equidistant grid with M-2 nodes on [min(x,xc),max(x,xc)] is used to build
sequence of Spline1DDiff() calls, but it can be several times faster when basis functions. Basis functions are cubic splines with continuous second
called for ordered X[] and X2[]. derivatives and non-fixed first derivatives at interval ends. Small
regularizing term is used when solving constrained tasks (to improve
stability).
INPUT PARAMETERS: Task is linear, so linear least squares solver is used. Complexity of this
X - spline nodes computational scheme is O(N*M^2), mostly dominated by least squares solver
Y - function values
OPTIONAL PARAMETERS: SEE ALSO
N - points count: Spline1DFitHermiteWC() - fitting by Hermite splines (more flexible,
* N>=2 less smooth)
* if given, only first N points are used Spline1DFitCubic() - "lightweight" fitting by cubic splines,
* if not given, automatically detected from X/Y sizes without invididual weights and constraints
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary INPUT PARAMETERS:
BoundL - left boundary condition (first or second derivative, X - points, array[0..N-1].
depending on the BoundLType) Y - function values, array[0..N-1].
BoundRType - boundary condition type for the right boundary W - weights, array[0..N-1]
BoundR - right boundary condition (first or second derivative, Each summand in square sum of approximation deviations from
depending on the BoundRType) given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
XC - points where spline values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints (optional):
* 0<=K<M.
* K=0 means no constraints (XC/YC/DC are not used)
* if given, only first K elements of XC/YC/DC are used
* if not given, automatically determined from XC/YC/DC
M - number of basis functions ( = number_of_nodes+2), M>=4.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
D1 - S' values at X[] Info- same format as in LSFitLinearWC() subroutine.
D2 - S'' values at X[] * Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
S - spline interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
ORDER OF POINTS ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array. Subroutine automatically sorts points, so caller may pass unsorted array.
Derivative values are correctly reordered on return, so D[I] is always
equal to S'(X[I]) independently of points order.
SETTING BOUNDARY VALUES: SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
The BoundLType/BoundRType parameters can have the following values:
* -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* excessive constraints can be inconsistent. Splines are piecewise cubic
functions, and it is easy to create an example, where large number of
constraints concentrated in small area will result in inconsistency.
Just because spline is not flexible enough to satisfy all of them. And
same constraints spread across the [min(x),max(x)] will be perfectly
consistent.
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints IS NOT GUARANTEED.
* in the several special cases, however, we CAN guarantee consistency.
* one of this cases is constraints on the function values AND/OR its
derivatives at the interval boundaries.
* another special case is ONE constraint on the function value (OR, but
not AND, derivative) anywhere in the interval
Problems with periodic boundary conditions have Y[first_point]=Y[last_point Our final recommendation is to use constraints WHEN AND ONLY WHEN you
]. can't solve your task without them. Anything beyond special cases given
However, this subroutine doesn't require you to specify equal values for above is not guaranteed and may result in inconsistency.
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dgriddiff2cubic(const real_1d_array &x, const real_1d_array &y, void spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, con
const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae st real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_
_int_t boundrtype, const double boundr, real_1d_array &d1, real_1d_array &d 1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t
2); m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
void spline1dgriddiff2cubic(const real_1d_array &x, const real_1d_array &y, void spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, con
real_1d_array &d1, real_1d_array &d2); st real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, cons
t integer_1d_array &dc, const ae_int_t m, ae_int_t &info, spline1dinterpola
nt &s, spline1dfitreport &rep);
/************************************************************************* /*************************************************************************
This function solves following problem: given table y[] of function values Weighted fitting by Hermite spline, with constraints on function values
at old nodes x[] and new nodes x2[], it calculates and returns table of or first derivatives.
function values y2[] (calculated at x2[]).
This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS:
X - old spline nodes
Y - function values
X2 - new spline nodes
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points from X/Y are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
N2 - new points count:
* N2>=2
* if given, only first N2 points from X2 are used
* if not given, automatically detected from X2 size
OUTPUT PARAMETERS:
F2 - function values at X2[]
ORDER OF POINTS Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are Hermite splines. Small regularizing
term is used when solving constrained tasks (to improve stability).
Subroutine automatically sorts points, so caller may pass unsorted array. Task is linear, so linear least squares solver is used. Complexity of this
Function values are correctly reordered on return, so F2[I] is always computational scheme is O(N*M^2), mostly dominated by least squares solver
equal to S(X2[I]) independently of points order.
SETTING BOUNDARY VALUES: SEE ALSO
Spline1DFitCubicWC() - fitting by Cubic splines (less flexible,
more smooth)
Spline1DFitHermite() - "lightweight" Hermite fitting, without
invididual weights and constraints
The BoundLType/BoundRType parameters can have the following values: INPUT PARAMETERS:
* -1, which corresonds to the periodic (cyclic) boundary conditions. X - points, array[0..N-1].
In this case: Y - function values, array[0..N-1].
* both BoundLType and BoundRType must be equal to -1. W - weights, array[0..N-1]
* BoundL/BoundR are ignored Each summand in square sum of approximation deviations from
* Y[last] is ignored (it is assumed to be equal to Y[first]). given values is multiplied by the square of corresponding
* 0, which corresponds to the parabolically terminated spline weight. Fill it by 1's if you don't want to solve weighted
(BoundL and/or BoundR are ignored). task.
* 1, which corresponds to the first derivative boundary condition N - number of points (optional):
* 2, which corresponds to the second derivative boundary condition * N>0
* by default, BoundType=0 is used * if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
XC - points where spline values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints (optional):
* 0<=K<M.
* K=0 means no constraints (XC/YC/DC are not used)
* if given, only first K elements of XC/YC/DC are used
* if not given, automatically determined from XC/YC/DC
M - number of basis functions (= 2 * number of nodes),
M>=4,
M IS EVEN!
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine:
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
-2 means odd M was passed (which is not supported)
-1 means another errors in parameters passed
(N<=0, for example)
S - spline interpolant.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
Problems with periodic boundary conditions have Y[first_point]=Y[last_point IMPORTANT:
]. this subroitine doesn't calculate task's condition number for K<>0.
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT -- IMPORTANT:
Copyright 03.09.2010 by Bochkanov Sergey this subroitine supports only even M's
*************************************************************************/
void spline1dconvcubic(const real_1d_array &x, const real_1d_array &y, cons
t ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_
t boundrtype, const double boundr, const real_1d_array &x2, const ae_int_t
n2, real_1d_array &y2);
void spline1dconvcubic(const real_1d_array &x, const real_1d_array &y, cons
t real_1d_array &x2, real_1d_array &y2);
/************************************************************************* ORDER OF POINTS
This function solves following problem: given table y[] of function values
at old nodes x[] and new nodes x2[], it calculates and returns table of
function values y2[] and derivatives d2[] (calculated at x2[]).
This function yields same result as Spline1DBuildCubic() call followed by Subroutine automatically sorts points, so caller may pass unsorted array.
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS: SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
X - old spline nodes
Y - function values
X2 - new spline nodes
OPTIONAL PARAMETERS: Setting constraints can lead to undesired results, like ill-conditioned
N - points count: behavior, or inconsistency being detected. From the other side, it allows
* N>=2 us to improve quality of the fit. Here we summarize our experience with
* if given, only first N points from X/Y are used constrained regression splines:
* if not given, automatically detected from X/Y sizes * excessive constraints can be inconsistent. Splines are piecewise cubic
(len(X) must be equal to len(Y)) functions, and it is easy to create an example, where large number of
BoundLType - boundary condition type for the left boundary constraints concentrated in small area will result in inconsistency.
BoundL - left boundary condition (first or second derivative, Just because spline is not flexible enough to satisfy all of them. And
depending on the BoundLType) same constraints spread across the [min(x),max(x)] will be perfectly
BoundRType - boundary condition type for the right boundary consistent.
BoundR - right boundary condition (first or second derivative, * the more evenly constraints are spread across [min(x),max(x)], the more
depending on the BoundRType) chances that they will be consistent
N2 - new points count: * the greater is M (given fixed constraints), the more chances that
* N2>=2 constraints will be consistent
* if given, only first N2 points from X2 are used * in the general case, consistency of constraints is NOT GUARANTEED.
* if not given, automatically detected from X2 size * in the several special cases, however, we can guarantee consistency.
* one of this cases is M>=4 and constraints on the function value
(AND/OR its derivative) at the interval boundaries.
* another special case is M>=4 and ONE constraint on the function value
(OR, BUT NOT AND, derivative) anywhere in [min(x),max(x)]
OUTPUT PARAMETERS: Our final recommendation is to use constraints WHEN AND ONLY when you
F2 - function values at X2[] can't solve your task without them. Anything beyond special cases given
D2 - first derivatives at X2[] above is not guaranteed and may result in inconsistency.
ORDER OF POINTS -- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
void spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, c
onst real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const rea
l_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_
t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
void spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, c
onst real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, co
nst integer_1d_array &dc, const ae_int_t m, ae_int_t &info, spline1dinterpo
lant &s, spline1dfitreport &rep);
Subroutine automatically sorts points, so caller may pass unsorted array. /*************************************************************************
Function values are correctly reordered on return, so F2[I] is always Least squares fitting by cubic spline.
equal to S(X2[I]) independently of points order.
SETTING BOUNDARY VALUES: This subroutine is "lightweight" alternative for more complex and feature-
rich Spline1DFitCubicWC(). See Spline1DFitCubicWC() for more information
about subroutine parameters (we don't duplicate it here because of length)
The BoundLType/BoundRType parameters can have the following values: -- ALGLIB PROJECT --
* -1, which corresonds to the periodic (cyclic) boundary conditions. Copyright 18.08.2009 by Bochkanov Sergey
In this case: *************************************************************************/
* both BoundLType and BoundRType must be equal to -1. void spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const
* BoundL/BoundR are ignored ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spli
* Y[last] is ignored (it is assumed to be equal to Y[first]). ne1dfitreport &rep);
* 0, which corresponds to the parabolically terminated spline void spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const
(BoundL and/or BoundR are ignored). ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep
* 1, which corresponds to the first derivative boundary condition );
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: /*************************************************************************
Least squares fitting by Hermite spline.
Problems with periodic boundary conditions have Y[first_point]=Y[last_point This subroutine is "lightweight" alternative for more complex and feature-
]. rich Spline1DFitHermiteWC(). See Spline1DFitHermiteWC() description for
However, this subroutine doesn't require you to specify equal values for more information about subroutine parameters (we don't duplicate it here
the first and last points - it automatically forces them to be equal by because of length).
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dconvdiffcubic(const real_1d_array &x, const real_1d_array &y, void spline1dfithermite(const real_1d_array &x, const real_1d_array &y, con
const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_ st ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, sp
int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_in line1dfitreport &rep);
t_t n2, real_1d_array &y2, real_1d_array &d2); void spline1dfithermite(const real_1d_array &x, const real_1d_array &y, con
void spline1dconvdiffcubic(const real_1d_array &x, const real_1d_array &y, st ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &r
const real_1d_array &x2, real_1d_array &y2, real_1d_array &d2); ep);
/************************************************************************* /*************************************************************************
This function solves following problem: given table y[] of function values Weighted linear least squares fitting.
at old nodes x[] and new nodes x2[], it calculates and returns table of
function values y2[], first and second derivatives d2[] and dd2[]
(calculated at x2[]).
This function yields same result as Spline1DBuildCubic() call followed by QR decomposition is used to reduce task to MxM, then triangular solver or
sequence of Spline1DDiff() calls, but it can be several times faster when SVD-based solver is used depending on condition number of the system. It
called for ordered X[] and X2[]. allows to maximize speed and retain decent accuracy.
INPUT PARAMETERS: INPUT PARAMETERS:
X - old spline nodes Y - array[0..N-1] Function values in N points.
Y - function values W - array[0..N-1] Weights corresponding to function values.
X2 - new spline nodes Each summand in square sum of approximation deviations
from given values is multiplied by the square of
OPTIONAL PARAMETERS: corresponding weight.
N - points count: FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
* N>=2 FMatrix[I, J] - value of J-th basis function in I-th point.
* if given, only first N points from X/Y are used N - number of points used. N>=1.
* if not given, automatically detected from X/Y sizes M - number of basis functions, M>=1.
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
N2 - new points count:
* N2>=2
* if given, only first N2 points from X2 are used
* if not given, automatically detected from X2 size
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
F2 - function values at X2[] Info - error code:
D2 - first derivatives at X2[] * -4 internal SVD decomposition subroutine failed (very
DD2 - second derivatives at X2[] rare and for degenerate systems only)
* -1 incorrect N/M were specified
ORDER OF POINTS * 1 task is solved
C - decomposition coefficients, array[0..M-1]
Subroutine automatically sorts points, so caller may pass unsorted array. Rep - fitting report. Following fields are set:
Function values are correctly reordered on return, so F2[I] is always * Rep.TaskRCond reciprocal of condition number
equal to S(X2[I]) independently of points order. * RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
SETTING BOUNDARY VALUES: -- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
void lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const rea
l_2d_array &fmatrix, const ae_int_t n, const ae_int_t m, ae_int_t &info, re
al_1d_array &c, lsfitreport &rep);
void lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const rea
l_2d_array &fmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
The BoundLType/BoundRType parameters can have the following values: /*************************************************************************
* -1, which corresonds to the periodic (cyclic) boundary conditions. Weighted constained linear least squares fitting.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: This is variation of LSFitLinearW(), which searchs for min|A*x=b| given
that K additional constaints C*x=bc are satisfied. It reduces original
Problems with periodic boundary conditions have Y[first_point]=Y[last_point task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinearW()
]. is called.
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/
void spline1dconvdiff2cubic(const real_1d_array &x, const real_1d_array &y,
const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae
_int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_i
nt_t n2, real_1d_array &y2, real_1d_array &d2, real_1d_array &dd2);
void spline1dconvdiff2cubic(const real_1d_array &x, const real_1d_array &y,
const real_1d_array &x2, real_1d_array &y2, real_1d_array &d2, real_1d_arr
ay &dd2);
/*************************************************************************
This subroutine builds Catmull-Rom spline interpolant.
INPUT PARAMETERS: INPUT PARAMETERS:
X - spline nodes, array[0..N-1]. Y - array[0..N-1] Function values in N points.
Y - function values, array[0..N-1]. W - array[0..N-1] Weights corresponding to function values.
Each summand in square sum of approximation deviations
OPTIONAL PARAMETERS: from given values is multiplied by the square of
N - points count: corresponding weight.
* N>=2 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
* if given, only first N points are used to build splin FMatrix[I,J] - value of J-th basis function in I-th point.
e CMatrix - a table of constaints, array[0..K-1,0..M].
* if not given, automatically detected from X/Y sizes I-th row of CMatrix corresponds to I-th linear constraint:
(len(X) must be equal to len(Y)) CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I
BoundType - boundary condition type: ,M]
* -1 for periodic boundary condition N - number of points used. N>=1.
* 0 for parabolically terminated spline (default) M - number of basis functions, M>=1.
Tension - tension parameter: K - number of constraints, 0 <= K < M
* tension=0 corresponds to classic Catmull-Rom spline K=0 corresponds to absence of constraints.
(default)
* 0<tension<1 corresponds to more general form - cardin
al spline
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
C - spline interpolant Info - error code:
* -4 internal SVD decomposition subroutine failed (very
ORDER OF POINTS rare and for degenerate systems only)
* -3 either too many constraints (M or more),
Subroutine automatically sorts points, so caller may pass unsorted array. degenerate constraints (some constraints are
repetead twice) or inconsistent constraints were
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: specified.
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
Problems with periodic boundary conditions have Y[first_point]=Y[last_point IMPORTANT:
]. this subroitine doesn't calculate task's condition number for K<>0.
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 23.06.2007 by Bochkanov Sergey Copyright 07.09.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dbuildcatmullrom(const real_1d_array &x, const real_1d_array &y void lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const re
, const ae_int_t n, const ae_int_t boundtype, const double tension, spline1 al_2d_array &fmatrix, const real_2d_array &cmatrix, const ae_int_t n, const
dinterpolant &c); ae_int_t m, const ae_int_t k, ae_int_t &info, real_1d_array &c, lsfitrepor
void spline1dbuildcatmullrom(const real_1d_array &x, const real_1d_array &y t &rep);
, spline1dinterpolant &c); void lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const re
al_2d_array &fmatrix, const real_2d_array &cmatrix, ae_int_t &info, real_1d
_array &c, lsfitreport &rep);
/************************************************************************* /*************************************************************************
This subroutine builds Hermite spline interpolant. Linear least squares fitting.
QR decomposition is used to reduce task to MxM, then triangular solver or
SVD-based solver is used depending on condition number of the system. It
allows to maximize speed and retain decent accuracy.
INPUT PARAMETERS: INPUT PARAMETERS:
X - spline nodes, array[0..N-1] Y - array[0..N-1] Function values in N points.
Y - function values, array[0..N-1] FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
D - derivatives, array[0..N-1] FMatrix[I, J] - value of J-th basis function in I-th point.
N - points count (optional): N - number of points used. N>=1.
* N>=2 M - number of basis functions, M>=1.
* if given, only first N points are used to build splin
e
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
C - spline interpolant. Info - error code:
* -4 internal SVD decomposition subroutine failed (very
ORDER OF POINTS rare and for degenerate systems only)
* 1 task is solved
Subroutine automatically sorts points, so caller may pass unsorted array. C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* Rep.TaskRCond reciprocal of condition number
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 23.06.2007 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, c void lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, cons
onst real_1d_array &d, const ae_int_t n, spline1dinterpolant &c); t ae_int_t n, const ae_int_t m, ae_int_t &info, real_1d_array &c, lsfitrepo
void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, c rt &rep);
onst real_1d_array &d, spline1dinterpolant &c); void lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, ae_i
nt_t &info, real_1d_array &c, lsfitreport &rep);
/************************************************************************* /*************************************************************************
This subroutine builds Akima spline interpolant Constained linear least squares fitting.
This is variation of LSFitLinear(), which searchs for min|A*x=b| given
that K additional constaints C*x=bc are satisfied. It reduces original
task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinear()
is called.
INPUT PARAMETERS: INPUT PARAMETERS:
X - spline nodes, array[0..N-1] Y - array[0..N-1] Function values in N points.
Y - function values, array[0..N-1] FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
N - points count (optional): FMatrix[I,J] - value of J-th basis function in I-th point.
* N>=5 CMatrix - a table of constaints, array[0..K-1,0..M].
* if given, only first N points are used to build splin I-th row of CMatrix corresponds to I-th linear constraint:
e CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I
* if not given, automatically detected from X/Y sizes ,M]
(len(X) must be equal to len(Y)) N - number of points used. N>=1.
M - number of basis functions, M>=1.
K - number of constraints, 0 <= K < M
K=0 corresponds to absence of constraints.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
C - spline interpolant Info - error code:
* -4 internal SVD decomposition subroutine failed (very
ORDER OF POINTS rare and for degenerate systems only)
* -3 either too many constraints (M or more),
degenerate constraints (some constraints are
repetead twice) or inconsistent constraints were
specified.
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
Subroutine automatically sorts points, so caller may pass unsorted array. IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 24.06.2007 by Bochkanov Sergey Copyright 07.09.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, con void lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, con
st ae_int_t n, spline1dinterpolant &c); st real_2d_array &cmatrix, const ae_int_t n, const ae_int_t m, const ae_int
void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, spl _t k, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
ine1dinterpolant &c); void lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, con
st real_2d_array &cmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &r
ep);
/************************************************************************* /*************************************************************************
This subroutine calculates the value of the spline at the given point X. Weighted nonlinear least squares fitting using function values only.
INPUT PARAMETERS: Combination of numerical differentiation and secant updates is used to
C - spline interpolant obtain function Jacobian.
X - point
Result: Nonlinear task min(F(c)) is solved, where
S(x)
-- ALGLIB PROJECT -- F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^
Copyright 23.06.2007 by Bochkanov Sergey 2,
*************************************************************************/
double spline1dcalc(const spline1dinterpolant &c, const double x);
/************************************************************************* * N is a number of points,
This subroutine differentiates the spline. * M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* w is an N-dimensional vector of weight coefficients,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]).
INPUT PARAMETERS: INPUT PARAMETERS:
C - spline interpolant. X - array[0..N-1,0..M-1], points (one row = one point)
X - point Y - array[0..N-1], function values.
W - weights, array[0..N-1]
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
DiffStep- numerical differentiation step;
should not be very small or large;
large = loss of accuracy
small = growth of round-off errors
Result: OUTPUT PARAMETERS:
S - S(x) State - structure which stores algorithm state
DS - S'(x)
D2S - S''(x)
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 24.06.2007 by Bochkanov Sergey Copyright 18.10.2008 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1ddiff(const spline1dinterpolant &c, const double x, double &s, void lsfitcreatewf(const real_2d_array &x, const real_1d_array &y, const re
double &ds, double &d2s); al_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m,
const ae_int_t k, const double diffstep, lsfitstate &state);
void lsfitcreatewf(const real_2d_array &x, const real_1d_array &y, const re
al_1d_array &w, const real_1d_array &c, const double diffstep, lsfitstate &
state);
/************************************************************************* /*************************************************************************
This subroutine unpacks the spline into the coefficients table. Nonlinear least squares fitting using function values only.
INPUT PARAMETERS: Combination of numerical differentiation and secant updates is used to
C - spline interpolant. obtain function Jacobian.
X - point
Result: Nonlinear task min(F(c)) is solved, where
Tbl - coefficients table, unpacked format, array[0..N-2, 0..5].
For I = 0...N-2:
Tbl[I,0] = X[i]
Tbl[I,1] = X[i+1]
Tbl[I,2] = C0
Tbl[I,3] = C1
Tbl[I,4] = C2
Tbl[I,5] = C3
On [x[i], x[i+1]] spline is equals to:
S(x) = C0 + C1*t + C2*t^2 + C3*t^3
t = x-x[i]
-- ALGLIB PROJECT -- F(c) = (f(c,x[0])-y[0])^2 + ... + (f(c,x[n-1])-y[n-1])^2,
Copyright 29.06.2007 by Bochkanov Sergey
*************************************************************************/
void spline1dunpack(const spline1dinterpolant &c, ae_int_t &n, real_2d_arra
y &tbl);
/************************************************************************* * N is a number of points,
This subroutine performs linear transformation of the spline argument. * M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* w is an N-dimensional vector of weight coefficients,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]).
INPUT PARAMETERS: INPUT PARAMETERS:
C - spline interpolant. X - array[0..N-1,0..M-1], points (one row = one point)
A, B- transformation coefficients: x = A*t + B Y - array[0..N-1], function values.
Result: C - array[0..K-1], initial approximation to the solution,
C - transformed spline N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
DiffStep- numerical differentiation step;
should not be very small or large;
large = loss of accuracy
small = growth of round-off errors
-- ALGLIB PROJECT -- OUTPUT PARAMETERS:
Copyright 30.06.2007 by Bochkanov Sergey State - structure which stores algorithm state
-- ALGLIB --
Copyright 18.10.2008 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline1dlintransx(const spline1dinterpolant &c, const double a, const void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const rea
double b); l_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const
double diffstep, lsfitstate &state);
void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const rea
l_1d_array &c, const double diffstep, lsfitstate &state);
/************************************************************************* /*************************************************************************
This subroutine performs linear transformation of the spline. Weighted nonlinear least squares fitting using gradient only.
INPUT PARAMETERS:
C - spline interpolant.
A, B- transformation coefficients: S2(x) = A*S(x) + B
Result:
C - transformed spline
-- ALGLIB PROJECT -- Nonlinear task min(F(c)) is solved, where
Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/
void spline1dlintransy(const spline1dinterpolant &c, const double a, const
double b);
/************************************************************************* F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^
This subroutine integrates the spline. 2,
INPUT PARAMETERS: * N is a number of points,
C - spline interpolant. * M is a dimension of a space points belong to,
X - right bound of the integration interval [a, x], * K is a dimension of a space of parameters being fitted,
here 'a' denotes min(x[]) * w is an N-dimensional vector of weight coefficients,
Result: * x is a set of N points, each of them is an M-dimensional vector,
integral(S(t)dt,a,x) * c is a K-dimensional vector of parameters being fitted
-- ALGLIB PROJECT -- This subroutine uses only f(c,x[i]) and its gradient.
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
double spline1dintegrate(const spline1dinterpolant &c, const double x);
/************************************************************************* INPUT PARAMETERS:
This subroutine builds bilinear spline coefficients table. X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
W - weights, array[0..N-1]
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
CheapFG - boolean flag, which is:
* True if both function and gradient calculation complexit
y
are less than O(M^2). An improved algorithm can
be used which corresponds to FGJ scheme from
MINLM unit.
* False otherwise.
Standard Jacibian-bases Levenberg-Marquardt algo
will be used (FJ scheme).
Input parameters: OUTPUT PARAMETERS:
X - spline abscissas, array[0..N-1] State - structure which stores algorithm state
Y - spline ordinates, array[0..M-1]
F - function values, array[0..M-1,0..N-1]
M,N - grid size, M>=2, N>=2
Output parameters: See also:
C - spline interpolant LSFitResults
LSFitCreateFG (fitting without weights)
LSFitCreateWFGH (fitting using Hessian)
LSFitCreateFGH (fitting using Hessian, without weights)
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 05.07.2007 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline2dbuildbilinear(const real_1d_array &x, const real_1d_array &y, void lsfitcreatewfg(const real_2d_array &x, const real_1d_array &y, const r
const real_2d_array &f, const ae_int_t m, const ae_int_t n, spline2dinterpo eal_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m
lant &c); , const ae_int_t k, const bool cheapfg, lsfitstate &state);
void lsfitcreatewfg(const real_2d_array &x, const real_1d_array &y, const r
eal_1d_array &w, const real_1d_array &c, const bool cheapfg, lsfitstate &st
ate);
/************************************************************************* /*************************************************************************
This subroutine builds bicubic spline coefficients table. Nonlinear least squares fitting using gradient only, without individual
weights.
Input parameters: Nonlinear task min(F(c)) is solved, where
X - spline abscissas, array[0..N-1]
Y - spline ordinates, array[0..M-1]
F - function values, array[0..M-1,0..N-1]
M,N - grid size, M>=2, N>=2
Output parameters: F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,
C - spline interpolant
-- ALGLIB PROJECT -- * N is a number of points,
Copyright 05.07.2007 by Bochkanov Sergey * M is a dimension of a space points belong to,
*************************************************************************/ * K is a dimension of a space of parameters being fitted,
void spline2dbuildbicubic(const real_1d_array &x, const real_1d_array &y, c * x is a set of N points, each of them is an M-dimensional vector,
onst real_2d_array &f, const ae_int_t m, const ae_int_t n, spline2dinterpol * c is a K-dimensional vector of parameters being fitted
ant &c);
/************************************************************************* This subroutine uses only f(c,x[i]) and its gradient.
This subroutine calculates the value of the bilinear or bicubic spline at
the given point X.
Input parameters: INPUT PARAMETERS:
C - coefficients table. X - array[0..N-1,0..M-1], points (one row = one point)
Built by BuildBilinearSpline or BuildBicubicSpline. Y - array[0..N-1], function values.
X, Y- point C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
CheapFG - boolean flag, which is:
* True if both function and gradient calculation complexit
y
are less than O(M^2). An improved algorithm can
be used which corresponds to FGJ scheme from
MINLM unit.
* False otherwise.
Standard Jacibian-bases Levenberg-Marquardt algo
will be used (FJ scheme).
Result: OUTPUT PARAMETERS:
S(x,y) State - structure which stores algorithm state
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 05.07.2007 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
double spline2dcalc(const spline2dinterpolant &c, const double x, const dou void lsfitcreatefg(const real_2d_array &x, const real_1d_array &y, const re
ble y); al_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const
bool cheapfg, lsfitstate &state);
void lsfitcreatefg(const real_2d_array &x, const real_1d_array &y, const re
al_1d_array &c, const bool cheapfg, lsfitstate &state);
/************************************************************************* /*************************************************************************
This subroutine calculates the value of the bilinear or bicubic spline at Weighted nonlinear least squares fitting using gradient/Hessian.
the given point X and its derivatives.
Input parameters: Nonlinear task min(F(c)) is solved, where
C - spline interpolant.
X, Y- point
Output parameters: F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^
F - S(x,y) 2,
FX - dS(x,y)/dX
FY - dS(x,y)/dY
FXY - d2S(x,y)/dXdY
-- ALGLIB PROJECT -- * N is a number of points,
Copyright 05.07.2007 by Bochkanov Sergey * M is a dimension of a space points belong to,
*************************************************************************/ * K is a dimension of a space of parameters being fitted,
void spline2ddiff(const spline2dinterpolant &c, const double x, const doubl * w is an N-dimensional vector of weight coefficients,
e y, double &f, double &fx, double &fy, double &fxy); * x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
/************************************************************************* This subroutine uses f(c,x[i]), its gradient and its Hessian.
This subroutine unpacks two-dimensional spline into the coefficients table
Input parameters: INPUT PARAMETERS:
C - spline interpolant. X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
W - weights, array[0..N-1]
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
Result: OUTPUT PARAMETERS:
M, N- grid size (x-axis and y-axis) State - structure which stores algorithm state
Tbl - coefficients table, unpacked format,
[0..(N-1)*(M-1)-1, 0..19].
For I = 0...M-2, J=0..N-2:
K = I*(N-1)+J
Tbl[K,0] = X[j]
Tbl[K,1] = X[j+1]
Tbl[K,2] = Y[i]
Tbl[K,3] = Y[i+1]
Tbl[K,4] = C00
Tbl[K,5] = C01
Tbl[K,6] = C02
Tbl[K,7] = C03
Tbl[K,8] = C10
Tbl[K,9] = C11
...
Tbl[K,19] = C33
On each grid square spline is equals to:
S(x) = SUM(c[i,j]*(x^i)*(y^j), i=0..3, j=0..3)
t = x-x[j]
u = y-y[i]
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 29.06.2007 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline2dunpack(const spline2dinterpolant &c, ae_int_t &m, ae_int_t &n, void lsfitcreatewfgh(const real_2d_array &x, const real_1d_array &y, const
real_2d_array &tbl); real_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t
m, const ae_int_t k, lsfitstate &state);
void lsfitcreatewfgh(const real_2d_array &x, const real_1d_array &y, const
real_1d_array &w, const real_1d_array &c, lsfitstate &state);
/************************************************************************* /*************************************************************************
This subroutine performs linear transformation of the spline argument. Nonlinear least squares fitting using gradient/Hessian, without individial
weights.
Input parameters:
C - spline interpolant
AX, BX - transformation coefficients: x = A*t + B
AY, BY - transformation coefficients: y = A*u + B
Result:
C - transformed spline
-- ALGLIB PROJECT -- Nonlinear task min(F(c)) is solved, where
Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/
void spline2dlintransxy(const spline2dinterpolant &c, const double ax, cons
t double bx, const double ay, const double by);
/************************************************************************* F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,
This subroutine performs linear transformation of the spline.
Input parameters: * N is a number of points,
C - spline interpolant. * M is a dimension of a space points belong to,
A, B- transformation coefficients: S2(x,y) = A*S(x,y) + B * K is a dimension of a space of parameters being fitted,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
Output parameters: This subroutine uses f(c,x[i]), its gradient and its Hessian.
C - transformed spline
-- ALGLIB PROJECT -- INPUT PARAMETERS:
Copyright 30.06.2007 by Bochkanov Sergey X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline2dlintransf(const spline2dinterpolant &c, const double a, const void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const r
double b); eal_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, lsfi
tstate &state);
void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const r
eal_1d_array &c, lsfitstate &state);
/************************************************************************* /*************************************************************************
Bicubic spline resampling Stopping conditions for nonlinear least squares fitting.
Input parameters: INPUT PARAMETERS:
A - function values at the old grid, State - structure which stores algorithm state
array[0..OldHeight-1, 0..OldWidth-1] EpsF - stopping criterion. Algorithm stops if
OldHeight - old grid height, OldHeight>1 |F(k+1)-F(k)| <= EpsF*max{|F(k)|, |F(k+1)|, 1}
OldWidth - old grid width, OldWidth>1 EpsX - stopping criterion. Algorithm stops if
NewHeight - new grid height, NewHeight>1 |X(k+1)-X(k)| <= EpsX*(1+|X(k)|)
NewWidth - new grid width, NewWidth>1 MaxIts - stopping criterion. Algorithm stops after MaxIts iterations
.
MaxIts=0 means no stopping criterion.
Output parameters: NOTE
B - function values at the new grid,
array[0..NewHeight-1, 0..NewWidth-1]
-- ALGLIB routine -- Passing EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic
15 May, 2007 stopping criterion selection (according to the scheme used by MINLM unit).
Copyright by Bochkanov Sergey
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline2dresamplebicubic(const real_2d_array &a, const ae_int_t oldheig ht, const ae_int_t oldwidth, real_2d_array &b, const ae_int_t newheight, co nst ae_int_t newwidth); void lsfitsetcond(const lsfitstate &state, const double epsf, const double epsx, const ae_int_t maxits);
/************************************************************************* /*************************************************************************
Bilinear spline resampling This function sets maximum step length
Input parameters: INPUT PARAMETERS:
A - function values at the old grid, State - structure which stores algorithm state
array[0..OldHeight-1, 0..OldWidth-1] StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
OldHeight - old grid height, OldHeight>1 want to limit step length.
OldWidth - old grid width, OldWidth>1
NewHeight - new grid height, NewHeight>1
NewWidth - new grid width, NewWidth>1
Output parameters: Use this subroutine when you optimize target function which contains exp()
B - function values at the new grid, or other fast growing functions, and optimization algorithm makes too
array[0..NewHeight-1, 0..NewWidth-1] large steps which leads to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d.
-- ALGLIB routine -- NOTE: non-zero StpMax leads to moderate performance degradation because
09.07.2007 intermediate step of preconditioned L-BFGS optimization is incompatible
Copyright by Bochkanov Sergey with limits on step size.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void spline2dresamplebilinear(const real_2d_array &a, const ae_int_t oldhei ght, const ae_int_t oldwidth, real_2d_array &b, const ae_int_t newheight, c onst ae_int_t newwidth); void lsfitsetstpmax(const lsfitstate &state, const double stpmax);
/************************************************************************* /*************************************************************************
IDW interpolation This function turns on/off reporting.
INPUT PARAMETERS: INPUT PARAMETERS:
Z - IDW interpolant built with one of model building State - structure which stores algorithm state
subroutines. NeedXRep- whether iteration reports are needed or not
X - array[0..NX-1], interpolation point
Result: When reports are needed, State.C (current parameters) and State.F (current
IDW interpolant Z(X) value of fitting function) are reported.
-- ALGLIB -- -- ALGLIB --
Copyright 02.03.2010 by Bochkanov Sergey Copyright 15.08.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
double idwcalc(const idwinterpolant &z, const real_1d_array &x); void lsfitsetxrep(const lsfitstate &state, const bool needxrep);
/************************************************************************* /*************************************************************************
IDW interpolant using modified Shepard method for uniform point This function provides reverse communication interface
distributions. Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API
*************************************************************************/
bool lsfititeration(const lsfitstate &state);
INPUT PARAMETERS: /*************************************************************************
XY - X and Y values, array[0..N-1,0..NX]. This family of functions is used to launcn iterations of nonlinear fitter
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
D - nodal function type, either:
* 0 constant model. Just for demonstration only, worst
model ever.
* 1 linear model, least squares fitting. Simpe model for
datasets too small for quadratic models
* 2 quadratic model, least squares fitting. Best model
available (if your dataset is large enough).
* -1 "fast" linear model, use with caution!!! It is
significantly faster than linear/quadratic and better
than constant model. But it is less robust (especially
in the presence of noise).
NQ - number of points used to calculate nodal functions (ignored
for constant models). NQ should be LARGER than:
* max(1.5*(1+NX),2^NX+1) for linear model,
* max(3/4*(NX+2)*(NX+1),2^NX+1) for quadratic model.
Values less than this threshold will be silently increased.
NW - number of points used to calculate weights and to interpolate.
Required: >=2^NX+1, values less than this threshold will be
silently increased.
Recommended value: about 2*NQ
OUTPUT PARAMETERS: These functions accept following parameters:
Z - IDW interpolant. state - algorithm state
func - callback which calculates function (or merit function)
value func at given point x
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
hess - callback which calculates function (or merit function)
value func, gradient grad and Hessian hess at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES: NOTES:
* best results are obtained with quadratic models, worst - with constant
models
* when N is large, NQ and NW must be significantly smaller than N both
to obtain optimal performance and to obtain optimal accuracy. In 2 or
3-dimensional tasks NQ=15 and NW=25 are good values to start with.
* NQ and NW may be greater than N. In such cases they will be
automatically decreased.
* this subroutine is always succeeds (as long as correct parameters are
passed).
* see 'Multivariate Interpolation of Large Sets of Scattered Data' by
Robert J. Renka for more information on this algorithm.
* this subroutine assumes that point distribution is uniform at the small
scales. If it isn't - for example, points are concentrated along
"lines", but "lines" distribution is uniform at the larger scale - then
you should use IDWBuildModifiedShepardR()
-- ALGLIB PROJECT -- 1. this algorithm is somewhat unusual because it works with parameterized
Copyright 02.03.2010 by Bochkanov Sergey function f(C,X), where X is a function argument (we have many points
*************************************************************************/ which are characterized by different argument values), and C is a
void idwbuildmodifiedshepard(const real_2d_array &xy, const ae_int_t n, con parameter to fit.
st ae_int_t nx, const ae_int_t d, const ae_int_t nq, const ae_int_t nw, idw
interpolant &z);
/************************************************************************* For example, if we want to do linear fit by f(c0,c1,x) = c0*x+c1, then
IDW interpolant using modified Shepard method for non-uniform datasets. x will be argument, and {c0,c1} will be parameters.
This type of model uses constant nodal functions and interpolates using It is important to understand that this algorithm finds minimum in the
all nodes which are closer than user-specified radius R. It may be used space of function PARAMETERS (not arguments), so it needs derivatives
when points distribution is non-uniform at the small scale, but it is at of f() with respect to C, not X.
the distances as large as R.
INPUT PARAMETERS: In the example above it will need f=c0*x+c1 and {df/dc0,df/dc1} = {x,1}
XY - X and Y values, array[0..N-1,0..NX]. instead of {df/dx} = {c0}.
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
R - radius, R>0
OUTPUT PARAMETERS: 2. Callback functions accept C as the first parameter, and X as the second
Z - IDW interpolant.
NOTES: 3. If state was created with LSFitCreateFG(), algorithm needs just
* if there is less than IDWKMin points within R-ball, algorithm selects function and its gradient, but if state was created with
IDWKMin closest ones, so that continuity properties of interpolant are LSFitCreateFGH(), algorithm will need function, gradient and Hessian.
preserved even far from points.
According to the said above, there ase several versions of this
function, which accept different sets of callbacks.
This flexibility opens way to subtle errors - you may create state with
LSFitCreateFGH() (optimization using Hessian), but call function which
does not accept Hessian. So when algorithm will request Hessian, there
will be no callback to call. In this case exception will be thrown.
Be careful to avoid such errors because there is no way to find them at
compile time - you can see them at runtime only.
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
-- ALGLIB PROJECT --
Copyright 11.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void idwbuildmodifiedshepardr(const real_2d_array &xy, const ae_int_t n, co void lsfitfit(lsfitstate &state,
nst ae_int_t nx, const double r, idwinterpolant &z); void (*func)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, void *ptr),
void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL,
void *ptr = NULL);
void lsfitfit(lsfitstate &state,
void (*func)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, void *ptr),
void (*grad)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, real_1d_array &grad, void *ptr),
void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL,
void *ptr = NULL);
void lsfitfit(lsfitstate &state,
void (*func)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, void *ptr),
void (*grad)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, real_1d_array &grad, void *ptr),
void (*hess)(const real_1d_array &c, const real_1d_array &x, double &fu
nc, real_1d_array &grad, real_2d_array &hess, void *ptr),
void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL,
void *ptr = NULL);
/************************************************************************* /*************************************************************************
IDW model for noisy data. Nonlinear least squares fitting results.
This subroutine may be used to handle noisy data, i.e. data with noise in
OUTPUT values. It differs from IDWBuildModifiedShepard() in the following
aspects:
* nodal functions are not constrained to pass through nodes: Qi(xi)<>yi,
i.e. we have fitting instead of interpolation.
* weights which are used during least squares fitting stage are all equal
to 1.0 (independently of distance)
* "fast"-linear or constant nodal functions are not supported (either not
robust enough or too rigid)
This problem require far more complex tuning than interpolation problems. Called after return from LSFitFit().
Below you can find some recommendations regarding this problem:
* focus on tuning NQ; it controls noise reduction. As for NW, you can just
make it equal to 2*NQ.
* you can use cross-validation to determine optimal NQ.
* optimal NQ is a result of complex tradeoff between noise level (more
noise = larger NQ required) and underlying function complexity (given
fixed N, larger NQ means smoothing of compex features in the data). For
example, NQ=N will reduce noise to the minimum level possible, but you
will end up with just constant/linear/quadratic (depending on D) least
squares model for the whole dataset.
INPUT PARAMETERS: INPUT PARAMETERS:
XY - X and Y values, array[0..N-1,0..NX]. State - algorithm state
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
D - nodal function degree, either:
* 1 linear model, least squares fitting. Simpe model for
datasets too small for quadratic models (or for very
noisy problems).
* 2 quadratic model, least squares fitting. Best model
available (if your dataset is large enough).
NQ - number of points used to calculate nodal functions. NQ should
be significantly larger than 1.5 times the number of
coefficients in a nodal function to overcome effects of noise:
* larger than 1.5*(1+NX) for linear model,
* larger than 3/4*(NX+2)*(NX+1) for quadratic model.
Values less than this threshold will be silently increased.
NW - number of points used to calculate weights and to interpolate.
Required: >=2^NX+1, values less than this threshold will be
silently increased.
Recommended value: about 2*NQ or larger
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
Z - IDW interpolant. Info - completetion code:
* 1 relative function improvement is no more than
NOTES: EpsF.
* best results are obtained with quadratic models, linear models are not * 2 relative step is no more than EpsX.
recommended to use unless you are pretty sure that it is what you want * 4 gradient norm is no more than EpsG
* this subroutine is always succeeds (as long as correct parameters are * 5 MaxIts steps was taken
passed). * 7 stopping conditions are too stringent,
* see 'Multivariate Interpolation of Large Sets of Scattered Data' by further improvement is impossible
Robert J. Renka for more information on this algorithm. C - array[0..K-1], solution
Rep - optimization report. Following fields are set:
* Rep.TerminationType completetion code:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero
Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB PROJECT -- -- ALGLIB --
Copyright 02.03.2010 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void idwbuildnoisy(const real_2d_array &xy, const ae_int_t n, const ae_int_ t nx, const ae_int_t d, const ae_int_t nq, const ae_int_t nw, idwinterpolan t &z); void lsfitresults(const lsfitstate &state, ae_int_t &info, real_1d_array &c , lsfitreport &rep);
/************************************************************************* /*************************************************************************
This function builds non-periodic 2-dimensional parametric spline which This function builds non-periodic 2-dimensional parametric spline which
starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]). starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]).
INPUT PARAMETERS: INPUT PARAMETERS:
XY - points, array[0..N-1,0..1]. XY - points, array[0..N-1,0..1].
XY[I,0:1] corresponds to the Ith point. XY[I,0:1] corresponds to the Ith point.
Order of points is important! Order of points is important!
N - points count, N>=5 for Akima splines, N>=2 for other types of N - points count, N>=5 for Akima splines, N>=2 for other types of
skipping to change at line 3445 skipping to change at line 3269
* B>A will result in positive length returned * B>A will result in positive length returned
* B<A will result in negative length returned * B<A will result in negative length returned
RESULT: RESULT:
length of arc starting at T=A and ending at T=B. length of arc starting at T=A and ending at T=B.
-- ALGLIB PROJECT -- -- ALGLIB PROJECT --
Copyright 30.05.2010 by Bochkanov Sergey Copyright 30.05.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
double pspline3arclength(const pspline3interpolant &p, const double a, cons t double b); double pspline3arclength(const pspline3interpolant &p, const double a, cons t double b);
}
///////////////////////////////////////////////////////////////////////// /*************************************************************************
// This subroutine builds bilinear spline coefficients table.
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
// Input parameters:
///////////////////////////////////////////////////////////////////////// X - spline abscissas, array[0..N-1]
namespace alglib_impl Y - spline ordinates, array[0..M-1]
{ F - function values, array[0..M-1,0..N-1]
void polynomialfit(/* Real */ ae_vector* x, M,N - grid size, M>=2, N>=2
/* Real */ ae_vector* y,
ae_int_t n, Output parameters:
ae_int_t m, C - spline interpolant
ae_int_t* info,
barycentricinterpolant* p, -- ALGLIB PROJECT --
polynomialfitreport* rep, Copyright 05.07.2007 by Bochkanov Sergey
ae_state *_state); *************************************************************************/
void polynomialfitwc(/* Real */ ae_vector* x, void spline2dbuildbilinear(const real_1d_array &x, const real_1d_array &y,
/* Real */ ae_vector* y, const real_2d_array &f, const ae_int_t m, const ae_int_t n, spline2dinterpo
/* Real */ ae_vector* w, lant &c);
ae_int_t n,
/* Real */ ae_vector* xc, /*************************************************************************
/* Real */ ae_vector* yc, This subroutine builds bicubic spline coefficients table.
/* Integer */ ae_vector* dc,
ae_int_t k, Input parameters:
ae_int_t m, X - spline abscissas, array[0..N-1]
ae_int_t* info, Y - spline ordinates, array[0..M-1]
barycentricinterpolant* p, F - function values, array[0..M-1,0..N-1]
polynomialfitreport* rep, M,N - grid size, M>=2, N>=2
ae_state *_state);
void barycentricfitfloaterhormannwc(/* Real */ ae_vector* x, Output parameters:
/* Real */ ae_vector* y, C - spline interpolant
/* Real */ ae_vector* w,
ae_int_t n, -- ALGLIB PROJECT --
/* Real */ ae_vector* xc, Copyright 05.07.2007 by Bochkanov Sergey
/* Real */ ae_vector* yc, *************************************************************************/
/* Integer */ ae_vector* dc, void spline2dbuildbicubic(const real_1d_array &x, const real_1d_array &y, c
ae_int_t k, onst real_2d_array &f, const ae_int_t m, const ae_int_t n, spline2dinterpol
ae_int_t m, ant &c);
ae_int_t* info,
barycentricinterpolant* b, /*************************************************************************
barycentricfitreport* rep, This subroutine calculates the value of the bilinear or bicubic spline at
ae_state *_state); the given point X.
void barycentricfitfloaterhormann(/* Real */ ae_vector* x,
/* Real */ ae_vector* y, Input parameters:
ae_int_t n, C - coefficients table.
ae_int_t m, Built by BuildBilinearSpline or BuildBicubicSpline.
ae_int_t* info, X, Y- point
barycentricinterpolant* b,
barycentricfitreport* rep, Result:
ae_state *_state); S(x,y)
void spline1dfitpenalized(/* Real */ ae_vector* x,
/* Real */ ae_vector* y, -- ALGLIB PROJECT --
ae_int_t n, Copyright 05.07.2007 by Bochkanov Sergey
ae_int_t m, *************************************************************************/
double rho, double spline2dcalc(const spline2dinterpolant &c, const double x, const dou
ae_int_t* info, ble y);
spline1dinterpolant* s,
spline1dfitreport* rep, /*************************************************************************
ae_state *_state); This subroutine calculates the value of the bilinear or bicubic spline at
void spline1dfitpenalizedw(/* Real */ ae_vector* x, the given point X and its derivatives.
/* Real */ ae_vector* y,
/* Real */ ae_vector* w, Input parameters:
ae_int_t n, C - spline interpolant.
ae_int_t m, X, Y- point
double rho,
ae_int_t* info, Output parameters:
spline1dinterpolant* s, F - S(x,y)
spline1dfitreport* rep, FX - dS(x,y)/dX
ae_state *_state); FY - dS(x,y)/dY
void spline1dfitcubicwc(/* Real */ ae_vector* x, FXY - d2S(x,y)/dXdY
/* Real */ ae_vector* y,
/* Real */ ae_vector* w, -- ALGLIB PROJECT --
ae_int_t n, Copyright 05.07.2007 by Bochkanov Sergey
/* Real */ ae_vector* xc, *************************************************************************/
/* Real */ ae_vector* yc, void spline2ddiff(const spline2dinterpolant &c, const double x, const doubl
/* Integer */ ae_vector* dc, e y, double &f, double &fx, double &fy, double &fxy);
ae_int_t k,
ae_int_t m, /*************************************************************************
ae_int_t* info, This subroutine unpacks two-dimensional spline into the coefficients table
spline1dinterpolant* s,
spline1dfitreport* rep, Input parameters:
ae_state *_state); C - spline interpolant.
void spline1dfithermitewc(/* Real */ ae_vector* x,
/* Real */ ae_vector* y, Result:
/* Real */ ae_vector* w, M, N- grid size (x-axis and y-axis)
ae_int_t n, Tbl - coefficients table, unpacked format,
/* Real */ ae_vector* xc, [0..(N-1)*(M-1)-1, 0..19].
/* Real */ ae_vector* yc, For I = 0...M-2, J=0..N-2:
/* Integer */ ae_vector* dc, K = I*(N-1)+J
ae_int_t k, Tbl[K,0] = X[j]
ae_int_t m, Tbl[K,1] = X[j+1]
ae_int_t* info, Tbl[K,2] = Y[i]
spline1dinterpolant* s, Tbl[K,3] = Y[i+1]
spline1dfitreport* rep, Tbl[K,4] = C00
ae_state *_state); Tbl[K,5] = C01
void spline1dfitcubic(/* Real */ ae_vector* x, Tbl[K,6] = C02
/* Real */ ae_vector* y, Tbl[K,7] = C03
ae_int_t n, Tbl[K,8] = C10
ae_int_t m, Tbl[K,9] = C11
ae_int_t* info, ...
spline1dinterpolant* s, Tbl[K,19] = C33
spline1dfitreport* rep, On each grid square spline is equals to:
ae_state *_state); S(x) = SUM(c[i,j]*(x^i)*(y^j), i=0..3, j=0..3)
void spline1dfithermite(/* Real */ ae_vector* x, t = x-x[j]
/* Real */ ae_vector* y, u = y-y[i]
ae_int_t n,
ae_int_t m, -- ALGLIB PROJECT --
ae_int_t* info, Copyright 29.06.2007 by Bochkanov Sergey
spline1dinterpolant* s, *************************************************************************/
spline1dfitreport* rep, void spline2dunpack(const spline2dinterpolant &c, ae_int_t &m, ae_int_t &n,
ae_state *_state); real_2d_array &tbl);
void lsfitlinearw(/* Real */ ae_vector* y,
/* Real */ ae_vector* w, /*************************************************************************
/* Real */ ae_matrix* fmatrix, This subroutine performs linear transformation of the spline argument.
ae_int_t n,
ae_int_t m, Input parameters:
ae_int_t* info, C - spline interpolant
/* Real */ ae_vector* c, AX, BX - transformation coefficients: x = A*t + B
lsfitreport* rep, AY, BY - transformation coefficients: y = A*u + B
ae_state *_state); Result:
void lsfitlinearwc(/* Real */ ae_vector* y, C - transformed spline
/* Real */ ae_vector* w,
/* Real */ ae_matrix* fmatrix, -- ALGLIB PROJECT --
/* Real */ ae_matrix* cmatrix, Copyright 30.06.2007 by Bochkanov Sergey
ae_int_t n, *************************************************************************/
ae_int_t m, void spline2dlintransxy(const spline2dinterpolant &c, const double ax, cons
ae_int_t k, t double bx, const double ay, const double by);
ae_int_t* info,
/* Real */ ae_vector* c, /*************************************************************************
lsfitreport* rep, This subroutine performs linear transformation of the spline.
ae_state *_state);
void lsfitlinear(/* Real */ ae_vector* y, Input parameters:
/* Real */ ae_matrix* fmatrix, C - spline interpolant.
ae_int_t n, A, B- transformation coefficients: S2(x,y) = A*S(x,y) + B
ae_int_t m,
ae_int_t* info, Output parameters:
/* Real */ ae_vector* c, C - transformed spline
lsfitreport* rep,
ae_state *_state); -- ALGLIB PROJECT --
void lsfitlinearc(/* Real */ ae_vector* y, Copyright 30.06.2007 by Bochkanov Sergey
/* Real */ ae_matrix* fmatrix, *************************************************************************/
/* Real */ ae_matrix* cmatrix, void spline2dlintransf(const spline2dinterpolant &c, const double a, const
ae_int_t n, double b);
ae_int_t m,
ae_int_t k, /*************************************************************************
ae_int_t* info, Bicubic spline resampling
/* Real */ ae_vector* c,
lsfitreport* rep, Input parameters:
ae_state *_state); A - function values at the old grid,
void lsfitcreatewf(/* Real */ ae_matrix* x, array[0..OldHeight-1, 0..OldWidth-1]
/* Real */ ae_vector* y, OldHeight - old grid height, OldHeight>1
/* Real */ ae_vector* w, OldWidth - old grid width, OldWidth>1
/* Real */ ae_vector* c, NewHeight - new grid height, NewHeight>1
ae_int_t n, NewWidth - new grid width, NewWidth>1
ae_int_t m,
ae_int_t k, Output parameters:
double diffstep, B - function values at the new grid,
lsfitstate* state, array[0..NewHeight-1, 0..NewWidth-1]
ae_state *_state);
void lsfitcreatef(/* Real */ ae_matrix* x, -- ALGLIB routine --
/* Real */ ae_vector* y, 15 May, 2007
/* Real */ ae_vector* c, Copyright by Bochkanov Sergey
ae_int_t n, *************************************************************************/
ae_int_t m, void spline2dresamplebicubic(const real_2d_array &a, const ae_int_t oldheig
ae_int_t k, ht, const ae_int_t oldwidth, real_2d_array &b, const ae_int_t newheight, co
double diffstep, nst ae_int_t newwidth);
lsfitstate* state,
ae_state *_state); /*************************************************************************
void lsfitcreatewfg(/* Real */ ae_matrix* x, Bilinear spline resampling
/* Real */ ae_vector* y,
/* Real */ ae_vector* w, Input parameters:
/* Real */ ae_vector* c, A - function values at the old grid,
ae_int_t n, array[0..OldHeight-1, 0..OldWidth-1]
ae_int_t m, OldHeight - old grid height, OldHeight>1
ae_int_t k, OldWidth - old grid width, OldWidth>1
ae_bool cheapfg, NewHeight - new grid height, NewHeight>1
lsfitstate* state, NewWidth - new grid width, NewWidth>1
ae_state *_state);
void lsfitcreatefg(/* Real */ ae_matrix* x, Output parameters:
/* Real */ ae_vector* y, B - function values at the new grid,
/* Real */ ae_vector* c, array[0..NewHeight-1, 0..NewWidth-1]
ae_int_t n,
ae_int_t m, -- ALGLIB routine --
ae_int_t k, 09.07.2007
ae_bool cheapfg, Copyright by Bochkanov Sergey
lsfitstate* state, *************************************************************************/
void spline2dresamplebilinear(const real_2d_array &a, const ae_int_t oldhei
ght, const ae_int_t oldwidth, real_2d_array &b, const ae_int_t newheight, c
onst ae_int_t newwidth);
}
/////////////////////////////////////////////////////////////////////////
//
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
//
/////////////////////////////////////////////////////////////////////////
namespace alglib_impl
{
double idwcalc(idwinterpolant* z,
/* Real */ ae_vector* x,
ae_state *_state); ae_state *_state);
void lsfitcreatewfgh(/* Real */ ae_matrix* x, void idwbuildmodifiedshepard(/* Real */ ae_matrix* xy,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
/* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
ae_int_t m, ae_int_t nx,
ae_int_t k, ae_int_t d,
lsfitstate* state, ae_int_t nq,
ae_int_t nw,
idwinterpolant* z,
ae_state *_state); ae_state *_state);
void lsfitcreatefgh(/* Real */ ae_matrix* x, void idwbuildmodifiedshepardr(/* Real */ ae_matrix* xy,
/* Real */ ae_vector* y,
/* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
ae_int_t m, ae_int_t nx,
ae_int_t k, double r,
lsfitstate* state, idwinterpolant* z,
ae_state *_state);
void lsfitsetcond(lsfitstate* state,
double epsf,
double epsx,
ae_int_t maxits,
ae_state *_state);
void lsfitsetstpmax(lsfitstate* state, double stpmax, ae_state *_state);
void lsfitsetxrep(lsfitstate* state, ae_bool needxrep, ae_state *_state);
ae_bool lsfititeration(lsfitstate* state, ae_state *_state);
void lsfitresults(lsfitstate* state,
ae_int_t* info,
/* Real */ ae_vector* c,
lsfitreport* rep,
ae_state *_state); ae_state *_state);
void lsfitscalexy(/* Real */ ae_vector* x, void idwbuildnoisy(/* Real */ ae_matrix* xy,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
ae_int_t n, ae_int_t n,
/* Real */ ae_vector* xc, ae_int_t nx,
/* Real */ ae_vector* yc, ae_int_t d,
/* Integer */ ae_vector* dc, ae_int_t nq,
ae_int_t k, ae_int_t nw,
double* xa, idwinterpolant* z,
double* xb,
double* sa,
double* sb,
/* Real */ ae_vector* xoriginal,
/* Real */ ae_vector* yoriginal,
ae_state *_state); ae_state *_state);
ae_bool _polynomialfitreport_init(polynomialfitreport* p, ae_state *_state, ae_bool _idwinterpolant_init(idwinterpolant* p, ae_state *_state, ae_bool m
ae_bool make_automatic); ake_automatic);
ae_bool _polynomialfitreport_init_copy(polynomialfitreport* dst, polynomial ae_bool _idwinterpolant_init_copy(idwinterpolant* dst, idwinterpolant* src,
fitreport* src, ae_state *_state, ae_bool make_automatic); ae_state *_state, ae_bool make_automatic);
void _polynomialfitreport_clear(polynomialfitreport* p); void _idwinterpolant_clear(idwinterpolant* p);
ae_bool _barycentricfitreport_init(barycentricfitreport* p, ae_state *_stat
e, ae_bool make_automatic);
ae_bool _barycentricfitreport_init_copy(barycentricfitreport* dst, barycent
ricfitreport* src, ae_state *_state, ae_bool make_automatic);
void _barycentricfitreport_clear(barycentricfitreport* p);
ae_bool _spline1dfitreport_init(spline1dfitreport* p, ae_state *_state, ae_
bool make_automatic);
ae_bool _spline1dfitreport_init_copy(spline1dfitreport* dst, spline1dfitrep
ort* src, ae_state *_state, ae_bool make_automatic);
void _spline1dfitreport_clear(spline1dfitreport* p);
ae_bool _lsfitreport_init(lsfitreport* p, ae_state *_state, ae_bool make_au
tomatic);
ae_bool _lsfitreport_init_copy(lsfitreport* dst, lsfitreport* src, ae_state
*_state, ae_bool make_automatic);
void _lsfitreport_clear(lsfitreport* p);
ae_bool _lsfitstate_init(lsfitstate* p, ae_state *_state, ae_bool make_auto
matic);
ae_bool _lsfitstate_init_copy(lsfitstate* dst, lsfitstate* src, ae_state *_
state, ae_bool make_automatic);
void _lsfitstate_clear(lsfitstate* p);
double barycentriccalc(barycentricinterpolant* b, double barycentriccalc(barycentricinterpolant* b,
double t, double t,
ae_state *_state); ae_state *_state);
void barycentricdiff1(barycentricinterpolant* b, void barycentricdiff1(barycentricinterpolant* b,
double t, double t,
double* f, double* f,
double* df, double* df,
ae_state *_state); ae_state *_state);
void barycentricdiff2(barycentricinterpolant* b, void barycentricdiff2(barycentricinterpolant* b,
double t, double t,
skipping to change at line 3911 skipping to change at line 3700
/* Real */ ae_matrix* tbl, /* Real */ ae_matrix* tbl,
ae_state *_state); ae_state *_state);
void spline1dlintransx(spline1dinterpolant* c, void spline1dlintransx(spline1dinterpolant* c,
double a, double a,
double b, double b,
ae_state *_state); ae_state *_state);
void spline1dlintransy(spline1dinterpolant* c, void spline1dlintransy(spline1dinterpolant* c,
double a, double a,
double b, double b,
ae_state *_state); ae_state *_state);
double spline1dintegrate(spline1dinterpolant* c, double spline1dintegrate(spline1dinterpolant* c,
double x, double x,
ae_state *_state);
void spline1dconvdiffinternal(/* Real */ ae_vector* xold,
/* Real */ ae_vector* yold,
/* Real */ ae_vector* dold,
ae_int_t n,
/* Real */ ae_vector* x2,
ae_int_t n2,
/* Real */ ae_vector* y,
ae_bool needy,
/* Real */ ae_vector* d1,
ae_bool needd1,
/* Real */ ae_vector* d2,
ae_bool needd2,
ae_state *_state);
void heapsortdpoints(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* d,
ae_int_t n,
ae_state *_state);
ae_bool _spline1dinterpolant_init(spline1dinterpolant* p, ae_state *_state,
ae_bool make_automatic);
ae_bool _spline1dinterpolant_init_copy(spline1dinterpolant* dst, spline1din
terpolant* src, ae_state *_state, ae_bool make_automatic);
void _spline1dinterpolant_clear(spline1dinterpolant* p);
void polynomialfit(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_int_t n,
ae_int_t m,
ae_int_t* info,
barycentricinterpolant* p,
polynomialfitreport* rep,
ae_state *_state);
void polynomialfitwc(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
ae_int_t n,
/* Real */ ae_vector* xc,
/* Real */ ae_vector* yc,
/* Integer */ ae_vector* dc,
ae_int_t k,
ae_int_t m,
ae_int_t* info,
barycentricinterpolant* p,
polynomialfitreport* rep,
ae_state *_state);
void barycentricfitfloaterhormannwc(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
ae_int_t n,
/* Real */ ae_vector* xc,
/* Real */ ae_vector* yc,
/* Integer */ ae_vector* dc,
ae_int_t k,
ae_int_t m,
ae_int_t* info,
barycentricinterpolant* b,
barycentricfitreport* rep,
ae_state *_state);
void barycentricfitfloaterhormann(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_int_t n,
ae_int_t m,
ae_int_t* info,
barycentricinterpolant* b,
barycentricfitreport* rep,
ae_state *_state);
void spline1dfitpenalized(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_int_t n,
ae_int_t m,
double rho,
ae_int_t* info,
spline1dinterpolant* s,
spline1dfitreport* rep,
ae_state *_state);
void spline1dfitpenalizedw(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
ae_int_t n,
ae_int_t m,
double rho,
ae_int_t* info,
spline1dinterpolant* s,
spline1dfitreport* rep,
ae_state *_state);
void spline1dfitcubicwc(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
ae_int_t n,
/* Real */ ae_vector* xc,
/* Real */ ae_vector* yc,
/* Integer */ ae_vector* dc,
ae_int_t k,
ae_int_t m,
ae_int_t* info,
spline1dinterpolant* s,
spline1dfitreport* rep,
ae_state *_state);
void spline1dfithermitewc(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
ae_int_t n,
/* Real */ ae_vector* xc,
/* Real */ ae_vector* yc,
/* Integer */ ae_vector* dc,
ae_int_t k,
ae_int_t m,
ae_int_t* info,
spline1dinterpolant* s,
spline1dfitreport* rep,
ae_state *_state);
void spline1dfitcubic(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_int_t n,
ae_int_t m,
ae_int_t* info,
spline1dinterpolant* s,
spline1dfitreport* rep,
ae_state *_state);
void spline1dfithermite(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
ae_int_t n,
ae_int_t m,
ae_int_t* info,
spline1dinterpolant* s,
spline1dfitreport* rep,
ae_state *_state);
void lsfitlinearw(/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
/* Real */ ae_matrix* fmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t* info,
/* Real */ ae_vector* c,
lsfitreport* rep,
ae_state *_state);
void lsfitlinearwc(/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
/* Real */ ae_matrix* fmatrix,
/* Real */ ae_matrix* cmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t k,
ae_int_t* info,
/* Real */ ae_vector* c,
lsfitreport* rep,
ae_state *_state);
void lsfitlinear(/* Real */ ae_vector* y,
/* Real */ ae_matrix* fmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t* info,
/* Real */ ae_vector* c,
lsfitreport* rep,
ae_state *_state); ae_state *_state);
void spline1dconvdiffinternal(/* Real */ ae_vector* xold, void lsfitlinearc(/* Real */ ae_vector* y,
/* Real */ ae_vector* yold, /* Real */ ae_matrix* fmatrix,
/* Real */ ae_vector* dold, /* Real */ ae_matrix* cmatrix,
ae_int_t n, ae_int_t n,
/* Real */ ae_vector* x2, ae_int_t m,
ae_int_t n2, ae_int_t k,
/* Real */ ae_vector* y, ae_int_t* info,
ae_bool needy, /* Real */ ae_vector* c,
/* Real */ ae_vector* d1, lsfitreport* rep,
ae_bool needd1,
/* Real */ ae_vector* d2,
ae_bool needd2,
ae_state *_state); ae_state *_state);
void heapsortdpoints(/* Real */ ae_vector* x, void lsfitcreatewf(/* Real */ ae_matrix* x,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
/* Real */ ae_vector* d, /* Real */ ae_vector* w,
/* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
ae_int_t m,
ae_int_t k,
double diffstep,
lsfitstate* state,
ae_state *_state); ae_state *_state);
ae_bool _spline1dinterpolant_init(spline1dinterpolant* p, ae_state *_state, void lsfitcreatef(/* Real */ ae_matrix* x,
ae_bool make_automatic);
ae_bool _spline1dinterpolant_init_copy(spline1dinterpolant* dst, spline1din
terpolant* src, ae_state *_state, ae_bool make_automatic);
void _spline1dinterpolant_clear(spline1dinterpolant* p);
void spline2dbuildbilinear(/* Real */ ae_vector* x,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
/* Real */ ae_matrix* f, /* Real */ ae_vector* c,
ae_int_t m,
ae_int_t n, ae_int_t n,
spline2dinterpolant* c, ae_int_t m,
ae_int_t k,
double diffstep,
lsfitstate* state,
ae_state *_state); ae_state *_state);
void spline2dbuildbicubic(/* Real */ ae_vector* x, void lsfitcreatewfg(/* Real */ ae_matrix* x,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
/* Real */ ae_matrix* f, /* Real */ ae_vector* w,
ae_int_t m, /* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
spline2dinterpolant* c, ae_int_t m,
ae_state *_state); ae_int_t k,
double spline2dcalc(spline2dinterpolant* c, ae_bool cheapfg,
double x, lsfitstate* state,
double y,
ae_state *_state);
void spline2ddiff(spline2dinterpolant* c,
double x,
double y,
double* f,
double* fx,
double* fy,
double* fxy,
ae_state *_state);
void spline2dunpack(spline2dinterpolant* c,
ae_int_t* m,
ae_int_t* n,
/* Real */ ae_matrix* tbl,
ae_state *_state);
void spline2dlintransxy(spline2dinterpolant* c,
double ax,
double bx,
double ay,
double by,
ae_state *_state);
void spline2dlintransf(spline2dinterpolant* c,
double a,
double b,
ae_state *_state);
void spline2dcopy(spline2dinterpolant* c,
spline2dinterpolant* cc,
ae_state *_state);
void spline2dresamplebicubic(/* Real */ ae_matrix* a,
ae_int_t oldheight,
ae_int_t oldwidth,
/* Real */ ae_matrix* b,
ae_int_t newheight,
ae_int_t newwidth,
ae_state *_state);
void spline2dresamplebilinear(/* Real */ ae_matrix* a,
ae_int_t oldheight,
ae_int_t oldwidth,
/* Real */ ae_matrix* b,
ae_int_t newheight,
ae_int_t newwidth,
ae_state *_state); ae_state *_state);
ae_bool _spline2dinterpolant_init(spline2dinterpolant* p, ae_state *_state, void lsfitcreatefg(/* Real */ ae_matrix* x,
ae_bool make_automatic); /* Real */ ae_vector* y,
ae_bool _spline2dinterpolant_init_copy(spline2dinterpolant* dst, spline2din /* Real */ ae_vector* c,
terpolant* src, ae_state *_state, ae_bool make_automatic); ae_int_t n,
void _spline2dinterpolant_clear(spline2dinterpolant* p); ae_int_t m,
double idwcalc(idwinterpolant* z, ae_int_t k,
/* Real */ ae_vector* x, ae_bool cheapfg,
lsfitstate* state,
ae_state *_state); ae_state *_state);
void idwbuildmodifiedshepard(/* Real */ ae_matrix* xy, void lsfitcreatewfgh(/* Real */ ae_matrix* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
/* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
ae_int_t nx, ae_int_t m,
ae_int_t d, ae_int_t k,
ae_int_t nq, lsfitstate* state,
ae_int_t nw,
idwinterpolant* z,
ae_state *_state); ae_state *_state);
void idwbuildmodifiedshepardr(/* Real */ ae_matrix* xy, void lsfitcreatefgh(/* Real */ ae_matrix* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
ae_int_t nx, ae_int_t m,
double r, ae_int_t k,
idwinterpolant* z, lsfitstate* state,
ae_state *_state); ae_state *_state);
void idwbuildnoisy(/* Real */ ae_matrix* xy, void lsfitsetcond(lsfitstate* state,
double epsf,
double epsx,
ae_int_t maxits,
ae_state *_state);
void lsfitsetstpmax(lsfitstate* state, double stpmax, ae_state *_state);
void lsfitsetxrep(lsfitstate* state, ae_bool needxrep, ae_state *_state);
ae_bool lsfititeration(lsfitstate* state, ae_state *_state);
void lsfitresults(lsfitstate* state,
ae_int_t* info,
/* Real */ ae_vector* c,
lsfitreport* rep,
ae_state *_state);
void lsfitscalexy(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_vector* w,
ae_int_t n, ae_int_t n,
ae_int_t nx, /* Real */ ae_vector* xc,
ae_int_t d, /* Real */ ae_vector* yc,
ae_int_t nq, /* Integer */ ae_vector* dc,
ae_int_t nw, ae_int_t k,
idwinterpolant* z, double* xa,
double* xb,
double* sa,
double* sb,
/* Real */ ae_vector* xoriginal,
/* Real */ ae_vector* yoriginal,
ae_state *_state); ae_state *_state);
ae_bool _idwinterpolant_init(idwinterpolant* p, ae_state *_state, ae_bool m ae_bool _polynomialfitreport_init(polynomialfitreport* p, ae_state *_state,
ake_automatic); ae_bool make_automatic);
ae_bool _idwinterpolant_init_copy(idwinterpolant* dst, idwinterpolant* src, ae_bool _polynomialfitreport_init_copy(polynomialfitreport* dst, polynomial
ae_state *_state, ae_bool make_automatic); fitreport* src, ae_state *_state, ae_bool make_automatic);
void _idwinterpolant_clear(idwinterpolant* p); void _polynomialfitreport_clear(polynomialfitreport* p);
ae_bool _barycentricfitreport_init(barycentricfitreport* p, ae_state *_stat
e, ae_bool make_automatic);
ae_bool _barycentricfitreport_init_copy(barycentricfitreport* dst, barycent
ricfitreport* src, ae_state *_state, ae_bool make_automatic);
void _barycentricfitreport_clear(barycentricfitreport* p);
ae_bool _spline1dfitreport_init(spline1dfitreport* p, ae_state *_state, ae_
bool make_automatic);
ae_bool _spline1dfitreport_init_copy(spline1dfitreport* dst, spline1dfitrep
ort* src, ae_state *_state, ae_bool make_automatic);
void _spline1dfitreport_clear(spline1dfitreport* p);
ae_bool _lsfitreport_init(lsfitreport* p, ae_state *_state, ae_bool make_au
tomatic);
ae_bool _lsfitreport_init_copy(lsfitreport* dst, lsfitreport* src, ae_state
*_state, ae_bool make_automatic);
void _lsfitreport_clear(lsfitreport* p);
ae_bool _lsfitstate_init(lsfitstate* p, ae_state *_state, ae_bool make_auto
matic);
ae_bool _lsfitstate_init_copy(lsfitstate* dst, lsfitstate* src, ae_state *_
state, ae_bool make_automatic);
void _lsfitstate_clear(lsfitstate* p);
void pspline2build(/* Real */ ae_matrix* xy, void pspline2build(/* Real */ ae_matrix* xy,
ae_int_t n, ae_int_t n,
ae_int_t st, ae_int_t st,
ae_int_t pt, ae_int_t pt,
pspline2interpolant* p, pspline2interpolant* p,
ae_state *_state); ae_state *_state);
void pspline3build(/* Real */ ae_matrix* xy, void pspline3build(/* Real */ ae_matrix* xy,
ae_int_t n, ae_int_t n,
ae_int_t st, ae_int_t st,
ae_int_t pt, ae_int_t pt,
skipping to change at line 4129 skipping to change at line 4068
double pspline3arclength(pspline3interpolant* p, double pspline3arclength(pspline3interpolant* p,
double a, double a,
double b, double b,
ae_state *_state); ae_state *_state);
ae_bool _pspline2interpolant_init(pspline2interpolant* p, ae_state *_state, ae_bool make_automatic); ae_bool _pspline2interpolant_init(pspline2interpolant* p, ae_state *_state, ae_bool make_automatic);
ae_bool _pspline2interpolant_init_copy(pspline2interpolant* dst, pspline2in terpolant* src, ae_state *_state, ae_bool make_automatic); ae_bool _pspline2interpolant_init_copy(pspline2interpolant* dst, pspline2in terpolant* src, ae_state *_state, ae_bool make_automatic);
void _pspline2interpolant_clear(pspline2interpolant* p); void _pspline2interpolant_clear(pspline2interpolant* p);
ae_bool _pspline3interpolant_init(pspline3interpolant* p, ae_state *_state, ae_bool make_automatic); ae_bool _pspline3interpolant_init(pspline3interpolant* p, ae_state *_state, ae_bool make_automatic);
ae_bool _pspline3interpolant_init_copy(pspline3interpolant* dst, pspline3in terpolant* src, ae_state *_state, ae_bool make_automatic); ae_bool _pspline3interpolant_init_copy(pspline3interpolant* dst, pspline3in terpolant* src, ae_state *_state, ae_bool make_automatic);
void _pspline3interpolant_clear(pspline3interpolant* p); void _pspline3interpolant_clear(pspline3interpolant* p);
void spline2dbuildbilinear(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_matrix* f,
ae_int_t m,
ae_int_t n,
spline2dinterpolant* c,
ae_state *_state);
void spline2dbuildbicubic(/* Real */ ae_vector* x,
/* Real */ ae_vector* y,
/* Real */ ae_matrix* f,
ae_int_t m,
ae_int_t n,
spline2dinterpolant* c,
ae_state *_state);
double spline2dcalc(spline2dinterpolant* c,
double x,
double y,
ae_state *_state);
void spline2ddiff(spline2dinterpolant* c,
double x,
double y,
double* f,
double* fx,
double* fy,
double* fxy,
ae_state *_state);
void spline2dunpack(spline2dinterpolant* c,
ae_int_t* m,
ae_int_t* n,
/* Real */ ae_matrix* tbl,
ae_state *_state);
void spline2dlintransxy(spline2dinterpolant* c,
double ax,
double bx,
double ay,
double by,
ae_state *_state);
void spline2dlintransf(spline2dinterpolant* c,
double a,
double b,
ae_state *_state);
void spline2dcopy(spline2dinterpolant* c,
spline2dinterpolant* cc,
ae_state *_state);
void spline2dresamplebicubic(/* Real */ ae_matrix* a,
ae_int_t oldheight,
ae_int_t oldwidth,
/* Real */ ae_matrix* b,
ae_int_t newheight,
ae_int_t newwidth,
ae_state *_state);
void spline2dresamplebilinear(/* Real */ ae_matrix* a,
ae_int_t oldheight,
ae_int_t oldwidth,
/* Real */ ae_matrix* b,
ae_int_t newheight,
ae_int_t newwidth,
ae_state *_state);
ae_bool _spline2dinterpolant_init(spline2dinterpolant* p, ae_state *_state,
ae_bool make_automatic);
ae_bool _spline2dinterpolant_init_copy(spline2dinterpolant* dst, spline2din
terpolant* src, ae_state *_state, ae_bool make_automatic);
void _spline2dinterpolant_clear(spline2dinterpolant* p);
} }
#endif #endif
 End of changes. 455 change blocks. 
2696 lines changed or deleted 2704 lines changed or added


 linalg.h   linalg.h 
skipping to change at line 1172 skipping to change at line 1172
Finding the eigenvalues and eigenvectors of a symmetric matrix Finding the eigenvalues and eigenvectors of a symmetric matrix
The algorithm finds eigen pairs of a symmetric matrix by reducing it to The algorithm finds eigen pairs of a symmetric matrix by reducing it to
tridiagonal form and using the QL/QR algorithm. tridiagonal form and using the QL/QR algorithm.
Input parameters: Input parameters:
A - symmetric matrix which is given by its upper or lower A - symmetric matrix which is given by its upper or lower
triangular part. triangular part.
Array whose indexes range within [0..N-1, 0..N-1]. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A. N - size of matrix A.
IsUpper - storage format.
ZNeeded - flag controlling whether the eigenvectors are needed or not . ZNeeded - flag controlling whether the eigenvectors are needed or not .
If ZNeeded is equal to: If ZNeeded is equal to:
* 0, the eigenvectors are not returned; * 0, the eigenvectors are not returned;
* 1, the eigenvectors are returned. * 1, the eigenvectors are returned.
IsUpper - storage format.
Output parameters: Output parameters:
D - eigenvalues in ascending order. D - eigenvalues in ascending order.
Array whose index ranges within [0..N-1]. Array whose index ranges within [0..N-1].
Z - if ZNeeded is equal to: Z - if ZNeeded is equal to:
* 0, Z hasn * 0, Z hasn
* 1, Z contains the eigenvectors. * 1, Z contains the eigenvectors.
Array whose indexes range within [0..N-1, 0..N-1]. Array whose indexes range within [0..N-1, 0..N-1].
The eigenvectors are stored in the matrix columns. The eigenvectors are stored in the matrix columns.
 End of changes. 2 change blocks. 
1 lines changed or deleted 1 lines changed or added


 optimization.h   optimization.h 
skipping to change at line 156 skipping to change at line 156
ae_int_t nhess; ae_int_t nhess;
ae_int_t ncholesky; ae_int_t ncholesky;
} minlmreport; } minlmreport;
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t n;
double epsg; double epsg;
double epsf; double epsf;
double epsx; double epsx;
ae_int_t maxits; ae_int_t maxits;
double stpmax;
ae_bool xrep; ae_bool xrep;
double stpmax;
ae_int_t cgtype; ae_int_t cgtype;
ae_int_t k;
ae_int_t nfev; ae_int_t nfev;
ae_int_t mcstage; ae_int_t mcstage;
ae_int_t k; ae_vector bndl;
ae_vector bndu;
ae_int_t curalgo;
ae_int_t acount;
double mu;
double finit;
double dginit;
ae_vector ak;
ae_vector xk; ae_vector xk;
ae_vector dk; ae_vector dk;
ae_vector an;
ae_vector xn; ae_vector xn;
ae_vector dn; ae_vector dn;
ae_vector d; ae_vector d;
double fold; double fold;
double stp; double stp;
ae_vector work; ae_vector work;
ae_vector yk; ae_vector yk;
ae_vector gc;
double laststep; double laststep;
ae_vector x; ae_vector x;
double f; double f;
ae_vector g; ae_vector g;
ae_bool needfg; ae_bool needfg;
ae_bool xupdated; ae_bool xupdated;
rcommstate rstate; rcommstate rstate;
ae_int_t repiterationscount; ae_int_t repiterationscount;
ae_int_t repnfev; ae_int_t repnfev;
ae_int_t repterminationtype; ae_int_t repterminationtype;
ae_int_t debugrestartscount; ae_int_t debugrestartscount;
linminstate lstate; linminstate lstate;
double betahs; double betahs;
double betady; double betady;
} mincgstate; } minasastate;
typedef struct typedef struct
{ {
ae_int_t iterationscount; ae_int_t iterationscount;
ae_int_t nfev; ae_int_t nfev;
ae_int_t terminationtype; ae_int_t terminationtype;
} mincgreport; ae_int_t activeconstraints;
} minasareport;
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t n;
double epsg; double epsg;
double epsf; double epsf;
double epsx; double epsx;
ae_int_t maxits; ae_int_t maxits;
ae_bool xrep;
double stpmax; double stpmax;
double suggestedstep;
ae_bool xrep;
ae_bool drep;
ae_int_t cgtype; ae_int_t cgtype;
ae_int_t k;
ae_int_t nfev; ae_int_t nfev;
ae_int_t mcstage; ae_int_t mcstage;
ae_vector bndl; ae_int_t k;
ae_vector bndu;
ae_int_t curalgo;
ae_int_t acount;
double mu;
double finit;
double dginit;
ae_vector ak;
ae_vector xk; ae_vector xk;
ae_vector dk; ae_vector dk;
ae_vector an;
ae_vector xn; ae_vector xn;
ae_vector dn; ae_vector dn;
ae_vector d; ae_vector d;
double fold; double fold;
double stp; double stp;
double curstpmax;
ae_vector work; ae_vector work;
ae_vector yk; ae_vector yk;
ae_vector gc;
double laststep; double laststep;
ae_int_t rstimer;
ae_vector x; ae_vector x;
double f; double f;
ae_vector g; ae_vector g;
ae_bool needfg; ae_bool needfg;
ae_bool xupdated; ae_bool xupdated;
ae_bool lsstart;
ae_bool lsend;
rcommstate rstate; rcommstate rstate;
ae_int_t repiterationscount; ae_int_t repiterationscount;
ae_int_t repnfev; ae_int_t repnfev;
ae_int_t repterminationtype; ae_int_t repterminationtype;
ae_int_t debugrestartscount; ae_int_t debugrestartscount;
linminstate lstate; linminstate lstate;
double betahs; double betahs;
double betady; double betady;
} minasastate; } mincgstate;
typedef struct typedef struct
{ {
ae_int_t iterationscount; ae_int_t iterationscount;
ae_int_t nfev; ae_int_t nfev;
ae_int_t terminationtype; ae_int_t terminationtype;
ae_int_t activeconstraints; } mincgreport;
} minasareport; typedef struct
{
ae_int_t n;
double innerepsg;
double innerepsf;
double innerepsx;
double outerepsx;
double outerepsi;
ae_int_t maxits;
ae_bool xrep;
double stpmax;
ae_int_t cgtype;
double mustart;
double mudecay;
ae_vector x;
double f;
ae_vector g;
ae_bool needfg;
ae_bool xupdated;
rcommstate rstate;
ae_int_t repinneriterationscount;
ae_int_t repouteriterationscount;
ae_int_t repnfev;
ae_int_t repterminationtype;
double repdebugeqerr;
double repdebugfs;
double repdebugff;
double repdebugdx;
ae_vector xcur;
ae_vector xprev;
ae_vector xstart;
ae_int_t itsleft;
ae_int_t mucounter;
ae_matrix ce;
ae_matrix ci;
ae_matrix cebasis;
ae_matrix cesvl;
ae_vector xe;
ae_int_t cecnt;
ae_int_t cicnt;
ae_int_t cedim;
ae_vector bndl;
ae_vector hasbndl;
ae_vector bndu;
ae_vector hasbndu;
ae_vector lm;
ae_int_t lmcnt;
double mu;
ae_vector w;
ae_vector tmp0;
ae_vector tmp1;
ae_vector r;
double v0;
double v1;
double v2;
double t;
double errfeas;
double errslack;
double gnorm;
double mpgnorm;
double lmdif;
double lmnorm;
double lmgrowth;
double mba;
double boundary;
ae_bool closetobarrier;
double bndmax;
linminstate lstate;
mincgstate cgstate;
mincgreport cgrep;
} minbleicstate;
typedef struct
{
ae_int_t inneriterationscount;
ae_int_t outeriterationscount;
ae_int_t nfev;
ae_int_t terminationtype;
double debugeqerr;
double debugfs;
double debugff;
double debugdx;
} minbleicreport;
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS C++ INTERFACE // THIS SECTION CONTAINS C++ INTERFACE
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib namespace alglib
{ {
skipping to change at line 410 skipping to change at line 498
ae_int_t &njac; ae_int_t &njac;
ae_int_t &ngrad; ae_int_t &ngrad;
ae_int_t &nhess; ae_int_t &nhess;
ae_int_t &ncholesky; ae_int_t &ncholesky;
}; };
/************************************************************************* /*************************************************************************
*************************************************************************/ *************************************************************************/
class _minasastate_owner
{
public:
_minasastate_owner();
_minasastate_owner(const _minasastate_owner &rhs);
_minasastate_owner& operator=(const _minasastate_owner &rhs);
virtual ~_minasastate_owner();
alglib_impl::minasastate* c_ptr();
alglib_impl::minasastate* c_ptr() const;
protected:
alglib_impl::minasastate *p_struct;
};
class minasastate : public _minasastate_owner
{
public:
minasastate();
minasastate(const minasastate &rhs);
minasastate& operator=(const minasastate &rhs);
virtual ~minasastate();
ae_bool &needfg;
ae_bool &xupdated;
double &f;
real_1d_array g;
real_1d_array x;
};
/*************************************************************************
*************************************************************************/
class _minasareport_owner
{
public:
_minasareport_owner();
_minasareport_owner(const _minasareport_owner &rhs);
_minasareport_owner& operator=(const _minasareport_owner &rhs);
virtual ~_minasareport_owner();
alglib_impl::minasareport* c_ptr();
alglib_impl::minasareport* c_ptr() const;
protected:
alglib_impl::minasareport *p_struct;
};
class minasareport : public _minasareport_owner
{
public:
minasareport();
minasareport(const minasareport &rhs);
minasareport& operator=(const minasareport &rhs);
virtual ~minasareport();
ae_int_t &iterationscount;
ae_int_t &nfev;
ae_int_t &terminationtype;
ae_int_t &activeconstraints;
};
/*************************************************************************
This object stores state of the nonlinear CG optimizer.
You should use ALGLIB functions to work with this object.
*************************************************************************/
class _mincgstate_owner class _mincgstate_owner
{ {
public: public:
_mincgstate_owner(); _mincgstate_owner();
_mincgstate_owner(const _mincgstate_owner &rhs); _mincgstate_owner(const _mincgstate_owner &rhs);
_mincgstate_owner& operator=(const _mincgstate_owner &rhs); _mincgstate_owner& operator=(const _mincgstate_owner &rhs);
virtual ~_mincgstate_owner(); virtual ~_mincgstate_owner();
alglib_impl::mincgstate* c_ptr(); alglib_impl::mincgstate* c_ptr();
alglib_impl::mincgstate* c_ptr() const; alglib_impl::mincgstate* c_ptr() const;
protected: protected:
skipping to change at line 466 skipping to change at line 615
mincgreport(const mincgreport &rhs); mincgreport(const mincgreport &rhs);
mincgreport& operator=(const mincgreport &rhs); mincgreport& operator=(const mincgreport &rhs);
virtual ~mincgreport(); virtual ~mincgreport();
ae_int_t &iterationscount; ae_int_t &iterationscount;
ae_int_t &nfev; ae_int_t &nfev;
ae_int_t &terminationtype; ae_int_t &terminationtype;
}; };
/************************************************************************* /*************************************************************************
This object stores nonlinear optimizer state.
You should use functions provided by MinBLEIC subpackage to work with this
object
*************************************************************************/ *************************************************************************/
class _minasastate_owner class _minbleicstate_owner
{ {
public: public:
_minasastate_owner(); _minbleicstate_owner();
_minasastate_owner(const _minasastate_owner &rhs); _minbleicstate_owner(const _minbleicstate_owner &rhs);
_minasastate_owner& operator=(const _minasastate_owner &rhs); _minbleicstate_owner& operator=(const _minbleicstate_owner &rhs);
virtual ~_minasastate_owner(); virtual ~_minbleicstate_owner();
alglib_impl::minasastate* c_ptr(); alglib_impl::minbleicstate* c_ptr();
alglib_impl::minasastate* c_ptr() const; alglib_impl::minbleicstate* c_ptr() const;
protected: protected:
alglib_impl::minasastate *p_struct; alglib_impl::minbleicstate *p_struct;
}; };
class minasastate : public _minasastate_owner class minbleicstate : public _minbleicstate_owner
{ {
public: public:
minasastate(); minbleicstate();
minasastate(const minasastate &rhs); minbleicstate(const minbleicstate &rhs);
minasastate& operator=(const minasastate &rhs); minbleicstate& operator=(const minbleicstate &rhs);
virtual ~minasastate(); virtual ~minbleicstate();
ae_bool &needfg; ae_bool &needfg;
ae_bool &xupdated; ae_bool &xupdated;
double &f; double &f;
real_1d_array g; real_1d_array g;
real_1d_array x; real_1d_array x;
}; };
/************************************************************************* /*************************************************************************
This structure stores optimization report:
* InnerIterationsCount number of inner iterations
* OuterIterationsCount number of outer iterations
* NFEV number of gradient evaluations
There are additional fields which can be used for debugging:
* DebugEqErr error in the equality constraints (2-norm)
* DebugFS f, calculated at projection of initial point
to the feasible set
* DebugFF f, calculated at the final point
* DebugDX |X_start-X_final|
*************************************************************************/ *************************************************************************/
class _minasareport_owner class _minbleicreport_owner
{ {
public: public:
_minasareport_owner(); _minbleicreport_owner();
_minasareport_owner(const _minasareport_owner &rhs); _minbleicreport_owner(const _minbleicreport_owner &rhs);
_minasareport_owner& operator=(const _minasareport_owner &rhs); _minbleicreport_owner& operator=(const _minbleicreport_owner &rhs);
virtual ~_minasareport_owner(); virtual ~_minbleicreport_owner();
alglib_impl::minasareport* c_ptr(); alglib_impl::minbleicreport* c_ptr();
alglib_impl::minasareport* c_ptr() const; alglib_impl::minbleicreport* c_ptr() const;
protected: protected:
alglib_impl::minasareport *p_struct; alglib_impl::minbleicreport *p_struct;
}; };
class minasareport : public _minasareport_owner class minbleicreport : public _minbleicreport_owner
{ {
public: public:
minasareport(); minbleicreport();
minasareport(const minasareport &rhs); minbleicreport(const minbleicreport &rhs);
minasareport& operator=(const minasareport &rhs); minbleicreport& operator=(const minbleicreport &rhs);
virtual ~minasareport(); virtual ~minbleicreport();
ae_int_t &iterationscount; ae_int_t &inneriterationscount;
ae_int_t &outeriterationscount;
ae_int_t &nfev; ae_int_t &nfev;
ae_int_t &terminationtype; ae_int_t &terminationtype;
ae_int_t &activeconstraints; double &debugeqerr;
double &debugfs;
double &debugff;
double &debugdx;
}; };
/************************************************************************* /*************************************************************************
LIMITED MEMORY BFGS METHOD FOR LARGE SCALE OPTIMIZATION LIMITED MEMORY BFGS METHOD FOR LARGE SCALE OPTIMIZATION
DESCRIPTION: DESCRIPTION:
The subroutine minimizes function F(x) of N arguments by using a quasi- The subroutine minimizes function F(x) of N arguments by using a quasi-
Newton method (LBFGS scheme) which is optimized to use a minimum amount Newton method (LBFGS scheme) which is optimized to use a minimum amount
of memory. of memory.
skipping to change at line 1312 skipping to change at line 1477
State - structure used for reverse communication previously State - structure used for reverse communication previously
allocated with MinLMCreateXXX call. allocated with MinLMCreateXXX call.
X - new starting point. X - new starting point.
-- ALGLIB -- -- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minlmrestartfrom(const minlmstate &state, const real_1d_array &x); void minlmrestartfrom(const minlmstate &state, const real_1d_array &x);
/************************************************************************* /*************************************************************************
NONLINEAR CONJUGATE GRADIENT METHOD NONLINEAR BOUND CONSTRAINED OPTIMIZATION USING
MODIFIED ACTIVE SET ALGORITHM
WILLIAM W. HAGER AND HONGCHAO ZHANG
DESCRIPTION: DESCRIPTION:
The subroutine minimizes function F(x) of N arguments by using one of the The subroutine minimizes function F(x) of N arguments with bound
nonlinear conjugate gradient methods. constraints: BndL[i] <= x[i] <= BndU[i]
These CG methods are globally convergent (even on non-convex functions) as This method is globally convergent as long as grad(f) is Lipschitz
long as grad(f) is Lipschitz continuous in a some neighborhood of the continuous on a level set: L = { x : f(x)<=f(x0) }.
L = { x : f(x)<=f(x0) }.
REQUIREMENTS: REQUIREMENTS:
Algorithm will request following information during its operation: Algorithm will request following information during its operation:
* function value F and its gradient G (simultaneously) at given point X * function value F and its gradient G (simultaneously) at given point X
USAGE: USAGE:
1. User initializes algorithm state with MinCGCreate() call 1. User initializes algorithm state with MinASACreate() call
2. User tunes solver parameters with MinCGSetCond(), MinCGSetStpMax() and 2. User tunes solver parameters with MinASASetCond() MinASASetStpMax() and
other functions other functions
3. User calls MinCGOptimize() function which takes algorithm state and 3. User calls MinASAOptimize() function which takes algorithm state and
pointer (delegate, etc.) to callback function which calculates F/G. pointer (delegate, etc.) to callback function which calculates F/G.
4. User calls MinCGResults() to get solution 4. User calls MinASAResults() to get solution
5. Optionally, user may call MinCGRestartFrom() to solve another problem 5. Optionally, user may call MinASARestartFrom() to solve another problem
with same N but another starting point and/or another function. with same N but another starting point and/or another function.
MinCGRestartFrom() allows to reuse already initialized structure. MinASARestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS: INPUT PARAMETERS:
N - problem dimension, N>0: N - problem dimension, N>0:
* if given, only leading N elements of X are used * if given, only leading N elements of X are used
* if not given, automatically determined from size of X * if not given, automatically determined from sizes of
X/BndL/BndU.
X - starting point, array[0..N-1]. X - starting point, array[0..N-1].
BndL - lower bounds, array[0..N-1].
all elements MUST be specified, i.e. all variables are
bounded. However, if some (all) variables are unbounded,
you may specify very small number as bound: -1000, -1.0E6
or -1.0E300, or something like that.
BndU - upper bounds, array[0..N-1].
all elements MUST be specified, i.e. all variables are
bounded. However, if some (all) variables are unbounded,
you may specify very large number as bound: +1000, +1.0E6
or +1.0E300, or something like that.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
State - structure which stores algorithm state State - structure stores algorithm state
NOTES:
1. you may tune stopping conditions with MinASASetCond() function
2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow,
use MinASASetStpMax() function to bound algorithm's steps.
3. this function does NOT support infinite/NaN values in X, BndL, BndU.
-- ALGLIB -- -- ALGLIB --
Copyright 25.03.2010 by Bochkanov Sergey Copyright 25.03.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgcreate(const ae_int_t n, const real_1d_array &x, mincgstate &stat void minasacreate(const ae_int_t n, const real_1d_array &x, const real_1d_a
e); rray &bndl, const real_1d_array &bndu, minasastate &state);
void mincgcreate(const real_1d_array &x, mincgstate &state); void minasacreate(const real_1d_array &x, const real_1d_array &bndl, const
real_1d_array &bndu, minasastate &state);
/************************************************************************* /*************************************************************************
This function sets stopping conditions for CG optimization algorithm. This function sets stopping conditions for the ASA optimization algorithm.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
EpsG - >=0 EpsG - >=0
The subroutine finishes its work if the condition The subroutine finishes its work if the condition
||G||<EpsG is satisfied, where ||.|| means Euclidian norm, ||G||<EpsG is satisfied, where ||.|| means Euclidian norm,
G - gradient. G - gradient.
EpsF - >=0 EpsF - >=0
The subroutine finishes its work if on k+1-th iteration The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1} the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
skipping to change at line 1377 skipping to change at line 1562
the condition |X(k+1)-X(k)| <= EpsX is fulfilled. the condition |X(k+1)-X(k)| <= EpsX is fulfilled.
MaxIts - maximum number of iterations. If MaxIts=0, the number of MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited. iterations is unlimited.
Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to
automatic stopping criterion selection (small EpsX). automatic stopping criterion selection (small EpsX).
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgsetcond(const mincgstate &state, const double epsg, const double epsf, const double epsx, const ae_int_t maxits); void minasasetcond(const minasastate &state, const double epsg, const doubl e epsf, const double epsx, const ae_int_t maxits);
/************************************************************************* /*************************************************************************
This function turns on/off reporting. This function turns on/off reporting.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinCGOptimize(). provided to MinASAOptimize().
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgsetxrep(const mincgstate &state, const bool needxrep); void minasasetxrep(const minasastate &state, const bool needxrep);
/************************************************************************* /*************************************************************************
This function sets CG algorithm. This function sets optimization algorithm.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm stat
CGType - algorithm type: UAType - algorithm type:
* -1 automatic selection of the best algorithm * -1 automatic selection of the best algorithm
* 0 DY (Dai and Yuan) algorithm * 0 DY (Dai and Yuan) algorithm
* 1 Hybrid DY-HS algorithm * 1 Hybrid DY-HS algorithm
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgsetcgtype(const mincgstate &state, const ae_int_t cgtype); void minasasetalgorithm(const minasastate &state, const ae_int_t algotype);
/************************************************************************* /*************************************************************************
This function sets maximum step length This function sets maximum step length
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length. want to limit step length (zero by default).
Use this subroutine when you optimize target function which contains exp() Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too or other fast growing functions, and optimization algorithm makes too
large steps which leads to overflow. This function allows us to reject large steps which leads to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d. overflow) without actually calculating function value at the x+stp*d.
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgsetstpmax(const mincgstate &state, const double stpmax); void minasasetstpmax(const minasastate &state, const double stpmax);
/************************************************************************* /*************************************************************************
This function provides reverse communication interface This function provides reverse communication interface
Reverse communication interface is not documented or recommended to use. Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API See below for functions which provide better documented API
*************************************************************************/ *************************************************************************/
bool mincgiteration(const mincgstate &state); bool minasaiteration(const minasastate &state);
/************************************************************************* /*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimize r This family of functions is used to launcn iterations of nonlinear optimize r
These functions accept following parameters: These functions accept following parameters:
state - algorithm state state - algorithm state
grad - callback which calculates function (or merit function) grad - callback which calculates function (or merit function)
value func and gradient grad at given point x value func and gradient grad at given point x
rep - optional callback which is called after each iteration rep - optional callback which is called after each iteration
can be NULL can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL can be NULL
-- ALGLIB -- -- ALGLIB --
Copyright 20.04.2009 by Bochkanov Sergey Copyright 20.03.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgoptimize(mincgstate &state, void minasaoptimize(minasastate &state,
void (*grad)(const real_1d_array &x, double &func, real_1d_array &grad, void *ptr), void (*grad)(const real_1d_array &x, double &func, real_1d_array &grad, void *ptr),
void (*rep)(const real_1d_array &x, double func, void *ptr) = NULL, void (*rep)(const real_1d_array &x, double func, void *ptr) = NULL,
void *ptr = NULL); void *ptr = NULL);
/************************************************************************* /*************************************************************************
Conjugate gradient results ASA results
INPUT PARAMETERS: INPUT PARAMETERS:
State - algorithm state State - algorithm state
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
X - array[0..N-1], solution X - array[0..N-1], solution
Rep - optimization report: Rep - optimization report:
* Rep.TerminationType completetion code: * Rep.TerminationType completetion code:
* -2 rounding errors prevent further improvement. * -2 rounding errors prevent further improvement.
X contains best point found. X contains best point found.
* -1 incorrect parameters were specified * -1 incorrect parameters were specified
* 1 relative function improvement is no more than * 1 relative function improvement is no more than
EpsF. EpsF.
* 2 relative step is no more than EpsX. * 2 relative step is no more than EpsX.
* 4 gradient norm is no more than EpsG * 4 gradient norm is no more than EpsG
* 5 MaxIts steps was taken * 5 MaxIts steps was taken
* 7 stopping conditions are too stringent, * 7 stopping conditions are too stringent,
further improvement is impossible further improvement is impossible
* Rep.IterationsCount contains iterations count * Rep.IterationsCount contains iterations count
* NFEV countains number of function calculations * NFEV countains number of function calculations
* ActiveConstraints contains number of active constraints
-- ALGLIB -- -- ALGLIB --
Copyright 20.04.2009 by Bochkanov Sergey Copyright 20.03.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgresults(const mincgstate &state, real_1d_array &x, mincgreport &r ep); void minasaresults(const minasastate &state, real_1d_array &x, minasareport &rep);
/************************************************************************* /*************************************************************************
Conjugate gradient results ASA results
Buffered implementation of MinCGResults(), which uses pre-allocated buffer Buffered implementation of MinASAResults() which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored. where array reallocation penalty is too large to be ignored.
-- ALGLIB -- -- ALGLIB --
Copyright 20.04.2009 by Bochkanov Sergey Copyright 20.03.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgresultsbuf(const mincgstate &state, real_1d_array &x, mincgreport &rep); void minasaresultsbuf(const minasastate &state, real_1d_array &x, minasarep ort &rep);
/************************************************************************* /*************************************************************************
This subroutine restarts CG algorithm from new point. All optimization This subroutine restarts CG algorithm from new point. All optimization
parameters are left unchanged. parameters are left unchanged.
This function allows to solve multiple optimization problems (which This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty. must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure used to store algorithm state. State - structure previously allocated with MinCGCreate call.
X - new starting point. X - new starting point.
BndL - new lower bounds
BndU - new upper bounds
-- ALGLIB -- -- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgrestartfrom(const mincgstate &state, const real_1d_array &x); void minasarestartfrom(const minasastate &state, const real_1d_array &x, co nst real_1d_array &bndl, const real_1d_array &bndu);
/************************************************************************* /*************************************************************************
NONLINEAR BOUND CONSTRAINED OPTIMIZATION USING NONLINEAR CONJUGATE GRADIENT METHOD
MODIFIED ACTIVE SET ALGORITHM
WILLIAM W. HAGER AND HONGCHAO ZHANG
DESCRIPTION: DESCRIPTION:
The subroutine minimizes function F(x) of N arguments with bound The subroutine minimizes function F(x) of N arguments by using one of the
constraints: BndL[i] <= x[i] <= BndU[i] nonlinear conjugate gradient methods.
This method is globally convergent as long as grad(f) is Lipschitz These CG methods are globally convergent (even on non-convex functions) as
continuous on a level set: L = { x : f(x)<=f(x0) }. long as grad(f) is Lipschitz continuous in a some neighborhood of the
L = { x : f(x)<=f(x0) }.
REQUIREMENTS: REQUIREMENTS:
Algorithm will request following information during its operation: Algorithm will request following information during its operation:
* function value F and its gradient G (simultaneously) at given point X * function value F and its gradient G (simultaneously) at given point X
USAGE: USAGE:
1. User initializes algorithm state with MinASACreate() call 1. User initializes algorithm state with MinCGCreate() call
2. User tunes solver parameters with MinASASetCond() MinASASetStpMax() and 2. User tunes solver parameters with MinCGSetCond(), MinCGSetStpMax() and
other functions other functions
3. User calls MinASAOptimize() function which takes algorithm state and 3. User calls MinCGOptimize() function which takes algorithm state and
pointer (delegate, etc.) to callback function which calculates F/G. pointer (delegate, etc.) to callback function which calculates F/G.
4. User calls MinASAResults() to get solution 4. User calls MinCGResults() to get solution
5. Optionally, user may call MinASARestartFrom() to solve another problem 5. Optionally, user may call MinCGRestartFrom() to solve another problem
with same N but another starting point and/or another function. with same N but another starting point and/or another function.
MinASARestartFrom() allows to reuse already initialized structure. MinCGRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS: INPUT PARAMETERS:
N - problem dimension, N>0: N - problem dimension, N>0:
* if given, only leading N elements of X are used * if given, only leading N elements of X are used
* if not given, automatically determined from sizes of * if not given, automatically determined from size of X
X/BndL/BndU.
X - starting point, array[0..N-1]. X - starting point, array[0..N-1].
BndL - lower bounds, array[0..N-1].
all elements MUST be specified, i.e. all variables are
bounded. However, if some (all) variables are unbounded,
you may specify very small number as bound: -1000, -1.0E6
or -1.0E300, or something like that.
BndU - upper bounds, array[0..N-1].
all elements MUST be specified, i.e. all variables are
bounded. However, if some (all) variables are unbounded,
you may specify very large number as bound: +1000, +1.0E6
or +1.0E300, or something like that.
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
State - structure stores algorithm state State - structure which stores algorithm state
NOTES:
1. you may tune stopping conditions with MinASASetCond() function
2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow,
use MinASASetStpMax() function to bound algorithm's steps.
3. this function does NOT support infinite/NaN values in X, BndL, BndU.
-- ALGLIB -- -- ALGLIB --
Copyright 25.03.2010 by Bochkanov Sergey Copyright 25.03.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasacreate(const ae_int_t n, const real_1d_array &x, const real_1d_a void mincgcreate(const ae_int_t n, const real_1d_array &x, mincgstate &stat
rray &bndl, const real_1d_array &bndu, minasastate &state); e);
void minasacreate(const real_1d_array &x, const real_1d_array &bndl, const void mincgcreate(const real_1d_array &x, mincgstate &state);
real_1d_array &bndu, minasastate &state);
/************************************************************************* /*************************************************************************
This function sets stopping conditions for the ASA optimization algorithm. This function sets stopping conditions for CG optimization algorithm.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
EpsG - >=0 EpsG - >=0
The subroutine finishes its work if the condition The subroutine finishes its work if the condition
||G||<EpsG is satisfied, where ||.|| means Euclidian norm, ||G||<EpsG is satisfied, where ||.|| means Euclidian norm,
G - gradient. G - gradient.
EpsF - >=0 EpsF - >=0
The subroutine finishes its work if on k+1-th iteration The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1} the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
skipping to change at line 1599 skipping to change at line 1767
the condition |X(k+1)-X(k)| <= EpsX is fulfilled. the condition |X(k+1)-X(k)| <= EpsX is fulfilled.
MaxIts - maximum number of iterations. If MaxIts=0, the number of MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited. iterations is unlimited.
Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to
automatic stopping criterion selection (small EpsX). automatic stopping criterion selection (small EpsX).
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasasetcond(const minasastate &state, const double epsg, const doubl e epsf, const double epsx, const ae_int_t maxits); void mincgsetcond(const mincgstate &state, const double epsg, const double epsf, const double epsx, const ae_int_t maxits);
/************************************************************************* /*************************************************************************
This function turns on/off reporting. This function turns on/off reporting.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinASAOptimize(). provided to MinCGOptimize().
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasasetxrep(const minasastate &state, const bool needxrep); void mincgsetxrep(const mincgstate &state, const bool needxrep);
/************************************************************************* /*************************************************************************
This function sets optimization algorithm. This function sets CG algorithm.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm stat State - structure which stores algorithm state
UAType - algorithm type: CGType - algorithm type:
* -1 automatic selection of the best algorithm * -1 automatic selection of the best algorithm
* 0 DY (Dai and Yuan) algorithm * 0 DY (Dai and Yuan) algorithm
* 1 Hybrid DY-HS algorithm * 1 Hybrid DY-HS algorithm
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasasetalgorithm(const minasastate &state, const ae_int_t algotype); void mincgsetcgtype(const mincgstate &state, const ae_int_t cgtype);
/************************************************************************* /*************************************************************************
This function sets maximum step length This function sets maximum step length
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length (zero by default). want to limit step length.
Use this subroutine when you optimize target function which contains exp() Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too or other fast growing functions, and optimization algorithm makes too
large steps which leads to overflow. This function allows us to reject large steps which leads to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d. overflow) without actually calculating function value at the x+stp*d.
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasasetstpmax(const minasastate &state, const double stpmax); void mincgsetstpmax(const mincgstate &state, const double stpmax);
/*************************************************************************
This function allows to suggest initial step length to the CG algorithm.
Suggested step length is used as starting point for the line search. It
can be useful when you have badly scaled problem, i.e. when ||grad||
(which is used as initial estimate for the first step) is many orders of
magnitude different from the desired step.
Line search may fail on such problems without good estimate of initial
step length. Imagine, for example, problem with ||grad||=10^50 and desired
step equal to 0.1 Line search function will use 10^50 as initial step,
then it will decrease step length by 2 (up to 20 attempts) and will get
10^44, which is still too large.
This function allows us to tell than line search should be started from
some moderate step length, like 1.0, so algorithm will be able to detect
desired step length in a several searches.
This function influences only first iteration of algorithm. It should be
called between MinCGCreate/MinCGRestartFrom() call and MinCGOptimize call.
INPUT PARAMETERS:
State - structure used to store algorithm state.
Stp - initial estimate of the step length.
Can be zero (no estimate).
-- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/
void mincgsuggeststep(const mincgstate &state, const double stp);
/************************************************************************* /*************************************************************************
This function provides reverse communication interface This function provides reverse communication interface
Reverse communication interface is not documented or recommended to use. Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API See below for functions which provide better documented API
*************************************************************************/ *************************************************************************/
bool minasaiteration(const minasastate &state); bool mincgiteration(const mincgstate &state);
/************************************************************************* /*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimize r This family of functions is used to launcn iterations of nonlinear optimize r
These functions accept following parameters: These functions accept following parameters:
state - algorithm state state - algorithm state
grad - callback which calculates function (or merit function) grad - callback which calculates function (or merit function)
value func and gradient grad at given point x value func and gradient grad at given point x
rep - optional callback which is called after each iteration rep - optional callback which is called after each iteration
can be NULL can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL can be NULL
-- ALGLIB -- -- ALGLIB --
Copyright 20.03.2009 by Bochkanov Sergey Copyright 20.04.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasaoptimize(minasastate &state, void mincgoptimize(mincgstate &state,
void (*grad)(const real_1d_array &x, double &func, real_1d_array &grad, void *ptr), void (*grad)(const real_1d_array &x, double &func, real_1d_array &grad, void *ptr),
void (*rep)(const real_1d_array &x, double func, void *ptr) = NULL, void (*rep)(const real_1d_array &x, double func, void *ptr) = NULL,
void *ptr = NULL); void *ptr = NULL);
/************************************************************************* /*************************************************************************
ASA results Conjugate gradient results
INPUT PARAMETERS: INPUT PARAMETERS:
State - algorithm state State - algorithm state
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
X - array[0..N-1], solution X - array[0..N-1], solution
Rep - optimization report: Rep - optimization report:
* Rep.TerminationType completetion code: * Rep.TerminationType completetion code:
* -2 rounding errors prevent further improvement.
X contains best point found.
* -1 incorrect parameters were specified
* 1 relative function improvement is no more than * 1 relative function improvement is no more than
EpsF. EpsF.
* 2 relative step is no more than EpsX. * 2 relative step is no more than EpsX.
* 4 gradient norm is no more than EpsG * 4 gradient norm is no more than EpsG
* 5 MaxIts steps was taken * 5 MaxIts steps was taken
* 7 stopping conditions are too stringent, * 7 stopping conditions are too stringent,
further improvement is impossible further improvement is impossible,
we return best X found so far
* Rep.IterationsCount contains iterations count * Rep.IterationsCount contains iterations count
* NFEV countains number of function calculations * NFEV countains number of function calculations
* ActiveConstraints contains number of active constraints
-- ALGLIB -- -- ALGLIB --
Copyright 20.03.2009 by Bochkanov Sergey Copyright 20.04.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasaresults(const minasastate &state, real_1d_array &x, minasareport &rep); void mincgresults(const mincgstate &state, real_1d_array &x, mincgreport &r ep);
/************************************************************************* /*************************************************************************
ASA results Conjugate gradient results
Buffered implementation of MinASAResults() which uses pre-allocated buffer Buffered implementation of MinCGResults(), which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored. where array reallocation penalty is too large to be ignored.
-- ALGLIB -- -- ALGLIB --
Copyright 20.03.2009 by Bochkanov Sergey Copyright 20.04.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasaresultsbuf(const minasastate &state, real_1d_array &x, minasarep ort &rep); void mincgresultsbuf(const mincgstate &state, real_1d_array &x, mincgreport &rep);
/************************************************************************* /*************************************************************************
This subroutine restarts CG algorithm from new point. All optimization This subroutine restarts CG algorithm from new point. All optimization
parameters are left unchanged. parameters are left unchanged.
This function allows to solve multiple optimization problems (which This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty. must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure previously allocated with MinCGCreate call. State - structure used to store algorithm state.
X - new starting point. X - new starting point.
BndL - new lower bounds
BndU - new upper bounds
-- ALGLIB -- -- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minasarestartfrom(const minasastate &state, const real_1d_array &x, co void mincgrestartfrom(const mincgstate &state, const real_1d_array &x);
nst real_1d_array &bndl, const real_1d_array &bndu);
/*************************************************************************
BOUND CONSTRAINED OPTIMIZATION
WITH ADDITIONAL LINEAR EQUALITY AND INEQUALITY CONSTRAINTS
DESCRIPTION:
The subroutine minimizes function F(x) of N arguments subject to any
combination of:
* bound constraints
* linear inequality constraints
* linear equality constraints
REQUIREMENTS:
* function value and gradient
* grad(f) must be Lipschitz continuous on a level set: L = { x : f(x)<=f(x0
) }
* function must be defined even in the infeasible points (algorithm make ta
ke
steps in the infeasible area before converging to the feasible point)
* starting point X0 must be feasible or not too far away from the feasible
set
* problem must satisfy strict complementary conditions
USAGE:
Constrained optimization if far more complex than the unconstrained one.
Here we give very brief outline of the BLEIC optimizer. We strongly recomme
nd
you to read examples in the ALGLIB Reference Manual and to read ALGLIB User
Guide
on optimization, which is available at http://www.alglib.net/optimization/
1. User initializes algorithm state with MinBLEICCreate() call
2. USer adds boundary and/or linear constraints by calling
MinBLEICSetBC() and MinBLEICSetLC() functions.
3. User sets stopping conditions for underlying unconstrained solver
with MinBLEICSetInnerCond() call.
This function controls accuracy of underlying optimization algorithm.
4. User sets stopping conditions for outer iteration by calling
MinBLEICSetOuterCond() function.
This function controls handling of boundary and inequality constraints.
5. User tunes barrier parameters:
* barrier width with MinBLEICSetBarrierWidth() call
* (optionally) dynamics of the barrier width with MinBLEICSetBarrierDeca
y() call
These functions control handling of boundary and inequality constraints.
6. Additionally, user may set limit on number of internal iterations
by MinBLEICSetMaxIts() call.
This function allows to prevent algorithm from looping forever.
7. User calls MinBLEICOptimize() function which takes algorithm state and
pointer (delegate, etc.) to callback function which calculates F/G.
8. User calls MinBLEICResults() to get solution
9. Optionally user may call MinBLEICRestartFrom() to solve another problem
with same N but another starting point.
MinBLEICRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size ofX
X - starting point, array[N]:
* it is better to set X to a feasible point
* but X can be infeasible, in which case algorithm will try
to find feasible point first, using X as initial
approximation.
OUTPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleiccreate(const ae_int_t n, const real_1d_array &x, minbleicstate
&state);
void minbleiccreate(const real_1d_array &x, minbleicstate &state);
/*************************************************************************
This function sets boundary constraints for BLEIC optimizer.
Boundary constraints are inactive by default (after initial creation).
They are preserved after algorithm restart with MinBLEICRestartFrom().
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify
very small number or -INF.
BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify
very large number or +INF.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetbc(const minbleicstate &state, const real_1d_array &bndl, c
onst real_1d_array &bndu);
/*************************************************************************
This function sets linear constraints for BLEIC optimizer.
Linear constraints are inactive by default (after initial creation).
They are preserved after algorithm restart with MinBLEICRestartFrom().
INPUT PARAMETERS:
State - structure previously allocated with MinBLEICCreate call.
C - linear constraints, array[K,N+1].
Each row of C represents one constraint, either equality
or inequality (see below):
* first N elements correspond to coefficients,
* last element corresponds to the right part.
All elements of C (including right part) must be finite.
CT - type of constraints, array[K]:
* if CT[i]>0, then I-th constraint is C[i,*]*x >= C[i,n+1]
* if CT[i]=0, then I-th constraint is C[i,*]*x = C[i,n+1]
* if CT[i]<0, then I-th constraint is C[i,*]*x <= C[i,n+1]
K - number of equality/inequality constraints, K>=0:
* if given, only leading K elements of C/CT are used
* if not given, automatically determined from sizes of C/CT
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetlc(const minbleicstate &state, const real_2d_array &c, cons
t integer_1d_array &ct, const ae_int_t k);
void minbleicsetlc(const minbleicstate &state, const real_2d_array &c, cons
t integer_1d_array &ct);
/*************************************************************************
This function sets stopping conditions for the underlying nonlinear CG
optimizer. It controls overall accuracy of solution. These conditions
should be strict enough in order for algorithm to converge.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsG - >=0
Algorithm finishes its work if 2-norm of the Lagrangian
gradient is less than or equal to EpsG.
EpsF - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied.
EpsX - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |X(k+1)-X(k)| <= EpsX is fulfilled.
Passing EpsG=0, EpsF=0 and EpsX=0 (simultaneously) will lead to
automatic stopping criterion selection.
These conditions are used to terminate inner iterations. However, you
need to tune termination conditions for outer iterations too.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetinnercond(const minbleicstate &state, const double epsg, co
nst double epsf, const double epsx);
/*************************************************************************
This function sets stopping conditions for outer iteration of BLEIC algo.
These conditions control accuracy of constraint handling and amount of
infeasibility allowed in the solution.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsX - >0, stopping condition on outer iteration step length
EpsI - >0, stopping condition on infeasibility
Both EpsX and EpsI must be non-zero.
MEANING OF EpsX
EpsX is a stopping condition for outer iterations. Algorithm will stop
when solution of the current modified subproblem will be within EpsX
(using 2-norm) of the previous solution.
MEANING OF EpsI
EpsI controls feasibility properties - algorithm won't stop until all
inequality constraints will be satisfied with error (distance from current
point to the feasible area) at most EpsI.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetoutercond(const minbleicstate &state, const double epsx, co
nst double epsi);
/*************************************************************************
This function sets initial barrier width.
BLEIC optimizer uses modified barrier functions to handle inequality
constraints. These functions are almost constant in the inner parts of the
feasible area, but grow rapidly to the infinity OUTSIDE of the feasible
area. Barrier width is a distance from feasible area to the point where
modified barrier function becomes infinite.
Barrier width must be:
* small enough (below some problem-dependent value) in order for algorithm
to converge. Necessary condition is that the target function must be
well described by linear model in the areas as small as barrier width.
* not VERY small (in order to avoid difficulties associated with rapid
changes in the modified function, ill-conditioning, round-off issues).
Choosing appropriate barrier width is very important for efficient
optimization, and it often requires error and trial. You can use two
strategies when choosing barrier width:
* set barrier width with MinBLEICSetBarrierWidth() call. In this case you
should try different barrier widths and examine results.
* set decreasing barrier width by combining MinBLEICSetBarrierWidth() and
MinBLEICSetBarrierDecay() calls. In this case algorithm will decrease
barrier width after each outer iteration until it encounters optimal
barrier width.
INPUT PARAMETERS:
State - structure which stores algorithm state
Mu - >0, initial barrier width
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetbarrierwidth(const minbleicstate &state, const double mu);
/*************************************************************************
This function sets decay coefficient for barrier width.
By default, no barrier decay is used (Decay=1.0).
BLEIC optimizer uses modified barrier functions to handle inequality
constraints. These functions are almost constant in the inner parts of the
feasible area, but grow rapidly to the infinity OUTSIDE of the feasible
area. Barrier width is a distance from feasible area to the point where
modified barrier function becomes infinite. Decay coefficient allows us to
decrease barrier width from the initial (suboptimial) value until
optimal value will be met.
We recommend you either to set MuDecay=1.0 (no decay) or use some moderate
value like 0.5-0.7
INPUT PARAMETERS:
State - structure which stores algorithm state
MuDecay - 0<MuDecay<=1, decay coefficient
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetbarrierdecay(const minbleicstate &state, const double mudec
ay);
/*************************************************************************
This function allows to stop algorithm after specified number of inner
iterations.
INPUT PARAMETERS:
State - structure which stores algorithm state
MaxIts - maximum number of inner iterations.
If MaxIts=0, the number of iterations is unlimited.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetmaxits(const minbleicstate &state, const ae_int_t maxits);
/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinBLEICOptimize().
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetxrep(const minbleicstate &state, const bool needxrep);
/*************************************************************************
This function sets maximum step length
INPUT PARAMETERS:
State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length.
Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too
large steps which lead to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetstpmax(const minbleicstate &state, const double stpmax);
/*************************************************************************
This function provides reverse communication interface
Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API
*************************************************************************/
bool minbleiciteration(const minbleicstate &state);
/*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimize
r
These functions accept following parameters:
state - algorithm state
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicoptimize(minbleicstate &state,
void (*grad)(const real_1d_array &x, double &func, real_1d_array &grad,
void *ptr),
void (*rep)(const real_1d_array &x, double func, void *ptr) = NULL,
void *ptr = NULL);
/*************************************************************************
BLEIC results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report:
* Rep.TerminationType completetion code:
* -3 inconsistent constraints. Feasible point is
either nonexistent or too hard to find. Try to
restart optimizer with better initial
approximation
* -2 rounding errors prevent further improvement.
X contains best point found.
* 4 conditions on constraints are fulfilled
with error less than or equal to EpsC
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
* Rep.IterationsCount contains iterations count
* NFEV countains number of function calculations
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicresults(const minbleicstate &state, real_1d_array &x, minbleic
report &rep);
/*************************************************************************
BLEIC results
Buffered implementation of MinBLEICResults() which uses pre-allocated buffe
r
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicresultsbuf(const minbleicstate &state, real_1d_array &x, minbl
eicreport &rep);
/*************************************************************************
This subroutine restarts algorithm from new point.
All optimization parameters (including constraints) are left unchanged.
This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS:
State - structure previously allocated with MinBLEICCreate call.
X - new starting point.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicrestartfrom(const minbleicstate &state, const real_1d_array &x
);
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
void minlbfgscreate(ae_int_t n, void minlbfgscreate(ae_int_t n,
skipping to change at line 1852 skipping to change at line 2424
ae_state *_state); ae_state *_state);
void minlmrestartfrom(minlmstate* state, void minlmrestartfrom(minlmstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
ae_state *_state); ae_state *_state);
ae_bool _minlmstate_init(minlmstate* p, ae_state *_state, ae_bool make_auto matic); ae_bool _minlmstate_init(minlmstate* p, ae_state *_state, ae_bool make_auto matic);
ae_bool _minlmstate_init_copy(minlmstate* dst, minlmstate* src, ae_state *_ state, ae_bool make_automatic); ae_bool _minlmstate_init_copy(minlmstate* dst, minlmstate* src, ae_state *_ state, ae_bool make_automatic);
void _minlmstate_clear(minlmstate* p); void _minlmstate_clear(minlmstate* p);
ae_bool _minlmreport_init(minlmreport* p, ae_state *_state, ae_bool make_au tomatic); ae_bool _minlmreport_init(minlmreport* p, ae_state *_state, ae_bool make_au tomatic);
ae_bool _minlmreport_init_copy(minlmreport* dst, minlmreport* src, ae_state *_state, ae_bool make_automatic); ae_bool _minlmreport_init_copy(minlmreport* dst, minlmreport* src, ae_state *_state, ae_bool make_automatic);
void _minlmreport_clear(minlmreport* p); void _minlmreport_clear(minlmreport* p);
void minasacreate(ae_int_t n,
/* Real */ ae_vector* x,
/* Real */ ae_vector* bndl,
/* Real */ ae_vector* bndu,
minasastate* state,
ae_state *_state);
void minasasetcond(minasastate* state,
double epsg,
double epsf,
double epsx,
ae_int_t maxits,
ae_state *_state);
void minasasetxrep(minasastate* state, ae_bool needxrep, ae_state *_state);
void minasasetalgorithm(minasastate* state,
ae_int_t algotype,
ae_state *_state);
void minasasetstpmax(minasastate* state, double stpmax, ae_state *_state);
ae_bool minasaiteration(minasastate* state, ae_state *_state);
void minasaresults(minasastate* state,
/* Real */ ae_vector* x,
minasareport* rep,
ae_state *_state);
void minasaresultsbuf(minasastate* state,
/* Real */ ae_vector* x,
minasareport* rep,
ae_state *_state);
void minasarestartfrom(minasastate* state,
/* Real */ ae_vector* x,
/* Real */ ae_vector* bndl,
/* Real */ ae_vector* bndu,
ae_state *_state);
ae_bool _minasastate_init(minasastate* p, ae_state *_state, ae_bool make_au
tomatic);
ae_bool _minasastate_init_copy(minasastate* dst, minasastate* src, ae_state
*_state, ae_bool make_automatic);
void _minasastate_clear(minasastate* p);
ae_bool _minasareport_init(minasareport* p, ae_state *_state, ae_bool make_
automatic);
ae_bool _minasareport_init_copy(minasareport* dst, minasareport* src, ae_st
ate *_state, ae_bool make_automatic);
void _minasareport_clear(minasareport* p);
void mincgcreate(ae_int_t n, void mincgcreate(ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
mincgstate* state, mincgstate* state,
ae_state *_state); ae_state *_state);
void mincgsetcond(mincgstate* state, void mincgsetcond(mincgstate* state,
double epsg, double epsg,
double epsf, double epsf,
double epsx, double epsx,
ae_int_t maxits, ae_int_t maxits,
ae_state *_state); ae_state *_state);
void mincgsetxrep(mincgstate* state, ae_bool needxrep, ae_state *_state); void mincgsetxrep(mincgstate* state, ae_bool needxrep, ae_state *_state);
void mincgsetdrep(mincgstate* state, ae_bool needdrep, ae_state *_state);
void mincgsetcgtype(mincgstate* state, ae_int_t cgtype, ae_state *_state); void mincgsetcgtype(mincgstate* state, ae_int_t cgtype, ae_state *_state);
void mincgsetstpmax(mincgstate* state, double stpmax, ae_state *_state); void mincgsetstpmax(mincgstate* state, double stpmax, ae_state *_state);
void mincgsuggeststep(mincgstate* state, double stp, ae_state *_state);
ae_bool mincgiteration(mincgstate* state, ae_state *_state); ae_bool mincgiteration(mincgstate* state, ae_state *_state);
void mincgresults(mincgstate* state, void mincgresults(mincgstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
mincgreport* rep, mincgreport* rep,
ae_state *_state); ae_state *_state);
void mincgresultsbuf(mincgstate* state, void mincgresultsbuf(mincgstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
mincgreport* rep, mincgreport* rep,
ae_state *_state); ae_state *_state);
void mincgrestartfrom(mincgstate* state, void mincgrestartfrom(mincgstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
ae_state *_state); ae_state *_state);
ae_bool _mincgstate_init(mincgstate* p, ae_state *_state, ae_bool make_auto matic); ae_bool _mincgstate_init(mincgstate* p, ae_state *_state, ae_bool make_auto matic);
ae_bool _mincgstate_init_copy(mincgstate* dst, mincgstate* src, ae_state *_ state, ae_bool make_automatic); ae_bool _mincgstate_init_copy(mincgstate* dst, mincgstate* src, ae_state *_ state, ae_bool make_automatic);
void _mincgstate_clear(mincgstate* p); void _mincgstate_clear(mincgstate* p);
ae_bool _mincgreport_init(mincgreport* p, ae_state *_state, ae_bool make_au tomatic); ae_bool _mincgreport_init(mincgreport* p, ae_state *_state, ae_bool make_au tomatic);
ae_bool _mincgreport_init_copy(mincgreport* dst, mincgreport* src, ae_state *_state, ae_bool make_automatic); ae_bool _mincgreport_init_copy(mincgreport* dst, mincgreport* src, ae_state *_state, ae_bool make_automatic);
void _mincgreport_clear(mincgreport* p); void _mincgreport_clear(mincgreport* p);
void minasacreate(ae_int_t n, void minbleiccreate(ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minbleicstate* state,
ae_state *_state);
void minbleicsetbc(minbleicstate* state,
/* Real */ ae_vector* bndl, /* Real */ ae_vector* bndl,
/* Real */ ae_vector* bndu, /* Real */ ae_vector* bndu,
minasastate* state,
ae_state *_state); ae_state *_state);
void minasasetcond(minasastate* state, void minbleicsetlc(minbleicstate* state,
/* Real */ ae_matrix* c,
/* Integer */ ae_vector* ct,
ae_int_t k,
ae_state *_state);
void minbleicsetinnercond(minbleicstate* state,
double epsg, double epsg,
double epsf, double epsf,
double epsx, double epsx,
ae_state *_state);
void minbleicsetoutercond(minbleicstate* state,
double epsx,
double epsi,
ae_state *_state);
void minbleicsetbarrierwidth(minbleicstate* state,
double mu,
ae_state *_state);
void minbleicsetbarrierdecay(minbleicstate* state,
double mudecay,
ae_state *_state);
void minbleicsetmaxits(minbleicstate* state,
ae_int_t maxits, ae_int_t maxits,
ae_state *_state); ae_state *_state);
void minasasetxrep(minasastate* state, ae_bool needxrep, ae_state *_state); void minbleicsetxrep(minbleicstate* state,
void minasasetalgorithm(minasastate* state, ae_bool needxrep,
ae_int_t algotype,
ae_state *_state); ae_state *_state);
void minasasetstpmax(minasastate* state, double stpmax, ae_state *_state); void minbleicsetstpmax(minbleicstate* state,
ae_bool minasaiteration(minasastate* state, ae_state *_state); double stpmax,
void minasaresults(minasastate* state, ae_state *_state);
ae_bool minbleiciteration(minbleicstate* state, ae_state *_state);
void minbleicresults(minbleicstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minasareport* rep, minbleicreport* rep,
ae_state *_state); ae_state *_state);
void minasaresultsbuf(minasastate* state, void minbleicresultsbuf(minbleicstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minasareport* rep, minbleicreport* rep,
ae_state *_state); ae_state *_state);
void minasarestartfrom(minasastate* state, void minbleicrestartfrom(minbleicstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* bndl,
/* Real */ ae_vector* bndu,
ae_state *_state); ae_state *_state);
ae_bool _minasastate_init(minasastate* p, ae_state *_state, ae_bool make_au void barrierfunc(double x,
tomatic); double mu,
ae_bool _minasastate_init_copy(minasastate* dst, minasastate* src, ae_state double* f,
*_state, ae_bool make_automatic); double* df,
void _minasastate_clear(minasastate* p); double* d2f,
ae_bool _minasareport_init(minasareport* p, ae_state *_state, ae_bool make_ ae_state *_state);
automatic); ae_bool _minbleicstate_init(minbleicstate* p, ae_state *_state, ae_bool mak
ae_bool _minasareport_init_copy(minasareport* dst, minasareport* src, ae_st e_automatic);
ate *_state, ae_bool make_automatic); ae_bool _minbleicstate_init_copy(minbleicstate* dst, minbleicstate* src, ae
void _minasareport_clear(minasareport* p); _state *_state, ae_bool make_automatic);
void _minbleicstate_clear(minbleicstate* p);
ae_bool _minbleicreport_init(minbleicreport* p, ae_state *_state, ae_bool m
ake_automatic);
ae_bool _minbleicreport_init_copy(minbleicreport* dst, minbleicreport* src,
ae_state *_state, ae_bool make_automatic);
void _minbleicreport_clear(minbleicreport* p);
} }
#endif #endif
 End of changes. 118 change blocks. 
182 lines changed or deleted 839 lines changed or added


 specialfunctions.h   specialfunctions.h 
skipping to change at line 644 skipping to change at line 644
Relative error: Relative error:
arithmetic domain # trials peak rms arithmetic domain # trials peak rms
IEEE 0,30 30000 8.1e-14 1.1e-14 IEEE 0,30 30000 8.1e-14 1.1e-14
Cephes Math Library Release 2.0: April, 1987 Cephes Math Library Release 2.0: April, 1987
Copyright 1984, 1987 by Stephen L. Moshier Copyright 1984, 1987 by Stephen L. Moshier
*************************************************************************/ *************************************************************************/
double beta(const double a, const double b); double beta(const double a, const double b);
/************************************************************************* /*************************************************************************
Incomplete beta integral
Returns incomplete beta integral of the arguments, evaluated
from zero to x. The function is defined as
x
- -
| (a+b) | | a-1 b-1
----------- | t (1-t) dt.
- - | |
| (a) | (b) -
0
The domain of definition is 0 <= x <= 1. In this
implementation a and b are restricted to positive values.
The integral from x to 1 may be obtained by the symmetry
relation
1 - incbet( a, b, x ) = incbet( b, a, 1-x ).
The integral is evaluated by a continued fraction expansion
or, when b*x is small, by a power series.
ACCURACY:
Tested at uniformly distributed random points (a,b,x) with a and b
in "domain" and x between 0 and 1.
Relative error
arithmetic domain # trials peak rms
IEEE 0,5 10000 6.9e-15 4.5e-16
IEEE 0,85 250000 2.2e-13 1.7e-14
IEEE 0,1000 30000 5.3e-12 6.3e-13
IEEE 0,10000 250000 9.3e-11 7.1e-12
IEEE 0,100000 10000 8.7e-10 4.8e-11
Outputs smaller than the IEEE gradual underflow threshold
were excluded from these statistics.
Cephes Math Library, Release 2.8: June, 2000
Copyright 1984, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double incompletebeta(const double a, const double b, const double x);
/*************************************************************************
Inverse of imcomplete beta integral
Given y, the function finds x such that
incbet( a, b, x ) = y .
The routine performs interval halving or Newton iterations to find the
root of incbet(a,b,x) - y = 0.
ACCURACY:
Relative error:
x a,b
arithmetic domain domain # trials peak rms
IEEE 0,1 .5,10000 50000 5.8e-12 1.3e-13
IEEE 0,1 .25,100 100000 1.8e-13 3.9e-15
IEEE 0,1 0,5 50000 1.1e-12 5.5e-15
With a and b constrained to half-integer or integer values:
IEEE 0,1 .5,10000 50000 5.8e-12 1.1e-13
IEEE 0,1 .5,100 100000 1.7e-14 7.9e-16
With a = .5, b constrained to half-integer or integer values:
IEEE 0,1 .5,10000 10000 8.3e-11 1.0e-11
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1996, 2000 by Stephen L. Moshier
*************************************************************************/
double invincompletebeta(const double a, const double b, const double y);
/*************************************************************************
Binomial distribution
Returns the sum of the terms 0 through k of the Binomial
probability density:
k
-- ( n ) j n-j
> ( ) p (1-p)
-- ( j )
j=0
The terms are not summed directly; instead the incomplete
beta integral is employed, according to the formula
y = bdtr( k, n, p ) = incbet( n-k, k+1, 1-p ).
The arguments must be positive, with p ranging from 0 to 1.
ACCURACY:
Tested at random points (a,b,p), with p between 0 and 1.
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 4.3e-15 2.6e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double binomialdistribution(const ae_int_t k, const ae_int_t n, const doubl
e p);
/*************************************************************************
Complemented binomial distribution
Returns the sum of the terms k+1 through n of the Binomial
probability density:
n
-- ( n ) j n-j
> ( ) p (1-p)
-- ( j )
j=k+1
The terms are not summed directly; instead the incomplete
beta integral is employed, according to the formula
y = bdtrc( k, n, p ) = incbet( k+1, n-k, p ).
The arguments must be positive, with p ranging from 0 to 1.
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 6.7e-15 8.2e-16
For p between 0 and .001:
IEEE 0,100 100000 1.5e-13 2.7e-15
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double binomialcdistribution(const ae_int_t k, const ae_int_t n, const doub
le p);
/*************************************************************************
Inverse binomial distribution
Finds the event probability p such that the sum of the
terms 0 through k of the Binomial probability density
is equal to the given cumulative probability y.
This is accomplished using the inverse beta integral
function and the relation
1 - p = incbi( n-k, k+1, y ).
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 2.3e-14 6.4e-16
IEEE 0,10000 100000 6.6e-12 1.2e-13
For p between 10^-6 and 0.001:
IEEE 0,100 100000 2.0e-12 1.3e-14
IEEE 0,10000 100000 1.5e-12 3.2e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double invbinomialdistribution(const ae_int_t k, const ae_int_t n, const do
uble y);
/*************************************************************************
Calculation of the value of the Chebyshev polynomials of the Calculation of the value of the Chebyshev polynomials of the
first and second kinds. first and second kinds.
Parameters: Parameters:
r - polynomial kind, either 1 or 2. r - polynomial kind, either 1 or 2.
n - degree, n>=0 n - degree, n>=0
x - argument, -1 <= x <= 1 x - argument, -1 <= x <= 1
Result: Result:
the value of the Chebyshev polynomial at x the value of the Chebyshev polynomial at x
skipping to change at line 703 skipping to change at line 873
Input parameters: Input parameters:
A - Chebyshev series coefficients A - Chebyshev series coefficients
N - degree, N>=0 N - degree, N>=0
Output parameters Output parameters
B - power series coefficients B - power series coefficients
*************************************************************************/ *************************************************************************/
void fromchebyshev(const real_1d_array &a, const ae_int_t n, real_1d_array &b); void fromchebyshev(const real_1d_array &a, const ae_int_t n, real_1d_array &b);
/************************************************************************* /*************************************************************************
Dawson's Integral Chi-square distribution
Approximates the integral Returns the area under the left hand tail (from 0 to x)
of the Chi square probability density function with
v degrees of freedom.
x x
- -
2 | | 2 1 | | v/2-1 -t/2
dawsn(x) = exp( -x ) | exp( t ) dt P( x | v ) = ----------- | t e dt
| | v/2 - | |
- 2 | (v/2) -
0 0
Three different rational approximations are employed, for where x is the Chi-square variable.
the intervals 0 to 3.25; 3.25 to 6.25; and 6.25 up.
The incomplete gamma integral is used, according to the
formula
y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
The arguments must both be positive.
ACCURACY: ACCURACY:
Relative error: See incomplete gamma function
arithmetic domain # trials peak rms
IEEE 0,10 10000 6.9e-16 1.0e-16
Cephes Math Library Release 2.8: June, 2000 Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/ *************************************************************************/
double dawsonintegral(const double x); double chisquaredistribution(const double v, const double x);
/************************************************************************* /*************************************************************************
Complete elliptic integral of the first kind Complemented Chi-square distribution
Approximates the integral Returns the area under the right hand tail (from x to
infinity) of the Chi square probability density function
with v degrees of freedom:
pi/2 inf.
- -
| | 1 | | v/2-1 -t/2
| dt P( x | v ) = ----------- | t e dt
K(m) = | ------------------ v/2 - | |
| 2 2 | (v/2) -
| | sqrt( 1 - m sin t ) x
-
0
using the approximation where x is the Chi-square variable.
P(x) - log x Q(x). The incomplete gamma integral is used, according to the
formula
y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
The arguments must both be positive.
ACCURACY: ACCURACY:
Relative error: See incomplete gamma function
arithmetic domain # trials peak rms
IEEE 0,1 30000 2.5e-16 6.8e-17
Cephes Math Library, Release 2.8: June, 2000 Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/ *************************************************************************/
double ellipticintegralk(const double m); double chisquarecdistribution(const double v, const double x);
/************************************************************************* /*************************************************************************
Complete elliptic integral of the first kind Inverse of complemented Chi-square distribution
Approximates the integral Finds the Chi-square argument x such that the integral
from x to infinity of the Chi-square density is equal
to the given cumulative probability y.
pi/2 This is accomplished using the inverse gamma integral
- function and the relation
| |
x/2 = igami( df/2, y );
ACCURACY:
See inverse incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
double invchisquaredistribution(const double v, const double y);
/*************************************************************************
Dawson's Integral
Approximates the integral
x
-
2 | | 2
dawsn(x) = exp( -x ) | exp( t ) dt
| |
-
0
Three different rational approximations are employed, for
the intervals 0 to 3.25; 3.25 to 6.25; and 6.25 up.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,10 10000 6.9e-16 1.0e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
double dawsonintegral(const double x);
/*************************************************************************
Complete elliptic integral of the first kind
Approximates the integral
pi/2
-
| |
| dt
K(m) = | ------------------
| 2
| | sqrt( 1 - m sin t )
-
0
using the approximation
P(x) - log x Q(x).
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,1 30000 2.5e-16 6.8e-17
Cephes Math Library, Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
double ellipticintegralk(const double m);
/*************************************************************************
Complete elliptic integral of the first kind
Approximates the integral
pi/2
-
| |
| dt | dt
K(m) = | ------------------ K(m) = | ------------------
| 2 | 2
| | sqrt( 1 - m sin t ) | | sqrt( 1 - m sin t )
- -
0 0
where m = 1 - m1, using the approximation where m = 1 - m1, using the approximation
P(x) - log x Q(x). P(x) - log x Q(x).
skipping to change at line 942 skipping to change at line 1199
Relative error: Relative error:
arithmetic domain # trials peak rms arithmetic domain # trials peak rms
IEEE 0, 30 10000 1.7e-15 3.6e-16 IEEE 0, 30 10000 1.7e-15 3.6e-16
Cephes Math Library Release 2.8: June, 2000 Cephes Math Library Release 2.8: June, 2000
Copyright 1985, 2000 by Stephen L. Moshier Copyright 1985, 2000 by Stephen L. Moshier
*************************************************************************/ *************************************************************************/
double exponentialintegralen(const double x, const ae_int_t n); double exponentialintegralen(const double x, const ae_int_t n);
/************************************************************************* /*************************************************************************
F distribution
Returns the area from zero to x under the F density
function (also known as Snedcor's density or the
variance ratio density). This is the density
of x = (u1/df1)/(u2/df2), where u1 and u2 are random
variables having Chi square distributions with df1
and df2 degrees of freedom, respectively.
The incomplete beta integral is used, according to the
formula
P(x) = incbet( df1/2, df2/2, (df1*x/(df2 + df1*x) ).
The arguments a and b are greater than zero, and x is
nonnegative.
ACCURACY:
Tested at random points (a,b,x).
x a,b Relative error:
arithmetic domain domain # trials peak rms
IEEE 0,1 0,100 100000 9.8e-15 1.7e-15
IEEE 1,5 0,100 100000 6.5e-15 3.5e-16
IEEE 0,1 1,10000 100000 2.2e-11 3.3e-12
IEEE 1,5 1,10000 100000 1.1e-11 1.7e-13
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double fdistribution(const ae_int_t a, const ae_int_t b, const double x);
/*************************************************************************
Complemented F distribution
Returns the area from x to infinity under the F density
function (also known as Snedcor's density or the
variance ratio density).
inf.
-
1 | | a-1 b-1
1-P(x) = ------ | t (1-t) dt
B(a,b) | |
-
x
The incomplete beta integral is used, according to the
formula
P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ).
ACCURACY:
Tested at random points (a,b,x) in the indicated intervals.
x a,b Relative error:
arithmetic domain domain # trials peak rms
IEEE 0,1 1,100 100000 3.7e-14 5.9e-16
IEEE 1,5 1,100 100000 8.0e-15 1.6e-15
IEEE 0,1 1,10000 100000 1.8e-11 3.5e-13
IEEE 1,5 1,10000 100000 2.0e-11 3.0e-12
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double fcdistribution(const ae_int_t a, const ae_int_t b, const double x);
/*************************************************************************
Inverse of complemented F distribution
Finds the F density argument x such that the integral
from x to infinity of the F density is equal to the
given probability p.
This is accomplished using the inverse beta integral
function and the relations
z = incbi( df2/2, df1/2, p )
x = df2 (1-z) / (df1 z).
Note: the following relations hold for the inverse of
the uncomplemented F distribution:
z = incbi( df1/2, df2/2, p )
x = df2 z / (df1 (1-z)).
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between .001 and 1:
IEEE 1,100 100000 8.3e-15 4.7e-16
IEEE 1,10000 100000 2.1e-11 1.4e-13
For p between 10^-6 and 10^-3:
IEEE 1,100 50000 1.3e-12 8.4e-15
IEEE 1,10000 50000 3.0e-12 4.8e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double invfdistribution(const ae_int_t a, const ae_int_t b, const double y)
;
/*************************************************************************
Fresnel integral Fresnel integral
Evaluates the Fresnel integrals Evaluates the Fresnel integrals
x x
- -
| | | |
C(x) = | cos(pi/2 t**2) dt, C(x) = | cos(pi/2 t**2) dt,
| | | |
- -
skipping to change at line 1021 skipping to change at line 1383
Input parameters: Input parameters:
N - polynomial degree, n>=0 N - polynomial degree, n>=0
Output parameters: Output parameters:
C - coefficients C - coefficients
*************************************************************************/ *************************************************************************/
void hermitecoefficients(const ae_int_t n, real_1d_array &c); void hermitecoefficients(const ae_int_t n, real_1d_array &c);
/************************************************************************* /*************************************************************************
Incomplete beta integral
Returns incomplete beta integral of the arguments, evaluated
from zero to x. The function is defined as
x
- -
| (a+b) | | a-1 b-1
----------- | t (1-t) dt.
- - | |
| (a) | (b) -
0
The domain of definition is 0 <= x <= 1. In this
implementation a and b are restricted to positive values.
The integral from x to 1 may be obtained by the symmetry
relation
1 - incbet( a, b, x ) = incbet( b, a, 1-x ).
The integral is evaluated by a continued fraction expansion
or, when b*x is small, by a power series.
ACCURACY:
Tested at uniformly distributed random points (a,b,x) with a and b
in "domain" and x between 0 and 1.
Relative error
arithmetic domain # trials peak rms
IEEE 0,5 10000 6.9e-15 4.5e-16
IEEE 0,85 250000 2.2e-13 1.7e-14
IEEE 0,1000 30000 5.3e-12 6.3e-13
IEEE 0,10000 250000 9.3e-11 7.1e-12
IEEE 0,100000 10000 8.7e-10 4.8e-11
Outputs smaller than the IEEE gradual underflow threshold
were excluded from these statistics.
Cephes Math Library, Release 2.8: June, 2000
Copyright 1984, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double incompletebeta(const double a, const double b, const double x);
/*************************************************************************
Inverse of imcomplete beta integral
Given y, the function finds x such that
incbet( a, b, x ) = y .
The routine performs interval halving or Newton iterations to find the
root of incbet(a,b,x) - y = 0.
ACCURACY:
Relative error:
x a,b
arithmetic domain domain # trials peak rms
IEEE 0,1 .5,10000 50000 5.8e-12 1.3e-13
IEEE 0,1 .25,100 100000 1.8e-13 3.9e-15
IEEE 0,1 0,5 50000 1.1e-12 5.5e-15
With a and b constrained to half-integer or integer values:
IEEE 0,1 .5,10000 50000 5.8e-12 1.1e-13
IEEE 0,1 .5,100 100000 1.7e-14 7.9e-16
With a = .5, b constrained to half-integer or integer values:
IEEE 0,1 .5,10000 10000 8.3e-11 1.0e-11
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1996, 2000 by Stephen L. Moshier
*************************************************************************/
double invincompletebeta(const double a, const double b, const double y);
/*************************************************************************
Jacobian Elliptic Functions Jacobian Elliptic Functions
Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m), Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m),
and dn(u|m) of parameter m between 0 and 1, and real and dn(u|m) of parameter m between 0 and 1, and real
argument u. argument u.
These functions are periodic, with quarter-period on the These functions are periodic, with quarter-period on the
real axis equal to the complete elliptic integral real axis equal to the complete elliptic integral
ellpk(1.0-m). ellpk(1.0-m).
skipping to change at line 1151 skipping to change at line 1441
Result: Result:
the value of the Laguerre polynomial Ln at x the value of the Laguerre polynomial Ln at x
*************************************************************************/ *************************************************************************/
double laguerrecalculate(const ae_int_t n, const double x); double laguerrecalculate(const ae_int_t n, const double x);
/************************************************************************* /*************************************************************************
Summation of Laguerre polynomials using Clenshaw Summation of Laguerre polynomials using Clenshaw
This routine calculates c[0]*L0(x) + c[1]*L1(x) + ... + c[N]*LN(x) This routine calculates c[0]*L0(x) + c[1]*L1(x) + ... + c[N]*LN(x)
Parameters: Parameters:
n - degree, n>=0 n - degree, n>=0
x - argument x - argument
Result:
the value of the Laguerre polynomial at x
*************************************************************************/
double laguerresum(const real_1d_array &c, const ae_int_t n, const double x
);
/*************************************************************************
Representation of Ln as C[0] + C[1]*X + ... + C[N]*X^N
Input parameters:
N - polynomial degree, n>=0
Output parameters:
C - coefficients
*************************************************************************/
void laguerrecoefficients(const ae_int_t n, real_1d_array &c);
/*************************************************************************
Calculation of the value of the Legendre polynomial Pn.
Parameters:
n - degree, n>=0
x - argument
Result:
the value of the Legendre polynomial Pn at x
*************************************************************************/
double legendrecalculate(const ae_int_t n, const double x);
/*************************************************************************
Summation of Legendre polynomials using Clenshaw
This routine calculates
c[0]*P0(x) + c[1]*P1(x) + ... + c[N]*PN(x)
Parameters:
n - degree, n>=0
x - argument
Result:
the value of the Legendre polynomial at x
*************************************************************************/
double legendresum(const real_1d_array &c, const ae_int_t n, const double x
);
/*************************************************************************
Representation of Pn as C[0] + C[1]*X + ... + C[N]*X^N
Input parameters:
N - polynomial degree, n>=0
Output parameters:
C - coefficients
*************************************************************************/
void legendrecoefficients(const ae_int_t n, real_1d_array &c);
/*************************************************************************
Psi (digamma) function
d -
psi(x) = -- ln | (x)
dx
is the logarithmic derivative of the gamma function.
For integer x,
n-1
-
psi(n) = -EUL + > 1/k.
-
k=1
This formula is used for 0 < n <= 10. If x is negative, it
is transformed to a positive argument by the reflection
formula psi(1-x) = psi(x) + pi cot(pi x).
For general positive x, the argument is made greater than 10
using the recurrence psi(x+1) = psi(x) + 1/x.
Then the following asymptotic expansion is applied:
inf. B
- 2k
psi(x) = log(x) - 1/2x - > -------
- 2k
k=1 2k x
where the B2k are Bernoulli numbers.
ACCURACY:
Relative error (except absolute when |psi| < 1):
arithmetic domain # trials peak rms
IEEE 0,30 30000 1.3e-15 1.4e-16
IEEE -30,0 40000 1.5e-15 2.2e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
double psi(const double x);
/*************************************************************************
Sine and cosine integrals
Evaluates the integrals
x
-
| cos t - 1
Ci(x) = eul + ln x + | --------- dt,
| t
-
0
x
-
| sin t
Si(x) = | ----- dt
| t
-
0
where eul = 0.57721566490153286061 is Euler's constant.
The integrals are approximated by rational functions.
For x > 8 auxiliary functions f(x) and g(x) are employed
such that
Ci(x) = f(x) sin(x) - g(x) cos(x)
Si(x) = pi/2 - f(x) cos(x) - g(x) sin(x)
ACCURACY:
Test interval = [0,50].
Absolute error, except relative when > 1:
arithmetic function # trials peak rms
IEEE Si 30000 4.4e-16 7.3e-17
IEEE Ci 30000 6.9e-16 5.1e-17
Cephes Math Library Release 2.1: January, 1989
Copyright 1984, 1987, 1989 by Stephen L. Moshier
*************************************************************************/
void sinecosineintegrals(const double x, double &si, double &ci);
/*************************************************************************
Hyperbolic sine and cosine integrals
Approximates the integrals
x
-
| | cosh t - 1
Chi(x) = eul + ln x + | ----------- dt,
| | t
-
0
x
-
| | sinh t
Shi(x) = | ------ dt
| | t
-
0
where eul = 0.57721566490153286061 is Euler's constant.
The integrals are evaluated by power series for x < 8
and by Chebyshev expansions for x between 8 and 88.
For large x, both functions approach exp(x)/2x.
Arguments greater than 88 in magnitude return MAXNUM.
ACCURACY:
Test interval 0 to 88.
Relative error:
arithmetic function # trials peak rms
IEEE Shi 30000 6.9e-16 1.6e-16
Absolute error, except relative when |Chi| > 1:
IEEE Chi 30000 8.4e-16 1.4e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
void hyperbolicsinecosineintegrals(const double x, double &shi, double &chi
);
/*************************************************************************
Binomial distribution
Returns the sum of the terms 0 through k of the Binomial
probability density:
k
-- ( n ) j n-j
> ( ) p (1-p)
-- ( j )
j=0
The terms are not summed directly; instead the incomplete
beta integral is employed, according to the formula
y = bdtr( k, n, p ) = incbet( n-k, k+1, 1-p ).
The arguments must be positive, with p ranging from 0 to 1.
ACCURACY:
Tested at random points (a,b,p), with p between 0 and 1.
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 4.3e-15 2.6e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double binomialdistribution(const ae_int_t k, const ae_int_t n, const doubl
e p);
/*************************************************************************
Complemented binomial distribution
Returns the sum of the terms k+1 through n of the Binomial
probability density:
n
-- ( n ) j n-j
> ( ) p (1-p)
-- ( j )
j=k+1
The terms are not summed directly; instead the incomplete
beta integral is employed, according to the formula
y = bdtrc( k, n, p ) = incbet( k+1, n-k, p ).
The arguments must be positive, with p ranging from 0 to 1.
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 6.7e-15 8.2e-16
For p between 0 and .001:
IEEE 0,100 100000 1.5e-13 2.7e-15
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double binomialcdistribution(const ae_int_t k, const ae_int_t n, const doub
le p);
/*************************************************************************
Inverse binomial distribution
Finds the event probability p such that the sum of the
terms 0 through k of the Binomial probability density
is equal to the given cumulative probability y.
This is accomplished using the inverse beta integral
function and the relation
1 - p = incbi( n-k, k+1, y ).
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 2.3e-14 6.4e-16
IEEE 0,10000 100000 6.6e-12 1.2e-13
For p between 10^-6 and 0.001:
IEEE 0,100 100000 2.0e-12 1.3e-14
IEEE 0,10000 100000 1.5e-12 3.2e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double invbinomialdistribution(const ae_int_t k, const ae_int_t n, const do
uble y);
/*************************************************************************
Chi-square distribution
Returns the area under the left hand tail (from 0 to x)
of the Chi square probability density function with
v degrees of freedom.
x
-
1 | | v/2-1 -t/2
P( x | v ) = ----------- | t e dt
v/2 - | |
2 | (v/2) -
0
where x is the Chi-square variable.
The incomplete gamma integral is used, according to the
formula
y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
The arguments must both be positive.
ACCURACY:
See incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
double chisquaredistribution(const double v, const double x);
/*************************************************************************
Complemented Chi-square distribution
Returns the area under the right hand tail (from x to
infinity) of the Chi square probability density function
with v degrees of freedom:
inf.
-
1 | | v/2-1 -t/2
P( x | v ) = ----------- | t e dt
v/2 - | |
2 | (v/2) -
x
where x is the Chi-square variable.
The incomplete gamma integral is used, according to the
formula
y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
The arguments must both be positive.
ACCURACY:
See incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
double chisquarecdistribution(const double v, const double x);
/*************************************************************************
Inverse of complemented Chi-square distribution
Finds the Chi-square argument x such that the integral
from x to infinity of the Chi-square density is equal
to the given cumulative probability y.
This is accomplished using the inverse gamma integral
function and the relation
x/2 = igami( df/2, y );
ACCURACY:
See inverse incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
double invchisquaredistribution(const double v, const double y);
/*************************************************************************
F distribution
Returns the area from zero to x under the F density
function (also known as Snedcor's density or the
variance ratio density). This is the density
of x = (u1/df1)/(u2/df2), where u1 and u2 are random
variables having Chi square distributions with df1
and df2 degrees of freedom, respectively.
The incomplete beta integral is used, according to the
formula
P(x) = incbet( df1/2, df2/2, (df1*x/(df2 + df1*x) ).
The arguments a and b are greater than zero, and x is
nonnegative.
ACCURACY:
Tested at random points (a,b,x).
x a,b Relative error:
arithmetic domain domain # trials peak rms
IEEE 0,1 0,100 100000 9.8e-15 1.7e-15
IEEE 1,5 0,100 100000 6.5e-15 3.5e-16
IEEE 0,1 1,10000 100000 2.2e-11 3.3e-12
IEEE 1,5 1,10000 100000 1.1e-11 1.7e-13
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
double fdistribution(const ae_int_t a, const ae_int_t b, const double x);
/*************************************************************************
Complemented F distribution
Returns the area from x to infinity under the F density
function (also known as Snedcor's density or the
variance ratio density).
inf.
-
1 | | a-1 b-1
1-P(x) = ------ | t (1-t) dt
B(a,b) | |
-
x
The incomplete beta integral is used, according to the
formula
P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ).
ACCURACY: Result:
the value of the Laguerre polynomial at x
*************************************************************************/
double laguerresum(const real_1d_array &c, const ae_int_t n, const double x
);
Tested at random points (a,b,x) in the indicated intervals. /*************************************************************************
x a,b Relative error: Representation of Ln as C[0] + C[1]*X + ... + C[N]*X^N
arithmetic domain domain # trials peak rms
IEEE 0,1 1,100 100000 3.7e-14 5.9e-16
IEEE 1,5 1,100 100000 8.0e-15 1.6e-15
IEEE 0,1 1,10000 100000 1.8e-11 3.5e-13
IEEE 1,5 1,10000 100000 2.0e-11 3.0e-12
Cephes Math Library Release 2.8: June, 2000 Input parameters:
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier N - polynomial degree, n>=0
Output parameters:
C - coefficients
*************************************************************************/ *************************************************************************/
double fcdistribution(const ae_int_t a, const ae_int_t b, const double x); void laguerrecoefficients(const ae_int_t n, real_1d_array &c);
/************************************************************************* /*************************************************************************
Inverse of complemented F distribution Calculation of the value of the Legendre polynomial Pn.
Finds the F density argument x such that the integral Parameters:
from x to infinity of the F density is equal to the n - degree, n>=0
given probability p. x - argument
This is accomplished using the inverse beta integral Result:
function and the relations the value of the Legendre polynomial Pn at x
*************************************************************************/
double legendrecalculate(const ae_int_t n, const double x);
z = incbi( df2/2, df1/2, p ) /*************************************************************************
x = df2 (1-z) / (df1 z). Summation of Legendre polynomials using Clenshaw
Note: the following relations hold for the inverse of This routine calculates
the uncomplemented F distribution: c[0]*P0(x) + c[1]*P1(x) + ... + c[N]*PN(x)
z = incbi( df1/2, df2/2, p ) Parameters:
x = df2 z / (df1 (1-z)). n - degree, n>=0
x - argument
ACCURACY: Result:
the value of the Legendre polynomial at x
*************************************************************************/
double legendresum(const real_1d_array &c, const ae_int_t n, const double x
);
Tested at random points (a,b,p). /*************************************************************************
Representation of Pn as C[0] + C[1]*X + ... + C[N]*X^N
a,b Relative error: Input parameters:
arithmetic domain # trials peak rms N - polynomial degree, n>=0
For p between .001 and 1:
IEEE 1,100 100000 8.3e-15 4.7e-16
IEEE 1,10000 100000 2.1e-11 1.4e-13
For p between 10^-6 and 10^-3:
IEEE 1,100 50000 1.3e-12 8.4e-15
IEEE 1,10000 50000 3.0e-12 4.8e-14
Cephes Math Library Release 2.8: June, 2000 Output parameters:
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier C - coefficients
*************************************************************************/ *************************************************************************/
double invfdistribution(const ae_int_t a, const ae_int_t b, const double y) ; void legendrecoefficients(const ae_int_t n, real_1d_array &c);
/************************************************************************* /*************************************************************************
Poisson distribution Poisson distribution
Returns the sum of the first k+1 terms of the Poisson Returns the sum of the first k+1 terms of the Poisson
distribution: distribution:
k j k j
-- -m m -- -m m
> e -- > e --
skipping to change at line 1698 skipping to change at line 1576
ACCURACY: ACCURACY:
See inverse incomplete gamma function See inverse incomplete gamma function
Cephes Math Library Release 2.8: June, 2000 Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/ *************************************************************************/
double invpoissondistribution(const ae_int_t k, const double y); double invpoissondistribution(const ae_int_t k, const double y);
/************************************************************************* /*************************************************************************
Psi (digamma) function
d -
psi(x) = -- ln | (x)
dx
is the logarithmic derivative of the gamma function.
For integer x,
n-1
-
psi(n) = -EUL + > 1/k.
-
k=1
This formula is used for 0 < n <= 10. If x is negative, it
is transformed to a positive argument by the reflection
formula psi(1-x) = psi(x) + pi cot(pi x).
For general positive x, the argument is made greater than 10
using the recurrence psi(x+1) = psi(x) + 1/x.
Then the following asymptotic expansion is applied:
inf. B
- 2k
psi(x) = log(x) - 1/2x - > -------
- 2k
k=1 2k x
where the B2k are Bernoulli numbers.
ACCURACY:
Relative error (except absolute when |psi| < 1):
arithmetic domain # trials peak rms
IEEE 0,30 30000 1.3e-15 1.4e-16
IEEE -30,0 40000 1.5e-15 2.2e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
double psi(const double x);
/*************************************************************************
Student's t distribution Student's t distribution
Computes the integral from minus infinity to t of the Student Computes the integral from minus infinity to t of the Student
t distribution with integer k > 0 degrees of freedom: t distribution with integer k > 0 degrees of freedom:
t t
- -
| | | |
- | 2 -(k+1)/2 - | 2 -(k+1)/2
| ( (k+1)/2 ) | ( x ) | ( (k+1)/2 ) | ( x )
skipping to change at line 1758 skipping to change at line 1677
Tested at random 1 <= k <= 100. The "domain" refers to p: Tested at random 1 <= k <= 100. The "domain" refers to p:
Relative error: Relative error:
arithmetic domain # trials peak rms arithmetic domain # trials peak rms
IEEE .001,.999 25000 5.7e-15 8.0e-16 IEEE .001,.999 25000 5.7e-15 8.0e-16
IEEE 10^-6,.001 25000 2.0e-12 2.9e-14 IEEE 10^-6,.001 25000 2.0e-12 2.9e-14
Cephes Math Library Release 2.8: June, 2000 Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/ *************************************************************************/
double invstudenttdistribution(const ae_int_t k, const double p); double invstudenttdistribution(const ae_int_t k, const double p);
/*************************************************************************
Sine and cosine integrals
Evaluates the integrals
x
-
| cos t - 1
Ci(x) = eul + ln x + | --------- dt,
| t
-
0
x
-
| sin t
Si(x) = | ----- dt
| t
-
0
where eul = 0.57721566490153286061 is Euler's constant.
The integrals are approximated by rational functions.
For x > 8 auxiliary functions f(x) and g(x) are employed
such that
Ci(x) = f(x) sin(x) - g(x) cos(x)
Si(x) = pi/2 - f(x) cos(x) - g(x) sin(x)
ACCURACY:
Test interval = [0,50].
Absolute error, except relative when > 1:
arithmetic function # trials peak rms
IEEE Si 30000 4.4e-16 7.3e-17
IEEE Ci 30000 6.9e-16 5.1e-17
Cephes Math Library Release 2.1: January, 1989
Copyright 1984, 1987, 1989 by Stephen L. Moshier
*************************************************************************/
void sinecosineintegrals(const double x, double &si, double &ci);
/*************************************************************************
Hyperbolic sine and cosine integrals
Approximates the integrals
x
-
| | cosh t - 1
Chi(x) = eul + ln x + | ----------- dt,
| | t
-
0
x
-
| | sinh t
Shi(x) = | ------ dt
| | t
-
0
where eul = 0.57721566490153286061 is Euler's constant.
The integrals are evaluated by power series for x < 8
and by Chebyshev expansions for x between 8 and 88.
For large x, both functions approach exp(x)/2x.
Arguments greater than 88 in magnitude return MAXNUM.
ACCURACY:
Test interval 0 to 88.
Relative error:
arithmetic function # trials peak rms
IEEE Shi 30000 6.9e-16 1.6e-16
Absolute error, except relative when |Chi| > 1:
IEEE Chi 30000 8.4e-16 1.4e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
void hyperbolicsinecosineintegrals(const double x, double &shi, double &chi
);
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
double gammafunction(double x, ae_state *_state); double gammafunction(double x, ae_state *_state);
skipping to change at line 1795 skipping to change at line 1795
double besseljn(ae_int_t n, double x, ae_state *_state); double besseljn(ae_int_t n, double x, ae_state *_state);
double bessely0(double x, ae_state *_state); double bessely0(double x, ae_state *_state);
double bessely1(double x, ae_state *_state); double bessely1(double x, ae_state *_state);
double besselyn(ae_int_t n, double x, ae_state *_state); double besselyn(ae_int_t n, double x, ae_state *_state);
double besseli0(double x, ae_state *_state); double besseli0(double x, ae_state *_state);
double besseli1(double x, ae_state *_state); double besseli1(double x, ae_state *_state);
double besselk0(double x, ae_state *_state); double besselk0(double x, ae_state *_state);
double besselk1(double x, ae_state *_state); double besselk1(double x, ae_state *_state);
double besselkn(ae_int_t nn, double x, ae_state *_state); double besselkn(ae_int_t nn, double x, ae_state *_state);
double beta(double a, double b, ae_state *_state); double beta(double a, double b, ae_state *_state);
double incompletebeta(double a, double b, double x, ae_state *_state);
double invincompletebeta(double a, double b, double y, ae_state *_state);
double binomialdistribution(ae_int_t k,
ae_int_t n,
double p,
ae_state *_state);
double binomialcdistribution(ae_int_t k,
ae_int_t n,
double p,
ae_state *_state);
double invbinomialdistribution(ae_int_t k,
ae_int_t n,
double y,
ae_state *_state);
double chebyshevcalculate(ae_int_t r, double chebyshevcalculate(ae_int_t r,
ae_int_t n, ae_int_t n,
double x, double x,
ae_state *_state); ae_state *_state);
double chebyshevsum(/* Real */ ae_vector* c, double chebyshevsum(/* Real */ ae_vector* c,
ae_int_t r, ae_int_t r,
ae_int_t n, ae_int_t n,
double x, double x,
ae_state *_state); ae_state *_state);
void chebyshevcoefficients(ae_int_t n, void chebyshevcoefficients(ae_int_t n,
/* Real */ ae_vector* c, /* Real */ ae_vector* c,
ae_state *_state); ae_state *_state);
void fromchebyshev(/* Real */ ae_vector* a, void fromchebyshev(/* Real */ ae_vector* a,
ae_int_t n, ae_int_t n,
/* Real */ ae_vector* b, /* Real */ ae_vector* b,
ae_state *_state); ae_state *_state);
double chisquaredistribution(double v, double x, ae_state *_state);
double chisquarecdistribution(double v, double x, ae_state *_state);
double invchisquaredistribution(double v, double y, ae_state *_state);
double dawsonintegral(double x, ae_state *_state); double dawsonintegral(double x, ae_state *_state);
double ellipticintegralk(double m, ae_state *_state); double ellipticintegralk(double m, ae_state *_state);
double ellipticintegralkhighprecision(double m1, ae_state *_state); double ellipticintegralkhighprecision(double m1, ae_state *_state);
double incompleteellipticintegralk(double phi, double m, ae_state *_state); double incompleteellipticintegralk(double phi, double m, ae_state *_state);
double ellipticintegrale(double m, ae_state *_state); double ellipticintegrale(double m, ae_state *_state);
double incompleteellipticintegrale(double phi, double m, ae_state *_state); double incompleteellipticintegrale(double phi, double m, ae_state *_state);
double exponentialintegralei(double x, ae_state *_state); double exponentialintegralei(double x, ae_state *_state);
double exponentialintegralen(double x, ae_int_t n, ae_state *_state); double exponentialintegralen(double x, ae_int_t n, ae_state *_state);
double fdistribution(ae_int_t a, ae_int_t b, double x, ae_state *_state);
double fcdistribution(ae_int_t a, ae_int_t b, double x, ae_state *_state);
double invfdistribution(ae_int_t a,
ae_int_t b,
double y,
ae_state *_state);
void fresnelintegral(double x, double* c, double* s, ae_state *_state); void fresnelintegral(double x, double* c, double* s, ae_state *_state);
double hermitecalculate(ae_int_t n, double x, ae_state *_state); double hermitecalculate(ae_int_t n, double x, ae_state *_state);
double hermitesum(/* Real */ ae_vector* c, double hermitesum(/* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
double x, double x,
ae_state *_state); ae_state *_state);
void hermitecoefficients(ae_int_t n, void hermitecoefficients(ae_int_t n,
/* Real */ ae_vector* c, /* Real */ ae_vector* c,
ae_state *_state); ae_state *_state);
double incompletebeta(double a, double b, double x, ae_state *_state);
double invincompletebeta(double a, double b, double y, ae_state *_state);
void jacobianellipticfunctions(double u, void jacobianellipticfunctions(double u,
double m, double m,
double* sn, double* sn,
double* cn, double* cn,
double* dn, double* dn,
double* ph, double* ph,
ae_state *_state); ae_state *_state);
double laguerrecalculate(ae_int_t n, double x, ae_state *_state); double laguerrecalculate(ae_int_t n, double x, ae_state *_state);
double laguerresum(/* Real */ ae_vector* c, double laguerresum(/* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
skipping to change at line 1853 skipping to change at line 1874
/* Real */ ae_vector* c, /* Real */ ae_vector* c,
ae_state *_state); ae_state *_state);
double legendrecalculate(ae_int_t n, double x, ae_state *_state); double legendrecalculate(ae_int_t n, double x, ae_state *_state);
double legendresum(/* Real */ ae_vector* c, double legendresum(/* Real */ ae_vector* c,
ae_int_t n, ae_int_t n,
double x, double x,
ae_state *_state); ae_state *_state);
void legendrecoefficients(ae_int_t n, void legendrecoefficients(ae_int_t n,
/* Real */ ae_vector* c, /* Real */ ae_vector* c,
ae_state *_state); ae_state *_state);
double poissondistribution(ae_int_t k, double m, ae_state *_state);
double poissoncdistribution(ae_int_t k, double m, ae_state *_state);
double invpoissondistribution(ae_int_t k, double y, ae_state *_state);
double psi(double x, ae_state *_state); double psi(double x, ae_state *_state);
double studenttdistribution(ae_int_t k, double t, ae_state *_state);
double invstudenttdistribution(ae_int_t k, double p, ae_state *_state);
void sinecosineintegrals(double x, void sinecosineintegrals(double x,
double* si, double* si,
double* ci, double* ci,
ae_state *_state); ae_state *_state);
void hyperbolicsinecosineintegrals(double x, void hyperbolicsinecosineintegrals(double x,
double* shi, double* shi,
double* chi, double* chi,
ae_state *_state); ae_state *_state);
double binomialdistribution(ae_int_t k,
ae_int_t n,
double p,
ae_state *_state);
double binomialcdistribution(ae_int_t k,
ae_int_t n,
double p,
ae_state *_state);
double invbinomialdistribution(ae_int_t k,
ae_int_t n,
double y,
ae_state *_state);
double chisquaredistribution(double v, double x, ae_state *_state);
double chisquarecdistribution(double v, double x, ae_state *_state);
double invchisquaredistribution(double v, double y, ae_state *_state);
double fdistribution(ae_int_t a, ae_int_t b, double x, ae_state *_state);
double fcdistribution(ae_int_t a, ae_int_t b, double x, ae_state *_state);
double invfdistribution(ae_int_t a,
ae_int_t b,
double y,
ae_state *_state);
double poissondistribution(ae_int_t k, double m, ae_state *_state);
double poissoncdistribution(ae_int_t k, double m, ae_state *_state);
double invpoissondistribution(ae_int_t k, double y, ae_state *_state);
double studenttdistribution(ae_int_t k, double t, ae_state *_state);
double invstudenttdistribution(ae_int_t k, double p, ae_state *_state);
} }
#endif #endif
 End of changes. 46 change blocks. 
598 lines changed or deleted 599 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/