25 from daal.algorithms
import pca
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')
40 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_1.csv'),
41 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_2.csv'),
42 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_3.csv'),
43 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_4.csv')
46 if __name__ ==
"__main__":
49 masterAlgorithm = pca.Distributed(step=daal.step2Master, method=pca.svdDense)
51 for i
in range(nBlocks):
53 dataSource = FileDataSource(
54 dataFileNames[i], DataSourceIface.doAllocateNumericTable,
55 DataSourceIface.doDictionaryFromContext
59 dataSource.loadDataBlock(nVectorsInBlock)
62 localAlgorithm = pca.Distributed(step=daal.step1Local, method=pca.svdDense)
65 localAlgorithm.input.setDataset(pca.data, dataSource.getNumericTable())
69 masterAlgorithm.input.add(pca.partialResults, localAlgorithm.compute())
72 masterAlgorithm.compute()
73 result = masterAlgorithm.finalizeCompute()
76 printNumericTable(result.get(pca.eigenvalues),
"Eigenvalues:")
77 printNumericTable(result.get(pca.eigenvectors),
"Eigenvectors:")