Skip to content

Commit

Permalink
Merge pull request #186 from imbs-hl/coverage
Browse files Browse the repository at this point in the history
Increase coverage
  • Loading branch information
mnwright authored Apr 20, 2017
2 parents 8d8e2fa + 1a35c96 commit e62ee27
Show file tree
Hide file tree
Showing 27 changed files with 188 additions and 363 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.Rcheck
ranger.Rcheck/
*.Rproj
.project
.cproject
2 changes: 1 addition & 1 deletion R/timepoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ timepoints <- function(x, ...) UseMethod("timepoints")
##' @author Marvin N. Wright
##' @export
timepoints.ranger.prediction <- function(x, ...) {
if (class(x) != "ranger.predicton") {
if (class(x) != "ranger.prediction") {
stop("Object ist no ranger.prediction object.")
}
if (x$treetype != "Survival") {
Expand Down
61 changes: 0 additions & 61 deletions cpp_version/test/.cproject

This file was deleted.

28 changes: 0 additions & 28 deletions cpp_version/test/.project

This file was deleted.

22 changes: 11 additions & 11 deletions cpp_version/test/utility_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ TEST(maxstat, trt) {
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 });

const double expect_maxstat = 0.095071135385996;
const double expect_split = 1;
const double expect_split = 1.5;

// Order
std::vector<size_t> indices = order(x, false);
Expand All @@ -985,7 +985,7 @@ TEST(maxstat, celltype) {
// library(survival)
// library(maxstat)
// y <- Surv(veteran$time, veteran$status)
// x <- veteran$trt
// x <- veteran$celltype
// m <- maxstat(y, x, pmethod = "Lau92", smethod = "LogRank")
// dput(y[, 1], control = NULL)
// dput(y[, 2], control = NULL)
Expand All @@ -1012,7 +1012,7 @@ TEST(maxstat, celltype) {
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 });

const double expect_maxstat = 3.44263138354529;
const double expect_split = 1;
const double expect_split = 1.5;

// Order
std::vector<size_t> indices = order(x, false);
Expand All @@ -1035,7 +1035,7 @@ TEST(maxstat, karno) {
// library(survival)
// library(maxstat)
// y <- Surv(veteran$time, veteran$status)
// x <- veteran$age
// x <- veteran$karno
// m <- maxstat(y, x, pmethod = "Lau92", smethod = "LogRank")
// dput(y[, 1], control = NULL)
// dput(y[, 2], control = NULL)
Expand Down Expand Up @@ -1064,7 +1064,7 @@ TEST(maxstat, karno) {
60, 80, 75, 60, 70, 80, 30 });

const double expect_maxstat = 4.61806159115936;
const double expect_split = 40;
const double expect_split = 45;

// Order
std::vector<size_t> indices = order(x, false);
Expand All @@ -1087,7 +1087,7 @@ TEST(maxstat, diagtime) {
// library(survival)
// library(maxstat)
// y <- Surv(veteran$time, veteran$status)
// x <- veteran$age
// x <- veteran$diagtime
// m <- maxstat(y, x, pmethod = "Lau92", smethod = "LogRank")
// dput(y[, 1], control = NULL)
// dput(y[, 2], control = NULL)
Expand Down Expand Up @@ -1115,7 +1115,7 @@ TEST(maxstat, diagtime) {
4, 15, 4, 12, 5, 11, 10, 1, 5, 18, 4, 3 });

const double expect_maxstat = 0.800489478294775;
const double expect_split = 3;
const double expect_split = 3.5;

// Order
std::vector<size_t> indices = order(x, false);
Expand Down Expand Up @@ -1167,7 +1167,7 @@ TEST(maxstat, age) {
49, 64, 65, 64, 67, 65, 37 });

const double expect_maxstat = 1.7992993341166;
const double expect_split = 58;
const double expect_split = 58.5;

// Order
std::vector<size_t> indices = order(x, false);
Expand All @@ -1190,7 +1190,7 @@ TEST(maxstat, prior) {
// library(survival)
// library(maxstat)
// y <- Surv(veteran$time, veteran$status)
// x <- veteran$age
// x <- veteran$prior
// m <- maxstat(y, x, pmethod = "Lau92", smethod = "LogRank")
// dput(y[, 1], control = NULL)
// dput(y[, 2], control = NULL)
Expand Down Expand Up @@ -1218,7 +1218,7 @@ TEST(maxstat, prior) {
10, 10, 0, 0, 10, 10, 0, 0, 10, 0, 0 });

const double expect_maxstat = 0.7158562778385;
const double expect_split = 0;
const double expect_split = 5;

// Order
std::vector<size_t> indices = order(x, false);
Expand Down Expand Up @@ -1274,7 +1274,7 @@ TEST(maxstat, regression) {
3.4, 3 });

const double expect_maxstat = 3.73535181856697;
const double expect_split = 3.3;
const double expect_split = 3.35;

// Order x
std::vector<size_t> indices = order(x, false);
Expand Down
2 changes: 2 additions & 0 deletions src/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void Data::addSparseData(unsigned char* sparse_data, size_t num_cols_sparse) {
this->sparse_data = sparse_data;
}

