Autotune Action Set

Tuning the Hyperparameters of t-Distributed Stochastic Neighbor Embedding

This section contains PROC CAS code.

Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.

This example illustrates the use of the tuneTsne action to automatically tune the hyperparameters for t-distributed stochastic neighbor embedding. The following DATA step loads the iris data set from the Sashelp library into a data table named mycas.iris. These statements assume that the CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

  data mycas.iris;
     set sashelp.iris;
     id=_n_;
  run;

The following PROC CAS code uses the tuneTsne action to automatically tune the hyperparameters of a two-dimensional embedding of the Iris data. Note that the syntax of the trainOptions parameter here is the same as the syntax of the tSne action. For more information about the tSne action, see Chapter 40, t-Distributed Stochastic Neighbor Embedding Action Set.

  proc cas noqueue;
     action autotune.tuneTsne /
        trainOptions     = {
           table         = {name='iris'},
           inputs        = {"SepalLength", "SepalWidth", "PetalLength", "PetalWidth"},
           nDimensions   = 2,
           perplexity    = 5,
           learningRate  = 100,
           maxIters      = 500,
           output        = {casOut={name="tsne_out", replace="TRUE"},
                            copyvars={"id", "species"}}
        },
        tunerOptions     = {
           searchMethod  = "GA",
           popSize       = 10,
           logLevel      = 3,
           seed          = 12345
        }
        /* Tuning Parameters

           You do not need to specify any tuning parameters for the default
           tuning process. If you want to make adjustments to the default
           tuning process, uncomment the following block of code and change
           any of the tuning parameters' attributes.

        , tuningParameters = {
           {name="perplexity",   initValue=30,   lb=5,    ub=50,   exclude=false},
           {name="learningRate", initValue=1000, lb=10,   ub=2000, exclude=false},
           {name="maxIters",     initValue=300,  lb=250,  ub=5000, exclude=false}
       }
       */
     ;
     ods output TunerResults      = TuneResults(keep=tSNEKLLoss);
     ods output EvaluationHistory = EvalHistory;
     ods output IterationHistory  = IterHistory;
     run;
  quit;

The following optional code includes two DATA steps and two SGPLOT procedure steps that generate the following two plots from the tuneTsne action results:

  • history of all evaluations (the objective value versus the evaluation number, grouped by iteration)

  • iteration history (the best objective value and total tuning time versus the iteration number)

 data _null_;
    set TuneResults;
    if _n_ = 1 then call symput('default', tSNEKLLoss);
    else if _n_ = 2 then call symput('best', tSNEKLLoss);
 run;

 data EvalHistory;
    set EvalHistory;
    default = &default.;
    best = &best.;
 run;

 proc sgplot data=EvalHistory;
    title "Tune tSne with GA on Iris Data";
    scatter x=Evaluation y=tSNEKLLoss / group=Iteration;
    series x=Evaluation y=default /
       curvelabel="default" lineattrs=(pattern=shortdash);
    series x=Evaluation y=best /
       curvelabel="best" lineattrs=(color=green pattern=shortdash);
 run;
 proc sgplot data=IterHistory;
    title "Tune tSne with GA on Iris Data";
    series x=Iteration y=Best_Obj;
    series x=Iteration y=Time_Sec / y2axis;
 run;

Output 7.18.1 shows the "Tuner Information" output table, which displays the values of parameters that the tuner used.

Output 7.18.1: Tuner Information Output

Results from tSne.tSne

Tuner Information
Model Typet-Distributed Stochastic Neighbor Embedding
Tuner Objective FunctionKullback-Leibler loss with pseudo-BIC penalty
Search MethodGA
Population Size10
Maximum Iterations5
Maximum Tuning Time in Seconds36000
Validation TypeValidation Type
Log Level3
Seed12345
Number of Parallel Evaluations15
Number of Workers per Subsession1


Output 7.18.2 shows the "Tuner Results" output table, which displays the default configuration (Evaluation 0) and up to 10 of the best configurations that the tuner found. For each configuration, the hyperparameter values and objective value are provided.

