22 from daal
import step1Local, step2Master
23 from daal.algorithms
import low_order_moments
24 from daal.data_management
import FileDataSource, DataSourceIface
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
31 DAAL_PREFIX = os.path.join(
'..',
'data')
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')
43 partialResult = [0] * nBlocks
47 def computestep1Local(block):
51 dataSource = FileDataSource(
52 datasetFileNames[block], DataSourceIface.doAllocateNumericTable,
53 DataSourceIface.doDictionaryFromContext
57 dataSource.loadDataBlock()
60 algorithm = low_order_moments.Distributed(step1Local)
63 algorithm.input.set(low_order_moments.data, dataSource.getNumericTable())
66 partialResult[block] = algorithm.compute()
69 def computeOnMasterNode():
73 algorithm = low_order_moments.Distributed(step2Master)
76 for i
in range(nBlocks):
77 algorithm.input.add(low_order_moments.partialResults, partialResult[i])
83 result = algorithm.finalizeCompute()
86 def printResults(res):
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:")
99 if __name__ ==
"__main__":
101 for i
in range(nBlocks):
104 computeOnMasterNode()