@@ -30,6 +30,9 @@ double feenox_builtin_vecminindex(vector_t **);
3030double feenox_builtin_vecmaxindex (vector_t * * );
3131double feenox_builtin_vecsum (vector_t * * );
3232double feenox_builtin_vecsize (vector_t * * );
33+ double feenox_builtin_vecmean (vector_t * * );
34+ double feenox_builtin_vecvariance (vector_t * * );
35+ double feenox_builtin_vecsd (vector_t * * );
3336
3437
3538struct builtin_vectorfunction_t builtin_vectorfunction [N_BUILTIN_VECTOR_FUNCTIONS ] = {
@@ -41,6 +44,9 @@ struct builtin_vectorfunction_t builtin_vectorfunction[N_BUILTIN_VECTOR_FUNCTION
4144 {"vecminindex" , 1 , 1 , & feenox_builtin_vecminindex },
4245 {"vecmaxindex" , 1 , 1 , & feenox_builtin_vecmaxindex },
4346 {"vecsum" , 1 , 1 , & feenox_builtin_vecsum },
47+ {"vecmean" , 1 , 1 , & feenox_builtin_vecmean },
48+ {"vecvariance" , 1 , 1 , & feenox_builtin_vecvariance },
49+ {"vecsd" , 1 , 1 , & feenox_builtin_vecsd },
4450};
4551
4652///fv+vecsize+usage vecsize(b)
@@ -188,3 +194,39 @@ double feenox_builtin_vecdot(vector_t **arg) {
188194 return s ;
189195}
190196
197+ ///fv+vecmean+usage vecmean(a)
198+ ///fv+vecmean+math \hat{\vec{a}} = \frac{1}{\text{vecsize}(\vec{a})} \cdot \sum_{i=1}^{\text{vecsize}(\vec{a})} a_i
199+ ///fv+vecmean+desc Computes the mean value of the elements of vector $\vec{a}$.
200+ double feenox_builtin_vecmean (vector_t * * arg ) {
201+
202+ if (!arg [0 ]-> initialized ) {
203+ feenox_vector_init (arg [0 ], FEENOX_VECTOR_INITIAL );
204+ }
205+
206+ return gsl_stats_mean (arg [0 ]-> value -> data , arg [0 ]-> value -> stride , arg [0 ]-> size );
207+ }
208+
209+ ///fv+vecvariance+usage vecvariance(a)
210+ ///fv+vecvariance+math \hat{\Sigma_\vec{a}} = \frac{1}{\text{vecsize}(\vec{a}) -1} \cdot \sum_{i=1}^{\text{vecsize}(\vec{a})} (a_i - \hat{\vec{a}})^2
211+ ///fv+vecvariance+desc Computes the variance of the elements of vector $\vec{a}$.
212+ double feenox_builtin_vecvariance (vector_t * * arg ) {
213+
214+ if (!arg [0 ]-> initialized ) {
215+ feenox_vector_init (arg [0 ], FEENOX_VECTOR_INITIAL );
216+ }
217+
218+ return gsl_stats_variance (arg [0 ]-> value -> data , arg [0 ]-> value -> stride , arg [0 ]-> size );
219+ }
220+
221+ ///fv+vecsd+usage vecsd(a)
222+ ///fv+vecsd+math \sqrt(\hat{\Sigma_\vec{a}}) = \sqrt{\frac{1}{\text{vecsize}(\vec{a}) -1} \cdot \sum_{i=1}^{\text{vecsize}(\vec{a})} (a_i - \hat{\vec{a}})^2}
223+ ///fv+vecsd+desc Computes the standar deviation of the elements of vector $\vec{a}$.
224+ ///fv+vecsd+desc This is the square root of the variance `vecvariance(a)`.
225+ double feenox_builtin_vecsd (vector_t * * arg ) {
226+
227+ if (!arg [0 ]-> initialized ) {
228+ feenox_vector_init (arg [0 ], FEENOX_VECTOR_INITIAL );
229+ }
230+
231+ return gsl_stats_sd (arg [0 ]-> value -> data , arg [0 ]-> value -> stride , arg [0 ]-> size );
232+ }
0 commit comments