本文整理汇总了C++中GMatrix::print方法的典型用法代码示例。如果您正苦于以下问题:C++ GMatrix::print方法的具体用法?C++ GMatrix::print怎么用?C++ GMatrix::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GMatrix
的用法示例。
在下文中一共展示了GMatrix::print方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lle
void lle(GArgReader& args)
{
// Load the file and params
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
unsigned int nSeed = getpid() * (unsigned int)time(NULL);
GRand prng(nSeed);
GNeighborFinder* pNF = instantiateNeighborFinder(pData, &prng, args);
Holder<GNeighborFinder> hNF(pNF);
int targetDims = args.pop_uint();
// Parse Options
while(args.size() > 0)
{
if(args.if_pop("-seed"))
prng.setSeed(args.pop_uint());
else
throw Ex("Invalid option: ", args.peek());
}
// Transform the data
GLLE transform(pNF->neighborCount(), targetDims, &prng);
transform.setNeighborFinder(pNF);
GMatrix* pDataAfter = transform.doit(*pData);
Holder<GMatrix> hDataAfter(pDataAfter);
pDataAfter->print(cout);
}
示例2: addNoise
void addNoise(GArgReader& args)
{
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
double dev = args.pop_double();
// Parse the options
unsigned int seed = getpid() * (unsigned int)time(NULL);
int excludeLast = 0;
while(args.next_is_flag())
{
if(args.if_pop("-seed"))
seed = args.pop_uint();
else if(args.if_pop("-excludelast"))
excludeLast = args.pop_uint();
else
ThrowError("Invalid neighbor finder option: ", args.peek());
}
GRand prng(seed);
size_t cols = pData->cols() - excludeLast;
for(size_t r = 0; r < pData->rows(); r++)
{
double* pRow = pData->row(r);
for(size_t c = 0; c < cols; c++)
*(pRow++) += dev * prng.normal();
}
pData->print(cout);
}
示例3: breadthFirstUnfolding
void breadthFirstUnfolding(GArgReader& args)
{
// Load the file and params
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
size_t nSeed = getpid() * (unsigned int)time(NULL);
GRand prng(nSeed);
GNeighborFinder* pNF = instantiateNeighborFinder(pData, &prng, args);
Holder<GNeighborFinder> hNF(pNF);
int targetDims = args.pop_uint();
// Parse Options
size_t reps = 1;
Holder<GMatrix> hControlData(NULL);
while(args.size() > 0)
{
if(args.if_pop("-seed"))
nSeed = args.pop_uint();
else if(args.if_pop("-reps"))
reps = args.pop_uint();
else
throw Ex("Invalid option: ", args.peek());
}
// Transform the data
GBreadthFirstUnfolding transform(reps, pNF->neighborCount(), targetDims);
transform.rand().setSeed(nSeed);
transform.setNeighborFinder(pNF);
GMatrix* pDataAfter = transform.reduce(*pData);
Holder<GMatrix> hDataAfter(pDataAfter);
pDataAfter->print(cout);
}
示例4: nominalToCat
void nominalToCat(GArgReader& args)
{
// Load the file
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
// Parse Options
int maxValues = 12;
while(args.size() > 0)
{
if(args.if_pop("-maxvalues"))
maxValues = args.pop_uint();
else
ThrowError("Invalid option: ", args.peek());
}
// Transform the data
GNominalToCat transform(maxValues);
transform.train(*pData);
GMatrix* pDataNew = transform.transformBatch(*pData);
Holder<GMatrix> hDataNew(pDataNew);
// Print results
pDataNew->print(cout);
}
示例5: AddIndexAttribute
void AddIndexAttribute(GArgReader& args)
{
// Parse args
const char* filename = args.pop_string();
double nStartValue = 0.0;
double nIncrement = 1.0;
while(args.size() > 0)
{
if(args.if_pop("-start"))
nStartValue = args.pop_double();
else if(args.if_pop("-increment"))
nIncrement = args.pop_double();
else
ThrowError("Invalid option: ", args.peek());
}
GMatrix* pData = loadData(filename);
Holder<GMatrix> hData(pData);
GArffRelation* pIndexRelation = new GArffRelation();
pIndexRelation->addAttribute("index", 0, NULL);
sp_relation pIndexRel = pIndexRelation;
GMatrix indexes(pIndexRel);
indexes.newRows(pData->rows());
for(size_t i = 0; i < pData->rows(); i++)
indexes.row(i)[0] = nStartValue + i * nIncrement;
GMatrix* pUnified = GMatrix::mergeHoriz(&indexes, pData);
Holder<GMatrix> hUnified(pUnified);
pUnified->print(cout);
}
示例6: enumerateValues
void enumerateValues(GArgReader& args)
{
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
size_t col = args.pop_uint();
if(pData->relation()->valueCount(col) > 0)
((GArffRelation*)pData->relation().get())->setAttrValueCount(col, 0);
else
{
size_t n = 0;
map<double,size_t> themap;
for(size_t i = 0; i < pData->rows(); i++)
{
double* pRow = pData->row(i);
map<double,size_t>::iterator it = themap.find(pRow[col]);
if(it == themap.end())
{
themap[pRow[col]] = n;
pRow[col] = (double)n;
n++;
}
else
pRow[col] = (double)it->second;
}
}
pData->print(cout);
}
示例7: isomap
void isomap(GArgReader& args)
{
// Load the file and params
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
unsigned int nSeed = getpid() * (unsigned int)time(NULL);
GRand prng(nSeed);
GNeighborFinder* pNF = instantiateNeighborFinder(pData, &prng, args);
Holder<GNeighborFinder> hNF(pNF);
int targetDims = args.pop_uint();
// Parse Options
bool tolerant = false;
while(args.size() > 0)
{
if(args.if_pop("-seed"))
prng.setSeed(args.pop_uint());
else if(args.if_pop("-tolerant"))
tolerant = true;
else
throw Ex("Invalid option: ", args.peek());
}
// Transform the data
GIsomap transform(pNF->neighborCount(), targetDims, &prng);
transform.setNeighborFinder(pNF);
if(tolerant)
transform.dropDisconnectedPoints();
GMatrix* pDataAfter = transform.reduce(*pData);
Holder<GMatrix> hDataAfter(pDataAfter);
pDataAfter->print(cout);
}
示例8: cholesky
void cholesky(GArgReader& args)
{
GMatrix* pA = loadData(args.pop_string());
Holder<GMatrix> hA(pA);
pA->cholesky();
pA->print(cout);
}
示例9: precisionRecall
void GRecommenderLib::precisionRecall(GArgReader& args)
{
// Parse options
unsigned int seed = getpid() * (unsigned int)time(NULL);
bool ideal = false;
while(args.next_is_flag())
{
if(args.if_pop("-seed"))
seed = args.pop_uint();
else if(args.if_pop("-ideal"))
ideal = true;
else
throw Ex("Invalid option: ", args.peek());
}
// Load the data
if(args.size() < 1)
throw Ex("No dataset specified.");
GMatrix data;
loadData(data, args.pop_string());
// Instantiate the recommender
GCollaborativeFilter* pModel = InstantiateAlgorithm(args);
std::unique_ptr<GCollaborativeFilter> hModel(pModel);
if(args.size() > 0)
throw Ex("Superfluous argument: ", args.peek());
pModel->rand().setSeed(seed);
// Generate precision-recall data
GMatrix* pResults = pModel->precisionRecall(data, ideal);
std::unique_ptr<GMatrix> hResults(pResults);
pResults->deleteColumns(2, 1); // we don't need the false-positive rate column
pResults->print(cout);
}
示例10: precisionRecall
void precisionRecall(GArgReader& args)
{
// Parse options
unsigned int seed = getpid() * (unsigned int)time(NULL);
bool ideal = false;
while(args.next_is_flag())
{
if(args.if_pop("-seed"))
seed = args.pop_uint();
else if(args.if_pop("-ideal"))
ideal = true;
else
ThrowError("Invalid option: ", args.peek());
}
// Load the data
if(args.size() < 1)
ThrowError("No dataset specified.");
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
// Instantiate the recommender
GRand prng(seed);
GCollaborativeFilter* pModel = InstantiateAlgorithm(prng, args);
Holder<GCollaborativeFilter> hModel(pModel);
if(args.size() > 0)
ThrowError("Superfluous argument: ", args.peek());
// Generate precision-recall data
GMatrix* pResults = pModel->precisionRecall(*pData, ideal);
Holder<GMatrix> hResults(pResults);
pResults->deleteColumn(2); // we don't need the false-positive rate column
pResults->print(cout);
}
示例11: reducedRowEchelonForm
void reducedRowEchelonForm(GArgReader& args)
{
GMatrix* pA = loadData(args.pop_string());
Holder<GMatrix> hA(pA);
pA->toReducedRowEchelonForm();
pA->print(cout);
}
示例12: fillMissingValues
void fillMissingValues(GArgReader& args)
{
// Load
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
// Parse options
unsigned int nSeed = getpid() * (unsigned int)time(NULL);
bool random = false;
while(args.size() > 0)
{
if(args.if_pop("-seed"))
nSeed = args.pop_uint();
else if(args.if_pop("-random"))
random = true;
else
ThrowError("Invalid option: ", args.peek());
}
// Replace missing values and print
GRand prng(nSeed);
if(random)
{
for(size_t i = 0; i < pData->relation()->size(); i++)
pData->replaceMissingValuesRandomly(i, &prng);
}
else
{
for(size_t i = 0; i < pData->relation()->size(); i++)
pData->replaceMissingValuesWithBaseline(i);
}
pData->print(cout);
}
示例13: aggregateCols
void aggregateCols(GArgReader& args)
{
size_t c = args.pop_uint();
vector<string> files;
GFile::fileList(files);
GMatrix* pResults = NULL;
Holder<GMatrix> hResults;
size_t i = 0;
for(vector<string>::iterator it = files.begin(); it != files.end(); it++)
{
PathData pd;
GFile::parsePath(it->c_str(), &pd);
if(strcmp(it->c_str() + pd.extStart, ".arff") != 0)
continue;
GMatrix* pData = loadData(it->c_str());
Holder<GMatrix> hData(pData);
if(!pResults)
{
pResults = new GMatrix(pData->rows(), files.size());
hResults.reset(pResults);
}
pResults->copyColumns(i, pData, c, 1);
i++;
}
pResults->print(cout);
}
示例14: kmeans
void kmeans(GArgReader& args)
{
// Load the file and params
GMatrix data;
loadData(data, args.pop_string());
int clusters = args.pop_uint();
// Parse Options
unsigned int nSeed = getpid() * (unsigned int)time(NULL);
size_t reps = 1;
while(args.size() > 0)
{
if(args.if_pop("-seed"))
nSeed = args.pop_uint();
else if(args.if_pop("-reps"))
reps = args.pop_uint();
else
throw Ex("Invalid option: ", args.peek());
}
// Do the clustering
GRand prng(nSeed);
GKMeans clusterer(clusters, &prng);
clusterer.setReps(reps);
GMatrix* pOut = clusterer.reduce(data);
std::unique_ptr<GMatrix> hOut(pOut);
pOut->print(cout);
}
示例15: DropMissingValues
void DropMissingValues(GArgReader& args)
{
GMatrix* pData = loadData(args.pop_string());
Holder<GMatrix> hData(pData);
GRelation* pRelation = pData->relation().get();
size_t dims = pRelation->size();
for(size_t i = pData->rows() - 1; i < pData->rows(); i--)
{
double* pPat = pData->row(i);
bool drop = false;
for(size_t j = 0; j < dims; j++)
{
if(pRelation->valueCount(j) == 0)
{
if(pPat[j] == UNKNOWN_REAL_VALUE)
{
drop = true;
break;
}
}
else
{
if(pPat[j] == UNKNOWN_DISCRETE_VALUE)
{
drop = true;
break;
}
}
}
if(drop)
pData->deleteRow(i);
}
pData->print(cout);
}