Skip to content

Commit

Permalink
fix example and saving of modified estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
egillax committed Apr 16, 2022
1 parent 0a1d8b3 commit d1c0293
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 118 deletions.
28 changes: 28 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by roxygen2: do not edit by hand

export(Dataset)
export(Estimator)
export(doubleLayerNN)
export(fitDeepNNTorch)
export(fitEstimator)
export(fitTabNetTorch)
export(gridCvDeep)
export(predictDeepEstimator)
export(predictDeepNN)
export(predictTabNetTorch)
export(setCIReNN)
export(setCNNTorch)
export(setCovNN)
export(setCovNN2)
export(setDeepNN)
export(setDeepNNTorch)
export(setRNNTorch)
export(setResNet)
export(setTabNetTorch)
export(setTransformer)
export(singleLayerNN)
export(toSparseMDeep)
export(toSparseRTorch)
export(transferLearning)
export(tripleLayerNN)
importFrom(zeallot,"%<-%")
5 changes: 2 additions & 3 deletions R/Estimator.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fitEstimator <- function(
trainData$labels <- merge(trainData$labels, trainData$fold, by = 'rowId')
}

mappedData <- PatientLevelPredictionArrow::toSparseM(
mappedData <- PatientLevelPrediction::toSparseM(
plpData = trainData,
map = NULL
)
Expand All @@ -55,7 +55,7 @@ fitEstimator <- function(
labels <- mappedData$labels
covariateRef <- mappedData$covariateRef

outLoc <- PatientLevelPredictionArrow:::createTempModelLoc() # export
outLoc <- PatientLevelPrediction:::createTempModelLoc() # export

cvResult <- do.call(
what = gridCvDeep,
Expand Down Expand Up @@ -245,7 +245,6 @@ gridCvDeep <- function(
device = device
)

browser()
estimator$fit(
trainDataset,
testDataset
Expand Down
5 changes: 4 additions & 1 deletion R/ResNet.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ setResNet <- function(
saveType = 'file',
modelParamNames = c("numLayers", "sizeHidden", "hiddenFactor",
"residualDropout", "hiddenDropout", "sizeEmbedding"),
baseModel = ResNet
baseModel = 'ResNet'
)

results <- list(
Expand Down Expand Up @@ -129,6 +129,9 @@ sparseLinearLayer <- torch::nn_module(
}
},
forward = function(input) {
if (input$dtype != torch::torch_float32()) {
input <- input$type_as(self$weight)
}
torch::nnf_linear(input, self$weight, self$bias)
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/Transformer.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ setTransformer <- function(numBlocks=3, dimToken=96, dimOut=1,
saveType = 'file',
modelParamNames = c('numBlocks', 'dimToken', 'dimOut', 'numHeads',
'attDropout', 'ffnDropout', 'resDropout', 'dimHidden'),
baseModel = Transformer
baseModel = 'Transformer'
)

results <- list(
Expand Down
90 changes: 30 additions & 60 deletions extras/example.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# testing code (requires sequential branch of FeatureExtraction):
# rm(list = ls())
library(FeatureExtraction)
library(PatientLevelPredictionArrow)
library(PatientLevelPrediction)
library(DeepPatientLevelPrediction)

arrow <- T
data(plpDataSimulationProfile)
sampleSize <- 1e4
plpData <- simulatePlpData(
Expand All @@ -13,68 +12,39 @@ plpData <- simulatePlpData(
)


populationSet <- PatientLevelPredictionArrow::createStudyPopulationSettings(
populationSet <- PatientLevelPrediction::createStudyPopulationSettings(
requireTimeAtRisk = F,
riskWindowStart = 1,
riskWindowEnd = 365)


# modelSettings <- PatientLevelPrediction::setGradientBoostingMachine(ntrees = 100, nthread = 16,
# earlyStopRound = 25, maxDepth = 6,
# minChildWeight = 1, learnRate = 0.3,
# seed = 42)

# modelSettings <- PatientLevelPredictionArrow::setLassoLogisticRegression()

modelSettings <- DeepPatientLevelPrediction::setTabNetTorch(device='cuda:0', randomSamples = 1,
batchSize = 32)

if (arrow) {
res2 <- runPlp(
plpData = plpData,
outcomeId = 3,
modelSettings = modelSettings,
analysisId = 'Test',
analysisName = 'Testing ARrow',
populationSettings = populationSet,
splitSettings = createDefaultSplitSetting(),
sampleSettings = createSampleSettings(), # none
featureEngineeringSettings = createFeatureEngineeringSettings(), # none
preprocessSettings = createPreprocessSettings(),
logSettings = createLogSettings(verbosity='TRACE'),
executeSettings = createExecuteSettings(
runSplitData = T,
runSampleData = F,
runfeatureEngineering = F,
runPreprocessData = T,
runModelDevelopment = T,
runCovariateSummary = T
),
saveDirectory = '~/test/arrow_new_plp/'
modelSettings <- setResNet(numLayers = 2, sizeHidden = 64, hiddenFactor = 1,
residualDropout = 0, hiddenDropout = 0.2, normalization = 'BatchNorm',
activation = 'RelU', sizeEmbedding = 64, weightDecay = 1e-6,
learningRate = 3e-4, seed = 42, hyperParamSearch = 'random',
randomSample = 1, device = 'cuda:0',batchSize = 32,epochs = 1)

res2 <- PatientLevelPrediction::runPlp(
plpData = plpData,
outcomeId = 3,
modelSettings = modelSettings,
analysisId = 'Test',
analysisName = 'Testing DeepPlp',
populationSettings = populationSet,
splitSettings = createDefaultSplitSetting(),
sampleSettings = createSampleSettings(), # none
featureEngineeringSettings = createFeatureEngineeringSettings(), # none
preprocessSettings = createPreprocessSettings(),
logSettings = createLogSettings(verbosity='TRACE'),
executeSettings = createExecuteSettings(
runSplitData = T,
runSampleData = F,
runfeatureEngineering = F,
runPreprocessData = T,
runModelDevelopment = T,
runCovariateSummary = T
),
saveDirectory = '~/test/new_plp/'
)
} else {
library(PatientLevelPrediction)
res2 <- PatientLevelPrediction::runPlp(
plpData = plpData,
outcomeId = 3,
modelSettings = modelSettings,
analysisId = 'Test',
analysisName = 'Testing Original',
populationSettings = populationSet,
splitSettings = createDefaultSplitSetting(),
sampleSettings = createSampleSettings(), # none
featureEngineeringSettings = createFeatureEngineeringSettings(), # none
preprocessSettings = createPreprocessSettings(),
logSettings = createLogSettings(verbosity='TRACE'),
executeSettings = createExecuteSettings(
runSplitData = T,
runSampleData = F,
runfeatureEngineering = F,
runPreprocessData = T,
runModelDevelopment = T,
runCovariateSummary = T
),
saveDirectory = '~/test/new_plp/'
)
}


43 changes: 0 additions & 43 deletions man/setDeepNNTorch.Rd

This file was deleted.

20 changes: 10 additions & 10 deletions man/setResNet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d1c0293

Please sign in to comment.