54 for (i = 0; i < count; i++) {
55 for (j = i; j < count; j++) {
56 double sum = covar[i][j];
58 for (k = i - 1; k >= 0; k--)
59 sum -= factor[i][k] * factor[j][k];
64 factor[i][i] = sqrt(sum);
66 factor[j][i] = sum / factor[i][i];
71 for (i = 0; i < count; i++) {
72 double sum = covar_y[i + 1];
74 for (k = i - 1; k >= 0; k--)
75 sum -= factor[i][k] * m->
coeff[0][k];
77 m->
coeff[0][i] = sum / factor[i][i];
80 for (j = count - 1; j >= min_order; j--) {
81 for (i = j; i >= 0; i--) {
82 double sum = m->
coeff[0][i];
84 for (k = i + 1; k <= j; k++)
85 sum -= factor[k][i] * m->
coeff[j][k];
87 m->
coeff[j][i] = sum / factor[i][i];
92 for (i = 0; i <= j; i++) {
93 double sum = m->
coeff[j][i] * covar[i][i] - 2 * covar_y[i + 1];
95 for (k = 0; k < i; k++)
96 sum += 2 * m->
coeff[j][k] * covar[k][i];
108 for (i = 0; i <= order; i++)
109 out += param[i] * m->
coeff[order][i];
124 #if FF_API_LLS_PRIVATE
158 for (i = 0; i < 100; i++) {
162 var[0] = (
av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
163 var[1] = var[0] +
av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
164 var[2] = var[1] +
av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
165 var[3] = var[2] +
av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
168 for (order = 0; order < 3; order++) {
170 printf(
"real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
171 var[0], order, eval, sqrt(m.
variance[order] / (i + 1)),
double covariance[(((32+1)+(4)-1)&~((4)-1))][(((32+1)+(4)-1)&~((4)-1))]
void(* update_lls)(struct LLSModel *m, double *var)
Take the outer-product of var[] with itself, and add to the covariance matrix.
Linear least squares model.
double variance[MAX_VARS]
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
void av_solve_lls(LLSModel *m, double threshold, int min_order)
int main(int argc, char **argv)
void av_update_lls(LLSModel *m, double *param, double decay)
Libavutil version macros.
av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
static void update_lls(LLSModel *m, double *var)
static double evaluate_lls(LLSModel *m, double *param, int order)
void av_lfg_init(AVLFG *c, unsigned int seed)
void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
av_cold void av_init_lls(LLSModel *m, int indep_count)
double av_evaluate_lls(LLSModel *m, double *param, int order)
Macro definitions for various function/variable attributes.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
double(* evaluate_lls)(struct LLSModel *m, double *var, int order)
Inner product of var[] and the LPC coefs.
#define LOCAL_ALIGNED(a, t, v,...)
void ff_init_lls_x86(LLSModel *m)