23 from daal.algorithms
import pca
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')
38 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_1.csv'),
39 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_2.csv'),
40 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_3.csv'),
41 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_4.csv')
44 if __name__ ==
"__main__":
47 masterAlgorithm = pca.Distributed(step=daal.step2Master, method=pca.svdDense)
49 for i
in range(nBlocks):
51 dataSource = FileDataSource(
52 dataFileNames[i], DataSourceIface.doAllocateNumericTable,
53 DataSourceIface.doDictionaryFromContext
57 dataSource.loadDataBlock(nVectorsInBlock)
60 localAlgorithm = pca.Distributed(step=daal.step1Local, method=pca.svdDense)
63 localAlgorithm.input.setDataset(pca.data, dataSource.getNumericTable())
67 masterAlgorithm.input.add(pca.partialResults, localAlgorithm.compute())
70 masterAlgorithm.compute()
71 result = masterAlgorithm.finalizeCompute()
74 printNumericTable(result.get(pca.eigenvalues),
"Eigenvalues:")
75 printNumericTable(result.get(pca.eigenvectors),
"Eigenvectors:")