48 from daal
import step1Local, step2Master
49 from daal.algorithms
import low_order_moments
51 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
52 if utils_folder
not in sys.path:
53 sys.path.insert(0, utils_folder)
54 from utils
import printNumericTable, createSparseTable
56 DAAL_PREFIX = os.path.join(
'..',
'data')
62 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_csr_1.csv'),
63 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_csr_2.csv'),
64 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_csr_3.csv'),
65 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_csr_4.csv')
68 partialResult = [0] * nBlocks
72 def computestep1Local(block):
74 dataTable = createSparseTable(datasetFileNames[block])
77 algorithm = low_order_moments.Distributed(step1Local, method=low_order_moments.fastCSR)
80 algorithm.input.set(low_order_moments.data, dataTable)
83 partialResult[block] = algorithm.compute()
86 def computeOnMasterNode():
90 algorithm = low_order_moments.Distributed(step2Master, method=low_order_moments.fastCSR)
93 for i
in range(nBlocks):
94 algorithm.input.add(low_order_moments.partialResults, partialResult[i])
100 result = algorithm.finalizeCompute()
103 def printResults(res):
105 printNumericTable(res.get(low_order_moments.minimum),
"Minimum:")
106 printNumericTable(res.get(low_order_moments.maximum),
"Maximum:")
107 printNumericTable(res.get(low_order_moments.sum),
"Sum:")
108 printNumericTable(res.get(low_order_moments.sumSquares),
"Sum of squares:")
109 printNumericTable(res.get(low_order_moments.sumSquaresCentered),
"Sum of squared difference from the means:")
110 printNumericTable(res.get(low_order_moments.mean),
"Mean:")
111 printNumericTable(res.get(low_order_moments.secondOrderRawMoment),
"Second order raw moment:")
112 printNumericTable(res.get(low_order_moments.variance),
"Variance:")
113 printNumericTable(res.get(low_order_moments.standardDeviation),
"Standard deviation:")
114 printNumericTable(res.get(low_order_moments.variation),
"Variation:")
116 if __name__ ==
"__main__":
117 for block
in range(nBlocks):
118 computestep1Local(block)
120 computeOnMasterNode()