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

low_order_moms_dense_distr.py

1 # file: low_order_moms_dense_distr.py
2 #===============================================================================
3 # Copyright 2014-2019 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 
18 
19 import os
20 import sys
21 
22 from daal import step1Local, step2Master
23 from daal.algorithms import low_order_moments
24 from daal.data_management import FileDataSource, DataSourceIface
25 
26 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
27 if utils_folder not in sys.path:
28  sys.path.insert(0, utils_folder)
29 from utils import printNumericTable
30 
31 DAAL_PREFIX = os.path.join('..', 'data')
32 
33 # Input data set parameters
34 nBlocks = 4
35 
36 datasetFileNames = [
37  os.path.join(DAAL_PREFIX, 'distributed', 'covcormoments_dense_1.csv'),
38  os.path.join(DAAL_PREFIX, 'distributed', 'covcormoments_dense_2.csv'),
39  os.path.join(DAAL_PREFIX, 'distributed', 'covcormoments_dense_3.csv'),
40  os.path.join(DAAL_PREFIX, 'distributed', 'covcormoments_dense_4.csv')
41 ]
42 
43 partialResult = [0] * nBlocks
44 result = None
45 
46 
47 def computestep1Local(block):
48  global partialResult
49 
50  # Initialize FileDataSource<CSVFeatureManager> to retrieve the input data from a .csv file
51  dataSource = FileDataSource(
52  datasetFileNames[block], DataSourceIface.doAllocateNumericTable,
53  DataSourceIface.doDictionaryFromContext
54  )
55 
56  # Retrieve the data from the input file
57  dataSource.loadDataBlock()
58 
59  # Create algorithm objects to compute low order moments in the distributed processing mode using the default method
60  algorithm = low_order_moments.Distributed(step1Local)
61 
62  # Set input objects for the algorithm
63  algorithm.input.set(low_order_moments.data, dataSource.getNumericTable())
64 
65  # Compute partial low order moments estimates on nodes
66  partialResult[block] = algorithm.compute() # Get the computed partial estimates
67 
68 
69 def computeOnMasterNode():
70  global result
71 
72  # Create algorithm objects to compute low order moments in the distributed processing mode using the default method
73  algorithm = low_order_moments.Distributed(step2Master)
74 
75  # Set input objects for the algorithm
76  for i in range(nBlocks):
77  algorithm.input.add(low_order_moments.partialResults, partialResult[i])
78 
79  # Compute a partial low order moments estimate on the master node from the partial estimates on local nodes
80  algorithm.compute()
81 
82  # Finalize the result in the distributed processing mode
83  result = algorithm.finalizeCompute() # Get the computed low order moments
84 
85 
86 def printResults(res):
87 
88  printNumericTable(res.get(low_order_moments.minimum), "Minimum:")
89  printNumericTable(res.get(low_order_moments.maximum), "Maximum:")
90  printNumericTable(res.get(low_order_moments.sum), "Sum:")
91  printNumericTable(res.get(low_order_moments.sumSquares), "Sum of squares:")
92  printNumericTable(res.get(low_order_moments.sumSquaresCentered), "Sum of squared difference from the means:")
93  printNumericTable(res.get(low_order_moments.mean), "Mean:")
94  printNumericTable(res.get(low_order_moments.secondOrderRawMoment), "Second order raw moment:")
95  printNumericTable(res.get(low_order_moments.variance), "Variance:")
96  printNumericTable(res.get(low_order_moments.standardDeviation), "Standard deviation:")
97  printNumericTable(res.get(low_order_moments.variation), "Variation:")
98 
99 if __name__ == "__main__":
100 
101  for i in range(nBlocks):
102  computestep1Local(i)
103 
104  computeOnMasterNode()
105  printResults(result)

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