本文整理汇总了C++中Matrix::GetColumnLabel方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::GetColumnLabel方法的具体用法?C++ Matrix::GetColumnLabel怎么用?C++ Matrix::GetColumnLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::GetColumnLabel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: appendGenotype
/**
* Append @param genotype to @param covariate in the right order
* @param phenotypeNameInOrder is the row names for @param covariate
* @param rowLabel is the row names for @param geno
* return 0 if succeed
*/
int appendGenotype(Matrix* covariate,
const std::vector<std::string>& phenotypeNameInOrder,
Matrix& geno, const std::vector<std::string>& rowLabel) {
if (!covariate) {
return -1;
}
Matrix& m = *covariate;
int baseCols = m.cols;
m.Dimension(phenotypeNameInOrder.size(), m.cols + geno.cols);
Indexer indexer(rowLabel);
if (indexer.hasDuplication()) {
return -1;
}
for (size_t i = 0; i < phenotypeNameInOrder.size(); ++i) {
for (int j = 0; j < m.cols; ++j) {
int index = indexer[phenotypeNameInOrder[i]];
if (index < 0) { // did not find a person
return -1;
}
m[i][baseCols + j] = geno[index][j];
if (i == 0) {
m.SetColumnLabel(baseCols + j, geno.GetColumnLabel(j));
}
}
}
return 0;
}
示例2: CopyLabels
void Matrix::CopyLabels(Matrix &M) {
for (int i = 0; i < rows; i++)
if (i < M.rows) data[i]->SetLabel(M[i].label);
for (int i = 0; i < cols; i++)
if (i < M.cols) SetColumnLabel(i, M.GetColumnLabel(i));
}
示例3: loadMarkerAsCovariate
int DataLoader::loadMarkerAsCovariate(const std::string& inVcf,
const std::string& marker) {
this->FLAG_inVcf = inVcf;
this->FLAG_condition = marker;
Matrix geno;
VCFGenotypeExtractor ge(FLAG_inVcf);
ge.excludeAllPeople();
ge.includePeople(phenotype.getRowName());
ge.setRangeList(marker);
if (ge.extractMultipleGenotype(&geno) != GenotypeExtractor::SUCCEED) {
logger->error("Load conditional markers [ %s ] from [ %s ] failed",
FLAG_condition.c_str(), FLAG_inVcf.c_str());
exit(1);
}
std::vector<double> d(geno.rows);
for (int i = 0; i < geno.cols; ++i) {
for (int j = 0; j < geno.rows; ++j) {
d[j] = geno[j][i];
}
covariate.appendCol(d, geno.GetColumnLabel(i));
}
// // load conditional markers
// if (!FLAG_condition.empty()) {
// Matrix geno;
// std::vector<std::string> rowLabel;
// if (loadMarkerFromVCF(FLAG_inVcf, FLAG_condition, &rowLabel, &geno) < 0)
// {
// logger->error("Load conditional markers [ %s ] from [ %s ] failed.",
// FLAG_condition.c_str(), FLAG_inVcf.c_str());
// exit(1);
// }
// if (appendGenotype(&covariate, phenotypeNameInOrder, geno, rowLabel) < 0)
// {
// logger->error(
// "Failed to combine conditional markers [ %s ] from [ %s ] failed.",
// FLAG_condition.c_str(), FLAG_inVcf.c_str());
// exit(1);
// }
// }
return 0;
}
示例4: useResidualAsPhenotype
int DataLoader::useResidualAsPhenotype() {
if (binaryPhenotype) {
logger->warn(
"WARNING: Skip transforming binary phenotype, although you want to "
"use residual as phenotype!");
return 0;
}
LinearRegression lr;
Vector pheno;
Matrix covAndInt;
const int numCovariate = covariate.ncol();
copyPhenotype(phenotype, &pheno);
copyCovariateAndIntercept(pheno.Length(), covariate, &covAndInt);
if (!lr.FitLinearModel(covAndInt, pheno)) {
if (numCovariate > 0) {
logger->error(
"Cannot fit model: [ phenotype ~ 1 + covariates ], now use the "
"original phenotype");
} else {
logger->error(
"Cannot fit model: [ phenotype ~ 1 ], now use the "
"original phenotype");
}
} else { // linear model fitted successfully
copyVectorToMatrixColumn(lr.GetResiduals(), &phenotype, 0);
// const int n = lr.GetResiduals().Length();
// for (int i = 0; i < n; ++i) {
// // phenotypeInOrder[i] = lr.GetResiduals()[i];
// phenotype[i][0] = lr.GetResiduals()[i];
// }
covariate.clear();
if (numCovariate > 0) {
logger->info(
"DONE: Fit model [ phenotype ~ 1 + covariates ] and model "
"residuals will be used as responses");
} else {
logger->info("DONE: Use residual as phenotype by centerng it");
}
// store fitting results
Vector& beta = lr.GetCovEst();
Matrix& betaSd = lr.GetCovB();
const int n = beta.Length();
for (int i = 0; i < n; ++i) {
addFittedParameter(covAndInt.GetColumnLabel(i), beta[i], betaSd[i][i]);
}
addFittedParameter("Sigma2", lr.GetSigma2(), NAN);
}
#if 0
if (covariate.ncol() > 0) {
LinearRegression lr;
Vector pheno;
Matrix covAndInt;
copyPhenotype(phenotype, &pheno);
copyCovariateAndIntercept(covariate.nrow(), covariate, &covAndInt);
if (!lr.FitLinearModel(covAndInt, pheno)) {
logger->error(
"Cannot fit model: [ phenotype ~ 1 + covariates ], now use the "
"original phenotype");
} else {
const int n = lr.GetResiduals().Length();
for (int i = 0; i < n; ++i) {
// phenotypeInOrder[i] = lr.GetResiduals()[i];
phenotype[i][0] = lr.GetResiduals()[i];
}
covariate.clear();
logger->info(
"DONE: Fit model [ phenotype ~ 1 + covariates ] and model "
"residuals will be used as responses");
}
storeFittedModel(lr);
} else { // no covaraites
// centerVector(&phenotypeInOrder);
std::vector<double> v;
phenotype.extractCol(0, &v);
centerVector(&v);
phenotype.setCol(0, v);
logger->info("DONE: Use residual as phenotype by centerng it");
}
#endif
return 0;
}
示例5: makeColNameToDict
void makeColNameToDict(Matrix& m, std::map<std::string, int>* dict) {
std::map<std::string, int>& d = *dict;
for (int i = 0; i < m.cols; ++i) {
d[m.GetColumnLabel(i)] = i;
}
}