1 /* 2 This file is part of the BOLT-LMM linear mixed model software package 3 developed by Po-Ru Loh. Copyright (C) 2014-2019 Harvard University. 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef NUMERICUTILS_HPP 20 #define NUMERICUTILS_HPP 21 22 #include <cstdlib> 23 #include <vector> 24 #include <utility> 25 26 #include "Types.hpp" 27 28 namespace NumericUtils { 29 sq(double x)30 inline double sq(double x) { return x*x; } 31 double sum(const double x[], uint64 N); 32 double mean(const std::vector <double> &x); 33 double median(std::vector <double> x); 34 35 // takes into account that some 0 values may indicate missing/ignored: divide out by Nused, not N 36 double mean(const double x[], uint64 N, uint64 Nused); 37 38 // regress y on x, assuming both have been 0-centered (so 0-filled missing values ok) 39 double regCoeff(const double y[], const double x[], uint64 N); 40 41 double dot(const double x[], const double y[], uint64 N); 42 double norm2(const double x[], uint64 N); 43 void normalize(double x[], uint64 N); 44 45 std::pair <double, double> meanStdDev(const double x[], uint64 N); 46 std::pair <double, double> meanStdErr(const double x[], uint64 N); 47 std::pair <double, double> meanStdDev(const std::vector <double> &x); 48 std::pair <double, double> meanStdErr(const std::vector <double> &x); 49 } 50 51 #endif 52