Output 7.18.2: Tuner Results Output

Tuner Results
Default and Best Configurations
EvaluationLearning
Rate
PerplexityMaximum
Number of
Iterations
Kullback-Leibler
Loss
Evaluation
Time
in Seconds
0100.0000005.0000005000.56641.95
63230.9544135.00000028890.51725.05
64128.2929505.00000028890.51765.03
5113.8713835.00000028890.52225.11
4210.0000005.00000050000.52338.66
2810.0000005.00000028890.52625.52
5510.0000005.00000026250.52684.78
6613.8713835.00000050000.53048.99
671008.8713835.00000028890.54265.26
29452.2222225.00000050000.54309.03
3210.0000005.00000036680.54436.59


Output 7.18.3 shows the "Tuner Iteration History" output table, which displays the results of each iteration. For each iteration, the number of evaluations, the best objective value so far, and the tuning time in seconds are provided.

Output 7.18.3: Tuner Iteration History Output

Tuner Iteration History
IterationEvaluationsBest
Objective
Elapsed
Time
in Seconds
010.571.95
1170.5521.42
2310.5330.45
3440.5239.11
4560.5247.72
5680.5256.71


Output 7.18.4 shows the "Tuner Evaluation History" output table, which displays all model configurations that the tuner evaluated. For each configuration, the hyperparameter values and objective value are provided.

Output 7.18.4: Tuner Evaluation History Output

Tuner History
All Evaluated Configurations
EvaluationIterationLearning
Rate
PerplexityMaximum
Number of
Iterations
Kullback-Leibler
Loss
Evaluation
Time
in Seconds
00100.0000005.0000005000.56641.95
1110.00000020.00000013060.82388.55
211778.88888935.00000044721.26779.26
311557.77777850.0000007781.75178.55
411115.55555640.00000023611.42569.26
51452.2222225.00000028890.54559.26
61673.33333325.00000039440.96429.26
711336.66666710.0000002503.77568.55
81894.44444430.00000018331.10829.26
91231.11111115.00000050000.696016.28
101100.0000005.0000005000.56646.66
1111005.00000027.50000026251.03129.79
1211005.00000050.00000026251.751710.35
1311005.0000005.00000026250.563111.16
1412000.00000027.50000026251.035111.81
15110.00000027.50000026251.031915.57
1611005.00000027.50000050001.031712.81
1711005.00000027.5000002503.81310.70
182206.87220416.2872602502.22551.17
192180.77649021.28726019850.85904.18
2021221.03700931.84631528071.17245.38
212547.3531615.00000017360.54903.87
222298.05652925.58329212080.98383.00
23278.30272611.54453428990.62815.55
242741.63605926.54453425631.00194.96
25218.0646829.9522792501.87001.02
262591.39801522.14179134520.87806.39
2721447.2222225.00000028890.55826.66
28210.0000005.00000028890.52625.52
292452.2222225.00000050000.54309.03
302452.2222225.0000005140.57881.55
312452.22222227.50000028891.03345.65
32310.0000005.00000036680.54436.59
33394.55054113.08930027540.65944.86
343916.89130321.22582328390.85605.13
353386.98674720.58357026250.83964.94
363526.16254014.10696831880.68516.08
373771.3755765.96284611810.55652.49
383302.3251418.41881023440.55464.31
393120.76156619.08888023830.78444.42
403238.04160523.38491316060.91163.20
4131005.0000005.00000028890.56275.30
42310.0000005.00000050000.52338.66
43310.0000005.0000005140.61921.39
44310.00000027.50000028891.03195.36
45410.00000010.24719432100.60495.48
464422.1829007.79123120470.57463.54
474227.82268910.09352424910.59254.21
484398.0548545.73907343200.55197.47
49410.0000005.15605026120.55274.77
504272.1208455.00000028890.56365.03
51413.8713835.00000028890.52225.11
52468.74459012.93210029070.62655.12
53483.01798611.98593327720.62584.62
5441005.0000005.00000050000.56078.57
55410.0000005.00000026250.52684.78
56410.00000027.50000050001.04028.61
575231.9162805.71045023690.56834.26
585257.1355005.47068438000.55277.17
59511.0397665.00000028890.54965.08
60527.4027155.00000028890.54505.26
61510.0000005.04891126360.54644.77
62510.0000006.10983429570.58005.41
635230.9544135.00000028890.51725.05
645128.2929505.00000028890.51765.03
65513.8713835.0000005140.58651.34
66513.8713835.00000050000.53048.99
6751008.8713835.00000028890.54265.26
68513.87138327.50000028891.03725.29


