Python* API Reference for Intel® Data Analytics Acceleration Library 2018 Update 3

kernel_func_lin_csr_batch.py

1 # file: kernel_func_lin_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 linear kernel function in the batch processing mode
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 k = 1.0 # Linear kernel coefficient in the k(X,Y) + b model
43 b = 0.0 # Linear kernel coefficient in the k(X,Y) + b model
44 
45 if __name__ == "__main__":
46 
47  # Read datasetFileName from a file and create a numeric tables to store input data
48  leftData = createSparseTable(leftDatasetFileName)
49  rightData = createSparseTable(rightDatasetFileName)
50 
51  # Create algorithm objects for the kernel algorithm using the default method
52  algorithm = kernel_function.linear.Batch(method=kernel_function.linear.fastCSR)
53 
54  # Set the kernel algorithm parameter
55  algorithm.parameter.k = k
56  algorithm.parameter.b = b
57  algorithm.parameter.computationMode = kernel_function.matrixMatrix
58 
59  # Set an input data table for the algorithm
60  algorithm.input.set(kernel_function.X, leftData)
61  algorithm.input.set(kernel_function.Y, rightData)
62 
63  # Compute the linear kernel function
64  # (Result class from daal.algorithms.kernel_function)
65  result = algorithm.compute()
66 
67  # Print the results
68  printNumericTable(result.get(kernel_function.values), "Values")

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