本文整理汇总了C++中DataVector类的典型用法代码示例。如果您正苦于以下问题:C++ DataVector类的具体用法?C++ DataVector怎么用?C++ DataVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
g_conf.number_of_feature = 3;
g_conf.max_depth = 4;
if (argc > 1) {
g_conf.max_depth = boost::lexical_cast<int>(argv[1]);
}
DataVector d;
bool r = LoadDataFromFile("../../data/train.dat", &d);
assert(r);
RegressionTree tree;
tree.Fit(&d);
std::ofstream model_output("../../data/model");
model_output << tree.Save();
RegressionTree tree2;
tree2.Load(tree.Save());
DataVector::iterator iter = d.begin();
PredictVector predict;
for ( ; iter != d.end(); ++iter) {
std::cout << (*iter)->ToString() << std::endl;
ValueType p = tree2.Predict(**iter);
predict.push_back(p);
std::cout << p << "," << tree.Predict(**iter) << std::endl;
}
std::cout << "rmse: " << RMSE(d, predict) << std::endl;
CleanDataVector(&d);
return 0;
}
示例2: test_datafilters
/**
* Test DataFilters
*/
void test_datafilters()
{
std::vector<std::string> datas;
datas.push_back("1");
datas.push_back("2");
datas.push_back("3");
DataVector datav;
datav.push_back(DataPoint(1,true));
datav.push_back(DataPoint(2,true));
datav.push_back(DataPoint(3,true));
DataFilters filters;
ASSERT(filters.isFiltered(datas), "DataFilters::isFiltered failed on string vector with no filter");
ASSERT(filters.isFiltered(datav), "DataFilters::isFiltered failed on data vector with no filter");
filters.addNumericFilter(0,1,1,true);
ASSERT(filters.isFiltered(datav), "DataFilters::isFiltered failed on data vector with numeric accepting filter on 0");
filters.addNumericFilter(1,4,4,false);
ASSERT(filters.isFiltered(datav), "DataFilters::isFiltered failed on data vector with numeric rejection filter on 1");
filters.addStringFilter(0,"1",true,true,true);
ASSERT(filters.isFiltered(datas), "DataFilters::isFiltered failed on data vector with string accepting filter on 0");
filters.addStringFilter(1,"4",true,true,false);
ASSERT(filters.isFiltered(datas), "DataFilters::isFiltered failed on data vector with string rejection filter on 1");
}
示例3: expand_cluster_order
/** Expands the cluster order while adding new neighbor points to the order.
* @param db All data points that are to be considered by the algorithm. Changes their values.
* @param p The point to be examined.
* @param eps The epsilon representing the radius of the epsilon-neighborhood.
* @param min_pts The minimum number of points to be found within an epsilon-neigborhood.
* @param[out] o_ordered_vector The ordered vector of data points. Elements will be added to this vector.
*/
void expand_cluster_order( DataVector& db, DataPoint* p, const real eps, const unsigned int min_pts, DataVector& o_ordered_vector) {
assert( eps >= 0 && "eps must not be negative");
assert( min_pts > 0 && "min_pts must be greater than 0");
DataVector N_eps = get_neighbors( p, eps, db);
p->reachability_distance( OPTICS::UNDEFINED);
const real core_dist_p = squared_core_distance( p, min_pts, N_eps);
p->processed( true);
o_ordered_vector.push_back( p);
if( core_dist_p == OPTICS::UNDEFINED)
return;
DataSet seeds;
update_seeds( N_eps, p, core_dist_p, seeds);
while( !seeds.empty()) {
DataPoint* q = *seeds.begin();
seeds.erase( seeds.begin()); // remove first element from seeds
DataVector N_q = get_neighbors( q, eps, db);
const real core_dist_q = squared_core_distance( q, min_pts, N_q);
q->processed( true);
o_ordered_vector.push_back( q);
if( core_dist_q != OPTICS::UNDEFINED) {
// *** q is a core-object ***
update_seeds( N_q, q, core_dist_q, seeds);
}
}
}
示例4: LOG
void FancyMeshSystem::handleDataLoading( Ra::Engine::Entity* entity, const std::string& rootFolder,
const std::map<std::string, Ra::Core::Any>& data )
{
LOG(logDEBUG) << "FancyMeshSystem : loading " << data.size() << " data items...";
// Find mesh
std::string filename;
auto meshData = data.find("mesh");
if ( meshData != data.end() )
{
filename = rootFolder + "/" + meshData->second.as<std::string>();
}
DataVector componentsData = FancyMeshLoader::loadFile( filename );
if (componentsData.empty())
{
// Something wrong happened while trying to load the file
return;
}
if (componentsData.size() > 1)
{
LOG(logWARNING) << "Too much objects have been loaded, some data will be ignored.";
}
FancyComponentData componentData = componentsData[0];
FancyMeshComponent* component = static_cast<FancyMeshComponent*>(addComponentToEntity(entity));
component->handleMeshLoading(componentData);
}
示例5: main
int main(int argc, char *argv[])
{
struct shm_remove
{
shm_remove() { boost::interprocess::shared_memory_object::remove("MySharedMemory"); }
~shm_remove(){ boost::interprocess::shared_memory_object::remove("MySharedMemory"); }
} remover;
boost::interprocess::managed_shared_memory segment(boost::interprocess::create_only, "MySharedMemory", 65536);
const ShmemAllocator alloc_inst (segment.get_segment_manager());
DataVector *myvector = segment.construct<DataVector>("MyVector")(alloc_inst);
for(int i = 0; i < 6; ++i) { //Insert data in the vector
printf("%d ", i);
myvector->push_back(i*3);
}
while(1)
{
for(int i = 0; i < 6; ++i) { //Insert data in the vector
printf("%d ", i);
myvector->at(i) = rand()*rand();
printf("%f ", myvector->at(i));
}
printf("\n");
}
return 0;
};
示例6: update_seeds
/** Updates the seeds priority queue with new neighbors or neighbors that now have a better
* reachability distance than before.
* @param N_eps All points in the the epsilon-neighborhood of the center_object, including p itself.
* @param center_object The point on which to start the update process.
* @param c_dist The core distance of the given center_object.
* @param[out] o_seeds The seeds priority queue (aka set with special comparator function) that will be modified.
*/
void update_seeds( const DataVector& N_eps, const DataPoint* center_object, const real c_dist, DataSet& o_seeds) {
assert( c_dist != OPTICS::UNDEFINED && "the core distance must be set <> UNDEFINED when entering update_seeds");
for( DataVector::const_iterator it=N_eps.begin(); it!=N_eps.end(); ++it) {
DataPoint* o = *it;
if( o->is_processed())
continue;
const real new_r_dist = std::max( c_dist, squared_distance( center_object, o));
// *** new_r_dist != UNDEFINED ***
if( o->reachability_distance() == OPTICS::UNDEFINED) {
// *** o not in seeds ***
o->reachability_distance( new_r_dist);
o_seeds.insert( o);
} else if( new_r_dist < o->reachability_distance()) {
// *** o already in seeds & can be improved ***
o_seeds.erase( o);
o->reachability_distance( new_r_dist);
o_seeds.insert( o);
}
}
}
示例7: convertBufferIntoVector
//notes: after using buffer, this function deletes buffer.
DataVector convertBufferIntoVector(char* buffer){
DataVector ColumnData;
char*p = nextNoneSpacePointer(buffer);
while ('\0' != *p){
std::vector< double > lineData;
lineData.reserve(200);
while ('\n' != *p && '\0' != *p){
std::size_t dataOffset = 0;
char *dataBeginning = p;
while (' ' != *p && '\n' != *p && '\0' != *p) {
++dataOffset;
++p;
}
char *dataBuf = new char[dataOffset + 1];
memcpy(dataBuf, dataBeginning, dataOffset);
dataBuf[dataOffset] = '\0';
double dataValue = atof(dataBuf);
delete[] dataBuf;
lineData.push_back(dataValue);
p = nextNoneSpacePointer(p);
}
if (lineData.size() > 0) ColumnData.push_back(lineData);
if ('\0' != *p) ++p;
}
delete[] buffer;
return ColumnData;
}
示例8: mult_transpose
/**
* Performs a transposed mass evaluation
*
* @param storage GridStorage object that contains the grid's points information
* @param basis a reference to a class that implements a specific basis
* @param source the coefficients of the grid points
* @param x the d-dimensional vector with data points (row-wise)
* @param result the result vector of the matrix vector multiplication
*/
void mult_transpose(GridStorage* storage, BASIS& basis, DataVector& source,
DataMatrix& x, DataVector& result) {
result.setAll(0.0);
size_t source_size = source.getSize();
#pragma omp parallel
{
DataVector privateResult(result.getSize());
privateResult.setAll(0.0);
DataVector line(x.getNcols());
AlgorithmEvaluationTransposed<BASIS> AlgoEvalTrans(storage);
privateResult.setAll(0.0);
#pragma omp for schedule(static)
for (size_t i = 0; i < source_size; i++) {
x.getRow(i, line);
AlgoEvalTrans(basis, line, source[i], privateResult);
}
#pragma omp critical
{
result.add(privateResult);
}
}
}
示例9: m_maxClusters
util::Clustering::Clustering(const DataVector& _data, unsigned _max) : m_maxClusters(_max) {
m_data.insert(m_data.begin(), _data.begin(), _data.end());
ClusterMap clusterQualityScores;
for (unsigned clusterCount = 1; clusterCount <= m_maxClusters; clusterCount++) {
clusterQualityScores[clusterCount] = _kmeans(clusterCount);
}
std::vector< CountClusterPair > sortedScores;
std::copy(clusterQualityScores.begin(), clusterQualityScores.end(), std::back_inserter(sortedScores));
ScoreComparator comparator;
std::sort(sortedScores.begin(), sortedScores.end(), comparator);
report("Scores:");
for (int i = 0; i < sortedScores.size(); i++) {
report(sortedScores[i].first << " clusters: " << sortedScores[i].second.getScore());
}
report("Clustering with highest score: ");
report(util::Indents(2) << "cluster count: " << sortedScores[0].first);
report(util::Indents(2) << "aggregate score: " << sortedScores[0].second.getScore());
report(util::Indents(2) << "detected clusters:");
for (auto it = sortedScores[0].second.getClusters().begin(); it != sortedScores[0].second.getClusters().end(); ++it) {
const Cluster& cluster = *it;
report(util::Indents(4) << "position = " << cluster.position << ", elements = " << cluster.data.size());
}
result = sortedScores[0].second;
}
示例10: test_mean
void test_mean()
{
DataVector d;
for (int i=1; i<=9; ++i)
d.push_back(i);
unit_assert(d.mean() == 5.0);
}
示例11: SolveEvolutionMatrix
void SolveEvolutionMatrix(
DataMatrix<double> & matM,
DataMatrix<double> & matB,
DataVector<double> & vecAlphaR,
DataVector<double> & vecAlphaI,
DataVector<double> & vecBeta,
DataMatrix<double> & matVR
) {
int iInfo = 0;
char jobvl = 'N';
char jobvr = 'V';
int n = matM.GetRows();
int lda = matM.GetRows();
int ldb = matM.GetRows();
int ldvl = 1;
int ldvr = matVR.GetRows();
DataVector<double> vecWork;
vecWork.Initialize(8 * n);
int lwork = vecWork.GetRows();
dggev_(
&jobvl,
&jobvr,
&n,
&(matM[0][0]),
&lda,
&(matB[0][0]),
&ldb,
&(vecAlphaR[0]),
&(vecAlphaI[0]),
&(vecBeta[0]),
NULL,
&ldvl,
&(matVR[0][0]),
&ldvr,
&(vecWork[0]),
&lwork,
&iInfo);
int nCount = 0;
for (int i = 0; i < n; i++) {
if (vecBeta[i] != 0.0) {
//printf("%i %1.5e %1.5e\n", i, vecAlphaR[i] / vecBeta[i], vecAlphaI[i] / vecBeta[i]);
nCount++;
}
}
/*
for (int i = 0; i < 40; i++) {
printf("%1.5e %1.5e\n", matVR[11][4*i+2], matVR[12][4*i+2]);
}
*/
Announce("%i total eigenvalues found", nCount);
}
示例12: main
int main(int argc, char *argv[])
{
boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "MySharedMemory");
DataVector *myvector = segment.find<DataVector>("MyVector").first;
for(int i = 0; i < 100; ++i) //Insert data in the vector
{
printf("%f ", (float)myvector->at(i));
}
return 0;
};
示例13: convertGrayToRGB
void convertGrayToRGB( DataVector& dataVec, size_t width, size_t height, int pixelSize )
{
size_t size = width * height;
switch( pixelSize )
{
case 1 :
{
char* ptrS = (char*) &dataVec.front();
char* ptrD = (char*) &dataVec.front();
// go to end of image
ptrS += size - 1;
ptrD += (3 * size) - 1;
// process from back to begin
for(size_t i = 0; i< size; i++)
{
*ptrD = *ptrS; ptrD--; // red
*ptrD = *ptrS; ptrD--; // green
*ptrD = *ptrS; ptrD--; ptrS--; // blue
}
break;
}
case 2:
{
short* ptrS = (short*) &dataVec.front();
short* ptrD = (short*) &dataVec.front();
// go to end of image
ptrS += size - 1;
ptrD += (3 * size) - 1;
// process from back to begin
for(size_t i = 0; i< size; i++)
{
*ptrD = *ptrS; ptrD--; // red
*ptrD = *ptrS; ptrD--; // green
*ptrD = *ptrS; ptrD--; ptrS--; // blue
}
break;
}
case 4 :
{
float* ptrS = (float*) &dataVec.front();
float* ptrD = (float*) &dataVec.front();
// go to end of image
ptrS += size - 1;
ptrD += (3 * size) - 1;
// process from back to begin
for(size_t i = 0; i< size; i++)
{
*ptrD = *ptrS; ptrD--; // red
*ptrD = *ptrS; ptrD--; // green
*ptrD = *ptrS; ptrD--; ptrS--; // blue
}
break;
}
}
}
示例14:
uint8 RadialMenuManager::findNextId (const DataVector & dv)
{
uint8 id = 1;
for (DataVector::const_iterator it = dv.begin (); it != dv.end (); ++it)
{
const ObjectMenuRequestData & data = *it;
id = std::max (id, static_cast<uint8>(data.m_id + 1));
}
return id;
}
示例15: RMSE
double RMSE(const DataVector &data, const PredictVector &predict, size_t len) {
assert(data.size() >= len);
assert(predict.size() >= len);
double s = 0;
double c = 0;
for (size_t i = 0; i < data.size(); ++i) {
s += Squared(predict[i] - data[i]->label) * data[i]->weight;
c += data[i]->weight;
}
return std::sqrt(s / c);
}