liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
regress_linear.h
Go to the documentation of this file.
1
7#ifndef LIBA_REGRESS_LINEAR_H
8#define LIBA_REGRESS_LINEAR_H
9
10#include "a.h"
11
19
20#if defined(__cplusplus)
21extern "C" {
22#endif /* __cplusplus */
23
31A_EXTERN void a_regress_linear_init(a_regress_linear *ctx, a_float *coef_p, a_size coef_n, a_float bias);
32
39A_EXTERN a_float a_regress_linear_eval(a_regress_linear const *ctx, a_float const *val);
40
49A_EXTERN void a_regress_linear_err1(a_regress_linear const *ctx, a_size n, a_float const *x, a_float const *y, a_float *err);
50
59A_EXTERN void a_regress_linear_err2(a_regress_linear const *ctx, a_size n, a_float const *const *x, a_float const *y, a_float *err);
60
69A_EXTERN void a_regress_linear_pdm1(a_regress_linear const *ctx, a_size n, a_float const *x, a_float *pdm, a_float y_mean);
70
79A_EXTERN void a_regress_linear_pdm2(a_regress_linear const *ctx, a_size n, a_float const *const *x, a_float *pdm, a_float y_mean);
80
88A_EXTERN void a_regress_linear_gd(a_regress_linear *ctx, a_float const *input, a_float error, a_float alpha);
89
97A_EXTERN void a_regress_linear_sgd(a_regress_linear *ctx, a_float const *x, a_float y, a_float alpha);
98
107A_EXTERN void a_regress_linear_sgd1(a_regress_linear *ctx, a_size n, a_float const *x, a_float const *y, a_float alpha);
108
117A_EXTERN void a_regress_linear_sgd2(a_regress_linear *ctx, a_size n, a_float const *const *x, a_float const *y, a_float alpha);
118
127A_EXTERN void a_regress_linear_bgd1(a_regress_linear *ctx, a_size n, a_float const *x, a_float const *err, a_float alpha);
128
137A_EXTERN void a_regress_linear_bgd2(a_regress_linear *ctx, a_size n, a_float const *const *x, a_float const *err, a_float alpha);
138
154A_EXTERN a_float a_regress_linear_mgd1(a_regress_linear *ctx, a_size n, a_float const *x, a_float const *y, a_float *err,
155 a_float delta, a_float lrmax, a_float lrmin, a_size lrtim, a_size epoch, a_size batch);
156
172A_EXTERN a_float a_regress_linear_mgd2(a_regress_linear *ctx, a_size n, a_float const *const *x, a_float const *y, a_float *err,
173 a_float delta, a_float lrmax, a_float lrmin, a_size lrtim, a_size epoch, a_size batch);
174
180
181#if defined(__cplusplus)
182} /* extern "C" */
183namespace a
184{
185typedef struct a_regress_linear regress_linear;
186} /* namespace a */
187#endif /* __cplusplus */
188
193{
194 a_float *coef_p; // points to regression coefficients
195 a_size coef_n; // number of regression coefficients
196 a_float bias; // intercept
197#if defined(__cplusplus)
198 A_INLINE void init(a_float *p, a_size n, a_float b = 0)
199 {
200 a_regress_linear_init(this, p, n, b);
201 }
202 A_INLINE a_float eval(a_float const *val) const
203 {
204 return a_regress_linear_eval(this, val);
205 }
206 A_INLINE void err1(a_size n, a_float const *x, a_float const *y, a_float *err) const
207 {
208 a_regress_linear_err1(this, n, x, y, err);
209 }
210 A_INLINE void err2(a_size n, a_float const *const *x, a_float const *y, a_float *err) const
211 {
212 a_regress_linear_err2(this, n, x, y, err);
213 }
214 A_INLINE void pdm1(a_size n, a_float const *x, a_float *pdm, a_float y_mean) const
215 {
216 a_regress_linear_pdm1(this, n, x, pdm, y_mean);
217 }
218 A_INLINE void pdm2(a_size n, a_float const *const *x, a_float *pdm, a_float y_mean) const
219 {
220 a_regress_linear_pdm2(this, n, x, pdm, y_mean);
221 }
222 A_INLINE void gd(a_float const *input, a_float error, a_float alpha)
223 {
224 a_regress_linear_gd(this, input, error, alpha);
225 }
226 A_INLINE void sgd(a_float const *x, a_float y, a_float alpha)
227 {
228 a_regress_linear_sgd(this, x, y, alpha);
229 }
230 A_INLINE void sgd1(a_size n, a_float const *x, a_float const *y, a_float alpha)
231 {
232 a_regress_linear_sgd1(this, n, x, y, alpha);
233 }
234 A_INLINE void sgd2(a_size n, a_float const *const *x, a_float const *y, a_float alpha)
235 {
236 a_regress_linear_sgd2(this, n, x, y, alpha);
237 }
238 A_INLINE void bgd1(a_size n, a_float const *x, a_float const *err, a_float alpha)
239 {
240 a_regress_linear_bgd1(this, n, x, err, alpha);
241 }
242 A_INLINE void bgd2(a_size n, a_float const *const *x, a_float const *err, a_float alpha)
243 {
244 a_regress_linear_bgd2(this, n, x, err, alpha);
245 }
246 A_INLINE a_float mgd1(a_size n, a_float const *x, a_float const *y, a_float *err, a_float delta,
247 a_float lrmax, a_float lrmin, a_size lrtim, a_size epoch, a_size batch)
248 {
249 return a_regress_linear_mgd1(this, n, x, y, err, delta, lrmax, lrmin, lrtim, epoch, batch);
250 }
251 A_INLINE a_float mgd2(a_size n, a_float const *const *x, a_float const *y, a_float *err, a_float delta,
252 a_float lrmax, a_float lrmin, a_size lrtim, a_size epoch, a_size batch)
253 {
254 return a_regress_linear_mgd2(this, n, x, y, err, delta, lrmax, lrmin, lrtim, epoch, batch);
255 }
256 A_INLINE void zero() { a_regress_linear_zero(this); }
257#endif /* __cplusplus */
258};
259
262#endif /* a/regress_linear.h */
algorithm library
#define a_float
Definition a.h:785
void a_regress_linear_sgd(a_regress_linear *ctx, double const *x, double y, double alpha)
stochastic gradient descent for linear regression
double a_regress_linear_eval(a_regress_linear const *ctx, double const *val)
calculate predicted value for linear regression
void a_regress_linear_pdm1(a_regress_linear const *ctx, size_t n, double const *x, double *pdm, double y_mean)
calculate prediction deviation from mean for linear regression
void a_regress_linear_bgd1(a_regress_linear *ctx, size_t n, double const *x, double const *err, double alpha)
batch gradient descent for linear regression
void a_regress_linear_sgd2(a_regress_linear *ctx, size_t n, double const *const *x, double const *y, double alpha)
stochastic gradient descent for linear regression
void a_regress_linear_bgd2(a_regress_linear *ctx, size_t n, double const *const *x, double const *err, double alpha)
batch gradient descent for linear regression
void a_regress_linear_init(a_regress_linear *ctx, double *coef_p, size_t coef_n, double bias)
initialize for linear regression
void a_regress_linear_zero(a_regress_linear *ctx)
zeroing for linear regression
void a_regress_linear_pdm2(a_regress_linear const *ctx, size_t n, double const *const *x, double *pdm, double y_mean)
calculate prediction deviation from mean for linear regression
void a_regress_linear_gd(a_regress_linear *ctx, double const *input, double error, double alpha)
gradient descent for linear regression
double a_regress_linear_mgd1(a_regress_linear *ctx, size_t n, double const *x, double const *y, double *err, double delta, double lrmax, double lrmin, size_t lrtim, size_t epoch, size_t batch)
mini-batch gradient descent for linear regression
void a_regress_linear_err1(a_regress_linear const *ctx, size_t n, double const *x, double const *y, double *err)
calculate residuals for linear regression
void a_regress_linear_err2(a_regress_linear const *ctx, size_t n, double const *const *x, double const *y, double *err)
calculate residuals for linear regression
void a_regress_linear_sgd1(a_regress_linear *ctx, size_t n, double const *x, double const *y, double alpha)
stochastic gradient descent for linear regression
double a_regress_linear_mgd2(a_regress_linear *ctx, size_t n, double const *const *x, double const *y, double *err, double delta, double lrmax, double lrmin, size_t lrtim, size_t epoch, size_t batch)
mini-batch gradient descent for linear regression
#define a_size
Definition a.h:610
instance structure for linear regression
Definition regress_linear.h:193