[Genabel-commits] r1599 - branches/ProbABEL-0.50/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Feb 6 22:29:08 CET 2014
Author: maartenk
Date: 2014-02-06 22:29:08 +0100 (Thu, 06 Feb 2014)
New Revision: 1599
Modified:
branches/ProbABEL-0.50/src/coxph_data.cpp
branches/ProbABEL-0.50/src/coxph_data.h
branches/ProbABEL-0.50/src/fvlib
branches/ProbABEL-0.50/src/main.cpp
branches/ProbABEL-0.50/src/maskedmatrix.cpp
branches/ProbABEL-0.50/src/maskedmatrix.h
branches/ProbABEL-0.50/src/reg1.cpp
branches/ProbABEL-0.50/src/reg1.h
branches/ProbABEL-0.50/src/regdata.cpp
Log:
-replaced loops for simple arrays with std::fill, std::copy, std::count
-replaced function to check for equal arrays with std::equal
-removed unused parameters in functions found by -Wextra
Modified: branches/ProbABEL-0.50/src/coxph_data.cpp
===================================================================
--- branches/ProbABEL-0.50/src/coxph_data.cpp 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/coxph_data.cpp 2014-02-06 21:29:08 UTC (rev 1599)
@@ -59,10 +59,7 @@
freq = 0;
masked_data = new unsigned short int[nids];
- for (int i = 0; i < nids; i++)
- {
- masked_data[i] = obj.masked_data[i];
- }
+ std::copy(obj.masked_data, obj.masked_data+nids,masked_data);
}
coxph_data::coxph_data(phedata &phed, gendata &gend, const int snpnum)
@@ -72,11 +69,9 @@
nids = gend.nids;
masked_data = new unsigned short int[nids];
- for (int i = 0; i < nids; i++)
- {
- masked_data[i] = 0;
- }
+ std::fill(masked_data,masked_data+nids,0);
+
ngpreds = gend.ngpreds;
if (snpnum >= 0)
{
@@ -145,11 +140,12 @@
// sort by time
double *tmptime = new double[nids];
int *passed_sorted = new int[nids];
+ std::fill (passed_sorted,passed_sorted+nids,0);
+
for (int i = 0; i < nids; i++)
{
tmptime[i] = stime[i];
- passed_sorted[i] = 0;
}
qsort(tmptime, nids, sizeof(double), cmpfun);
@@ -217,9 +213,7 @@
for (int j = 0; j < ngpreds; j++) {
double *snpdata = new double[nids];
- for (int i = 0; i < nids; i++) {
- masked_data[i] = 0;
- }
+ std::fill (masked_data,masked_data+nids,0);
gend->get_var(snpnum * ngpreds + j, snpdata);
@@ -294,15 +288,9 @@
coxph_data to; // = coxph_data(*this);
// filter missing data
- int nmeasured = 0;
- for (int i = 0; i < nids; i++)
- {
- if (masked_data[i] == 0)
- {
- nmeasured++;
- }
- }
+ int nmeasured=std::count (masked_data, masked_data+nids, 0);
+
to.nids = nmeasured;
to.ncov = ncov;
to.ngpreds = ngpreds;
@@ -336,11 +324,7 @@
//delete [] to.masked_data;
to.masked_data = new unsigned short int[to.nids];
- for (int i = 0; i < to.nids; i++)
- {
- to.masked_data[i] = 0;
- }
-
+ std::fill(to.masked_data,to.masked_data+to.nids,0);
return (to);
}
@@ -357,7 +341,7 @@
}
-void coxph_reg::estimate(coxph_data &cdatain, const int verbose,
+void coxph_reg::estimate(coxph_data &cdatain,
int maxiter, double eps,
double tol_chol, const int model,
const int interaction, const int ngpreds,
Modified: branches/ProbABEL-0.50/src/coxph_data.h
===================================================================
--- branches/ProbABEL-0.50/src/coxph_data.h 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/coxph_data.h 2014-02-06 21:29:08 UTC (rev 1599)
@@ -68,7 +68,7 @@
int niter;
coxph_reg(coxph_data &cdatain);
- void estimate(coxph_data &cdatain, const int verbose, int maxiter,
+ void estimate(coxph_data &cdatain, int maxiter,
double eps, double tol_chol, const int model,
const int interaction, const int ngpreds, const bool iscox,
const int nullmodel, const mlinfo &snpinfo, const int cursnp);
Modified: branches/ProbABEL-0.50/src/fvlib
===================================================================
--- branches/ProbABEL-0.50/src/fvlib 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/fvlib 2014-02-06 21:29:08 UTC (rev 1599)
@@ -1 +1 @@
-link ../../filevector/fvlib
\ No newline at end of file
+link include/filevector/fvlib
\ No newline at end of file
Modified: branches/ProbABEL-0.50/src/main.cpp
===================================================================
--- branches/ProbABEL-0.50/src/main.cpp 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/main.cpp 2014-02-06 21:29:08 UTC (rev 1599)
@@ -127,7 +127,7 @@
#if LOGISTIC
logistic_reg nrd = logistic_reg(nrgd);
- nrd.estimate( 0, MAXITER, EPS, CHOLTOL, 0,
+ nrd.estimate( 0, MAXITER, EPS, 0,
input_var.getInteraction(),
input_var.getNgpreds(),
invvarmatrix,
@@ -144,7 +144,7 @@
input_var.getRobust(), 1);
#elif COXPH
coxph_reg nrd = coxph_reg(nrgd);
- nrd.estimate(nrgd, 0, MAXITER, EPS, CHOLTOL, 0,
+ nrd.estimate(nrgd, MAXITER, EPS, CHOLTOL, 0,
input_var.getInteraction(), input_var.getNgpreds(),
true, 1, mli, 0);
#endif
@@ -273,14 +273,14 @@
logistic_reg rd(rgd);
if (input_var.getScore())
{
- rd.score(nrd.residuals, 0, CHOLTOL, model,
+ rd.score(nrd.residuals, CHOLTOL, model,
input_var.getInteraction(),
input_var.getNgpreds(),
invvarmatrix);
}
else
{
- rd.estimate( 0, MAXITER, EPS, CHOLTOL, model,
+ rd.estimate( 0, MAXITER, EPS, model,
input_var.getInteraction(),
input_var.getNgpreds(),
invvarmatrix,
@@ -290,7 +290,7 @@
linear_reg rd(rgd);
if (input_var.getScore())
{
- rd.score(nrd.residuals, 0, CHOLTOL, model,
+ rd.score(nrd.residuals, CHOLTOL, model,
input_var.getInteraction(),
input_var.getNgpreds(),
invvarmatrix);
@@ -305,7 +305,7 @@
}
#elif COXPH
coxph_reg rd(rgd);
- rd.estimate(rgd, 0, MAXITER, EPS, CHOLTOL, model,
+ rd.estimate(rgd, MAXITER, EPS, CHOLTOL, model,
input_var.getInteraction(),
input_var.getNgpreds(), true, 0, mli, csnp);
#endif
@@ -393,7 +393,7 @@
new_rgd.remove_snp_from_X();
logistic_reg new_null_rd(new_rgd);
new_null_rd.estimate( 0, MAXITER, EPS,
- CHOLTOL, model,
+ model,
input_var.getInteraction(),
input_var.getNgpreds(),
invvarmatrix,
@@ -403,7 +403,7 @@
coxph_data new_rgd = rgd;
new_rgd.remove_snp_from_X();
coxph_reg new_null_rd(new_rgd);
- new_null_rd.estimate(new_rgd, 0, MAXITER,
+ new_null_rd.estimate(new_rgd, MAXITER,
EPS, CHOLTOL, model,
input_var.getInteraction(),
input_var.getNgpreds(),
Modified: branches/ProbABEL-0.50/src/maskedmatrix.cpp
===================================================================
--- branches/ProbABEL-0.50/src/maskedmatrix.cpp 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/maskedmatrix.cpp 2014-02-06 21:29:08 UTC (rev 1599)
@@ -26,10 +26,7 @@
// matrix_original = M;
masked_data = &matrix_original;
mask_of_old = new unsigned short int[M.nrow];
- for (int i = 0; i < M.nrow; i++)
- {
- mask_of_old[i] = 0;
- }
+ std::fill (mask_of_old,mask_of_old+M.nrow,0);
//TODO:set length of mask for all types
length_of_mask = M.nrow;
//TODO:set type (row,column,symmetric)
@@ -41,10 +38,7 @@
matrix_original = M;
masked_data = &matrix_original;
mask_of_old = new unsigned short int[M.nrow];
- for (int i = 0; i < M.nrow; i++)
- {
- mask_of_old[i] = 0;
- }
+ std::fill (mask_of_old,mask_of_old+M.nrow,0);
//TODO:set length of mask for all types
length_of_mask = M.nrow;
//TODO:set type (row,column,symmetric)
@@ -59,14 +53,8 @@
void masked_matrix::update_mask(short unsigned int *newmask)
{
//find length of masked matrix
- int nmeasured = 0;
- for (int i = 0; i < length_of_mask; i++)
- {
- if (newmask[i] == 0)
- {
- nmeasured++;
- }
- }
+ int nmeasured=std::count (newmask, newmask+length_of_mask, 0);
+
//Check update mask is the same as original matrix
if (nmeasured == length_of_mask)
{
@@ -76,7 +64,7 @@
else
{
//Check update mask is the same as old matrix
- if (is_equal_array(newmask, mask_of_old, length_of_mask))
+ if (std::equal (newmask, newmask+length_of_mask, mask_of_old))
{
//new mask is the same as old matrix
masked_data = &matrix_masked_data;
@@ -85,11 +73,7 @@
{
// new mask differs from old matrix and create new.
// mask_of_old = newmask;
- //TODO(maarten): there must be a smarter way to copy these values
- for (int i = 0; i < length_of_mask; i++)
- {
- mask_of_old[i] = newmask[i];
- }
+ std::copy(newmask, newmask+length_of_mask,mask_of_old);
mask_symmetric(nmeasured);
masked_data = &matrix_masked_data;
}
@@ -118,15 +102,3 @@
}
}
-bool masked_matrix::is_equal_array(unsigned short int *a, unsigned short int *b,
- int size)
-{
- for (int i = 0; i < size; i++)
- {
- if (a[i] != b[i])
- {
- return false;
- }
- }
- return true;
-}
Modified: branches/ProbABEL-0.50/src/maskedmatrix.h
===================================================================
--- branches/ProbABEL-0.50/src/maskedmatrix.h 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/maskedmatrix.h 2014-02-06 21:29:08 UTC (rev 1599)
@@ -32,7 +32,6 @@
mematrix<double> matrix_masked_data;
unsigned short int *mask_of_old;
void mask_symmetric(int nmeasured);
- bool is_equal_array(unsigned short int *a, unsigned short int *b, int size);
};
#endif /* MASKEDMATRIX_H_ */
Modified: branches/ProbABEL-0.50/src/reg1.cpp
===================================================================
--- branches/ProbABEL-0.50/src/reg1.cpp 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/reg1.cpp 2014-02-06 21:29:08 UTC (rev 1599)
@@ -244,7 +244,7 @@
chi2_score = -1.;
}
-void base_reg::base_score(mematrix<double>& resid, int verbose,
+void base_reg::base_score(mematrix<double>& resid,
double tol_chol, int model, int interaction, int ngpreds,
const masked_matrix& invvarmatrix, int nullmodel) {
mematrix<double> oX = reg_data.extract_genotypes();
@@ -578,11 +578,11 @@
}
-void linear_reg::score(mematrix<double>& resid, int verbose,
+void linear_reg::score(mematrix<double>& resid,
double tol_chol, int model, int interaction, int ngpreds,
const masked_matrix& invvarmatrix, int nullmodel) {
// regdata rdata = rdatain.get_unmasked_data();
- base_score(resid, verbose, tol_chol, model, interaction, ngpreds,
+ base_score(resid, tol_chol, model, interaction, ngpreds,
invvarmatrix, nullmodel = 0);
}
@@ -605,7 +605,7 @@
}
void logistic_reg::estimate( int verbose, int maxiter,
- double eps, double tol_chol, int model, int interaction, int ngpreds,
+ double eps, int model, int interaction, int ngpreds,
masked_matrix& invvarmatrixin, int robust, int nullmodel) {
// In contrast to the 'linear' case 'invvarmatrix' contains the
// inverse of correlation matrix (not the inverse of var-cov matrix)
@@ -834,9 +834,9 @@
// exit(1);
}
-void logistic_reg::score(mematrix<double>& resid, int verbose,
+void logistic_reg::score(mematrix<double>& resid,
double tol_chol, int model, int interaction, int ngpreds,
masked_matrix& invvarmatrix, int nullmodel) {
- base_score(resid, verbose, tol_chol, model, interaction, ngpreds,
+ base_score(resid, tol_chol, model, interaction, ngpreds,
invvarmatrix, nullmodel = 0);
}
Modified: branches/ProbABEL-0.50/src/reg1.h
===================================================================
--- branches/ProbABEL-0.50/src/reg1.h 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/reg1.h 2014-02-06 21:29:08 UTC (rev 1599)
@@ -51,7 +51,7 @@
double chi2_score;
regdata reg_data;
- void base_score(mematrix<double>& resid, int verbose,
+ void base_score(mematrix<double>& resid,
double tol_chol, int model, int interaction, int ngpreds,
const masked_matrix& invvarmatrix, int nullmodel);
};
@@ -72,7 +72,7 @@
masked_matrix& invvarmatrixin,
int robust, int nullmodel = 0);
- void score(mematrix<double>& resid, int verbose,
+ void score(mematrix<double>& resid,
double tol_chol, int model, int interaction, int ngpreds,
const masked_matrix& invvarmatrix, int nullmodel = 0);
};
@@ -90,11 +90,11 @@
}
void estimate( int verbose, int maxiter, double eps,
- double tol_chol, int model, int interaction, int ngpreds,
+ int model, int interaction, int ngpreds,
masked_matrix& invvarmatrixin, int robust,
int nullmodel = 0);
// just a stupid copy from linear_reg
- void score(mematrix<double>& resid, int verbose,
+ void score(mematrix<double>& resid,
double tol_chol, int model, int interaction, int ngpreds,
masked_matrix& invvarmatrix, int nullmodel = 0);
};
Modified: branches/ProbABEL-0.50/src/regdata.cpp
===================================================================
--- branches/ProbABEL-0.50/src/regdata.cpp 2014-02-06 17:03:13 UTC (rev 1598)
+++ branches/ProbABEL-0.50/src/regdata.cpp 2014-02-06 21:29:08 UTC (rev 1599)
@@ -40,11 +40,7 @@
freq = obj.freq;
is_interaction_excluded = obj.is_interaction_excluded;
masked_data = new unsigned short int[nids];
-
- for (int i = 0; i < nids; i++)
- {
- masked_data[i] = obj.masked_data[i];
- }
+ std::copy(obj.masked_data, obj.masked_data+nids,masked_data);
}
@@ -56,10 +52,7 @@
nids = gend.nids;
masked_data = new unsigned short int[nids];
- for (int i = 0; i < nids; i++)
- {
- masked_data[i] = 0;
- }
+ std::fill (masked_data,masked_data+nids,0);
ngpreds = gend.ngpreds;
if (snpnum >= 0)
@@ -116,11 +109,9 @@
for (int j = 0; j < ngpreds; j++)
{
double *snpdata = new double[nids];
- for (int i = 0; i < nids; i++)
- {
- masked_data[i] = 0;
- }
+ std::fill (masked_data,masked_data+nids,0);
+
gend->get_var(snpnum * ngpreds + j, snpdata);
for (int i = 0; i < nids; i++) {
@@ -187,13 +178,9 @@
regdata regdata::get_unmasked_data()
{
regdata to; // = regdata(*this);
- int nmeasured = 0;
- for (int i = 0; i < nids; i++)
- {
- if (masked_data[i] == 0)
- nmeasured++;
- }
+ int nmeasured=std::count (masked_data, masked_data+nids, 0);
+
to.nids = nmeasured;
to.ncov = ncov;
to.ngpreds = ngpreds;
More information about the Genabel-commits
mailing list