diff options
Diffstat (limited to 'src/c/statisticsFunctions')
20 files changed, 1662 insertions, 13 deletions
diff --git a/src/c/statisticsFunctions/Makefile.am b/src/c/statisticsFunctions/Makefile.am index c27afc34..e87f3868 100644 --- a/src/c/statisticsFunctions/Makefile.am +++ b/src/c/statisticsFunctions/Makefile.am @@ -17,4 +17,5 @@ SUBDIRS= mean \ min\ max\ meanf\ - variancef + variancef\ + stdevf diff --git a/src/c/statisticsFunctions/Makefile.in b/src/c/statisticsFunctions/Makefile.in index fa08fb04..856ee3d0 100644 --- a/src/c/statisticsFunctions/Makefile.in +++ b/src/c/statisticsFunctions/Makefile.in @@ -182,7 +182,8 @@ SUBDIRS = mean \ min\ max\ meanf\ - variancef + variancef\ + stdevf all: all-recursive diff --git a/src/c/statisticsFunctions/includes/stdevf.h b/src/c/statisticsFunctions/includes/stdevf.h new file mode 100644 index 00000000..5ccec182 --- /dev/null +++ b/src/c/statisticsFunctions/includes/stdevf.h @@ -0,0 +1,119 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + +#ifndef __STDEVF_H__ +#define __STDEVF_H__ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + + +#include "dynlib_statisticsfunctions.h" +#include "subtraction.h" +#include "division.h" + + +#include "pow.h" +#include "sum.h" +#include "size.h" +#include "sqrt.h" +#include "meanf.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + + + + +/* +** \brief Standard deviation of a scalar element, just returns it +*/ +#define sstdevfs(in1,in2) 0.0f +#define srowstdevfs(in1,in2) 0.0f +#define scolumnstdevfs(in1,in2) 0.0f + + +/* +** \brief Standard deviation of a scalar element, just returns it +*/ +#define dstdevfs(in1,in2) 0.0 +#define drowstdevfs(in1,in2) 0.0 +#define dcolumnstdevfs(in1,in2) 0.0 + + +/* +** \brief Standard deviation of a scalar element, just returns it +*/ +#define cstdevfs(in1,in2) FloatComplex(0.0f , 0.0f) +#define crowstdevfs(in1,in2) FloatComplex(0.0f , 0.0f) +#define ccolumnstdevfs(in1,in2) FloatComplex(0.0f , 0.0f) + + +/* +** \brief Standard deviation of a scalar element, just returns it +*/ +#define zstdevfs(in1,in2) DoubleComplex(0.0 , 0.0) +#define zrowstdevfs(in1,in2) DoubleComplex(0.0 , 0.0) +#define zcolumnstdevfs(in1,in2) DoubleComplex(0.0 , 0.0) + + +/* +** \brief Standard deviation of a float array +** \param in the float array to process +** \param size, the size of the array +** \returns the stdevf. +*/ +EXTERN_STATFUNC float sstdevfa(float *in1, int lines, int columns, float *in2); +EXTERN_STATFUNC void srowstdevfa(float *in1, int lines, int columns, float *in2, float* out); +EXTERN_STATFUNC void scolumnstdevfa(float *in1, int lines, int columns, float *in2, float* out); + +/* +** \brief Standard deviation of a double array +** \param in the double array to process +** \param size, the size of the array +** \returns the stdevf. +*/ +EXTERN_STATFUNC double dstdevfa(double *in1, int lines, int columns, double *in2); +EXTERN_STATFUNC void drowstdevfa(double *in1, int lines, int columns, double *in2, double* out); +EXTERN_STATFUNC void dcolumnstdevfa(double *in1, int lines, int columns, double *in2, double* out); + +/* +** \brief Standard deviation of a float complex array +** \param in the float array to process +** \param size, the size of the array +** \returns the stdevf. +*/ +EXTERN_STATFUNC floatComplex cstdevfa(floatComplex *in1, int lines, int columns, floatComplex *in2); +EXTERN_STATFUNC void crowstdevfa(floatComplex *in1, int lines, int columns, floatComplex *in2, floatComplex* out); +EXTERN_STATFUNC void ccolumnstdevfa(floatComplex *in1, int lines, int columns, floatComplex *in2, floatComplex* out); + +/* +** \brief Standard deviation of a double complex array +** \param in the double array to process +** \param size, the size of the array +** \returns the stdevf. +*/ +EXTERN_STATFUNC doubleComplex zstdevfa(doubleComplex *in1, int lines, int columns, doubleComplex *in2); +EXTERN_STATFUNC void zrowstdevfa(doubleComplex *in1, int lines, int columns, doubleComplex *in2, doubleComplex* out); +EXTERN_STATFUNC void zcolumnstdevfa(doubleComplex *in1, int lines, int columns, doubleComplex *in2, doubleComplex* out); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* !__STDEVF_H__ */ diff --git a/src/c/statisticsFunctions/includes/variancef.h b/src/c/statisticsFunctions/includes/variancef.h index e86a65eb..e682a187 100644 --- a/src/c/statisticsFunctions/includes/variancef.h +++ b/src/c/statisticsFunctions/includes/variancef.h @@ -10,8 +10,8 @@ * */ -#ifndef __VARIANCE_H__ -#define __VARIANCE_H__ +#ifndef __VARIANCEF_H__ +#define __VARIANCEF_H__ #include <stdio.h> #include <stdlib.h> @@ -114,4 +114,4 @@ EXTERN_STATFUNC void zcolumnvariancefa(doubleComplex *in1, int lines, int colum #endif -#endif /* !__VARIANCE_H__ */ +#endif /* !__VARIANCEF_H__ */ diff --git a/src/c/statisticsFunctions/stdevf/Makefile.am b/src/c/statisticsFunctions/stdevf/Makefile.am new file mode 100644 index 00000000..cebe3c93 --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/Makefile.am @@ -0,0 +1,88 @@ +## +## Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +## Copyright (C) 2006-2008 - INRIA - Bruno JOFRET +## +## This file must be used under the terms of the CeCILL. +## This source file is licensed as described in the file COPYING, which +## you should have received as part of this distribution. The terms +## are also available at +## http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +## +## + +libStdevf_la_CFLAGS = -I $(top_builddir)/src/c/type \ + -I $(top_builddir)/src/c/operations/includes \ + -I $(top_builddir)/src/c/auxiliaryFunctions/includes \ + -I $(top_builddir)/src/c/elementaryFunctions/includes \ + -I ../includes + +instdir = $(top_builddir)/lib + +pkglib_LTLIBRARIES = libStdevf.la + +libStdevf_la_SOURCES = $(HEAD) $(SRC) + +SRC = sstdevfa.c \ + srowstdevfa.c \ + scolumnstdevfa.c \ + dstdevfa.c \ + drowstdevfa.c \ + dcolumnstdevfa.c \ + cstdevfa.c \ + crowstdevfa.c \ + ccolumnstdevfa.c \ + zstdevfa.c \ + zrowstdevfa.c \ + zcolumnstdevfa.c + +HEAD = ../includes/stdevf.h + +#### +# Checking Part +#### + +check_INCLUDES = -I $(top_builddir)/src/c/statisticsFunctions/includes \ + -I $(top_builddir)/src/c/operations/includes \ + -I $(top_builddir)/src/c/auxiliaryFunctions/includes \ + -I $(top_builddir)/src/c/elementaryFunctions/includes \ + -I $(top_builddir)/src/c/type + +check_LDADD = $(top_builddir)/src/c/type/libDoubleComplex.la \ + $(top_builddir)/src/c/type/libFloatComplex.la \ + $(top_builddir)/src/c/operations/addition/libAddition.la \ + $(top_builddir)/src/fortran/lapack/libscilapack.la \ + $(top_builddir)/src/c/operations/subtraction/libSubtraction.la \ + $(top_builddir)/src/c/statisticsFunctions/stdevf/libStdevf.la \ + $(top_builddir)/src/c/statisticsFunctions/sum/libSum.la \ + $(top_builddir)/src/c/statisticsFunctions/meanf/libMeanf.la \ + $(top_builddir)/src/c/operations/division/libDivision.la \ + $(top_builddir)/src/c/operations/multiplication/libMultiplication.la \ + $(top_builddir)/src/c/auxiliaryFunctions/conj/libConj.la \ + $(top_builddir)/src/c/elementaryFunctions/pow/libPow.la \ + $(top_builddir)/src/c/elementaryFunctions/exp/libExp.la \ + $(top_builddir)/src/c/elementaryFunctions/sin/libSin.la \ + $(top_builddir)/src/c/elementaryFunctions/cos/libCos.la \ + $(top_builddir)/src/c/elementaryFunctions/cosh/libCosh.la \ + $(top_builddir)/src/c/elementaryFunctions/log/libLog.la \ + $(top_builddir)/src/c/elementaryFunctions/log1p/libLog1p.la \ + $(top_builddir)/src/c/elementaryFunctions/lnp1m1/libLnp1m1.la \ + $(top_builddir)/src/c/auxiliaryFunctions/pythag/libPythag.la \ + $(top_builddir)/src/c/auxiliaryFunctions/abs/libAbs.la \ + $(top_builddir)/src/c/elementaryFunctions/sinh/libSinh.la \ + $(top_builddir)/src/c/elementaryFunctions/sqrt/libSqrt.la \ + @LIBMATH@ + +check_PROGRAMS = testFloatStdevf testDoubleStdevf + +TESTS = testFloatStdevf testDoubleStdevf + +# +# -*- Stdevf Tests -*- +# +testFloatStdevf_SOURCES = testFloatStdevf.c +testFloatStdevf_CFLAGS = $(check_INCLUDES) +testFloatStdevf_LDADD = $(check_LDADD) + +testDoubleStdevf_SOURCES =testDoubleStdevf.c +testDoubleStdevf_CFLAGS = $(check_INCLUDES) +testDoubleStdevf_LDADD = $(check_LDADD) diff --git a/src/c/statisticsFunctions/stdevf/ccolumnstdevfa.c b/src/c/statisticsFunctions/stdevf/ccolumnstdevfa.c new file mode 100644 index 00000000..64c2deed --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/ccolumnstdevfa.c @@ -0,0 +1,56 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + + +#include "stdevf.h" + + +void ccolumnstdevfa(floatComplex *in1, int lines, int columns, floatComplex*in2, floatComplex* out){ + int i = 0; + int j = 0; + floatComplex temp = FloatComplex(0.0f,0.0f); + floatComplex accumulate = FloatComplex(0.0f,0.0f); + float accumulateFre =0.0f ; + + ccolumnmeanfa(in1, lines, columns, in2, out ); + + + /*we first multiply each cell of the input matrix by its coefficient*/ + for (j = 0; j < lines; ++j) + { + accumulate = FloatComplex(0.0f,0.0f); + accumulateFre =0.0f ; + temp = FloatComplex(0.0f,0.0f); + + for ( i = 0 ; i < columns; ++i ) + { + + temp = cpows ( cdiffs (in1[lines*i + j] ,out[j] ) ,FloatComplex (2.0f, 0.0f ) ); + temp = cmuls( in2[lines*i + j] , temp); + + accumulate = cadds( temp , accumulate); + accumulateFre += creals(in2[lines*i + j]); + + } + + if (lines <= 1) + { + out[j] = cmuls (FloatComplex(0.0f,0.0f) , accumulate ) ; + } + else + { + accumulate = FloatComplex( creals(accumulate ) / (accumulateFre - 1) , cimags(accumulate) / (accumulateFre - 1)); + out[j] =csqrts(accumulate); + } + } + +} diff --git a/src/c/statisticsFunctions/stdevf/crowstdevfa.c b/src/c/statisticsFunctions/stdevf/crowstdevfa.c new file mode 100644 index 00000000..b22f90a9 --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/crowstdevfa.c @@ -0,0 +1,57 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + + +#include "stdevf.h" +#include "meanf.h" + + + +void crowstdevfa(floatComplex *in1, int lines, int columns, floatComplex*in2, floatComplex* out){ + int i = 0; + int j = 0; + floatComplex temp = FloatComplex(0.0f,0.0f); + floatComplex accumulate = FloatComplex(0.0f,0.0f); + float accumulateFre = 0.0f ; + + crowmeanfa(in1, lines, columns, in2, out ); + + /*we first multiply each cell of the input matrix by its coefficient*/ + for (j = 0; j < columns; ++j) + { + accumulate = FloatComplex(0.0f,0.0f); + accumulateFre = 0.0f ; + temp = FloatComplex(0.0f,0.0f); + + for ( i = 0 ; i < lines; ++i ) + { + + temp = cpows ( cdiffs (in1[lines*j + i] ,out[j] ) ,FloatComplex (2.0f, 0.0f ) ); + temp = cmuls( in2[lines*j + i] , temp); + + accumulate = cadds( temp , accumulate); + accumulateFre += creals(in2[lines*j + i]); + + } + + if (lines <= 1) + { + out[j] = cmuls (FloatComplex(0.0f,0.0f) , accumulate ) ; + } + else + { + accumulate = FloatComplex( creals(accumulate ) / (accumulateFre - 1) , cimags(accumulate) / (accumulateFre - 1)); + out[j] = csqrts(accumulate); + } + } + +} diff --git a/src/c/statisticsFunctions/stdevf/cstdevfa.c b/src/c/statisticsFunctions/stdevf/cstdevfa.c new file mode 100644 index 00000000..63ce3948 --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/cstdevfa.c @@ -0,0 +1,41 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + +#include "stdevf.h" + +floatComplex cstdevfa(floatComplex *in1, int lines, int columns, floatComplex* in2) +{ + int i = 0 ; + floatComplex temp = FloatComplex(0.0f,0.0f); + floatComplex accumulate = FloatComplex(0.0f,0.0f); + float accumulateFre = 0.0f ; + floatComplex meanf = cmeanfa (in1 , lines*columns , in2); +/*equivalent to (in1 - meanf(x , in2 )).^2 .*in2 */ + for(i = 0 ; i < lines*columns ; ++i) + { + temp = cpows ( cdiffs (in1[i] , meanf ) ,FloatComplex (2.0f, 0.0f ) ); + temp = cmuls( in2[i] , temp); + + accumulate = cadds( temp , accumulate); + accumulateFre += creals(in2[i]); + } + + if (lines <= 1) + { + return cmuls (FloatComplex(0.0f,0.0f) , accumulate ) ; + } + else + { + accumulate = FloatComplex( creals(accumulate ) / (accumulateFre - 1) , cimags(accumulate) / (accumulateFre - 1)); + return csqrts(accumulate); + } +} diff --git a/src/c/statisticsFunctions/stdevf/dcolumnstdevfa.c b/src/c/statisticsFunctions/stdevf/dcolumnstdevfa.c new file mode 100644 index 00000000..9c8e76d3 --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/dcolumnstdevfa.c @@ -0,0 +1,70 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + + +#include "stdevf.h" +#include "meanf.h" + +#include <stdio.h> + +void dcolumnstdevfa(double *in1, int lines, int columns, double *in2, double* out){ + int i = 0; + int j = 0; + double temp = 0.0; + double accumulate = 0.0; + double accumulateFre = 0.0 ; + + dcolumnmeanfa(in1, lines, columns, in2, out ); + + + /*we first multiply each cell of the input matrix by its coefficient*/ + for (j = 0; j < lines; ++j) + { + accumulate = 0.0; + accumulateFre= 0.0; + temp = 0.0; + + for ( i = 0 ; i < columns; ++i ) + { + temp = dpows ( (in1[lines*i + j] - out[j] ) ,2 ); + temp *= in2[lines*i + j]; + + accumulate += temp ; + accumulateFre += in2[lines*i + j]; + } + + if (lines <= 1) + { + out[j] = 0.0 * accumulate ; + } + else + { + out[j] = dsqrts(accumulate / (accumulateFre - 1)); + } + } + +} +/* + + ! +! elseif o == 'c' | o == 2 then ! +! // here ones is used becaue we work on matrix , but in C we work on element so we only need iteratation ! +! y = x - meanf(x, fre, o) * ones(1, size(x, o)) ! +! ! + +! if size(x, 1) == 1 then ! ! +! s = 0 * sum(y.^2 .* fre, o) ! +! else ! ! +! s = sqrt(sum(y.^2 .* fre, o) ./ (sum(fre, o) - 1)); ! + ! +*/ + diff --git a/src/c/statisticsFunctions/stdevf/drowstdevfa.c b/src/c/statisticsFunctions/stdevf/drowstdevfa.c new file mode 100644 index 00000000..c861f06b --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/drowstdevfa.c @@ -0,0 +1,53 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + + +#include "stdevf.h" + + +void drowstdevfa(double *in1, int lines, int columns, double *in2, double* out){ + int i = 0; + int j = 0; + double temp = 0.0f; + double accumulate = 0.0f; + double accumulateFre = 0.0f ; + + drowmeanfa(in1, lines, columns, in2, out ); + + + /*we first multiply each cell of the input matrix by its coefficient*/ + for (j = 0; j < columns; ++j) + { + accumulate = 0.0f; + accumulateFre= 0.0f; + temp = 0.0f; + + for ( i = 0 ; i < lines; ++i ) + { + temp = dpows ( (in1[lines*j + i] - out[j] ) ,2 ); + temp *= in2[lines*j + i]; + + accumulate += temp ; + accumulateFre += in2[lines*j + i]; + } + + if (lines <= 1) + { + out[j] = 0.0 * accumulate ; + } + else + { + out[j] = dsqrts(accumulate / (accumulateFre - 1)); + } + } + +} diff --git a/src/c/statisticsFunctions/stdevf/dstdevfa.c b/src/c/statisticsFunctions/stdevf/dstdevfa.c new file mode 100644 index 00000000..4194435c --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/dstdevfa.c @@ -0,0 +1,43 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + +#include "stdevf.h" + +double dstdevfa(double *in1, int lines, int columns, double* in2) +{ + int i = 0 ; + double meanf = dmeanfa (in1 , lines*columns , in2); + double temp = 0.0; + double accumulate = 0.0 ; + double accumulateFre = 0.0 ; + /*printf ("\nmeanf %lf \n" ,meanf);*/ + + /*equivalent to (in1 - meanf(x , in2 )).^2 .*in2 */ + for(i = 0 ; i < lines*columns; ++i) + { + + temp = dpows ( (in1[i] - meanf ) ,2 ); + temp *= in2[i]; + + accumulate += temp ; + accumulateFre += in2[i]; + } + + if (lines <= 1) + { + return 0.0 * accumulate ; + } + else + { + return dsqrts(accumulate) / (accumulateFre - 1); + } +} diff --git a/src/c/statisticsFunctions/stdevf/scolumnstdevfa.c b/src/c/statisticsFunctions/stdevf/scolumnstdevfa.c new file mode 100644 index 00000000..d39ce88a --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/scolumnstdevfa.c @@ -0,0 +1,70 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + + +#include "stdevf.h" +#include "meanf.h" + +#include <stdio.h> + +void scolumnstdevfa(float *in1, int lines, int columns, float *in2, float* out){ + int i = 0; + int j = 0; + float temp = 0.0f; + float accumulate = 0.0f; + float accumulateFre = 0.0f ; + + scolumnmeanfa(in1, lines, columns, in2, out ); + + + /*we first multiply each cell of the input matrix by its coefficient*/ + for (j = 0; j < lines; ++j) + { + accumulate = 0.0f; + accumulateFre= 0.0f; + temp = 0.0f; + + for ( i = 0 ; i < columns; ++i ) + { + temp = spows ( (in1[lines*i + j] - out[j] ) ,2 ); + temp *= in2[lines*i + j]; + + accumulate += temp ; + accumulateFre += in2[lines*i + j]; + } + + if (lines <= 1) + { + out[j] = 0.0f * accumulate ; + } + else + { + out[j] = ssqrts(accumulate / (accumulateFre - 1)); + } + } + +} +/* + + ! +! elseif o == 'c' | o == 2 then ! +! // here ones is used becaue we work on matrix , but in C we work on element so we only need iteratation ! +! y = x - meanf(x, fre, o) * ones(1, size(x, o)) ! +! ! + +! if size(x, 1) == 1 then ! ! +! s = 0 * sum(y.^2 .* fre, o) ! +! else ! ! +! s = sqrt(sum(y.^2 .* fre, o) ./ (sum(fre, o) - 1)); ! + ! +*/ + diff --git a/src/c/statisticsFunctions/stdevf/srowstdevfa.c b/src/c/statisticsFunctions/stdevf/srowstdevfa.c new file mode 100644 index 00000000..486111b6 --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/srowstdevfa.c @@ -0,0 +1,55 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + + +#include "stdevf.h" +#include "meanf.h" + +#include <stdio.h> + +void srowstdevfa(float *in1, int lines, int columns, float *in2, float* out){ + int i = 0; + int j = 0; + float temp = 0.0f; + float accumulate = 0.0f; + float accumulateFre = 0.0f ; + + srowmeanfa(in1, lines, columns, in2, out ); +printf ("\nmfwerfwerfwefwef \n" ); + + /*we first multiply each cell of the input matrix by its coefficient*/ + for (j = 0; j < columns; ++j) + { + accumulate = 0.0f; + accumulateFre= 0.0f; + temp = 0.0f; + + for ( i = 0 ; i < lines; ++i ) + { + temp = spows ( (in1[lines*j + i] - out[j] ) ,2 ); + temp *= in2[lines*j + i]; + + accumulate += temp ; + accumulateFre += in2[lines*j + i]; + } + + if (lines <= 1) + { + out[j] = 0.0f * accumulate ; + } + else + { + out[j] = ssqrts(accumulate/ (accumulateFre - 1)); + } + } + +} diff --git a/src/c/statisticsFunctions/stdevf/sstdevfa.c b/src/c/statisticsFunctions/stdevf/sstdevfa.c new file mode 100644 index 00000000..fd67544b --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/sstdevfa.c @@ -0,0 +1,68 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + +#include "stdevf.h" +#include <stdio.h> +float sstdevfa(float *in1, int lines, int columns, float* in2) +{ + int i = 0 ; + float meanf = smeanfa (in1 , lines*columns , in2); + float temp = 0.0f; + float accumulate = 0.0f ; + float accumulateFre = 0.0f ; + + + /*equivalent to (in1 - meanf(x , in2 )).^2 .*in2 */ + for(i = 0 ; i < lines*columns; ++i) + { + + temp = spows ( (in1[i] - meanf ) ,2 ); + temp *= in2[i]; + + accumulate += temp ; + accumulateFre += in2[i]; + } + + if (lines <= 1) + { + return 0.0f * accumulate ; + } + else + { + return ssqrts( accumulate/(accumulateFre - 1) ); + } +} +/* + +! o = '*' ! + +! //remove the median ! +! ! +! if o == '*' then ! +! ! +! y = x - meanf(x, fre) ! +! ! +! elseif o == 'r' | o == 1 then ! +! ! +! y = x - ones(size(x, o), 1) * meanf(x, fre, o) ! +! ! +! elseif o == 'c' | o == 2 then ! +! ! +! y = x - meanf(x, fre, o) * ones(1, size(x, o)) ! +! ! + +! if size(x, 1) == 1 then ! ! +! s = 0 * sum(y.^2 .* fre, o) ! +! else ! ! +! s = sqrt( sum(y.^2 .* fre, o) ./ (sum(fre, o) - 1) ); ! + ! +*/ diff --git a/src/c/statisticsFunctions/stdevf/testDoubleStdevf.c b/src/c/statisticsFunctions/stdevf/testDoubleStdevf.c new file mode 100644 index 00000000..4b979e4d --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/testDoubleStdevf.c @@ -0,0 +1,389 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + +#include <assert.h> +#include <stdio.h> +#include <math.h> +#include "stdevf.h" + + +/* #define LOCAL_DEBUG */ + +#define ERROR(x) printf("diff = %e\n", x) + +static int dstdevfsTest(void) { + double value1 = 3.0; + double value2 = 1.123456789f; + double coef1 = 56.0 ; + double coef2 = 2.0 ; + + printf("\n>>>> stdevf Double Scalar Test\n"); + printf("result : %e " ,dstdevfs(value1,coef1)) ; + printf("result : %e " ,dstdevfs(value2,coef)) ; + assert( ( dstdevfs(value1,coef1) ) == 0.0 ); + assert( ( dstdevfs(value2,coef2) ) == 0.0 ); + + value1 = 3.0; + value2 = 1.123456789f; + coef1 = 56.0 ; + coef2 = 2.0 ; + + + return 0; +} + +static int dstdevfaTest(void) { + double table1[3] = {3.0, 6.0, 9.0}; + double coef1[3] = {10.0, 2.0, 6.0}; + + double table2[5] = {3.186784563, + 4.186784563, + 5.186784563, + 6.186784563, + 7.186784563}; + + double coef2[5] = {3.0, + 4.0, + 5.0, + 6.0, + 7.0}; + + double table3[10] = {3.0, 6.0, 9.0,10.0, 5.0, + 6.0,18.0, 7.0,14.0, 2.0}; + double coef3 [10] = {3.0, 8.0,14.0,13.0, 2.0, + 5.0, 8.0, 2.0, 6.0, 8.0}; + + double result_2_5 = dstdevfa(table3,2, 5, coef3); + + printf("\n>>>> stdevf Double Array Test\n"); + printf("\nresult : %e " ,dstdevfa(table1,1, 3, coef1)) ; + printf("\nresult : %e " ,dstdevfa(table2,1, 5, coef2)) ; + printf("\nresult : %e " ,result_2_5) ; + + assert(dstdevfa(table1,1, 3, coef1) == 0.0); + assert(dstdevfa(table1,1, 3, coef1) == 0.0); + assert( ( fabs(result_2_5 ) - ( 4.6440201 ) ) / fabs ( result_2_5 ) < 1e-6 ); + return 0; +} + + +static int dcolumnstdevfaTest(void) { + + double table1[9] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0}; + double coef1[9] = {10.0, 1.0, 5.0,11.0 , 2.0, 6.0,12.0, 3.0, 7.0}; + + double columnStdevfedTable1_3_3[3] = {0}; + double columnStdevfedTable1_1_9[1] = {0}; + + + printf("\n>>>> Column stdevf Double Array Test\n"); + +/**/ + + dcolumnstdevfa(table1, 3, 3, coef1 ,columnStdevfedTable1_3_3); + + printf("\nresult1 : %e " ,columnStdevfedTable1_3_3[0]) ; + printf("\nresult2 : %e " ,columnStdevfedTable1_3_3[1]) ; + printf("\nresult3 : %e " ,columnStdevfedTable1_3_3[2]) ; + + assert( fabs(columnStdevfedTable1_3_3[0] - 0.8268689) / fabs ( columnStdevfedTable1_3_3[0] ) < 1e-6 ); + assert( fabs(columnStdevfedTable1_3_3[1] - 0.8164966) / fabs ( columnStdevfedTable1_3_3[1] ) < 1e-6 ); + assert( fabs(columnStdevfedTable1_3_3[2] - 0.8323524 ) / fabs ( columnStdevfedTable1_3_3[2] ) < 1e-6 ); + + + + dcolumnstdevfa(table1, 1, 9, coef1 ,columnStdevfedTable1_1_9); + printf("\nresult_1_9: %e\n " ,columnStdevfedTable1_1_9[0]) ; + assert( columnStdevfedTable1_1_9[0] == 0.0); + + + return 0; +} + + +static int drowstdevfaTest(void) { + int i = 0; + double table1[9] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0}; + double coef1[9] = {10.0, 1.0, 5.0,11.0 , 2.0, 6.0,12.0, 3.0, 7.0}; + + double table2[10] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0, 10.0}; + double coef2[10] = {10.0, 1.0, 5.0,11.0 , 2.0, 6.0,12.0, 3.0, 7.0, 19.0}; + + + + double rowStdevfedTable1_3_3[3] = {0}; + double rowStdevfedTable1_1_9[9] = {0}; + double rowStdevfedTable2_2_5[5] = {0}; + printf("\n>>>> Row Mean Double Array Test\n"); + + + drowstdevfa(table1, 3, 3, coef1 , rowStdevfedTable1_3_3); + for ( i = 0 ; i < 3 ; ++i) { + printf("rowStdevfedTable1_3_3[%d] = %e\n", i, rowStdevfedTable1_3_3[i]); + } + assert( fabs(rowStdevfedTable1_3_3[0] - 2.8394542 ) / fabs ( rowStdevfedTable1_3_3[0] ) < 1e-6 ); + assert( fabs(rowStdevfedTable1_3_3[1] - 2.8003759) / fabs ( rowStdevfedTable1_3_3[1] ) < 1e-6 ); + assert( fabs(rowStdevfedTable1_3_3[2] - 2.7669196) / fabs ( rowStdevfedTable1_3_3[2] ) < 1e-6 ); + +/**/ + drowstdevfa(table1, 1, 9, coef1, rowStdevfedTable1_1_9); + for ( i = 0 ; i < 9 ; ++i) { + printf("rowStdevfedTable1_1_9[%d] = %e\n", i, rowStdevfedTable1_1_9[i]); + assert(rowStdevfedTable1_1_9[i] == 0.0); + } + + +/**/ + /**/ + drowstdevfa(table2 , 2 , 5 , coef2 , rowStdevfedTable2_2_5); + for (i = 0 ; i < 5 ; ++i ) + { + printf("rowStdevfedTable_2_5[%d] = %e \n", i, rowStdevfedTable2_2_5[i]); + } + assert( fabs(rowStdevfedTable2_2_5[0] - 0.9045340 ) / fabs ( rowStdevfedTable2_2_5[0] ) < 1e-6 ); + assert( fabs(rowStdevfedTable2_2_5[1] - 2.3935678 ) / fabs ( rowStdevfedTable2_2_5[1] ) < 1e-6 ); + assert( fabs(rowStdevfedTable2_2_5[2] - 1.3887301 ) / fabs ( rowStdevfedTable2_2_5[2] ) < 1e-6 ); + assert( fabs(rowStdevfedTable2_2_5[3] - 1.2421180 ) / fabs ( rowStdevfedTable2_2_5[3] ) < 1e-6 ); + assert( fabs(rowStdevfedTable2_2_5[4] - 0.4523443 ) / fabs ( rowStdevfedTable2_2_5[4] ) < 1e-6 ); + return 0; +} + + +static int zstdevfsTest(void) { + doubleComplex value1; + doubleComplex coef1 ; + doubleComplex value2; + doubleComplex coef2 ; + + value1 = DoubleComplex(3.0, 3.0); + coef1 = DoubleComplex(3.0, 0.0); + value2 = DoubleComplex(1.123456789f, 1.123456789f); + coef2 = DoubleComplex(9.0, 0.0); + + printf("\n>>>> Mean Double Complex Scalar Test\n"); + assert( zreals(zstdevfs(value1,coef1)) == 0.0 ); + assert( zimags(zstdevfs(value1,coef1)) == 0.0 ); + assert( zreals(zstdevfs(value2,coef2)) == 0.0 ); + assert( zimags(zstdevfs(value2,coef2)) == 0.0 ); + + return 0; +} + + + +static int zstdevfaTest(void) { + + double tableR1[9] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0}; + double tableI1[9] = {1.0, 2.0, 3.0, 4.0 , 5.0, 6.0, 7.0, 8.0, 9.0}; + double coefR1[9] = {10.0, 1.0, 5.0,11.0 , 2.0, 6.0,12.0, 3.0, 7.0}; + double coefI1[9] = { 0.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0}; + + + double tableR3[10] = {3.0, 6.0, 9.0,10.0, 5.0, + 6.0,18.0, 7.0,14.0, 2.0}; + double tableI3[10] = {3.0,12.0,25.0, 1.0, 2.0, + 5.0,18.0, 7.0, 4.0, 1.0}; + + + double coefR3 [10] = {3.0, 8.0,14.0,13.0, 2.0, + 5.0, 8.0, 2.0, 6.0, 8.0}; + double coefI3 [10] = {0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0}; + + + doubleComplex* table1 = DoubleComplexMatrix (tableR1, tableI1, 9); + doubleComplex* coef1 = DoubleComplexMatrix (coefR1, coefI1, 9); + + doubleComplex* table3 = DoubleComplexMatrix (tableR3, tableI3, 10); + doubleComplex* coef3 = DoubleComplexMatrix (coefR3, coefI3, 10); + + doubleComplex result =DoubleComplex(0.0 , 0.0); + + printf("\n>>>> Mean Double Complex Array Test\n"); + result = zstdevfa(table1,1, 9, coef1); + printf("\nresult_1_9 : %e \t+ %e i " ,zreals(result) ,zimags(result)) ; + assert( zreals(result) == 0.0 ); + assert( zimags(result) == 0.0 ); + + + result = zstdevfa(table3,2, 5, coef3); + printf("\nresult_2_5 : %e \t+ %e i " ,zreals(result) ,zimags(result)) ; + assert( fabs(zreals(result) - 1.7749350 ) / fabs ( zimags(result) ) < 1e-6 ); + assert( fabs(zimags(result) - 8.3811287) / fabs ( zreals(result) ) < 1e-6 ); + + return 0; +} + + +static int zrowstdevfaTest(void) { + + int i = 0 ; + + double tableR1[9] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0}; + double tableI1[9] = {1.0, 2.0, 3.0, 4.0 , 5.0, 6.0, 7.0, 8.0, 9.0}; + double coefR1[9] = {10.0, 1.0, 5.0,11.0 , 2.0, 6.0,12.0, 3.0, 7.0}; + double coefI1[9] = { 0.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0}; + + double tableR2[10] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0, 10.0}; + double tableI2[10] = {1.0, 2.0, 3.0, 4.0 , 5.0, 6.0, 7.0, 8.0, 9.0, 15.0}; + double coefR2[10] = {10.0, 1.0, 5.0,11.0 , 2.0, 6.0,12.0, 3.0, 7.0, 19.0}; + double coefI2[10] = { 0.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + + doubleComplex* table1 = DoubleComplexMatrix (tableR1, tableI1, 9); + doubleComplex* coef1 = DoubleComplexMatrix (coefR1, coefI1, 9); + + doubleComplex* table2 = DoubleComplexMatrix (tableR2, tableI2, 10); + doubleComplex* coef2 = DoubleComplexMatrix (coefR2, coefI2, 10); + + doubleComplex rowStdevfedTable1_3_3[3]; + doubleComplex rowStdevfedTable2_2_5[5]; + + printf("\n>>>> Row stdevf Double Complex Array Test\n"); + + rowStdevfedTable1_3_3[0] = DoubleComplex(0.0, 0.0); + rowStdevfedTable1_3_3[1] = DoubleComplex(0.0, 0.0); + rowStdevfedTable1_3_3[2] = DoubleComplex(0.0, 0.0); + + rowStdevfedTable2_2_5[0] = DoubleComplex(0.0, 0.0); + rowStdevfedTable2_2_5[1] = DoubleComplex(0.0, 0.0); + rowStdevfedTable2_2_5[2] = DoubleComplex(0.0, 0.0); + rowStdevfedTable2_2_5[3] = DoubleComplex(0.0, 0.0); + rowStdevfedTable2_2_5[4] = DoubleComplex(0.0, 0.0); + + + zrowstdevfa(table1 , 3 , 3 , coef1 , rowStdevfedTable1_3_3); + + for (i = 0 ; i < 3 ; ++i ) + { + printf("rowStdevfedTable_3_3[%d] = %e + %ei\n", i, zreals(rowStdevfedTable1_3_3[i]), zimags(rowStdevfedTable1_3_3[i])); + } + assert( fabs(zreals(rowStdevfedTable1_3_3[0]) - 2.8394542 ) / fabs ( zimags(rowStdevfedTable1_3_3[0]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable1_3_3[0]) - 0.9464847) / fabs ( zreals(rowStdevfedTable1_3_3[0]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable1_3_3[1]) - 2.8003759) / fabs ( zimags(rowStdevfedTable1_3_3[1]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable1_3_3[1]) - 0.9334586) / fabs ( zreals(rowStdevfedTable1_3_3[1]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable1_3_3[2]) - 2.7669196) / fabs ( zimags(rowStdevfedTable1_3_3[2]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable1_3_3[2]) - 0.9223065) / fabs ( zreals(rowStdevfedTable1_3_3[2]) ) < 1e-6 ); +/**/ + zrowstdevfa(table2 , 2 , 5 , coef2 , rowStdevfedTable2_2_5); + for (i = 0 ; i < 5 ; ++i ) + { + printf("rowStdevfedTable_2_5[%d] = %e + %ei\n", i, zreals(rowStdevfedTable2_2_5[i]), zimags(rowStdevfedTable2_2_5[i])); + } + assert( fabs(zreals(rowStdevfedTable2_2_5[0]) - 0.9045340 ) / fabs ( zimags(rowStdevfedTable2_2_5[0]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable2_2_5[0]) - 0.3015113 ) / fabs ( zreals(rowStdevfedTable2_2_5[0]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable2_2_5[1]) - 2.3935678 ) / fabs ( zimags(rowStdevfedTable2_2_5[1]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable2_2_5[1]) + 0.4787136) / fabs ( zreals(rowStdevfedTable2_2_5[1]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable2_2_5[2]) - 1.3887301 ) / fabs ( zimags(rowStdevfedTable2_2_5[2]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable2_2_5[2]) - 0.4629100 ) / fabs ( zreals(rowStdevfedTable2_2_5[2]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable2_2_5[3]) - 1.2421180 ) / fabs ( zimags(rowStdevfedTable2_2_5[3]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable2_2_5[3]) - 0.4140393 ) / fabs ( zreals(rowStdevfedTable2_2_5[3]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable2_2_5[4]) - 0.4523443 ) / fabs ( zimags(rowStdevfedTable2_2_5[4]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable2_2_5[4]) - 2.7140659) / fabs ( zreals(rowStdevfedTable2_2_5[4]) ) < 1e-6 ); + + return 0; +} + + + + +static int zcolumnstdevfaTest(void) { + + int i = 0 ; + + double tableR1[9] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0}; + double tableI1[9] = {1.0, 2.0, 3.0, 4.0 , 5.0, 6.0, 7.0, 8.0, 9.0}; + double coefR1[9] = {10.0, 1.0, 5.0,11.0 , 2.0, 6.0,12.0, 3.0, 7.0}; + double coefI1[9] = { 0.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0}; + + double tableR2[10] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0, 10.0}; + double tableI2[10] = {1.0, 2.0, 3.0, 4.0 , 5.0, 6.0, 7.0, 8.0, 9.0, 15.0}; + double coefR2[10] = {10.0, 1.0, 5.0,11.0 , 2.0, 6.0,12.0, 3.0, 7.0, 19.0}; + double coefI2[10] = { 0.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + + doubleComplex* table1 = DoubleComplexMatrix (tableR1, tableI1, 9); + doubleComplex* coef1 = DoubleComplexMatrix (coefR1, coefI1, 9); + + doubleComplex* table2 = DoubleComplexMatrix (tableR2, tableI2, 10); + doubleComplex* coef2 = DoubleComplexMatrix (coefR2, coefI2, 10); + + doubleComplex rowStdevfedTable1_3_3[3]; + doubleComplex rowStdevfedTable2_2_5[2]; + + rowStdevfedTable1_3_3[0] = DoubleComplex(0.0, 0.0); + rowStdevfedTable1_3_3[1] = DoubleComplex(0.0, 0.0); + rowStdevfedTable1_3_3[2] = DoubleComplex(0.0, 0.0); + + rowStdevfedTable2_2_5[0] = DoubleComplex(0.0, 0.0); + rowStdevfedTable2_2_5[1] = DoubleComplex(0.0, 0.0); + + + + printf("\n>>>> Column stdevf Double Complex Array Test\n"); + + + + zcolumnstdevfa(table1 , 3 , 3 , coef1 , rowStdevfedTable1_3_3); + + for (i = 0 ; i < 3 ; ++i ) + { + printf("columnStdevfedTable_3_3[%d] = %e + %ei\n", i, zreals(rowStdevfedTable1_3_3[i]), zimags(rowStdevfedTable1_3_3[i])); + } + assert( fabs(zreals(rowStdevfedTable1_3_3[0]) - 0.8268689) / fabs ( zimags(rowStdevfedTable1_3_3[0]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable1_3_3[0]) - 2.4806066) / fabs ( zreals(rowStdevfedTable1_3_3[0]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable1_3_3[1]) - 0.8164966) / fabs ( zimags(rowStdevfedTable1_3_3[1]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable1_3_3[1]) - 2.4494897) / fabs ( zreals(rowStdevfedTable1_3_3[1]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable1_3_3[2]) - 0.8323524 ) / fabs ( zimags(rowStdevfedTable1_3_3[2]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable1_3_3[2]) - 2.4970571 ) / fabs ( zreals(rowStdevfedTable1_3_3[2]) ) < 1e-6 ); +/**/ + zcolumnstdevfa(table2 , 2 , 5 , coef2 , rowStdevfedTable2_2_5); + for (i = 0 ; i < 2 ; ++i ) + { + printf("columnStdevfedTable_2_5[%d] = %e + %ei\n", i, zreals(rowStdevfedTable2_2_5[i]), zimags(rowStdevfedTable2_2_5[i])); + } + assert( fabs(zreals(rowStdevfedTable2_2_5[0]) - 2.3683811 ) / fabs ( zimags(rowStdevfedTable2_2_5[0]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable2_2_5[0]) - 2.4784193 ) / fabs ( zreals(rowStdevfedTable2_2_5[0]) ) < 1e-6 ); + + assert( fabs(zreals(rowStdevfedTable2_2_5[1]) - 3.1890422 ) / fabs ( zimags(rowStdevfedTable2_2_5[1]) ) < 1e-6 ); + assert( fabs(zimags(rowStdevfedTable2_2_5[1]) - 4.9966774 ) / fabs ( zreals(rowStdevfedTable2_2_5[1]) ) < 1e-6 ); + + + return 0; +} + + +static int teststdevf(void) { + + dstdevfsTest(); + dstdevfaTest(); + dcolumnstdevfaTest(); + drowstdevfaTest(); + zstdevfsTest(); + zstdevfaTest(); + zrowstdevfaTest(); + zcolumnstdevfaTest(); + + return 0; +} + +int main(void) { + assert(teststdevf() == 0); + return 0; +} + diff --git a/src/c/statisticsFunctions/stdevf/testFloatStdevf.c b/src/c/statisticsFunctions/stdevf/testFloatStdevf.c new file mode 100644 index 00000000..bdf61a63 --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/testFloatStdevf.c @@ -0,0 +1,389 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + +#include <assert.h> +#include <stdio.h> +#include <math.h> +#include "stdevf.h" + + +/* #define LOCAL_DEBUG */ + +#define ERROR(x) printf("diff = %e\n", x) + +static int sstdevfsTest(void) { + float value1 = 3.0f; + float value2 = 1.123456789f; + float coef1 = 56.0f ; + float coef2 = 2.0f ; + + printf("\n>>>> stdevf Float Scalar Test\n"); + printf("result : %f " ,sstdevfs(value1,coef1)) ; + printf("result : %f " ,sstdevfs(value2,coef)) ; + assert( ( sstdevfs(value1,coef1) ) == 0.0f ); + assert( ( sstdevfs(value2,coef2) ) == 0.0f ); + + value1 = 3.0f; + value2 = 1.123456789f; + coef1 = 56.0f ; + coef2 = 2.0f ; + + + return 0; +} + +static int sstdevfaTest(void) { + float table1[3] = {3.0f, 6.0f, 9.0f}; + float coef1[3] = {10.0f, 2.0f, 6.0f}; + + float table2[5] = {3.186784563f, + 4.186784563f, + 5.186784563f, + 6.186784563f, + 7.186784563f}; + + float coef2[5] = {3.0f, + 4.0f, + 5.0f, + 6.0f, + 7.0f}; + + float table3[10] = {3.0f, 6.0f, 9.0f,10.0f, 5.0f, + 6.0f,18.0f, 7.0f,14.0f, 2.0f}; + float coef3 [10] = {3.0f, 8.0f,14.0f,13.0f, 2.0f, + 5.0f, 8.0f, 2.0f, 6.0f, 8.0f}; + + float result_2_5 = sstdevfa(table3,2, 5, coef3); + + printf("\n>>>> stdevf Float Array Test\n"); + printf("\nresult : %f " ,sstdevfa(table1,1, 3, coef1)) ; + printf("\nresult : %f " ,sstdevfa(table2,1, 5, coef2)) ; + printf("\nresult : %f " ,result_2_5) ; + + assert(sstdevfa(table1,1, 3, coef1) == 0.0f); + assert(sstdevfa(table1,1, 3, coef1) == 0.0f); + assert( ( fabs(result_2_5 ) - ( 4.6440201f ) ) / fabs ( result_2_5 ) < 1e-6 ); + return 0; +} + + +static int scolumnstdevfaTest(void) { + + float table1[9] = {1.0f, 4.0f, 7.0f, 2.0f , 5.0f, 8.0f, 3.0f, 6.0f, 9.0f}; + float coef1[9] = {10.0f, 1.0f, 5.0f,11.0f , 2.0f, 6.0f,12.0f, 3.0f, 7.0f}; + + float columnStdevfedTable1_3_3[3] = {0}; + float columnStdevfedTable1_1_9[1] = {0}; + + + printf("\n>>>> Column stdevf Float Array Test\n"); + +/**/ + + scolumnstdevfa(table1, 3, 3, coef1 ,columnStdevfedTable1_3_3); + + printf("\nresult1 : %f " ,columnStdevfedTable1_3_3[0]) ; + printf("\nresult2 : %f " ,columnStdevfedTable1_3_3[1]) ; + printf("\nresult3 : %f " ,columnStdevfedTable1_3_3[2]) ; + + assert( fabs(columnStdevfedTable1_3_3[0] - 0.8268689f ) / fabs ( columnStdevfedTable1_3_3[0] ) < 1e-6 ); + assert( fabs(columnStdevfedTable1_3_3[1] - 0.8164966f ) / fabs ( columnStdevfedTable1_3_3[1] ) < 1e-6 ); + assert( fabs(columnStdevfedTable1_3_3[2] - 0.8323524f ) / fabs ( columnStdevfedTable1_3_3[2] ) < 1e-6 ); + + + + scolumnstdevfa(table1, 1, 9, coef1 ,columnStdevfedTable1_1_9); + printf("\nresult_1_9: %f\n " ,columnStdevfedTable1_1_9[0]) ; + assert( columnStdevfedTable1_1_9[0] == 0.0f); + + + return 0; +} + + +static int srowstdevfaTest(void) { + int i = 0; + float table1[9] = {1.0f, 4.0f, 7.0f, 2.0f , 5.0f, 8.0f, 3.0f, 6.0f, 9.0f}; + float coef1[9] = {10.0f, 1.0f, 5.0f,11.0f , 2.0f, 6.0f,12.0f, 3.0f, 7.0f}; + + float table2[10] = {1.0f, 4.0f, 7.0f, 2.0f , 5.0f, 8.0f, 3.0f, 6.0f, 9.0f, 10.0f}; + float coef2[10] = {10.0f, 1.0f, 5.0f,11.0f , 2.0f, 6.0f,12.0f, 3.0f, 7.0f, 19.0f}; + + + + float rowStdevfedTable1_3_3[3] = {0}; + float rowStdevfedTable1_1_9[9] = {0}; + float rowStdevfedTable2_2_5[5] = {0}; + printf("\n>>>> Row Mean Float Array Test\n"); + + + srowstdevfa(table1, 3, 3, coef1 , rowStdevfedTable1_3_3); + for ( i = 0 ; i < 3 ; ++i) { + printf("rowStdevfedTable1_3_3[%d] = %e\n", i, rowStdevfedTable1_3_3[i]); + } + assert( fabs(rowStdevfedTable1_3_3[0] - 2.8394542f ) / fabs ( rowStdevfedTable1_3_3[0] ) < 1e-6 ); + assert( fabs(rowStdevfedTable1_3_3[1] - 2.8003759f ) / fabs ( rowStdevfedTable1_3_3[1] ) < 1e-6 ); + assert( fabs(rowStdevfedTable1_3_3[2] - 2.7669196f ) / fabs ( rowStdevfedTable1_3_3[2] ) < 1e-6 ); + +/**/ + srowstdevfa(table1, 1, 9, coef1, rowStdevfedTable1_1_9); + for ( i = 0 ; i < 9 ; ++i) { + printf("rowStdevfedTable1_1_9[%d] = %e\n", i, rowStdevfedTable1_1_9[i]); + assert(rowStdevfedTable1_1_9[i] == 0.0f); + } + + +/**/ + /**/ + srowstdevfa(table2 , 2 , 5 , coef2 , rowStdevfedTable2_2_5); + for (i = 0 ; i < 5 ; ++i ) + { + printf("rowStdevfedTable_2_5[%d] = %e \n", i, rowStdevfedTable2_2_5[i]); + } + assert( fabs(rowStdevfedTable2_2_5[0] - 0.9045340f ) / fabs ( rowStdevfedTable2_2_5[0] ) < 1e-6 ); + assert( fabs(rowStdevfedTable2_2_5[1] - 2.3935678f ) / fabs ( rowStdevfedTable2_2_5[1] ) < 1e-6 ); + assert( fabs(rowStdevfedTable2_2_5[2] - 1.3887301f ) / fabs ( rowStdevfedTable2_2_5[2] ) < 1e-6 ); + assert( fabs(rowStdevfedTable2_2_5[3] - 1.2421180f ) / fabs ( rowStdevfedTable2_2_5[3] ) < 1e-6 ); + assert( fabs(rowStdevfedTable2_2_5[4] - 0.4523443f ) / fabs ( rowStdevfedTable2_2_5[4] ) < 1e-6 ); + return 0; +} + + +static int cstdevfsTest(void) { + floatComplex value1; + floatComplex coef1 ; + floatComplex value2; + floatComplex coef2 ; + + value1 = FloatComplex(3.0f, 3.0f); + coef1 = FloatComplex(3.0f, 0.0f); + value2 = FloatComplex(1.123456789f, 1.123456789f); + coef2 = FloatComplex(9.0f, 0.0f); + + printf("\n>>>> Mean Float Complex Scalar Test\n"); + assert( creals(cstdevfs(value1,coef1)) == 0.0f ); + assert( cimags(cstdevfs(value1,coef1)) == 0.0f ); + assert( creals(cstdevfs(value2,coef2)) == 0.0f ); + assert( cimags(cstdevfs(value2,coef2)) == 0.0f ); + + return 0; +} + + + +static int cstdevfaTest(void) { + + float tableR1[9] = {1.0f, 4.0f, 7.0f, 2.0f , 5.0f, 8.0f, 3.0f, 6.0f, 9.0f}; + float tableI1[9] = {1.0f, 2.0f, 3.0f, 4.0f , 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; + float coefR1[9] = {10.0f, 1.0f, 5.0f,11.0f , 2.0f, 6.0f,12.0f, 3.0f, 7.0f}; + float coefI1[9] = { 0.0f, 0.0f, 0.0f, 0.0f , 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + + float tableR3[10] = {3.0f, 6.0f, 9.0f,10.0f, 5.0f, + 6.0f,18.0f, 7.0f,14.0f, 2.0f}; + float tableI3[10] = {3.0f,12.0f,25.0f, 1.0f, 2.0f, + 5.0f,18.0f, 7.0f, 4.0f, 1.0f}; + + + float coefR3 [10] = {3.0f, 8.0f,14.0f,13.0f, 2.0f, + 5.0f, 8.0f, 2.0f, 6.0f, 8.0f}; + float coefI3 [10] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + + floatComplex* table1 = FloatComplexMatrix (tableR1, tableI1, 9); + floatComplex* coef1 = FloatComplexMatrix (coefR1, coefI1, 9); + + floatComplex* table3 = FloatComplexMatrix (tableR3, tableI3, 10); + floatComplex* coef3 = FloatComplexMatrix (coefR3, coefI3, 10); + + floatComplex result =FloatComplex(0.0f , 0.0f); + + printf("\n>>>> Mean Float Complex Array Test\n"); + result = cstdevfa(table1,1, 9, coef1); + printf("\nresult_1_9 : %f \t+ %f i " ,creals(result) ,cimags(result)) ; + assert( creals(result) == 0.0f ); + assert( cimags(result) == 0.0f ); + + + result = cstdevfa(table3,2, 5, coef3); + printf("\nresult_2_5 : %f \t+ %f i " ,creals(result) ,cimags(result)) ; + assert( fabs(creals(result) - 1.7749350f ) / fabs ( cimags(result) ) < 1e-6 ); + assert( fabs(cimags(result) - 8.3811287f ) / fabs ( creals(result) ) < 1e-6 ); + + return 0; +} + + +static int crowstdevfaTest(void) { + + int i = 0 ; + + float tableR1[9] = {1.0f, 4.0f, 7.0f, 2.0f , 5.0f, 8.0f, 3.0f, 6.0f, 9.0f}; + float tableI1[9] = {1.0f, 2.0f, 3.0f, 4.0f , 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; + float coefR1[9] = {10.0f, 1.0f, 5.0f,11.0f , 2.0f, 6.0f,12.0f, 3.0f, 7.0f}; + float coefI1[9] = { 0.0f, 0.0f, 0.0f, 0.0f , 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + float tableR2[10] = {1.0f, 4.0f, 7.0f, 2.0f , 5.0f, 8.0f, 3.0f, 6.0f, 9.0f, 10.0f}; + float tableI2[10] = {1.0f, 2.0f, 3.0f, 4.0f , 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 15.0f}; + float coefR2[10] = {10.0f, 1.0f, 5.0f,11.0f , 2.0f, 6.0f,12.0f, 3.0f, 7.0f, 19.0f}; + float coefI2[10] = { 0.0f, 0.0f, 0.0f, 0.0f , 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + floatComplex* table1 = FloatComplexMatrix (tableR1, tableI1, 9); + floatComplex* coef1 = FloatComplexMatrix (coefR1, coefI1, 9); + + floatComplex* table2 = FloatComplexMatrix (tableR2, tableI2, 10); + floatComplex* coef2 = FloatComplexMatrix (coefR2, coefI2, 10); + + floatComplex rowStdevfedTable1_3_3[3]; + floatComplex rowStdevfedTable2_2_5[5]; + + printf("\n>>>> Row stdevf Float Complex Array Test\n"); + + rowStdevfedTable1_3_3[0] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable1_3_3[1] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable1_3_3[2] = FloatComplex(0.0f, 0.0f); + + rowStdevfedTable2_2_5[0] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable2_2_5[1] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable2_2_5[2] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable2_2_5[3] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable2_2_5[4] = FloatComplex(0.0f, 0.0f); + + + crowstdevfa(table1 , 3 , 3 , coef1 , rowStdevfedTable1_3_3); + + for (i = 0 ; i < 3 ; ++i ) + { + printf("rowStdevfedTable_3_3[%d] = %e + %ei\n", i, creals(rowStdevfedTable1_3_3[i]), cimags(rowStdevfedTable1_3_3[i])); + } + assert( fabs(creals(rowStdevfedTable1_3_3[0]) - 2.8394542f ) / fabs ( cimags(rowStdevfedTable1_3_3[0]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable1_3_3[0]) - 0.9464847f ) / fabs ( creals(rowStdevfedTable1_3_3[0]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable1_3_3[1]) - 2.8003759f ) / fabs ( cimags(rowStdevfedTable1_3_3[1]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable1_3_3[1]) - 0.9334586f ) / fabs ( creals(rowStdevfedTable1_3_3[1]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable1_3_3[2]) - 2.7669196f ) / fabs ( cimags(rowStdevfedTable1_3_3[2]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable1_3_3[2]) - 0.9223065f ) / fabs ( creals(rowStdevfedTable1_3_3[2]) ) < 1e-6 ); +/**/ + crowstdevfa(table2 , 2 , 5 , coef2 , rowStdevfedTable2_2_5); + for (i = 0 ; i < 5 ; ++i ) + { + printf("rowStdevfedTable_2_5[%d] = %e + %ei\n", i, creals(rowStdevfedTable2_2_5[i]), cimags(rowStdevfedTable2_2_5[i])); + } + assert( fabs(creals(rowStdevfedTable2_2_5[0]) - 0.9045340f ) / fabs ( cimags(rowStdevfedTable2_2_5[0]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable2_2_5[0]) - 0.3015113f ) / fabs ( creals(rowStdevfedTable2_2_5[0]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable2_2_5[1]) - 2.3935678f ) / fabs ( cimags(rowStdevfedTable2_2_5[1]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable2_2_5[1]) + 0.4787136f ) / fabs ( creals(rowStdevfedTable2_2_5[1]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable2_2_5[2]) - 1.3887301f ) / fabs ( cimags(rowStdevfedTable2_2_5[2]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable2_2_5[2]) - 0.4629100f ) / fabs ( creals(rowStdevfedTable2_2_5[2]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable2_2_5[3]) - 1.2421180f ) / fabs ( cimags(rowStdevfedTable2_2_5[3]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable2_2_5[3]) - 0.4140393f ) / fabs ( creals(rowStdevfedTable2_2_5[3]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable2_2_5[4]) - 0.4523443f ) / fabs ( cimags(rowStdevfedTable2_2_5[4]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable2_2_5[4]) - 2.7140659f ) / fabs ( creals(rowStdevfedTable2_2_5[4]) ) < 1e-6 ); + + return 0; +} + + + + +static int ccolumnstdevfaTest(void) { + + int i = 0 ; + + float tableR1[9] = {1.0f, 4.0f, 7.0f, 2.0f , 5.0f, 8.0f, 3.0f, 6.0f, 9.0f}; + float tableI1[9] = {1.0f, 2.0f, 3.0f, 4.0f , 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; + float coefR1[9] = {10.0f, 1.0f, 5.0f,11.0f , 2.0f, 6.0f,12.0f, 3.0f, 7.0f}; + float coefI1[9] = { 0.0f, 0.0f, 0.0f, 0.0f , 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + float tableR2[10] = {1.0f, 4.0f, 7.0f, 2.0f , 5.0f, 8.0f, 3.0f, 6.0f, 9.0f, 10.0f}; + float tableI2[10] = {1.0f, 2.0f, 3.0f, 4.0f , 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 15.0f}; + float coefR2[10] = {10.0f, 1.0f, 5.0f,11.0f , 2.0f, 6.0f,12.0f, 3.0f, 7.0f, 19.0f}; + float coefI2[10] = { 0.0f, 0.0f, 0.0f, 0.0f , 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + floatComplex* table1 = FloatComplexMatrix (tableR1, tableI1, 9); + floatComplex* coef1 = FloatComplexMatrix (coefR1, coefI1, 9); + + floatComplex* table2 = FloatComplexMatrix (tableR2, tableI2, 10); + floatComplex* coef2 = FloatComplexMatrix (coefR2, coefI2, 10); + + floatComplex rowStdevfedTable1_3_3[3]; + floatComplex rowStdevfedTable2_2_5[2]; + + rowStdevfedTable1_3_3[0] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable1_3_3[1] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable1_3_3[2] = FloatComplex(0.0f, 0.0f); + + rowStdevfedTable2_2_5[0] = FloatComplex(0.0f, 0.0f); + rowStdevfedTable2_2_5[1] = FloatComplex(0.0f, 0.0f); + + + + printf("\n>>>> Column stdevf Float Complex Array Test\n"); + + + + ccolumnstdevfa(table1 , 3 , 3 , coef1 , rowStdevfedTable1_3_3); + + for (i = 0 ; i < 3 ; ++i ) + { + printf("columnStdevfedTable_3_3[%d] = %e + %ei\n", i, creals(rowStdevfedTable1_3_3[i]), cimags(rowStdevfedTable1_3_3[i])); + } + assert( fabs(creals(rowStdevfedTable1_3_3[0]) - 0.8268689f ) / fabs ( cimags(rowStdevfedTable1_3_3[0]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable1_3_3[0]) - 2.4806066f ) / fabs ( creals(rowStdevfedTable1_3_3[0]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable1_3_3[1]) - 0.8164966f ) / fabs ( cimags(rowStdevfedTable1_3_3[1]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable1_3_3[1]) - 2.4494897f ) / fabs ( creals(rowStdevfedTable1_3_3[1]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable1_3_3[2]) - 0.8323524f ) / fabs ( cimags(rowStdevfedTable1_3_3[2]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable1_3_3[2]) - 2.4970571f ) / fabs ( creals(rowStdevfedTable1_3_3[2]) ) < 1e-6 ); +/**/ + ccolumnstdevfa(table2 , 2 , 5 , coef2 , rowStdevfedTable2_2_5); + for (i = 0 ; i < 2 ; ++i ) + { + printf("columnStdevfedTable_2_5[%d] = %e + %ei\n", i, creals(rowStdevfedTable2_2_5[i]), cimags(rowStdevfedTable2_2_5[i])); + } + assert( fabs(creals(rowStdevfedTable2_2_5[0]) - 2.3683811f ) / fabs ( cimags(rowStdevfedTable2_2_5[0]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable2_2_5[0]) - 2.4784193f ) / fabs ( creals(rowStdevfedTable2_2_5[0]) ) < 1e-6 ); + + assert( fabs(creals(rowStdevfedTable2_2_5[1]) - 3.1890422f ) / fabs ( cimags(rowStdevfedTable2_2_5[1]) ) < 1e-6 ); + assert( fabs(cimags(rowStdevfedTable2_2_5[1]) - 4.9966774f ) / fabs ( creals(rowStdevfedTable2_2_5[1]) ) < 1e-6 ); + + + return 0; +} + + +static int teststdevf(void) { + + sstdevfsTest(); + sstdevfaTest(); + scolumnstdevfaTest(); + srowstdevfaTest(); + cstdevfsTest(); + cstdevfaTest(); + crowstdevfaTest(); + ccolumnstdevfaTest(); + + return 0; +} + +int main(void) { + assert(teststdevf() == 0); + return 0; +} + diff --git a/src/c/statisticsFunctions/stdevf/zcolumnstdevfa.c b/src/c/statisticsFunctions/stdevf/zcolumnstdevfa.c new file mode 100644 index 00000000..3d1e8ec9 --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/zcolumnstdevfa.c @@ -0,0 +1,58 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + + +#include "stdevf.h" +#include "meanf.h" + +#include <stdio.h> + +void zcolumnstdevfa(doubleComplex *in1, int lines, int columns, doubleComplex*in2, doubleComplex* out){ + int i = 0; + int j = 0; + doubleComplex temp = DoubleComplex(0.0,0.0); + doubleComplex accumulate = DoubleComplex(0.0,0.0); + double accumulateFre = 0.0; + + zcolumnmeanfa(in1, lines, columns, in2, out ); + + + /*we first multiply each zell of the input matrix by its zoefficient*/ + for (j = 0; j < lines; ++j) + { + accumulate = DoubleComplex(0.0,0.0); + accumulateFre = 0.0; + temp = DoubleComplex(0.0,0.0); + + for ( i = 0 ; i < columns; ++i ) + { + + temp = zpows ( zdiffs (in1[lines*i + j] ,out[j] ) ,DoubleComplex (2.0, 0.0 ) ); + temp = zmuls( in2[lines*i + j] , temp); + + accumulate = zadds( temp , accumulate); + accumulateFre += zreals(in2[lines*i + j]); + + } + + if (lines <= 1) + { + out[j] = zmuls (DoubleComplex(0.0,0.0) , accumulate ) ; + } + else + { + accumulate = DoubleComplex( zreals(accumulate ) / (accumulateFre - 1) , zimags(accumulate) / (accumulateFre - 1)); + out[j] = zsqrts(accumulate); + } + } + +} diff --git a/src/c/statisticsFunctions/stdevf/zrowstdevfa.c b/src/c/statisticsFunctions/stdevf/zrowstdevfa.c new file mode 100644 index 00000000..8a35d4de --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/zrowstdevfa.c @@ -0,0 +1,57 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + +#include "stdevf.h" +#include "meanf.h" + +#include <stdio.h> + + +void zrowstdevfa(doubleComplex *in1, int lines, int columns, doubleComplex*in2, doubleComplex* out){ + int i = 0; + int j = 0; + doubleComplex temp = DoubleComplex(0.0,0.0); + doubleComplex accumulate = DoubleComplex(0.0,0.0); + double accumulateFre = 0.0; + + zrowmeanfa(in1, lines, columns, in2, out ); + + /*we first multiply each zell of the input matrix by its coefficient*/ + for (j = 0; j < columns; ++j) + { + accumulate = DoubleComplex(0.0,0.0); + accumulateFre = 0.0; + temp = DoubleComplex(0.0,0.0); + + for ( i = 0 ; i < lines; ++i ) + { + + temp = zpows ( zdiffs (in1[lines*j + i] ,out[j] ) ,DoubleComplex (2.0, 0.0 ) ); + temp = zmuls( in2[lines*j + i] , temp); + + accumulate = zadds( temp , accumulate); + accumulateFre += zreals(in2[lines*j + i]); + + } + + if (lines <= 1) + { + out[j] = zmuls (DoubleComplex(0.0,0.0) , accumulate ) ; + } + else + { + accumulate = DoubleComplex( zreals(accumulate ) / (accumulateFre - 1) , zimags(accumulate) / (accumulateFre - 1)); + out[j] = zsqrts(accumulate); + } + } + +} diff --git a/src/c/statisticsFunctions/stdevf/zstdevfa.c b/src/c/statisticsFunctions/stdevf/zstdevfa.c new file mode 100644 index 00000000..f9a2f4c3 --- /dev/null +++ b/src/c/statisticsFunctions/stdevf/zstdevfa.c @@ -0,0 +1,41 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Allan SIMON + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + +#include "stdevf.h" + +doubleComplex zstdevfa(doubleComplex *in1, int lines, int columns, doubleComplex* in2) +{ + int i = 0 ; + doubleComplex temp = DoubleComplex(0.0,0.0); + doubleComplex accumulate = DoubleComplex(0.0,0.0); + double accumulateFre = 0.0 ; + doubleComplex meanf = zmeanfa (in1 , lines*columns , in2); + + for(i = 0 ; i < lines*columns ; ++i) + { + temp = zpows ( zdiffs (in1[i] , meanf ) ,DoubleComplex (2.0, 0.0 ) ); + temp = zmuls( in2[i] , temp); + + accumulate = zadds( temp , accumulate); + accumulateFre += zreals(in2[i]); + } + + if (lines <= 1) + { + return zmuls (DoubleComplex(0.0,0.0) , accumulate ) ; + } + else + { + accumulate = DoubleComplex( zreals(accumulate ) / (accumulateFre - 1) , zimags(accumulate) / (accumulateFre - 1)); + return zsqrts(accumulate); + } +} diff --git a/src/c/statisticsFunctions/variancef/scolumnvariancefa.c b/src/c/statisticsFunctions/variancef/scolumnvariancefa.c index 2dfb30be..a0283aa1 100644 --- a/src/c/statisticsFunctions/variancef/scolumnvariancefa.c +++ b/src/c/statisticsFunctions/variancef/scolumnvariancefa.c @@ -14,7 +14,6 @@ #include "variancef.h" #include "meanf.h" -#include <stdio.h> void scolumnvariancefa(float *in1, int lines, int columns, float *in2, float* out){ int i = 0; @@ -29,25 +28,19 @@ void scolumnvariancefa(float *in1, int lines, int columns, float *in2, float* ou /*we first multiply each cell of the input matrix by its coefficient*/ for (j = 0; j < lines; ++j) { - printf ("\tinside mean[%d] : %f\n" , j , out[j]); - accumulate = 0.0f; accumulateFre= 0.0f; temp = 0.0f; + for ( i = 0 ; i < columns; ++i ) { - printf("\tinside number = %d\n",lines*i + j ); temp = spows ( (in1[lines*i + j] - out[j] ) ,2 ); temp *= in2[lines*i + j]; - printf("\tinside temp^2 .* fre = %f\n", temp ); accumulate += temp ; accumulateFre += in2[lines*i + j]; } - - printf("\tinside %lf/%lf ",accumulate ,accumulateFre - 1 ); out[j] = accumulate / (accumulateFre - 1) ; - printf ("\tinside out[%d] : %f\n" , j , out[j]); } } |