Database Reference
In-Depth Information
t1.setRandomIntegerEntries( 0, 1 ); // fill tensor with ran-
dom entries
SparseTensor sp1 ¼ new SparseTensor( t1 );
// Perform HOSVD, truncate for specified ranks:
TruncatedHosvdAlgorithm truncSVD
¼
new TruncatedHosv-
dAlgorithm();
int[] ranks ¼ {2,3,3};
HigherOrderSVD hosvd ¼ truncSVD.buildModel( sp1, ranks );
// Get core tensor:
Tensor core ¼ hosvd.getCore();
core.print(2, 2);
// Get mode factors:
for ( int i ¼ 1; i < t1.getOrder() + 1; i++ )
{
Matrix U ¼ hosvd.getMatrices()[i - 1];
U.print(2, 2);
} For the same example, we demonstrate the incremental HOSVD. Suppose we
add one slice to the existing tensor and update the model, then we need to add the
following code to the previous one:
// Add slice on mode 3:
SparseMatrixHash slNew
¼
new SparseMatrixHash( sp1.
getDimensions()[0],
sp1.getDimensions()[1] );
setRandomIntegerEntries( slNew, 0, 1, 0.2 ); // fill matrix
with random entries
int nMode ¼ 3;
// Update HOVSM:
hosvd.update( sp1, slNew, nMode );
// Add slice to sparse tensor:
sp1.addSlice( slNew, nMode );
// Compare results (updated HOSVD and sparse tensor in
Frobenius norm):
Tensor spEnd ¼ hosvd.getCore()
.nModeMult( hosvd.getMatrices()[0], 1 )
.nModeMult( hosvd.getMatrices()[1], 2 )
.nModeMult( hosvd.getMatrices()[2], 3 );
double normF ¼ spEnd.minus( sp1 ).getFNorm();
System.out.printf("F-Norm of the difference: " + normF); ■
Search WWH ::




Custom Search