{"id":15684531,"url":"https://github.com/shchur/survival_distributions","last_synced_at":"2025-05-07T18:09:34.955Z","repository":{"id":41068656,"uuid":"440536971","full_name":"shchur/survival_distributions","owner":"shchur","description":"Extended functionality for univariate probability distributions in PyTorch","archived":false,"fork":false,"pushed_at":"2022-06-28T08:43:38.000Z","size":54,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T18:09:29.554Z","etag":null,"topics":["probabilistic-modeling","pytorch","survival-analysis","temporal-point-processes","torch-distributions"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shchur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-21T14:03:30.000Z","updated_at":"2025-03-14T02:03:19.000Z","dependencies_parsed_at":"2022-09-02T18:50:07.734Z","dependency_job_id":null,"html_url":"https://github.com/shchur/survival_distributions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shchur%2Fsurvival_distributions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shchur%2Fsurvival_distributions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shchur%2Fsurvival_distributions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shchur%2Fsurvival_distributions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shchur","download_url":"https://codeload.github.com/shchur/survival_distributions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252931555,"owners_count":21827112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["probabilistic-modeling","pytorch","survival-analysis","temporal-point-processes","torch-distributions"],"created_at":"2024-10-03T17:18:25.909Z","updated_at":"2025-05-07T18:09:34.923Z","avatar_url":"https://github.com/shchur.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# survival_distributions\n\nThis package extends the functionality of univariate distributions in [`torch.distributions`](https://pytorch.org/docs/stable/distributions.html)\nby implementing several new methods:\n- `sf`: survival function (complementary CDF)\n- `logsf`: logarithm of the survival function (negative cumulative hazard function)\n- `logcdf`: logarithm of the CDF\n- `log_hazard`: logarithm of the hazard function (logarithm of the failure rate)\n- `isf`: inverse of the survival function\n- `sample_cond`: instead of sampling from the full support of the distribution, \ngenerate samples between `lower_bound` and `upper_bound`\n \nThis is especially useful when working with\n[temporal point processes](https://shchur.github.io/blog/2020/tpp1-conditional-intensity/)\nor [survival analysis](https://en.wikipedia.org/wiki/Survival_analysis).\n\nNaive implementation based on existing PyTorch functionality (e.g., \n`torch.log(1.0 - dist.cdf(x))` for `logsf`) will often not be as accurate and numerically \nstable as the implementation provided by `survival_distributions`.\nHopefully, these methods will be implemented in PyTorch [sometime in the future](https://github.com/pytorch/pytorch/issues/52973), \nbut this package provides an alternative for the time being.\n\nSee [`DISTRIBUTIONS.md`](https://github.com/shchur/survival_distributions/blob/main/DISTRIBUTIONS.md) for more details about the implemented functions and supported distributions.\n\n## Installation\n1. Install the latest version of [PyTorch](https://pytorch.org/get-started/locally/).\n2. Install `survival_distributions`\n    ```bash\n    pip install survival_distributions\n    ```\n\n## Supported distributions\n\n### Numerically stable implementation\nFor these distributions we provide a numerically stable implementation of `logsf`.\n- `Exponential`\n- `Logistic`\n- `LogLogistic`\n- `MixtureSameFamily`\n- `TransformedDistribution`\n- `Uniform`\n- `Weibull`\n\n### Naive implementation \nFor these distributions we implement `logsf(x)` as `log(1.0 - dist.cdf(x))`, which is less \nnumerically stable.\n- `LogNormal`\n- `Normal`\n\n\n## Usage\nThe package provides a drop-in replacement for `torch.distributions`, so you can just modify your code as follows.\n\n**Old code**\n```python\nimport torch\n\ndist = torch.distributions.Exponential(rate=torch.tensor(2.0))\nx = torch.tensor(1.5)\n\nlog_survival_proba = torch.log(1.0 - dist.cdf(x))\n```\n**New code**\n```python\nimport torch\nimport survival_distributions as sd\n\ndist = sd.Exponential(rate=torch.tensor(2.0))\nx = torch.tensor(1.5)\n\nlog_survival_proba = dist.logsf(x)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshchur%2Fsurvival_distributions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshchur%2Fsurvival_distributions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshchur%2Fsurvival_distributions/lists"}