Python* API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

low_order_moms_csr_distr.py

1 # file: low_order_moms_csr_distr.py
2 #===============================================================================
3 # Copyright 2014-2020 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #===============================================================================
17 
18 
19 
20 
21 import os
22 import sys
23 
24 from daal import step1Local, step2Master
25 from daal.algorithms import low_order_moments
26 
27 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
28 if utils_folder not in sys.path:
29  sys.path.insert(0, utils_folder)
30 from utils import printNumericTable, createSparseTable
31 
32 DAAL_PREFIX = os.path.join('..', 'data')
33 
34 # Input data set parameters
35 nBlocks = 4
36 
37 datasetFileNames = [
38  os.path.join(DAAL_PREFIX, 'distributed', 'covcormoments_csr_1.csv'),
39  os.path.join(DAAL_PREFIX, 'distributed', 'covcormoments_csr_2.csv'),
40  os.path.join(DAAL_PREFIX, 'distributed', 'covcormoments_csr_3.csv'),
41  os.path.join(DAAL_PREFIX, 'distributed', 'covcormoments_csr_4.csv')
42 ]
43 
44 partialResult = [0] * nBlocks
45 result = None
46 
47 
48 def computestep1Local(block):
49 
50  dataTable = createSparseTable(datasetFileNames[block])
51 
52  # Create algorithm objects to compute low order moments in the distributed processing mode using the default method
53  algorithm = low_order_moments.Distributed(step1Local, method=low_order_moments.fastCSR)
54 
55  # Set input objects for the algorithm
56  algorithm.input.set(low_order_moments.data, dataTable)
57 
58  # Compute partial low order moments estimates on nodes
59  partialResult[block] = algorithm.compute() # Get the computed partial estimates
60 
61 
62 def computeOnMasterNode():
63  global result
64 
65  # Create algorithm objects to compute low order moments in the distributed processing mode using the default method
66  algorithm = low_order_moments.Distributed(step2Master, method=low_order_moments.fastCSR)
67 
68  # Set input objects for the algorithm
69  for i in range(nBlocks):
70  algorithm.input.add(low_order_moments.partialResults, partialResult[i])
71 
72  # Compute a partial low order moments estimate on the master node from the partial estimates on local nodes
73  algorithm.compute()
74 
75  # Finalize the result in the distributed processing mode and get the computed low order moments
76  result = algorithm.finalizeCompute()
77 
78 
79 def printResults(res):
80 
81  printNumericTable(res.get(low_order_moments.minimum), "Minimum:")
82  printNumericTable(res.get(low_order_moments.maximum), "Maximum:")
83  printNumericTable(res.get(low_order_moments.sum), "Sum:")
84  printNumericTable(res.get(low_order_moments.sumSquares), "Sum of squares:")
85  printNumericTable(res.get(low_order_moments.sumSquaresCentered), "Sum of squared difference from the means:")
86  printNumericTable(res.get(low_order_moments.mean), "Mean:")
87  printNumericTable(res.get(low_order_moments.secondOrderRawMoment), "Second order raw moment:")
88  printNumericTable(res.get(low_order_moments.variance), "Variance:")
89  printNumericTable(res.get(low_order_moments.standardDeviation), "Standard deviation:")
90  printNumericTable(res.get(low_order_moments.variation), "Variation:")
91 
92 if __name__ == "__main__":
93  for block in range(nBlocks):
94  computestep1Local(block)
95 
96  computeOnMasterNode()
97  printResults(result)

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