Skip to content

Commit

Permalink
samples & runtimes for apl 4.2225.0
Browse files Browse the repository at this point in the history
  • Loading branch information
i317814 committed Nov 22, 2022
1 parent 65ff8e4 commit 9d7f935
Show file tree
Hide file tree
Showing 53 changed files with 1,106 additions and 44 deletions.
Binary file modified dataForHANACloud.tar.gz
Binary file not shown.
Binary file modified runtimes/java/KxJRT.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ DO BEGIN
:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('ModelFormat', 'bin'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum
:config.insert(('APL/ModelType', 'binary classification',null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DO BEGIN

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
2 changes: 1 addition & 1 deletion sql/any/parallel/forecast-segmented.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DO BEGIN
:header.insert(('ModelFormat', 'bin'));
-- :header.insert(('ProgressLog','true'));
-- :header.insert(('Cancelable','true'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for forecast
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for forecast

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum
:config.insert(('APL/Horizon', '20',null));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- @required(hanaMinimumVersion,2.0.32)
-- ================================================================
connect USER_APL password Password1;
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE';

DO BEGIN
declare header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER";
declare config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare test_config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare debrief_config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare var_desc "SAP_PA_APL"."sap.pa.apl.base::BASE.T.VARIABLE_DESC_OID";
declare var_role "SAP_PA_APL"."sap.pa.apl.base::BASE.T.VARIABLE_ROLES_WITH_COMPOSITES_OID";
declare out_model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_model_test "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
declare out_sum "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";
declare out_debrief_metric "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID";
declare out_debrief_property "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID";

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '8'));
:header.insert(('ModelFormat', 'bin'));

:config.insert(('APL/ModelType', 'binary classification',null));
:config.insert(('APL/MaxIterations', '100',null)); -- default value: 1000
:config.insert(('APL/EarlyStoppingPatience', '10',null)); -- default value: 10
:config.insert(('APL/LearningRate', '.08',null)); -- default value: 0.1
:config.insert(('APL/CorrelationsMaxKept', '10',null)); -- default value: 1024
:config.insert(('APL/CorrelationsLowerBound', '.99',null)); -- default value: 0.50
:config.insert(('APL/EvalMetric', 'LogLoss,AUC',null));

:config.insert(('APL/VariableAutoSelection', 'true',null));
:config.insert(('APL/VariableSelectionPercentageOfContributionKeptByStep', '0.97',null)); -- default value: 0.95
:config.insert(('APL/VariableSelectionQualityBar', '0.02',null)); -- default value: 0.01
:config.insert(('APL/VariableSelectionMaxIterations', '4',null)); -- default value: 2

:var_role.insert(('class', 'target', null, null, null));

"SAP_PA_APL"."sap.pa.apl.base::CREATE_MODEL_AND_TRAIN"(:header, :config, :var_desc,:var_role, 'APL_SAMPLES','ADULT01',out_model,out_log,out_sum, out_indicators);
"SAP_PA_APL"."sap.pa.apl.base::TEST_MODEL"(:header, :out_model, :test_config,'APL_SAMPLES','ADULT01', out_model_test, out_log, out_indicators);
"SAP_PA_APL"."sap.pa.apl.base::GET_MODEL_DEBRIEF"(:header, :out_model_test, :debrief_config, out_debrief_metric, out_debrief_property, out_debrief_summary);

-- Dump Statistics Report
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::Statistics_Partition"(:out_debrief_property, :out_debrief_metric);

-- Dump Statistics Binary Target
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::BinaryTarget_CurveRoc"(:out_debrief_property, :out_debrief_metric);
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::BinaryTarget_CurveLift"(:out_debrief_property, :out_debrief_metric);
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::BinaryTarget_CurveGain"(:out_debrief_property, :out_debrief_metric);
END;
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DO BEGIN
:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('ModelFormat', 'bin'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DO BEGIN
:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('ModelFormat', 'bin'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum
:config.insert(('APL/ModelType', 'binary classification',null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DO BEGIN

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ DO BEGIN

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- @required(hanaMinimumVersion,2.0.40)
-- ================================================================
-- APL_AREA, APPLY_MODEL, using a binary format for the model
-- This script demonstrates the application of the binary classification model
-- to predict the target and to get the individual contributions per input
--
-- Assumption 1: The users & privileges have been created & granted (see apl_admin_ex.sql).
-- Assumption 2: There's a valid trained model (created by APL) in the MODEL_TRAIN_BIN table.
-- @depend(segmented_create_train.sql)
connect USER_APL password Password1;
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE';

drop table TEST_INDICATORS;
create table TEST_INDICATORS like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS";

drop table TEST_MODEL_BIN;
create table TEST_MODEL_BIN like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";

drop table TEST_OPERATION_LOG;
create table TEST_OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";

DO BEGIN
declare header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER";
declare config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
declare out_indicators "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS";

model = select * from MODEL_TRAIN_BIN;

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

"SAP_PA_APL"."sap.pa.apl.base::TEST_MODEL"(:header, :model, :config,'USER_APL','ADULT01_SORTED', out_model, out_log, out_indicators);

-- store result into table
insert into TEST_INDICATORS select * from :out_indicators;
insert into TEST_MODEL_BIN select * from :out_model;
insert into TEST_OPERATION_LOG select * from :out_log;
END;

select * from TEST_INDICATORS;
select * from TEST_MODEL_BIN;
select * from TEST_OPERATION_LOG;
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- @required(hanaMinimumVersion,2.0.40)
-- ================================================================
-- APL_AREA, APPLY_MODEL, using a binary format for the model
-- This script demonstrates the application of the binary classification model
-- to predict the target and to get the individual contributions per input
--
-- Assumption 1: The users & privileges have been created & granted (see apl_admin_ex.sql).
-- Assumption 2: There's a valid trained model (created by APL) in the MODEL_TRAIN_BIN table.
-- @depend(segmented_create_train.sql)
connect USER_APL password Password1;
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE';

drop table TEST_SUMMARY;
create table TEST_SUMMARY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";

drop table TEST_METRIC;
create table TEST_METRIC like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID";

drop table TEST_PROPERTY;
create table TEST_PROPERTY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID";

drop table TEST_MODEL_BIN;
create table TEST_MODEL_BIN like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";

drop table TEST_OPERATION_LOG;
create table TEST_OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";

DO BEGIN
declare header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER";
declare config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
declare out_summary "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";
declare out_metric "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID";
declare out_property "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID";

model = select * from MODEL_TRAIN_BIN;

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

"SAP_PA_APL"."sap.pa.apl.base::TEST_MODEL_DEBRIEF"(:header, :model, :config,'USER_APL','ADULT01_SORTED', out_model, out_log, out_summary, out_metric,out_property);

-- store result into table
insert into TEST_PROPERTY select * from :out_property;
insert into TEST_METRIC select * from :out_metric;
insert into TEST_SUMMARY select * from :out_summary;
insert into TEST_MODEL_BIN select * from :out_model;
insert into TEST_OPERATION_LOG select * from :out_log;
END;

select * from TEST_MODEL_BIN;
select * from TEST_OPERATION_LOG;

-- Nb trained models
select count(*) from TEST_SUMMARY where "KEY" = 'AplTaskElapsedTime';

-- Average time to train a segment
select AVG(to_double("VALUE")) from TEST_SUMMARY where "KEY" = 'AplTaskElapsedTime';

-- Total time
select * from TEST_SUMMARY where "KEY" = 'AplTotalElapsedTime';

-- Debrief all models by segment
select * from "SAP_PA_APL"."sap.pa.apl.debrief.report::ClassificationRegression_Performance"(TEST_PROPERTY, TEST_METRIC);
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DO BEGIN
:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('ModelFormat', 'bin'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DO BEGIN
:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('ModelFormat', 'bin'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DO BEGIN
:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('ModelFormat', 'bin'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum
:config.insert(('APL/ModelType', 'regression/classification',null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DO BEGIN
:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('ModelFormat', 'bin'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum
:config.insert(('APL/ModelType', 'regression/classification',null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DO BEGIN

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DO BEGIN

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ DO BEGIN

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ DO BEGIN

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '4')); -- define nb parallel tasks to use for train
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- @required(hanaMinimumVersion,2.0.40)
-- ================================================================
-- APL_AREA, APPLY_MODEL, using a binary format for the model
-- This script demonstrates the application of the binary classification model
-- to predict the target and to get the individual contributions per input
--
-- Assumption 1: The users & privileges have been created & granted (see apl_admin_ex.sql).
-- Assumption 2: There's a valid trained model (created by APL) in the MODEL_TRAIN_BIN table.
-- @depend(segmented_create_train_class.sql)
connect USER_APL password Password1;
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE';

drop table TEST_INDICATORS;
create table TEST_INDICATORS like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS";

drop table TEST_MODEL_BIN;
create table TEST_MODEL_BIN like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";

drop table TEST_OPERATION_LOG;
create table TEST_OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";

DO BEGIN
declare header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER";
declare config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
declare out_indicators "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS";

model = select * from MODEL_TRAIN_BIN;

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '2'));
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum

"SAP_PA_APL"."sap.pa.apl.base::TEST_MODEL"(:header, :model, :config,'USER_APL','ADULT01_SORTED', out_model, out_log, out_indicators);

-- store result into table
insert into TEST_INDICATORS select * from :out_indicators;
insert into TEST_MODEL_BIN select * from :out_model;
insert into TEST_OPERATION_LOG select * from :out_log;
END;

select * from TEST_INDICATORS;
select * from TEST_MODEL_BIN;
select * from TEST_OPERATION_LOG;
Loading

0 comments on commit 9d7f935

Please sign in to comment.