48 from daal.algorithms
import pca
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')
63 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_1.csv'),
64 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_2.csv'),
65 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_3.csv'),
66 os.path.join(DAAL_PREFIX,
'distributed',
'pca_normalized_4.csv')
69 if __name__ ==
"__main__":
72 masterAlgorithm = pca.Distributed(step=daal.step2Master, method=pca.svdDense)
74 for i
in range(nBlocks):
76 dataSource = FileDataSource(
77 dataFileNames[i], DataSourceIface.doAllocateNumericTable,
78 DataSourceIface.doDictionaryFromContext
82 dataSource.loadDataBlock(nVectorsInBlock)
85 localAlgorithm = pca.Distributed(step=daal.step1Local, method=pca.svdDense)
88 localAlgorithm.input.setDataset(pca.data, dataSource.getNumericTable())
92 masterAlgorithm.input.add(pca.partialResults, localAlgorithm.compute())
95 masterAlgorithm.compute()
96 result = masterAlgorithm.finalizeCompute()
99 printNumericTable(result.get(pca.eigenvalues),
"Eigenvalues:")
100 printNumericTable(result.get(pca.eigenvectors),
"Eigenvectors:")