Output 7.18.5 shows the "Best Configuration" output table, which displays the values of hyperparameters and the objective value for the best configuration that the tuner found.

Output 7.18.5: Best Configuration Output

Best Configuration
Evaluation63
Perplexity5
Learning Rate230.954413
Maximum Number of Iterations2889
Kullback-Leibler loss with pseudo-BIC pe0.52


Output 7.18.6 shows the "Tuner Summary" output table, which displays statistics about the tuning process.

Output 7.18.6: Tuner Summary Output

Tuner Summary
Initial Configuration Objective Value0.5664
Best Configuration Objective Value0.5172
Worst Configuration Objective Value3.8131
Initial Configuration Evaluation Time in Seconds1.9486
Best Configuration Evaluation Time in Seconds5.0482
Number of Improved Configurations6
Number of Evaluated Configurations68
Total Tuning Time in Seconds63.9364
Parallel Tuning Speedup5.4529


Output 7.18.7 shows the "Tuner Task Timing" output table, which displays timing information about the different tasks that were performed during the tuning process.

Output 7.18.7: Tuner Task Timing Output

Tuner Task Timing
TaskSecondsPercent
Model Training338.7097.15
Model Scoring0.000.00
Total Objective Evaluations338.7197.15
Tuner9.932.85
Total CPU Time348.64100.00


Output 7.18.8 shows the "Output CAS Tables" output table, which displays a list of CAS tables that were created during the tuning process.

Output 7.18.8: Output CAS Tables

Output CAS Tables
CAS LibraryNameNumber
of Rows
Number
of Columns
YOUR_CAS_LIBtsne_out1504


Output 7.18.9 shows the "Hyperparameter Importance" output table, which displays the relative importance of each hyperparameter during the tuning process, normalized by the effect of the most influential hyperparameter (importance set to 1) and listed in order of decreasing effect.

Output 7.18.9: Hyperparameter Importance Output

Hyperparameter Importance
HyperparameterRelative
Importance
perplexity1.0000
maxIters0.9942
learningRate0.6953


The first PROC SGPLOT step creates a scatter plot of the objective value (Kullback-Leibler loss in this case) evaluation history by iteration, which is shown in Output 7.18.10. The second PROC SGPLOT step creates a line plot of the best objective value by iteration and a line plot of the total tuning time by iteration, which are shown in Output 7.18.11.

Output 7.18.10: Tuner Evaluation History Plot

Tuner Evaluation History Plot


Output 7.18.11: Tuner Iteration History Plot

Tuner Iteration History Plot


Tuning the Hyperparameters of t-Distributed Stochastic Neighbor Embedding

This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the iris data to the comma-separated-value (CSV) file iris.csv and then use the following code to load the CSV file into CAS:

s:loadtable{casLib="casuser", path="iris.csv"}

For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.

The following Lua code uses the tuneTsne action to automatically tune the hyperparameters of a two-dimensional embedding of the iris data table. The data and the parameters are the same as in the PROC CAS version of this example. Note that the syntax of the trainOptions parameter here is the same as the syntax of the tSne action. For more information about the tSne action, see Chapter 40, t-Distributed Stochastic Neighbor Embedding Action Set.

