本文整理汇总了C++中MDArray::get方法的典型用法代码示例。如果您正苦于以下问题:C++ MDArray::get方法的具体用法?C++ MDArray::get怎么用?C++ MDArray::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDArray
的用法示例。
在下文中一共展示了MDArray::get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: randomRead
/// random read from nxn array. all indices are read once
void randomRead()
{
i64 k[n*n];
for (int i = 0; i < n*n; i++)
{
k[i] = i;
}
MDArray *array = new MDArray(fileName);
PagedStorageContainer::resetPerfCounts();
permute(k, n*n);
gettimeofday(&tim, NULL);
t1 = tim.tv_sec + tim.tv_usec/1000000.0;
for (int i = 0; i < n*n; i++)
{
coord = MDCoord(2, k[i]/n, k[i]%n);
array->get(coord, datum);
}
delete array;
gettimeofday(&tim, NULL);
t2 = tim.tv_sec + tim.tv_usec/1000000.0;
readCount += PagedStorageContainer::readCount;
writeCount += PagedStorageContainer::writeCount;
accessTime += PagedStorageContainer::accessTime;
execTime += (t2 - t1);
fprintf(pFile, "%-14s %8i %8i %11.3f %11.3f\n", "rand read", PagedStorageContainer::readCount, PagedStorageContainer::writeCount, PagedStorageContainer::accessTime, t2-t1);
}
示例2: dim
TEST(MDArray, Read)
{
i64 rows = 20L;
i64 cols = 20L;
MDCoord dim(2, rows, cols);
StorageType type = DMA;
i64 blockDims[] = {10L, 10L};
u8 blockOrders[] = {0, 1};
u8 microOrders[] = {0, 1};
//permute(blockOrders, dim.nDim);
//permute(microOrders, dim.nDim);
Linearization *block = new BlockBased(dim.nDim, dim.coords, blockDims,
blockOrders, microOrders);
const char *fileName = "test1.bin";
MDCoord key;
Datum_t datum = 1.0;
MDArray *array = new MDArray(dim, type, block, fileName);
MDIterator *it = array->createIterator(Dense, block);
srand(time(NULL));
const int num=100;
std::map<int, MDCoord> keys;
std::map<int, Datum_t> data;
int total = rows*cols;
for(int i=0; i<num; i++) {
int k = rand() % total;
if (data.find(k) == data.end()) {
data[k] = rand();
it->setIndexRange(k, k+1);
it->moveNext();
it->put(data[k]);
MDCoord key;
it->get(key, datum);
keys[k] = key;
}
else
i--;
}
delete it;
delete array;
array = new MDArray(fileName);
Datum_t datum1;
for (std::map<int,MDCoord>::iterator s = keys.begin();
s != keys.end();
++s) {
//cout<<"checking "<<s->second.toString()<<endl;
array->get(s->second, datum1);
ASSERT_DOUBLE_EQ(data[s->first], datum1);
}
delete array;
delete block;
}
示例3: checkRect
void checkRect(const MDArray<2> &array, const MDCoord<2> &begin, const MDCoord<2> &end, const Datum_t *data)
{
int k = 0;
Datum_t datum;
for (i64 j=begin[1]; j<=end[1]; ++j)
for (i64 i=begin[0]; i<=end[0]; ++i) {
array.get(MDCoord<2>(i,j), datum);
ASSERT_EQ(data[k++], datum);
}
}
示例4: printMDArray
void printMDArray(const MDArray<nDim> &array)
{
MDCoord<nDim> dim = array.getDims();
Datum_t datum;
for (int i=0; i<dim[0]; i++) {
for (int j=0; j<dim[1]; j++) {
MDCoord<2> c(i,j);
array.get(c, datum);
cout<<datum<<"\t";
}
cout<<endl;
}
}
示例5: backtrack_pass
void ForwardBacktracker::backtrack_pass(uint start, uint end, uint seq_len, MDArray<eMISMASK> & mismask, RandomGen* rg) {
uint choice = 0;
MDArray<double> transition_matrix(vec(hidden_node_size));
// The backtrack loop
for(int l=end-1; l >= ((int) start); l--) {
uint i = l - start;
DiscreteNode *node;
// Setup the node, cpd and nodes
if(i==0) {
node = hd_0;
}
else {
node = hd_1;
}
// Choose whether to sample from the forward probability
// distribution or take the previous choice into account
if ( ((uint) l)==end-1 ) {
transition_matrix = forward.get_view(i);
}
else {
// TODO: Make this sum faster
for (uint j=0; j<hidden_node_size; j++)
transition_matrix[j] = forward.get(i,j) * transition_matrices[i+1]->get(j, choice);
transition_matrix.normalize();
}
// Sample the hidden node from the forward probability distribution
transition_matrix.cumsum();
assert(rg);
double r = rg->get_rand();
choice = transition_matrix.bisect(r);
node->parentmap.set(l, choice);
// Sample the children
for(vector<Node*>::iterator child=node->children_1.begin(); child < node->children_1.end(); child++) {
if (mismask.get(l, (*child)->node_index) != MOCAPY_OBSERVED) {
(*child)->sample(l);
}
}
}
}
示例6: generate_wk
void Shrinkage::generate_wk(MDArray<double> mat,int SDM_type)
{
int n=mat.get_shape()[0];
int p=mat.get_shape()[1];
vector<uint> index;
double sum,term1,term2;
MDArray<double> sub_means(get_sub_means(mat));
for(int i=0;i<p;i++)
for(int j=0;j<p;j++){
sum=0;
for(int k=0;k<n;k++){
term1=mat.get(k,i)-sub_means[i];
term2=mat.get(k,j)-sub_means[j];
index=vec((uint)k, (uint)i, (uint)j);
if(SDM_type)
wk_StDM[index]=term1*term2;
else
wk[index]=term1*term2;
}
}
}
示例7: forward_pass
void ForwardBacktracker::forward_pass(uint start, uint end, uint seq_len, MDArray<eMISMASK> & mismask, bool multiply_by_parents) {
// Set variables used in the forward algorithm
uint slice_count = end - start;
// Setup the forward array and the scales
scales.clear();
scales.reserve(slice_count);
forward.set_shape(vec(slice_count, hidden_node_size));
transition_matrices.clear();
transition_matrices.reserve(slice_count);
// Fill out the forward array
for(uint i=0, l=start; i < slice_count; i++, l++) {
DiscreteNode *node;
MDArray<double> *cpd;
vector<Node*> *nodes;
// For the first slice in the network
if(l==0 || i==0) {
// Get the appropriate hidden node
if(l==0) {
node = hd_0;
cpd = cpd_0;
}
else {
node = hd_1;
cpd = cpd_1;
}
// Get the values of the parents of the hidden node
// (and remove the value of the hidden node)
vector<double> dpv;
vector<uint> ipv;
node->parentmap.get(l, dpv);
dpv.pop_back();
toint(dpv, ipv);
// Get the transition probability and store it in the forward array
MDArray<double> *cpd_sliced = &cpd->get_view(ipv);
forward.set(i, *cpd_sliced);
// Store the transition matrix from a posible backtrack
transition_matrices.push_back(cpd_sliced);
}
// For the remaining slices
else {
// Get the appropriate hidden node
node = hd_1;
// Get the values of the parents of the hidden node
// (and remove the value of the hidden node)
vector<double> dpv;
vector<uint> ipv;
node->parentmap.get(l, dpv);
dpv.pop_back();
dpv.erase(dpv.begin());
toint(dpv, ipv);
MDArray<double> *cpd_sliced = &cpd_1_swaped.get_view(ipv);
// Store the transition matrix from a posible backtrack
transition_matrices.push_back(cpd_sliced);
// Multiply transitions probabilities P(HD_l = g | HD_{l-1} = h ) by the
// forward values forward[i-1, g] and sum over node values of g
// TODO: This can probably be done faster
for(uint j=0; j < hidden_node_size; j++ ) {
// Sum over the previous hidden value
double sum = 0;
for(uint k=0; k < hidden_node_size; k++ ) {
sum += forward.get(i-1, k) * cpd_sliced->get(k, j);
}
forward.set(i, j, sum);
}
}
// Multiply the forward value by the probability of the parents
if(multiply_by_parents) {
if(l==0)
nodes = &nodes_0;
else
nodes = &nodes_1;
for(vector<uint>::iterator parent=node->parents_1.begin(); parent < node->parents_1.end(); parent++) {
double parent_likelihood = exp( (*nodes)[(*parent)]->get_slice_log_likelihood(l) );
forward.get_view(i).multiply_inplace(parent_likelihood);
}
}
// Multiply the forward values by the probability of the observed children
// Note that the value of the hidden node is preserved in prev_node_value
for(vector<Node*>::iterator child=node->children_1.begin(); child < node->children_1.end(); child++) {
if (mismask.get(l, (*child)->node_index) == MOCAPY_OBSERVED) {
// Get the original value of the hidden node
vector<double> dpv;
//.........这里部分代码省略.........