47 from daal
import step1Local, step2Master
48 from daal.algorithms
import low_order_moments
50 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
51 if utils_folder
not in sys.path:
52 sys.path.insert(0, utils_folder)
53 from utils
import printNumericTable, createSparseTable
55 DAAL_PREFIX = os.path.join(
'..',
'data')
61 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_csr_1.csv'),
62 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_csr_2.csv'),
63 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_csr_3.csv'),
64 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_csr_4.csv')
67 partialResult = [0] * nBlocks
71 def computestep1Local(block):
73 dataTable = createSparseTable(datasetFileNames[block])
76 algorithm = low_order_moments.Distributed(step1Local, method=low_order_moments.fastCSR)
79 algorithm.input.set(low_order_moments.data, dataTable)
82 partialResult[block] = algorithm.compute()
85 def computeOnMasterNode():
89 algorithm = low_order_moments.Distributed(step2Master, method=low_order_moments.fastCSR)
92 for i
in range(nBlocks):
93 algorithm.input.add(low_order_moments.partialResults, partialResult[i])
99 result = algorithm.finalizeCompute()
102 def printResults(res):
104 printNumericTable(res.get(low_order_moments.minimum),
"Minimum:")
105 printNumericTable(res.get(low_order_moments.maximum),
"Maximum:")
106 printNumericTable(res.get(low_order_moments.sum),
"Sum:")
107 printNumericTable(res.get(low_order_moments.sumSquares),
"Sum of squares:")
108 printNumericTable(res.get(low_order_moments.sumSquaresCentered),
"Sum of squared difference from the means:")
109 printNumericTable(res.get(low_order_moments.mean),
"Mean:")
110 printNumericTable(res.get(low_order_moments.secondOrderRawMoment),
"Second order raw moment:")
111 printNumericTable(res.get(low_order_moments.variance),
"Variance:")
112 printNumericTable(res.get(low_order_moments.standardDeviation),
"Standard deviation:")
113 printNumericTable(res.get(low_order_moments.variation),
"Variation:")
115 if __name__ ==
"__main__":
116 for block
in range(nBlocks):
117 computestep1Local(block)
119 computeOnMasterNode()