From 87265202ef1b39aa7d50c6d513fc1b841a8de33b Mon Sep 17 00:00:00 2001 From: "Brian W. Hart" Date: Fri, 24 Apr 2020 18:33:51 +0000 Subject: [PATCH] add pysurvival feedstock Add feedstock for pysurvival, an open source package for Survival Analysis modeling. See: - https://www.pysurvival.io/ - https://github.com/square/pysurvival Include several local fixes, including some that should improve correctness. See: https://github.com/square/pysurvival/pull/25 --- .travis.yml | 19 +- .../.ci_support/linux_ppc64le_python3.6.yaml | 12 ++ .../.ci_support/linux_ppc64le_python3.7.yaml | 12 ++ .../.ci_support/linux_python3.6.yaml | 12 ++ .../.ci_support/linux_python3.7.yaml | 12 ++ .../pysurvival-feedstock/LICENSE.txt | 88 ++++++++ conda-recipes/pysurvival-feedstock/README.md | 100 +++++++++ ...signedness-comparison-build-warnings.patch | 196 ++++++++++++++++++ .../0002-remove-some-unused-variables.patch | 63 ++++++ ...me-logical-vs-bitwise-operator-cases.patch | 96 +++++++++ ...behavior-in-SurvivalForest-Data-get-.patch | 38 ++++ .../pysurvival-feedstock/recipe/meta.yaml | 50 +++++ 12 files changed, 696 insertions(+), 2 deletions(-) create mode 100644 conda-recipes/pysurvival-feedstock/.ci_support/linux_ppc64le_python3.6.yaml create mode 100644 conda-recipes/pysurvival-feedstock/.ci_support/linux_ppc64le_python3.7.yaml create mode 100644 conda-recipes/pysurvival-feedstock/.ci_support/linux_python3.6.yaml create mode 100644 conda-recipes/pysurvival-feedstock/.ci_support/linux_python3.7.yaml create mode 100644 conda-recipes/pysurvival-feedstock/LICENSE.txt create mode 100644 conda-recipes/pysurvival-feedstock/README.md create mode 100644 conda-recipes/pysurvival-feedstock/recipe/0001-quiet-signedness-comparison-build-warnings.patch create mode 100644 conda-recipes/pysurvival-feedstock/recipe/0002-remove-some-unused-variables.patch create mode 100644 conda-recipes/pysurvival-feedstock/recipe/0003-fix-some-logical-vs-bitwise-operator-cases.patch create mode 100644 conda-recipes/pysurvival-feedstock/recipe/0004-avoid-undefined-behavior-in-SurvivalForest-Data-get-.patch create mode 100644 conda-recipes/pysurvival-feedstock/recipe/meta.yaml diff --git a/.travis.yml b/.travis.yml index 1731f0e..f702515 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,11 +29,26 @@ branches: matrix: include: - - env: CONFIG=linux_noarch UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py36-x86_64 + - env: CONFIG=linux_ppc64le_python3.6 UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py36-ppc64le + os: linux + arch: ppc64le + language: generic + + - env: CONFIG=linux_ppc64le_python3.7 UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py37-ppc64le + os: linux + arch: ppc64le + language: generic + + - env: CONFIG=linux_python3.6 UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py36-x86_64 + os: linux + arch: amd64 + language: generic + + - env: CONFIG=linux_python3.7 UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py37-x86_64 os: linux arch: amd64 language: generic script: - "travis_wait 60 sleep 3600 &" - - ./conda-recipes/build_scripts/run_docker_build.sh pycox-feedstock + - ./conda-recipes/build_scripts/run_docker_build.sh pysurvival-feedstock diff --git a/conda-recipes/pysurvival-feedstock/.ci_support/linux_ppc64le_python3.6.yaml b/conda-recipes/pysurvival-feedstock/.ci_support/linux_ppc64le_python3.6.yaml new file mode 100644 index 0000000..1467bdc --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/.ci_support/linux_ppc64le_python3.6.yaml @@ -0,0 +1,12 @@ +channel_sources: +- powerai,conda-forge,defaults +channel_targets: +- powerai main +docker_image: +- ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py36-ppc64le +pin_run_as_build: + python: + min_pin: x.x + max_pin: x.x +python: +- '3.6' diff --git a/conda-recipes/pysurvival-feedstock/.ci_support/linux_ppc64le_python3.7.yaml b/conda-recipes/pysurvival-feedstock/.ci_support/linux_ppc64le_python3.7.yaml new file mode 100644 index 0000000..6a01275 --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/.ci_support/linux_ppc64le_python3.7.yaml @@ -0,0 +1,12 @@ +channel_sources: +- powerai,conda-forge,defaults +channel_targets: +- powerai main +docker_image: +- ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py37-ppc64le +pin_run_as_build: + python: + min_pin: x.x + max_pin: x.x +python: +- '3.7' diff --git a/conda-recipes/pysurvival-feedstock/.ci_support/linux_python3.6.yaml b/conda-recipes/pysurvival-feedstock/.ci_support/linux_python3.6.yaml new file mode 100644 index 0000000..c414f57 --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/.ci_support/linux_python3.6.yaml @@ -0,0 +1,12 @@ +channel_sources: +- powerai,conda-forge,defaults +channel_targets: +- powerai main +docker_image: +- ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py36-x86_64 +pin_run_as_build: + python: + min_pin: x.x + max_pin: x.x +python: +- '3.6' diff --git a/conda-recipes/pysurvival-feedstock/.ci_support/linux_python3.7.yaml b/conda-recipes/pysurvival-feedstock/.ci_support/linux_python3.7.yaml new file mode 100644 index 0000000..286e5d4 --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/.ci_support/linux_python3.7.yaml @@ -0,0 +1,12 @@ +channel_sources: +- powerai,conda-forge,defaults +channel_targets: +- powerai main +docker_image: +- ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py37-x86_64 +pin_run_as_build: + python: + min_pin: x.x + max_pin: x.x +python: +- '3.7' diff --git a/conda-recipes/pysurvival-feedstock/LICENSE.txt b/conda-recipes/pysurvival-feedstock/LICENSE.txt new file mode 100644 index 0000000..f03fdd6 --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/LICENSE.txt @@ -0,0 +1,88 @@ +Copyright 2019 Square Inc. + +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + + "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + + Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + + Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + + You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + You must give any other recipients of the Work or Derivative Works a copy of this License; and + You must cause any modified files to carry prominent notices stating that You changed the files; and + You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + + Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + + This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + + Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + + In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + + While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work + + To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. + +Copyright 2019 Square Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/conda-recipes/pysurvival-feedstock/README.md b/conda-recipes/pysurvival-feedstock/README.md new file mode 100644 index 0000000..44ad2f1 --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/README.md @@ -0,0 +1,100 @@ +# PySurvival + +
pysurvival_logo
+ +## What is Pysurvival ? +PySurvival is an open source python package for Survival Analysis modeling - *the modeling concept used to analyze or predict when an event is likely to happen*. It is built upon the most commonly used machine learning packages such [NumPy](http://www.numpy.org/), [SciPy](https://www.scipy.org/) and [PyTorch](https://pytorch.org/). + +PySurvival is compatible with Python 2.7-3.7. + +Check out the documentation [here](https://www.pysurvival.io) + +--- + +## Content +PySurvival provides a very easy way to navigate between theoretical knowledge on Survival Analysis and detailed tutorials on how to conduct a full analysis, build and use a model. Indeed, the package contains: + +* 10+ models ranging from the [Cox Proportional Hazard model](https://www.pysurvival.io/models/coxph.html), the [Neural Multi-Task Logistic Regression](https://www.pysurvival.io/models/neural_mtlr.html) to [Random Survival Forest](https://www.pysurvival.io/models/random_survival_forest.html) +* Summaries of the theory behind each model as well as API descriptions and examples. +* Tutorials displaying in great details how to perform exploratory data analysis, survival modeling, cross-validation and prediction, for [churn modeling](https://www.pysurvival.io/tutorials/churn.html) and [credit risk](https://www.pysurvival.io/tutorials/credit_risk.html) to name a few. +* Performance metrics to assess the models' abilities like [c-index](https://www.pysurvival.io/metrics/c_index.html) or [brier score](https://www.pysurvival.io/metrics/brier_score.html) +* Simple ways to [load and save models](https://www.pysurvival.io/miscellaneous/save_load.html) +* ... and more ! + +--- + +## Installation + +If you have already installed a working version of gcc, the easiest way to install Pysurvival is using pip +``` +pip install pysurvival +``` +The full description of the installation steps can be found [here](https://www.pysurvival.io/installation.html). + +--- + +## Get Started + +Because of its simple API, Pysurvival has been built to provide to best user experience when it comes to modeling. +Here's a quick modeling example to get you started: + +```python +# Loading the modules +from pysurvival.models.semi_parametric import CoxPHModel +from pysurvival.models.multi_task import LinearMultiTaskModel +from pysurvival.datasets import Dataset +from pysurvival.utils.metrics import concordance_index + +# Loading and splitting a simple example into train/test sets +X_train, T_train, E_train, X_test, T_test, E_test = \ + Dataset('simple_example').load_train_test() + +# Building a CoxPH model +coxph_model = CoxPHModel() +coxph_model.fit(X=X_train, T=T_train, E=E_train, init_method='he_uniform', + l2_reg = 1e-4, lr = .4, tol = 1e-4) + +# Building a MTLR model +mtlr = LinearMultiTaskModel() +mtlr.fit(X=X_train, T=T_train, E=E_train, init_method = 'glorot_uniform', + optimizer ='adam', lr = 8e-4) + +# Checking the model performance +c_index1 = concordance_index(model=coxph_model, X=X_test, T=T_test, E=E_test ) +print("CoxPH model c-index = {:.2f}".format(c_index1)) + +c_index2 = concordance_index(model=mtlr, X=X_test, T=T_test, E=E_test ) +print("MTLR model c-index = {:.2f}".format(c_index2)) +``` + +--- + +## Citation and License + +### Citation +If you use Pysurvival in your research and we would greatly appreciate if you could use the following: + +``` +@Misc{ pysurvival_cite, + author = {Stephane Fotso and others}, + title = {PySurvival: Open source package for Survival Analysis modeling}, + year = {2019--}, + url = "https://www.pysurvival.io/" +} +``` + +### License + +Copyright 2019 Square Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/conda-recipes/pysurvival-feedstock/recipe/0001-quiet-signedness-comparison-build-warnings.patch b/conda-recipes/pysurvival-feedstock/recipe/0001-quiet-signedness-comparison-build-warnings.patch new file mode 100644 index 0000000..8bc59bc --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/recipe/0001-quiet-signedness-comparison-build-warnings.patch @@ -0,0 +1,196 @@ +From a7d77401168d3a6a4b1c721ead18bc86b1cb9ddd Mon Sep 17 00:00:00 2001 +From: "Brian W. Hart" +Date: Fri, 24 Apr 2020 19:12:33 +0000 +Subject: [PATCH 1/4] quiet signedness comparison build warnings + +Various fixes to avoid build complaints about mixed signedness +in comparisons (as from g++'s -Wsign-compare), mostly between +int and size_t. +--- + pysurvival/cpp_extensions/functions.cpp | 16 ++++++++-------- + pysurvival/cpp_extensions/metrics.cpp | 2 +- + pysurvival/cpp_extensions/non_parametric.cpp | 8 ++++---- + pysurvival/cpp_extensions/survival_forest.cpp | 14 +++++++------- + 4 files changed, 20 insertions(+), 20 deletions(-) + +diff --git a/pysurvival/cpp_extensions/functions.cpp b/pysurvival/cpp_extensions/functions.cpp +index 1942de7..12e4db3 100644 +--- a/pysurvival/cpp_extensions/functions.cpp ++++ b/pysurvival/cpp_extensions/functions.cpp +@@ -29,19 +29,19 @@ vector argsort(vector v, bool descending){ + vector temp_v; + + if(descending){ +- for (int i = 0; i < n; ++i){ ++ for (size_t i = 0; i < n; ++i){ + temp_v.push_back(-v[i]); + } + v = temp_v; + } + +- for (int i = 0; i < n; ++i){ ++ for (size_t i = 0; i < n; ++i){ + a.push_back(make_pair(v[i], i)); + } + + //sort indexes based on comparing values in v + sort(a.begin(),a.end()); +- for (int i = 0; i < n; ++i){ ++ for (size_t i = 0; i < n; ++i){ + idx.push_back( a[i].second ); + } + return idx; +@@ -53,7 +53,7 @@ vector > get_time_buckets(vector times ){ + vector > results; + + // Computing the time buckets +- for (int i = 0; i < N-1; ++i){ ++ for (size_t i = 0; i < N-1; ++i){ + results.push_back(make_pair(times[i], times[i+1])); + } + +@@ -103,7 +103,7 @@ vector reverse(vector x){ + int argmin_buckets(double x, vector > buckets){ + size_t index_x = 0, J = buckets.size(); + double a, min_value = numeric_limits::max(); +- for (int j = 0; j < J; ++j){ ++ for (size_t j = 0; j < J; ++j){ + a = buckets[j].first; + if(fabs(x-a)<= min_value){ + min_value = fabs(x-a); +@@ -151,7 +151,7 @@ vector cumsum( vector v){ + size_t N = v.size(); + vector results; + results.resize(N, 0.); +- for (int i = 0; i < N; ++i){ ++ for (size_t i = 0; i < N; ++i){ + s += v[i]; + results[i] = s; + } +@@ -186,7 +186,7 @@ map< int, vector > baseline_functions(vector score, + vector times, T_temp, E_temp; + vector desc_index = argsort(T, true); + int n; +- for (int i = 0; i < N; ++i){ ++ for (size_t i = 0; i < N; ++i){ + n = desc_index[i]; + T_temp.push_back(T[n]); + E_temp.push_back(E[n]); +@@ -195,7 +195,7 @@ map< int, vector > baseline_functions(vector score, + E = E_temp; + + // Calculating the Baseline hazard function +- for (int i = 0; i < N; ++i){ ++ for (size_t i = 0; i < N; ++i){ + + // Calculating the at risk variables + sum_theta_risk += score[i]; +diff --git a/pysurvival/cpp_extensions/metrics.cpp b/pysurvival/cpp_extensions/metrics.cpp +index 5808cb8..6e4cc41 100644 +--- a/pysurvival/cpp_extensions/metrics.cpp ++++ b/pysurvival/cpp_extensions/metrics.cpp +@@ -129,7 +129,7 @@ map > brier_score(vector > Survival, + size_t i, j, M, N = Survival.size(); + double censored_s, bs, t, S; + map > results; +- int n, times_ = 0; //'times' ++ size_t n, times_ = 0; //'times' + int brier_scores_ = 1; //'brier_scores' + KaplanMeierModel censored_km; + vector weights_km, times_to_consider, brier_scores_values; +diff --git a/pysurvival/cpp_extensions/non_parametric.cpp b/pysurvival/cpp_extensions/non_parametric.cpp +index 1592e9c..6dac90d 100644 +--- a/pysurvival/cpp_extensions/non_parametric.cpp ++++ b/pysurvival/cpp_extensions/non_parametric.cpp +@@ -122,7 +122,7 @@ vector KaplanMeierModel::fit(vector T, vector E, + vector T_temp, E_temp, weights_temp; + vector desc_index = argsort(T, true); + int n; +- for (int i = 0; i < N; ++i){ ++ for (size_t i = 0; i < N; ++i){ + n = desc_index[i]; + T_temp.push_back(T[n]); + +@@ -139,7 +139,7 @@ vector KaplanMeierModel::fit(vector T, vector E, + + // Looping through the data to calculate Survival, hazard, + // Cumulative_Hazard and Variance +- for (int i = 0; i < N; ++i){ ++ for (size_t i = 0; i < N; ++i){ + + // Computing the at risk vector + nb_at_risk += weights[i]; +@@ -180,7 +180,7 @@ vector KaplanMeierModel::fit(vector T, vector E, + cum_std_error = 0.; + survival_old = 1.; + +- for (int j = 0; j < Nt; ++j){ ++ for (size_t j = 0; j < Nt; ++j){ + + // Calculating hazard + hazard_new = events[j]*1./at_risk[j]; +@@ -382,7 +382,7 @@ vector KernelModel::fit(vector T, vector E, + this->survival.push_back(1.-s); + } + +- for (int i = 0; i < N; ++i){ ++ for (size_t i = 0; i < N; ++i){ + this->hazard.push_back( this->density[i]/max(this->survival[i], min_survival) ); + this->cumulative_hazard.push_back(log(max(this->survival[i], min_survival))); + } +diff --git a/pysurvival/cpp_extensions/survival_forest.cpp b/pysurvival/cpp_extensions/survival_forest.cpp +index bab2425..7a034a4 100644 +--- a/pysurvival/cpp_extensions/survival_forest.cpp ++++ b/pysurvival/cpp_extensions/survival_forest.cpp +@@ -1046,8 +1046,8 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + } + + // Adjusting the number of threads to be <= number of cores +- uint max_num_threads = (uint) thread::hardware_concurrency(); +- if ((num_threads < 0) | (num_threads >= max_num_threads)){ ++ uint max_num_threads = thread::hardware_concurrency(); ++ if ((num_threads < 0) | ((uint)num_threads >= max_num_threads)){ + num_threads = max_num_threads; + } else if(num_threads == 0){ + num_threads = 1; +@@ -1157,8 +1157,8 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + } + + // Adjusting the number of threads to be <= number of cores +- uint max_num_threads = (uint) thread::hardware_concurrency(); +- if ((num_threads < 0) | (num_threads >= max_num_threads)){ ++ uint max_num_threads = thread::hardware_concurrency(); ++ if ((num_threads < 0) | ((uint)num_threads >= max_num_threads)){ + num_threads = max_num_threads; + } else if(num_threads == 0){ + num_threads = 1; +@@ -1216,7 +1216,7 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + std::string dependent_variable_name = this->variable_names[this->dependent_varID]; + std::string status_variable_name = this->variable_names[this->status_varID]; + std::vector case_weights; +- for (int i = 0; i < input_data.size(); ++i){ ++ for (size_t i = 0; i < input_data.size(); ++i){ + case_weights.push_back(0.); + } + +@@ -1272,7 +1272,7 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + std::string dependent_variable_name = this->variable_names[this->dependent_varID]; + std::string status_variable_name = this->variable_names[this->status_varID]; + std::vector case_weights; +- for (int i = 0; i < input_data.size(); ++i){ ++ for (size_t i = 0; i < input_data.size(); ++i){ + case_weights.push_back(1./input_data.size()); + } + +@@ -1327,7 +1327,7 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + std::string dependent_variable_name = this->variable_names[this->dependent_varID]; + std::string status_variable_name = this->variable_names[this->status_varID]; + std::vector case_weights; +- for (int i = 0; i < input_data.size(); ++i){ ++ for (size_t i = 0; i < input_data.size(); ++i){ + case_weights.push_back(1./input_data.size()); + } + +-- +1.8.3.1 + diff --git a/conda-recipes/pysurvival-feedstock/recipe/0002-remove-some-unused-variables.patch b/conda-recipes/pysurvival-feedstock/recipe/0002-remove-some-unused-variables.patch new file mode 100644 index 0000000..32b09f5 --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/recipe/0002-remove-some-unused-variables.patch @@ -0,0 +1,63 @@ +From 5287c161ef9bdfd0b2d4f8ad2086001375508a11 Mon Sep 17 00:00:00 2001 +From: "Brian W. Hart" +Date: Fri, 24 Apr 2020 20:36:21 +0000 +Subject: [PATCH 2/4] remove some unused variables + +--- + pysurvival/cpp_extensions/metrics.cpp | 1 - + pysurvival/cpp_extensions/survival_forest.cpp | 6 ------ + 2 files changed, 7 deletions(-) + +diff --git a/pysurvival/cpp_extensions/metrics.cpp b/pysurvival/cpp_extensions/metrics.cpp +index 6e4cc41..aab730d 100644 +--- a/pysurvival/cpp_extensions/metrics.cpp ++++ b/pysurvival/cpp_extensions/metrics.cpp +@@ -141,7 +141,6 @@ map > brier_score(vector > Survival, + + // Initializing/computing the brier score vector + M = times.size(); +- size_t Nt = time_buckets.size(); + for (j = 0; j < M; ++j){ + bs = 0.; + +diff --git a/pysurvival/cpp_extensions/survival_forest.cpp b/pysurvival/cpp_extensions/survival_forest.cpp +index 7a034a4..fc5b2c0 100644 +--- a/pysurvival/cpp_extensions/survival_forest.cpp ++++ b/pysurvival/cpp_extensions/survival_forest.cpp +@@ -1006,7 +1006,6 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + + // variable names to be always selected + std::vector always_split_variable_names; +- bool use_always_split_variable_names; + always_split_variable_names.clear(); + + // Dealing with unordered factor covariates-> all features are numerical so it doesn't apply +@@ -1062,8 +1061,6 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + + // Data + std::unique_ptr data { }; +- size_t num_rows = input_data.size(); +- size_t num_cols = input_data[0].size(); + data = make_unique(); + data->loadData(input_data, variable_names); + +@@ -1116,7 +1113,6 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + + // variable names to be always selected + std::vector always_split_variable_names; +- bool use_always_split_variable_names; + always_split_variable_names.clear(); + + // Dealing with unordered factor covariates-> all features are numerical so it doesn't apply +@@ -1173,8 +1169,6 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + + // Data + std::unique_ptr data { }; +- size_t num_rows = input_data.size(); +- size_t num_cols = input_data[0].size(); + data = make_unique(); + data->loadData(input_data, variable_names); + +-- +1.8.3.1 + diff --git a/conda-recipes/pysurvival-feedstock/recipe/0003-fix-some-logical-vs-bitwise-operator-cases.patch b/conda-recipes/pysurvival-feedstock/recipe/0003-fix-some-logical-vs-bitwise-operator-cases.patch new file mode 100644 index 0000000..c48888c --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/recipe/0003-fix-some-logical-vs-bitwise-operator-cases.patch @@ -0,0 +1,96 @@ +From d2215e8da9741f34f9b33cac7a767cea9772bb39 Mon Sep 17 00:00:00 2001 +From: "Brian W. Hart" +Date: Fri, 24 Apr 2020 20:18:25 +0000 +Subject: [PATCH 3/4] fix some logical vs bitwise operator cases + +Update a few comparisons that use bitwise operators (&, |), where +logical operators (&&, ||) seem intended instead. +--- + pysurvival/cpp_extensions/functions.cpp | 2 +- + pysurvival/cpp_extensions/metrics.cpp | 4 ++-- + pysurvival/cpp_extensions/non_parametric.cpp | 4 ++-- + pysurvival/cpp_extensions/survival_forest.cpp | 4 ++-- + 4 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/pysurvival/cpp_extensions/functions.cpp b/pysurvival/cpp_extensions/functions.cpp +index 12e4db3..ce38194 100644 +--- a/pysurvival/cpp_extensions/functions.cpp ++++ b/pysurvival/cpp_extensions/functions.cpp +@@ -205,7 +205,7 @@ map< int, vector > baseline_functions(vector score, + nb_fails += 1; + } + +- if (i < N-1 & T[i] == T[i+1]){ ++ if (i < N-1 && T[i] == T[i+1]){ + continue; + } + +diff --git a/pysurvival/cpp_extensions/metrics.cpp b/pysurvival/cpp_extensions/metrics.cpp +index aab730d..2d00d3a 100644 +--- a/pysurvival/cpp_extensions/metrics.cpp ++++ b/pysurvival/cpp_extensions/metrics.cpp +@@ -69,7 +69,7 @@ map concordance_index(vector risk, vector T, + w *= censored_km.predict_survival(T[i], true); + + // count pairs +- if( (T[i] concordance_index(vector risk, vector T, + } + + // pairs with equal predictions count 1/2 or nothing +- if ((risk[i] == risk[j]) & include_ties){ ++ if ((risk[i] == risk[j]) && include_ties){ + weightedConcPairs += (1./w)/2.; + } + +diff --git a/pysurvival/cpp_extensions/non_parametric.cpp b/pysurvival/cpp_extensions/non_parametric.cpp +index 6dac90d..21c6124 100644 +--- a/pysurvival/cpp_extensions/non_parametric.cpp ++++ b/pysurvival/cpp_extensions/non_parametric.cpp +@@ -149,7 +149,7 @@ vector KaplanMeierModel::fit(vector T, vector E, + nb_events += weights[i]; + } + +- if (i < N-1 & T[i] == T[i+1]){ ++ if (i < N-1 && T[i] == T[i+1]){ + continue; + } else{ + times.push_back(T[i]); +@@ -315,7 +315,7 @@ vector KernelModel::fit(vector T, vector E, + + // check if the kernel matrix fits in memory + size = this->times.size()*km_times.size(); +- while(k_ < 10 & size/exp(k_*log(10)) > 1.){ ++ while(k_ < 10 && size/exp(k_*log(10)) > 1.){ + k_+=1; + } + +diff --git a/pysurvival/cpp_extensions/survival_forest.cpp b/pysurvival/cpp_extensions/survival_forest.cpp +index fc5b2c0..9a6c9f0 100644 +--- a/pysurvival/cpp_extensions/survival_forest.cpp ++++ b/pysurvival/cpp_extensions/survival_forest.cpp +@@ -1046,7 +1046,7 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + + // Adjusting the number of threads to be <= number of cores + uint max_num_threads = thread::hardware_concurrency(); +- if ((num_threads < 0) | ((uint)num_threads >= max_num_threads)){ ++ if ((num_threads < 0) || ((uint)num_threads >= max_num_threads)){ + num_threads = max_num_threads; + } else if(num_threads == 0){ + num_threads = 1; +@@ -1154,7 +1154,7 @@ size_t ForestSurvival::getTreePredictionTerminalNodeID(size_t tree_idx, size_t s + + // Adjusting the number of threads to be <= number of cores + uint max_num_threads = thread::hardware_concurrency(); +- if ((num_threads < 0) | ((uint)num_threads >= max_num_threads)){ ++ if ((num_threads < 0) || ((uint)num_threads >= max_num_threads)){ + num_threads = max_num_threads; + } else if(num_threads == 0){ + num_threads = 1; +-- +1.8.3.1 + diff --git a/conda-recipes/pysurvival-feedstock/recipe/0004-avoid-undefined-behavior-in-SurvivalForest-Data-get-.patch b/conda-recipes/pysurvival-feedstock/recipe/0004-avoid-undefined-behavior-in-SurvivalForest-Data-get-.patch new file mode 100644 index 0000000..a30fc81 --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/recipe/0004-avoid-undefined-behavior-in-SurvivalForest-Data-get-.patch @@ -0,0 +1,38 @@ +From 28fb6380869c3835ccf0102d5e57a198e1149263 Mon Sep 17 00:00:00 2001 +From: "Brian W. Hart" +Date: Fri, 24 Apr 2020 21:16:26 +0000 +Subject: [PATCH 4/4] avoid undefined behavior in SurvivalForest Data get() and + getIndex() + +SurvivalForest Data implementation's get() and getIndex() functions +can terminate without returning a defined value. + +It's not clear what should be returned in the undefined code path +so throw an exception instead. +--- + pysurvival/cpp_extensions/survival_forest_data.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/pysurvival/cpp_extensions/survival_forest_data.h b/pysurvival/cpp_extensions/survival_forest_data.h +index 8d42dfa..87d3777 100644 +--- a/pysurvival/cpp_extensions/survival_forest_data.h ++++ b/pysurvival/cpp_extensions/survival_forest_data.h +@@ -40,6 +40,7 @@ namespace ranger { + if (col < num_cols_no_snp) { + return data[col * num_rows + row]; + } ++ throw std::runtime_error("get(): col out of bounds"); + }; + + size_t getVariableID(const std::string& variable_name) const; +@@ -67,6 +68,7 @@ namespace ranger { + if (col < num_cols_no_snp) { + return index_data[col * num_rows + row]; + } ++ throw std::runtime_error("getIndex(): col out of bounds"); + } + + void loadData(std::vector > Input_Data, std::vector variable_names){ +-- +1.8.3.1 + diff --git a/conda-recipes/pysurvival-feedstock/recipe/meta.yaml b/conda-recipes/pysurvival-feedstock/recipe/meta.yaml new file mode 100644 index 0000000..7bef488 --- /dev/null +++ b/conda-recipes/pysurvival-feedstock/recipe/meta.yaml @@ -0,0 +1,50 @@ +{% set version = "0.1.2" %} # see pysurvival/__init__.py in source tree + +package: + name: pysurvival + version: {{ version }} + +source: + git_url: https://github.com/square/pysurvival + git_rev: 841b9bc6ce700ba8898d2a1488aa9cd25ee7a8e6 + patches: + - 0001-quiet-signedness-comparison-build-warnings.patch + - 0002-remove-some-unused-variables.patch + - 0003-fix-some-logical-vs-bitwise-operator-cases.patch + - 0004-avoid-undefined-behavior-in-SurvivalForest-Data-get-.patch + +requirements: + build: + - {{ compiler('cxx') }} + host: + - python + - numpy + run: + - python + - matplotlib + - numpy + - pandas + - progressbar + - pyarrow + - scikit-learn + - scipy + - pytorch + +build: + number: 0 + script: {{ PYTHON }} setup.py install --single-version-externally-managed --record=record.txt + +test: + imports: + - pysurvival + - pysurvival.datasets + - pysurvival.models + - pysurvival.utils + +about: + home: https://www.pysurvival.io/ + license: Apache-2.0 + license_family: APACHE + license_file: LICENSE.txt + summary: Open source package for Survival Analysis modeling + dev_url: https://github.com/square/pysurvival