result = s:autotune_tuneTsne {
   trainOptions     = {
      table         = {name='iris'},
      inputs        = {"SepalLength", "SepalWidth", "PetalLength", "PetalWidth"},
      nDimensions   = 2,
      perplexity    = 5,
      learningRate  = 100,
      maxIters      = 500,
      output        = {casOut={name="tsne_out", replace="TRUE"},
                       copyvars={"id", "species"}}
   },
   tunerOptions     = {
      searchMethod  = "GA",
      popSize       = 10,
      logLevel      = 3,
      seed          = 12345
   }
   --[[ Tuning Parameters

     You do not need to specify any tuning parameters for the default
     tuning process. If you want to make adjustments to the default
     tuning process, uncomment the following block of code and change
     any of the tuning parameters' attributes.

   , tuningParameters = {
      {name="perplexity",   initValue=30,   lb=5,   ub=50,    exclude=false},
      {name="learningRate", initValue=1000, lb=10,  ub=2000,  exclude=false},
      {name="maxIters",     initValue=300,  lb=250, ub=5000,  exclude=false}
  }
  --]]

}

The following commands display the tables that are produced by this action call:

print(result.TunerInfo)
print(result.TunerResults)
print(result.IterationHistory)
print(result.EvaluationHistory)
print(result.BestConfiguration)
print(result.TunerSummary)
print(result.TunerTiming)
print(result.TunerCasOutputTables)
print(result.HyperparameterImportance)

For details about the results of this analysis, see the PROC CAS version of this example.

Tuning the Hyperparameters of t-Distributed Stochastic Neighbor Embedding

This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the iris data to the comma-separated-value (CSV) file iris.csv and then use the following code to load the CSV file into CAS:

s.upload_file('iris.csv')

For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.

The following Python code uses the tuneTsne action to automatically tune the hyperparameters of a two-dimensional embedding of the iris data table. The data and the parameters are the same as in the PROC CAS version of this example. Note that the syntax of the trainOptions parameter here is the same as the syntax of the tSne action. For more information about the tSne action, see Chapter 40, t-Distributed Stochastic Neighbor Embedding Action Set.

result = s.autotune.tuneTsne (
   trainOptions      = {
      "table"        : {"name":"iris"},
      "inputs"       : {"SepalLength", "SepalWidth", "PetalLength", "PetalWidth"},
      "nDimensions"  : 2,
      "perplexity"   : 5,
      "learningRate" : 100,
      "maxIters"     : 500,
      "output"       : {"casOut":{"name":"tsne_out", "replace":"TRUE"},
                        "copyvars":{"id", "species"}}
   },
   tunerOptions      = {
      "searchMethod" : "GA",
      "popSize"      : 10,
      "logLevel"     : 3,
      "seed"         : 12345
   }
   # Tuning Parameters
   #
   # You do not need to specify any tuning parameters for the default
   # tuning process. If you want to make adjustments to the default
   # tuning process, uncomment the following block of code and change
   # any of the tuning parameters' attributes.
   #
   # , tuningParameters = [
   #    {"name":"perplexity",
   #       "initValue":30,   "lb":5,   "ub":50,    "exclude":"false"},
   #    {"name":"learningRate",
   #       "initValue":1000, "lb":10,  "ub":2000,  "exclude":"false"},
   #    {"name":"maxIters",
   #       "initValue":300,  "lb":250, "ub":5000,  "exclude":"false"}
   # ]

)

The following commands display the tables that are produced by this action call:

print(result.TunerInfo)
print(result.TunerResults)
print(result.IterationHistory)
print(result.EvaluationHistory)
print(result.BestConfiguration)
print(result.TunerSummary)
print(result.TunerTiming)
print(result.TunerCasOutputTables)
print(result.HyperparameterImportance)

For details about the results of this analysis, see the PROC CAS version of this example.

Tuning the Hyperparameters of t-Distributed Stochastic Neighbor Embedding

This example is not available for the R programming language.

Last updated: August 04, 2026