52 #ifndef __VMML__T3_IHOPM__HPP__
53 #define __VMML__T3_IHOPM__HPP__
55 #include <vmmlib/t3_hopm.hpp>
59 template<
size_t R,
size_t NBLOCKS,
size_t I1,
size_t I2,
size_t I3,
typename T_val =
float,
typename T_coeff =
double >
126 #define VMML_TEMPLATE_STRING template< size_t R, size_t NBLOCKS, size_t I1, size_t I2, size_t I3, typename T_val, typename T_coeff >
127 #define VMML_TEMPLATE_CLASSNAME t3_ihopm< R, NBLOCKS, I1, I2, I3, T_val, T_coeff >
132 VMML_TEMPLATE_CLASSNAME::incremental_als(
const t3_type& data_, u1_type& u1_, u2_type& u2_, u3_type& u3_, lambda_type& lambdas_,
const size_t max_iterations_,
const float tolerance_) {
135 if (R % NBLOCKS != 0) {
136 std::ostringstream convert1, convert2;
139 VMMLIB_ERROR(
"In incremental CP, R = " + convert1.str() +
", NBLOCKS = " + convert2.str() +
" (must be divisible)", VMMLIB_HERE);
141 t3_coeff_type* approx_data =
new t3_coeff_type;
143 t3_coeff_type* residual_data =
new t3_coeff_type;
144 residual_data->cast_from(data_);
146 lambda_tmp_type* lambdas_tmp =
new lambda_tmp_type;
148 u1_tmp_type* u1_tmp =
new u1_tmp_type;
149 u2_tmp_type* u2_tmp =
new u2_tmp_type;
150 u3_tmp_type* u3_tmp =
new u3_tmp_type;
152 lambda_incr_type* lambdas_incr =
new lambda_incr_type;
153 lambdas_incr->set(0);
154 u1_incr_type* u1_incr =
new u1_incr_type;
156 u2_incr_type* u2_incr =
new u2_incr_type;
158 u3_incr_type* u3_incr =
new u3_incr_type;
161 u1_1col_type* u1_1col =
new u1_1col_type;
162 u2_1col_type* u2_1col =
new u2_1col_type;
163 u3_1col_type* u3_1col =
new u3_1col_type;
165 typedef t3_hopm < R / NBLOCKS, I1, I2, I3, T_coeff > hopm_type;
167 for (
size_t i = 0; i < NBLOCKS; ++i) {
169 std::cout <<
"Incremental CP: block number '" << i <<
"'" << std::endl;
178 result += hopm_type::als(*residual_data, *u1_tmp, *u2_tmp, *u3_tmp, *lambdas_tmp,
typename hopm_type::init_hosvd(), max_iterations_, tolerance_);
182 T_coeff lambda_r = 0;
183 for (
size_t r = 0; r < R / NBLOCKS; ++r) {
184 r_incr = i * R / NBLOCKS + r;
185 u1_tmp->get_column(r, *u1_1col);
186 u1_incr->set_column(r_incr, *u1_1col);
187 u2_tmp->get_column(r, *u2_1col);
188 u2_incr->set_column(r_incr, *u2_1col);
189 u3_tmp->get_column(r, *u3_1col);
190 u3_incr->set_column(r_incr, *u3_1col);
192 lambda_r = lambdas_tmp->at(r);
193 lambdas_incr->at(r_incr) = lambda_r;
198 t3_hopm < R / NBLOCKS, I1, I2, I3, T_coeff >::reconstruct(*approx_data, *u1_tmp, *u2_tmp, *u3_tmp, *lambdas_tmp);
200 *residual_data = *residual_data - *approx_data;
203 u1_.cast_from(*u1_incr);
204 u2_.cast_from(*u2_incr);
205 u3_.cast_from(*u3_incr);
206 lambdas_.cast_from(*lambdas_incr);
219 delete residual_data;
227 VMML_TEMPLATE_CLASSNAME::reconstruct(t3_type& data_,
const u1_type& u1_,
const u2_type& u2_,
const u3_type& u3_,
const lambda_type& lambdas_) {
228 u1_inv_type* u1_t =
new u1_inv_type;
229 u2_inv_type* u2_t =
new u2_inv_type;
230 u3_inv_type* u3_t =
new u3_inv_type;
231 typedef matrix< R*NBLOCKS, I2 * I3, T_val > m_temp_type;
232 m_temp_type* temp =
new m_temp_type;
234 u1_.transpose_to(*u1_t);
235 u2_.transpose_to(*u2_t);
236 u3_.transpose_to(*u3_t);
238 data_.reconstruct_CP(lambdas_, *u1_t, *u2_t, *u3_t, *temp);
246 #undef VMML_TEMPLATE_STRING
247 #undef VMML_TEMPLATE_CLASSNAME