47 from daal
import step1Local, step2Master
48 from daal.algorithms
import low_order_moments
49 from daal.data_management
import FileDataSource, DataSourceIface
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
56 DAAL_PREFIX = os.path.join(
'..',
'data')
62 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_1.csv'),
63 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_2.csv'),
64 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_3.csv'),
65 os.path.join(DAAL_PREFIX,
'distributed',
'covcormoments_dense_4.csv')
68 partialResult = [0] * nBlocks
72 def computestep1Local(block):
76 dataSource = FileDataSource(
77 datasetFileNames[block], DataSourceIface.doAllocateNumericTable,
78 DataSourceIface.doDictionaryFromContext
82 dataSource.loadDataBlock()
85 algorithm = low_order_moments.Distributed(step1Local)
88 algorithm.input.set(low_order_moments.data, dataSource.getNumericTable())
91 partialResult[block] = algorithm.compute()
94 def computeOnMasterNode():
98 algorithm = low_order_moments.Distributed(step2Master)
101 for i
in range(nBlocks):
102 algorithm.input.add(low_order_moments.partialResults, partialResult[i])
108 result = algorithm.finalizeCompute()
111 def printResults(res):
113 printNumericTable(res.get(low_order_moments.minimum),
"Minimum:")
114 printNumericTable(res.get(low_order_moments.maximum),
"Maximum:")
115 printNumericTable(res.get(low_order_moments.sum),
"Sum:")
116 printNumericTable(res.get(low_order_moments.sumSquares),
"Sum of squares:")
117 printNumericTable(res.get(low_order_moments.sumSquaresCentered),
"Sum of squared difference from the means:")
118 printNumericTable(res.get(low_order_moments.mean),
"Mean:")
119 printNumericTable(res.get(low_order_moments.secondOrderRawMoment),
"Second order raw moment:")
120 printNumericTable(res.get(low_order_moments.variance),
"Variance:")
121 printNumericTable(res.get(low_order_moments.standardDeviation),
"Standard deviation:")
122 printNumericTable(res.get(low_order_moments.variation),
"Variation:")
124 if __name__ ==
"__main__":
126 for i
in range(nBlocks):
129 computeOnMasterNode()