24 from daal
import step1Local, step2Master
25 from daal.algorithms
import low_order_moments
26 from daal.data_management
import FileDataSource, DataSourceIface
28 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
29 if utils_folder
not in sys.path:
30 sys.path.insert(0, utils_folder)
31 from utils
import printNumericTable
33 DAAL_PREFIX = os.path.join(
'..',
'data')
39 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_1.csv'),
40 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_2.csv'),
41 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_3.csv'),
42 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_4.csv')
45 partialResult = [0] * nBlocks
49 def computestep1Local(block):
53 dataSource = FileDataSource(
54 datasetFileNames[block], DataSourceIface.doAllocateNumericTable,
55 DataSourceIface.doDictionaryFromContext
59 dataSource.loadDataBlock()
62 algorithm = low_order_moments.Distributed(step1Local)
65 algorithm.input.set(low_order_moments.data, dataSource.getNumericTable())
68 partialResult[block] = algorithm.compute()
71 def computeOnMasterNode():
75 algorithm = low_order_moments.Distributed(step2Master)
78 for i
in range(nBlocks):
79 algorithm.input.add(low_order_moments.partialResults, partialResult[i])
85 result = algorithm.finalizeCompute()
88 def printResults(res):
90 printNumericTable(res.get(low_order_moments.minimum),
"Minimum:")
91 printNumericTable(res.get(low_order_moments.maximum),
"Maximum:")
92 printNumericTable(res.get(low_order_moments.sum),
"Sum:")
93 printNumericTable(res.get(low_order_moments.sumSquares),
"Sum of squares:")
94 printNumericTable(res.get(low_order_moments.sumSquaresCentered),
"Sum of squared difference from the means:")
95 printNumericTable(res.get(low_order_moments.mean),
"Mean:")
96 printNumericTable(res.get(low_order_moments.secondOrderRawMoment),
"Second order raw moment:")
97 printNumericTable(res.get(low_order_moments.variance),
"Variance:")
98 printNumericTable(res.get(low_order_moments.standardDeviation),
"Standard deviation:")
99 printNumericTable(res.get(low_order_moments.variation),
"Variation:")
101 if __name__ ==
"__main__":
103 for i
in range(nBlocks):
106 computeOnMasterNode()