Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions R/evaluation.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ evaluate_survdnn <- function(model,
data <- if (is.null(newdata)) model$data else newdata
n_before <- nrow(data)

# Build model frame first with explicit NA policy (so y aligns with predictions)
# build model frame first with explicit NA policy
mf <- model.frame(
model$formula,
data = data,
Expand All @@ -50,10 +50,10 @@ evaluate_survdnn <- function(model,
y <- model.response(mf)
if (!inherits(y, "Surv")) stop("The response must be a 'Surv' object.", call. = FALSE)

# Predict on the filtered mf to keep row alignment
# predict on the filtered mf to keep row alignment
sp_matrix <- predict(model, newdata = mf, times = times, type = "survival")

purrr::map_dfr(metrics, function(metric) {
purrr::map_dfr(metrics, function(metric) { ## to replace with fmap from functionals package
if (metric == "brier" && length(times) > 1) {
tibble::tibble(
metric = "brier",
Expand Down
4 changes: 2 additions & 2 deletions R/tune_survdnn.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ tune_survdnn <- function(formula,

summary_tbl <- summarize_tune_survdnn(all_results, by_time = FALSE)

## Select best hyperparameters
## select best hyperparameters
primary_metric <- metrics[1]

best_row_all <- all_results |>
Expand All @@ -99,7 +99,7 @@ tune_survdnn <- function(formula,
stop("No valid configuration found for primary metric: ", primary_metric, call. = FALSE)
}

## Refitting the best model
## refitting the best model
if (refit) {
message("Refitting best model on full data...")
best_model <- survdnn(
Expand Down
7 changes: 2 additions & 5 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
"fold", "metric", "value", "id", "time", "surv", "group", "mean_surv",
"n", "se", "hidden", "lr", "activation", "epochs", "loss_name", ".loss_fn"
))

# IMPORTANT: never load or probe torch here (because CRAN/Windows may segfault).
# No torch checks, no tensor creation on load.
# never load or probe torch here (because CRAN/Windows may segfault)
}

## handles user-facing messaging
.onAttach <- function(libname, pkgname) {
# Do NOT load torch or call torch::torch_is_installed() here.
# friendly hint that doesn't load the namespace:
torch_pkg_present <- nzchar(system.file(package = "torch"))

Expand Down Expand Up @@ -51,7 +48,7 @@ survdnn_set_seed <- function(.seed = NULL) {



## Internal utility to choose a torch device for survdnn
## internal utility to choose a torch device for survdnn
survdnn_get_device <- function(.device = c("auto", "cpu", "cuda")) {
.device <- match.arg(.device)

Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ output: github_document

# survdnn <img src="https://raw.githubusercontent.com/ielbadisy/survdnn/main/inst/logo.png" align="right" height="140"/>

> Deep Neural Networks for Survival Analysis using [torch](https://torch.mlverse.org/)
> Deep Neural Networks for Survival Analysis using [R torch](https://torch.mlverse.org/)

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![R-CMD-check](https://github.com/ielbadisy/survdnn/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ielbadisy/survdnn/actions/workflows/R-CMD-check.yaml)
Expand Down Expand Up @@ -43,7 +43,7 @@ A methodological paper describing the design, implementation, and evaluation of

```{r, eval = FALSE}
# Install from CRAN
install.packages("surdnn")
install.packages("survdnn")


# Install from GitHub
Expand Down
Loading
Loading