本文整理汇总了C++中vec::fill方法的典型用法代码示例。如果您正苦于以下问题:C++ vec::fill方法的具体用法?C++ vec::fill怎么用?C++ vec::fill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec
的用法示例。
在下文中一共展示了vec::fill方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialize
void initialize(mat meansInput, bool useKmeansIni, bool _fixW,
double sigma2_ini) {
Sigma.fill(sigma2_ini);
if (useKmeansIni) {
mat means;
bool status = kmeans(means, trans(y), K, static_spread, 10, false);
mu = means.t();
// initialize sigma2 via K-means
Expectation();
updateSigma();
} else {
mu = meansInput;
}
fixW = _fixW;
}
示例2: init
static void init(vec mean[2], mat sgma[2], vec& alpha)
{
for (int i = 0; i < 2; i++) {
mean[i].set_size(2);
sgma[i].set_size(2,2);
}
alpha.set_size(2);
// Following intializations are based on average over largne number of runs.
// Average parameters for clonal population:
mean[0] << 0.48811 << 1.61692;
sgma[0] << 0.004836 << 0.032828 << endr
<< 0.032828 << 0.548305 << endr;
// Average parameters for mixed population:
mean[1] << 0.693371 << 4.397405;
sgma[1] = sgma[0];
// Start by assuming that clonal and mixed populations are equinumerous:
alpha.fill(0.5);
}
示例3: fit
virtual void fit(const record_array & train_data, unsigned int n_iter = 1, bool continue_fit=false) {
try {
unsigned int batch_size = 1000;
unsigned int block_size = train_data.size / batch_size / 16;
double shrink = 1 - lambda;
unsigned int n_user = 0, n_movie = 0;
unsigned int *shuffle_idx;
unsigned int *shuffle_idx_batch;
timer tmr;
tmr.display_mode = 1;
learning_rate_per_record = learning_rate;
// Generate shuffle_idx
cout << train_data.size << endl;
shuffle_idx = new unsigned int[train_data.size / batch_size];
for (int i = 0; i < train_data.size / batch_size; i++) {
shuffle_idx[i] = i;
}
//shuffle_idx_batch = new unsigned int[batch_size];
//for (int i = 0; i < batch_size; i++) {
// shuffle_idx_batch[i] = i;
//}
if (!continue_fit) {
// Calculate n_user and n_movies
for (int i = 0; i < train_data.size; i++) {
if (train_data[i].user > n_user) {
n_user = train_data[i].user;
}
if (train_data[i].movie > n_movie) {
n_movie = train_data[i].movie;
}
}
// Calculate mu
unsigned int cnt[6];
long long s;
for (int i = 0; i < 6; i++) {
cnt[i] = 0;
}
for (int i = 0; i < train_data.size; i++) {
cnt[int(train_data[i].score)]++;
}
s = 0;
for (int i = 0; i < 6; i++) {
s += cnt[i] * i;
}
mu = 1.0 * s / train_data.size;
// Reshape the matrix based on n_user and n_movie
U.set_size(K, n_user);
V.set_size(K, n_movie);
A.set_size(n_user);
B.set_size(n_movie);
U.fill(fill::randu);
V.fill(fill::randu);
A.fill(fill::randu);
B.fill(fill::randu);
}
for (int i_iter = 0; i_iter < n_iter; i_iter++) {
tmr.tic();
cout << "Iter\t" << i_iter << '\t';
// Reshuffle first
reshuffle(shuffle_idx, train_data.size / batch_size);
#pragma omp parallel for num_threads(8)
for (int i = 0; i < train_data.size / batch_size; i++) {
unsigned int index_base = shuffle_idx[i] * batch_size;
//reshuffle(shuffle_idx_batch, batch_size);
for (int j = 0; j < batch_size; j++) {
unsigned int index = index_base + j;
// shuffle_idx_batch[j] do harm to the result
if (index < train_data.size) {
const record& rcd = train_data[index];
update(rcd);
}
}
if (i % block_size == 0) {
cout << '.';
}
}
if (ptr_test_data != NULL) {
vector<float> result = this->predict_list(*ptr_test_data);
//.........这里部分代码省略.........