Skip to content

Commit

Permalink
PUBDEV-3474: progress bar now working for PDP
Browse files Browse the repository at this point in the history
  • Loading branch information
ivyywang committed Sep 29, 2016
1 parent 96211e5 commit 13b69be
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/core/components/notebook.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ Flow.Notebook = (_, _renderers) ->
,
createMenu 'Score', [
createMenuItem 'Predict...', executeCommand 'predict'
createMenuItem 'Partial Dependence Plots...', executeCommand 'partialDependence'
createMenuItem 'Partial Dependence Plots...', executeCommand 'getPartialDependence'
menuDivider
createMenuItem 'List All Predictions', executeCommand 'getPredictions'
#TODO Confusion Matrix
Expand Down
101 changes: 53 additions & 48 deletions src/ext/components/partial-dependence-input.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,50 @@ H2O.PartialDependenceInput = (_, _go) ->
_models = signals []
_selectedModel = signals null
_selectedFrame = signal null
_nbins = signal null

_leftColumns = signals []
_selectedLeftColumn = signal null
_includeAllLeftRows = signal false

_selectedRightFrame = signal null
_rightColumns = signals []
_selectedRightColumn = signal null
_includeAllRightRows = signal false

_canCompute = lift _selectedFrame, _selectedLeftColumn, _selectedRightFrame, _selectedRightColumn, (lf, lc, rf, rc) ->
lf and lc and rf and rc

react _selectedFrame, (frameKey) ->
if frameKey
_.requestFrameSummaryWithoutData frameKey, (error, frame) ->
_leftColumns map frame.columns, (column, i) ->
label: column.label
index: i
else
_selectedLeftColumn null
_leftColumns []

react _selectedRightFrame, (frameKey) ->
if frameKey
_.requestFrameSummaryWithoutData frameKey, (error, frame) ->
_rightColumns map frame.columns, (column, i) ->
label: column.label
index: i
else
_selectedRightColumn null
_rightColumns []

_computer = ->
return unless _canMerge()

cs = "mergeFrames #{stringify _destinationKey()}, #{stringify _selectedFrame()}, #{_selectedLeftColumn().index}, #{_includeAllLeftRows()}, #{stringify _selectedRightFrame()}, #{_selectedRightColumn().index}, #{_includeAllRightRows()}"
_nbins = signal 20

# _leftColumns = signals []
# _selectedLeftColumn = signal null
# _includeAllLeftRows = signal false

# _selectedRightFrame = signal null
# _rightColumns = signals []
# _selectedRightColumn = signal null
# _includeAllRightRows = signal false

_canCompute = lift _destinationKey, _selectedFrame, _selectedModel, _nbins, (dk, sf, sm, nb) ->
dk and sf and sm and nb

# react _selectedFrame, (frameKey) ->
# if frameKey
# _.requestFrameSummaryWithoutData frameKey, (error, frame) ->
# _leftColumns map frame.columns, (column, i) ->
# label: column.label
# index: i
# else
# _selectedLeftColumn null
# _leftColumns []

# react _selectedRightFrame, (frameKey) ->
# if frameKey
# _.requestFrameSummaryWithoutData frameKey, (error, frame) ->
# _rightColumns map frame.columns, (column, i) ->
# label: column.label
# index: i
# else
# _selectedRightColumn null
# _rightColumns []

_compute = ->
return unless _canCompute()

opts =
destination_key: _destinationKey()
model_id: _selectedModel()
frame_id: _selectedFrame()
nbins: _nbins()

cs = "getPartialDependence #{stringify opts}"

_.insertAndExecuteCell 'cs', cs

Expand All @@ -68,16 +74,15 @@ H2O.PartialDependenceInput = (_, _go) ->
selectedModel: _selectedModel
selectedFrame: _selectedFrame
nbins: _nbins

leftColumns: _leftColumns
selectedLeftColumn: _selectedLeftColumn
includeAllLeftRows: _includeAllLeftRows
selectedRightFrame: _selectedRightFrame
rightColumns: _rightColumns
selectedRightColumn: _selectedRightColumn
includeAllRightRows: _includeAllRightRows
merge: _merge
canMerge: _canMerge
# leftColumns: _leftColumns
# selectedLeftColumn: _selectedLeftColumn
# includeAllLeftRows: _includeAllLeftRows
# selectedRightFrame: _selectedRightFrame
# rightColumns: _rightColumns
# selectedRightColumn: _selectedRightColumn
# includeAllRightRows: _includeAllRightRows
compute: _compute
canCompute: _canCompute

template: 'flow-partial-dependence-input'

Expand Down
2 changes: 1 addition & 1 deletion src/ext/components/partial-dependence-input.jade
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tbody
tr
th(width='150')
label Save PDP frame as:
label Save Destination PDP as:
td
input(data-bind="value:destinationKey" style='width:250px')
tr
Expand Down
8 changes: 4 additions & 4 deletions src/ext/components/partial-dependence-output.coffee
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
H2O.PartialDependenceOutput = (_, _go, _mergeFramesResult) ->
H2O.PartialDependenceOutput = (_, _go, _partialDependenceResult) ->

_frameKey = _mergeFramesResult.key
_destinationKey = _partialDependenceResult.dest.name

_viewFrame = ->
_.insertAndExecuteCell 'cs', "getFrameSummary #{stringify _frameKey}"
_.insertAndExecuteCell 'cs', "requestPartialDependenceData #{stringify _destinationKey}"

defer _go

frameKey: _frameKey
_destinationKey: _destinationKey
viewFrame: _viewFrame
template: 'flow-partial-dependence-output'

1 change: 1 addition & 0 deletions src/ext/modules/application-context.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ H2O.ApplicationContext = (_) ->
_.requestPredict = do slot
_.requestPrediction = do slot
_.requestPredictions = do slot
_.requestPartialDependence = do slot
_.requestGrids = do slot
_.requestModels = do slot
_.requestGrid = do slot
Expand Down
11 changes: 11 additions & 0 deletions src/ext/modules/proxy.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ H2O.Proxy = (_) ->
chunk_size: chunkSize
doPost '/3/Parse', opts, go

requestPartialDependence = (opts, go) ->
doPost '/3/PartialDependence/', opts, go

# requestPartialDependenceData = (key, go) ->
# doGet "/3/PartialDependence/#{encodeURIComponent key}", (error, result) ->
# if error
# go error, result
# else go error, result.data

requestGrids = (go, opts) ->
doGet "/99/Grids", (error, result) ->
if error
Expand Down Expand Up @@ -575,6 +584,8 @@ H2O.Proxy = (_) ->
link _.requestParseSetup, requestParseSetup
link _.requestParseSetupPreview, requestParseSetupPreview
link _.requestParseFiles, requestParseFiles
link _.requestPartialDependence, requestPartialDependence
# link _.requestPartialDependenceData, requestPartialDependenceData
link _.requestGrids, requestGrids
link _.requestModels, requestModels
link _.requestGrid, requestGrid
Expand Down
35 changes: 18 additions & 17 deletions src/ext/modules/routines.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ H2O.Routines = (_) ->
result

extendPartialDependence = (result) ->
render_ result, H2O.partialDependenceOutput, result
render_ result, H2O.PartialDependenceOutput, result
result

# inspectOutputsAcrossModels = (modelCategory, models) -> ->
Expand Down Expand Up @@ -1027,6 +1027,17 @@ H2O.Routines = (_) ->
else
go null, extendJob job

requestPartialDependence = (opts, go) ->
_.requestPartialDependence opts, (error, result) ->
if error
go error
else
_.requestJob result.key.name, (error, job) ->
if error
go error
else
go null, extendJob job

computeSplits = (ratios, keys) ->
parts = []
sum = 0
Expand Down Expand Up @@ -1108,16 +1119,6 @@ H2O.Routines = (_) ->
go null, extendMergeFramesResult
key: destinationKey

requestPartialDependence = (destinationKey, modelKey, frameKey, nbins, go) ->

statement = "(assign #{destinationKey} (merge #{leftFrameKey} #{rightFrameKey} #{lr} #{rr} #{leftColumnIndex} #{rightColumnIndex} \"radix\"))"
_.requestExec statement, (error, result) ->
if error
go error
else
go null, extendPartialDependence
key: destinationKey

createFrame = (opts) ->
if opts
_fork requestCreateFrame, opts
Expand All @@ -1136,11 +1137,11 @@ H2O.Routines = (_) ->
else
assist mergeFrames

partialDependence = (destinationKey, leftFrameKey, leftColumnIndex, includeAllLeftRows, rightFrameKey, rightColumnIndex, includeAllRightRows) ->
if destinationKey and leftFrameKey and rightFrameKey
_fork requestPartialDependence, destinationKey, leftFrameKey, leftColumnIndex, includeAllLeftRows, rightFrameKey, rightColumnIndex, includeAllRightRows
getPartialDependence = (opts) ->
if opts
_fork requestPartialDependence, opts
else
assist partialDependence
assist getPartialDependence

getFrames = ->
_fork requestFrames
Expand Down Expand Up @@ -1836,7 +1837,7 @@ H2O.Routines = (_) ->
_fork proceed, H2O.SplitFrameInput, args
when mergeFrames
_fork proceed, H2O.MergeFramesInput, args
when partialDependence
when getPartialDependence
_fork proceed, H2O.PartialDependenceInput, args
when exportFrame
_fork proceed, H2O.ExportFrameInput, args
Expand Down Expand Up @@ -1921,7 +1922,7 @@ H2O.Routines = (_) ->
createFrame: createFrame
splitFrame: splitFrame
mergeFrames: mergeFrames
partialDependence: partialDependence
getPartialDependence: getPartialDependence
getFrames: getFrames
getFrame: getFrame
bindFrames: bindFrames
Expand Down

0 comments on commit 13b69be

Please sign in to comment.