// #nocov start
bool Data::loadFromFile(std::string filename) {

bool result;
Expand Down Expand Up @@ -166,6 +167,7 @@ bool Data::loadFromFileOther(std::ifstream& input_file, std::string header_line,
num_rows = row;
return error;
}
// #nocov end

void Data::getAllValues(std::vector<double>& all_values, std::vector<size_t>& sampleIDs, size_t varID) {

Expand Down
5 changes: 5 additions & 0 deletions src/DataChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Ratzeburger Allee 160
[email protected]
#-------------------------------------------------------------------------------*/

// Ignore in coverage report (not used in R package)
// #nocov start

#include <limits.h>
#include <math.h>
#include <iostream>
Expand Down Expand Up @@ -66,3 +69,5 @@ DataChar::~DataChar() {
delete[] data;
}
}

// #nocov end
4 changes: 4 additions & 0 deletions src/DataChar.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Ratzeburger Allee 160
[email protected]
#-------------------------------------------------------------------------------*/

// Ignore in coverage report (not used in R package)
// #nocov start

#ifndef DATACHAR_H_
#define DATACHAR_H_

Expand Down Expand Up @@ -71,3 +74,4 @@ class DataChar: public Data {
};

#endif /* DATACHAR_H_ */
// #nocov end
5 changes: 5 additions & 0 deletions src/DataFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Ratzeburger Allee 160
[email protected]
#-------------------------------------------------------------------------------*/

// Ignore in coverage report (not used in R package)
// #nocov start

#include <iostream>
#include <vector>

Expand Down Expand Up @@ -55,3 +58,5 @@ DataFloat::~DataFloat() {
}
}

// #nocov end

5 changes: 5 additions & 0 deletions src/DataFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Ratzeburger Allee 160
[email protected]
#-------------------------------------------------------------------------------*/

// Ignore in coverage report (not used in R package)
// #nocov start

#ifndef DATAFLOAT_H_
#define DATAFLOAT_H_

Expand Down Expand Up @@ -63,3 +66,5 @@ class DataFloat: public Data {
};

#endif /* DATAFLOAT_H_ */
// #nocov end

6 changes: 6 additions & 0 deletions src/Forest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Forest::~Forest() {
}
}

// #nocov start
void Forest::initCpp(std::string dependent_variable_name, MemoryMode memory_mode, std::string input_file, uint mtry,
std::string output_prefix, uint num_trees, std::ostream* verbose_out, uint seed, uint num_threads,
std::string load_forest_filename, ImportanceMode importance_mode, uint min_node_size,
Expand Down Expand Up @@ -149,6 +150,7 @@ void Forest::initCpp(std::string dependent_variable_name, MemoryMode memory_mode
}
}
}
// #nocov end

void Forest::initR(std::string dependent_variable_name, Data* input_data, uint mtry, uint num_trees,
std::ostream* verbose_out, uint seed, uint num_threads, ImportanceMode importance_mode, uint min_node_size,
Expand Down Expand Up @@ -306,6 +308,7 @@ void Forest::run(bool verbose) {
}
}

// #nocov start
void Forest::writeOutput() {

*verbose_out << std::endl;
Expand Down Expand Up @@ -399,6 +402,7 @@ void Forest::saveToFile() {
outfile.close();
*verbose_out << "Saved forest to file " << filename << "." << std::endl;
}
// #nocov end

void Forest::grow() {

Expand Down Expand Up @@ -732,6 +736,7 @@ void Forest::computeTreePermutationImportanceInThread(uint thread_idx, std::vect
}
#endif

// #nocov start
void Forest::loadFromFile(std::string filename) {
*verbose_out << "Loading forest from file " << filename << "." << std::endl;

Expand All @@ -757,6 +762,7 @@ void Forest::loadFromFile(std::string filename) {
// Create thread ranges
equalSplit(thread_ranges, 0, num_trees - 1, num_threads);
}
// #nocov end

void Forest::setSplitWeightVector(std::vector<std::vector<double>>& split_select_weights) {

Expand Down
3 changes: 2 additions & 1 deletion src/ForestClassification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ void ForestClassification::computePredictionErrorInternal() {
overall_prediction_error = (double) num_missclassifications / (double) num_predictions;
}

// #nocov start
void ForestClassification::writeOutputInternal() {
*verbose_out << "Tree type: " << "Classification" << std::endl;
}
Expand Down Expand Up @@ -323,4 +324,4 @@ void ForestClassification::loadFromFileInternal(std::ifstream& infile) {
trees.push_back(tree);
}
}

// #nocov end
3 changes: 2 additions & 1 deletion src/ForestProbability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void ForestProbability::computePredictionErrorInternal() {
overall_prediction_error /= (double) num_predictions;
}

// #nocov start
void ForestProbability::writeOutputInternal() {
*verbose_out << "Tree type: " << "Probability estimation" << std::endl;
}
Expand Down Expand Up @@ -309,4 +310,4 @@ void ForestProbability::loadFromFileInternal(std::ifstream& infile) {
trees.push_back(tree);
}
}

// #nocov end
3 changes: 2 additions & 1 deletion src/ForestRegression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void ForestRegression::computePredictionErrorInternal() {
overall_prediction_error /= (double) num_predictions;
}

// #nocov start
void ForestRegression::writeOutputInternal() {
*verbose_out << "Tree type: " << "Regression" << std::endl;
}
Expand Down Expand Up @@ -257,4 +258,4 @@ void ForestRegression::loadFromFileInternal(std::ifstream& infile) {
trees.push_back(tree);
}
}

// #nocov end
2 changes: 2 additions & 0 deletions src/ForestSurvival.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ void ForestSurvival::computePredictionErrorInternal() {
overall_prediction_error = 1 - computeConcordanceIndex(data, sum_chf, dependent_varID, status_varID, temp);
}

// #nocov start
void ForestSurvival::writeOutputInternal() {
*verbose_out << "Tree type: " << "Survival" << std::endl;
*verbose_out << "Status variable name: " << data->getVariableNames()[status_varID] << std::endl;
Expand Down Expand Up @@ -349,4 +350,5 @@ void ForestSurvival::loadFromFileInternal(std::ifstream& infile) {
trees.push_back(tree);
}
}
// #nocov end

Loading

0 comments on commit e62ee27

Please sign in to comment.