48 from daal
import step1Local, step2Master
49 from daal.algorithms
import low_order_moments
50 from daal.data_management
import FileDataSource, DataSourceIface
52 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
53 if utils_folder
not in sys.path:
54 sys.path.insert(0, utils_folder)
55 from utils
import printNumericTable
57 DAAL_PREFIX = os.path.join(
'..',
'data')
63 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_1.csv'),
64 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_2.csv'),
65 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_3.csv'),
66 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_4.csv')
69 partialResult = [0] * nBlocks
73 def computestep1Local(block):
77 dataSource = FileDataSource(
78 datasetFileNames[block], DataSourceIface.doAllocateNumericTable,
79 DataSourceIface.doDictionaryFromContext
83 dataSource.loadDataBlock()
86 algorithm = low_order_moments.Distributed(step1Local)
89 algorithm.input.set(low_order_moments.data, dataSource.getNumericTable())
92 partialResult[block] = algorithm.compute()
95 def computeOnMasterNode():
99 algorithm = low_order_moments.Distributed(step2Master)
102 for i
in range(nBlocks):
103 algorithm.input.add(low_order_moments.partialResults, partialResult[i])
109 result = algorithm.finalizeCompute()
112 def printResults(res):
114 printNumericTable(res.get(low_order_moments.minimum),
"Minimum:")
115 printNumericTable(res.get(low_order_moments.maximum),
"Maximum:")
116 printNumericTable(res.get(low_order_moments.sum),
"Sum:")
117 printNumericTable(res.get(low_order_moments.sumSquares),
"Sum of squares:")
118 printNumericTable(res.get(low_order_moments.sumSquaresCentered),
"Sum of squared difference from the means:")
119 printNumericTable(res.get(low_order_moments.mean),
"Mean:")
120 printNumericTable(res.get(low_order_moments.secondOrderRawMoment),
"Second order raw moment:")
121 printNumericTable(res.get(low_order_moments.variance),
"Variance:")
122 printNumericTable(res.get(low_order_moments.standardDeviation),
"Standard deviation:")
123 printNumericTable(res.get(low_order_moments.variation),
"Variation:")
125 if __name__ ==
"__main__":
127 for i
in range(nBlocks):
130 computeOnMasterNode()