Python* API Reference for Intel® Data Analytics Acceleration Library 2019

kernel_func_rbf_csr_batch.py

1 # file: kernel_func_rbf_csr_batch.py
2 #===============================================================================
3 # Copyright 2014-2018 Intel Corporation.
4 #
5 # This software and the related documents are Intel copyrighted materials, and
6 # your use of them is governed by the express license under which they were
7 # provided to you (License). Unless the License provides otherwise, you may not
8 # use, modify, copy, publish, distribute, disclose or transmit this software or
9 # the related documents without Intel's prior written permission.
10 #
11 # This software and the related documents are provided as is, with no express
12 # or implied warranties, other than those that are expressly stated in the
13 # License.
14 #===============================================================================
15 
16 #
17 # ! Content:
18 # ! Python example of computing a radial basis function (RBF) kernel
19 # !
20 # !*****************************************************************************
21 
22 #
23 
24 
25 #
26 import os
27 import sys
28 
29 from daal.algorithms import kernel_function
30 
31 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
32 if utils_folder not in sys.path:
33  sys.path.insert(0, utils_folder)
34 from utils import printNumericTable, createSparseTable
35 
36 data_dir = os.path.join('..', 'data', 'batch')
37 # Input data set parameters
38 leftDatasetFileName = os.path.join(data_dir, 'kernel_function_csr.csv')
39 rightDatasetFileName = os.path.join(data_dir, 'kernel_function_csr.csv')
40 
41 # Kernel algorithm parameters
42 sigma = 1.0 # RBF kernel coefficient
43 
44 if __name__ == "__main__":
45 
46  # Initialize FileDataSource<CSVFeatureManager> to retrieve the input data from a .csv file
47  leftData = createSparseTable(leftDatasetFileName)
48  rightData = createSparseTable(rightDatasetFileName)
49 
50  # Create algorithm objects for the kernel algorithm using the default method
51  algorithm = kernel_function.rbf.Batch(method=kernel_function.rbf.fastCSR)
52 
53  # Set the kernel algorithm parameter
54  algorithm.parameter.sigma = sigma
55  algorithm.parameter.computationMode = kernel_function.matrixMatrix
56 
57  # Set an input data table for the algorithm
58  algorithm.input.set(kernel_function.X, leftData)
59  algorithm.input.set(kernel_function.Y, rightData)
60 
61  # Compute the RBF kernel
62  # (Result class from daal.algorithms.kernel_function)
63  result = algorithm.compute()
64 
65  # Print the results
66  printNumericTable(result.get(kernel_function.values), "Values")

For more complete information about compiler optimizations, see our Optimization Notice.