本文整理汇总了C++中ModelType类的典型用法代码示例。如果您正苦于以下问题:C++ ModelType类的具体用法?C++ ModelType怎么用?C++ ModelType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModelType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calcConProbs
void* calcConProbs(void* arg) {
Params *params = (Params*)arg;
ModelType *model = (ModelType*)(params->model);
ReadReader<ReadType> *reader = (ReadReader<ReadType>*)(params->reader);
HitContainer<HitType> *hitv = (HitContainer<HitType>*)(params->hitv);
double *ncpv = (double*)(params->ncpv);
ReadType read;
READ_INT_TYPE N = hitv->getN();
HIT_INT_TYPE fr, to;
assert(model->getNeedCalcConPrb());
reader->reset();
for (READ_INT_TYPE i = 0; i < N; i++) {
general_assert(reader->next(read), "Can not load a read!");
fr = hitv->getSAt(i);
to = hitv->getSAt(i + 1);
ncpv[i] = model->getNoiseConPrb(read);
for (HIT_INT_TYPE j = fr; j < to; j++) {
HitType &hit = hitv->getHitAt(j);
hit.setConPrb(model->getConPrb(read, hit));
}
}
return NULL;
}
示例2: processquerypattern
void processquerypattern(ModelType & model, ClassDecoder * classdecoder, const Pattern & pattern, const string & dorelations, bool doinstantiate) {
if (!model.has(pattern)) {
cout << "PATTERN \"" << pattern.tostring(*classdecoder) << "\" NOT FOUND IN MODEL" << endl;
} else {
model.print(&cout, *classdecoder, pattern, doinstantiate);
if (!dorelations.empty()) model.outputrelations(pattern, *classdecoder, &cout, dorelations == "all" ? "" : dorelations);
}
}
示例3: GET_SS_STEP
void* GET_SS_STEP(void* arg) {
Params *params = (Params*)arg;
ModelType *model = (ModelType*)(params->model);
ReadReader<ReadType> *reader = (ReadReader<ReadType>*)(params->reader);
HitContainer<HitType> *hitv = (HitContainer<HitType>*)(params->hitv);
double *ncpv = (double*)(params->ncpv);
ModelType *mhp = (ModelType*)(params->mhp);
assert(!model->getNeedCalcConPrb());
ReadType read;
READ_INT_TYPE N = hitv->getN();
double sum;
vector<double> fracs; //to remove this, do calculation twice
HIT_INT_TYPE fr, to, id;
reader->reset();
mhp->init();
for (READ_INT_TYPE i = 0; i < N; i++) {
general_assert(reader->next(read), "Can not load a read!");
fr = hitv->getSAt(i);
to = hitv->getSAt(i + 1);
fracs.resize(to - fr + 1);
sum = 0.0;
fracs[0] = probv[0] * ncpv[i];
if (fracs[0] < EPSILON) fracs[0] = 0.0;
sum += fracs[0];
for (HIT_INT_TYPE j = fr; j < to; j++) {
HitType &hit = hitv->getHitAt(j);
id = j - fr + 1;
fracs[id] = probv[hit.getSid()] * hit.getConPrb();
if (fracs[id] < EPSILON) fracs[id] = 0.0;
sum += fracs[id];
}
if (sum >= EPSILON) {
fracs[0] /= sum;
//mhp->updateNoise(read, fracs[0]);
for (HIT_INT_TYPE j = fr; j < to; j++) {
HitType &hit = hitv->getHitAt(j);
id = j - fr + 1;
fracs[id] /= sum;
mhp->update(read, hit, fracs[id]);
}
}
}
return NULL;
}
示例4: dofsFromModelName
SizeType dofsFromModelName(const ModelType& model)
{
const PsimagLite::String& modelName = model.params().model;
SizeType site = 0; // FIXME : account for Hilbert spaces changing with site
SizeType dofs = SizeType(log(model.hilbertSize(site))/log(2.0));
std::cerr<<"DOFS= "<<dofs<<" <------------------------------------\n";
if (modelName.find("FeAsBasedSc")!=PsimagLite::String::npos) return dofs;
if (modelName.find("FeAsBasedScExtended")!=PsimagLite::String::npos) return dofs;
if (modelName.find("HubbardOneBand")!=PsimagLite::String::npos) return dofs;
// max number here, site dependence taken into account elsewhere
if (modelName.find("Immm")!=PsimagLite::String::npos) return 4;
return 0;
}
示例5: train
//Classification
void CARTTrainer::train(ModelType& model, ClassificationDataset const& dataset){
//Store the number of input dimensions
m_inputDimension = inputDimension(dataset);
//Pass input dimension (i.e., number of attributes) to tree model
model.setInputDimension(m_inputDimension);
//Find the largest label, so we know how big the histogram should be
m_maxLabel = static_cast<unsigned int>(numberOfClasses(dataset))-1;
// create cross-validation folds
ClassificationDataset set=dataset;
CVFolds<ClassificationDataset> folds = createCVSameSizeBalanced(set, m_numberOfFolds);
//find the best tree for the cv folds
double bestErrorRate = std::numeric_limits<double>::max();
CARTClassifier<RealVector>::TreeType bestTree;
//Run through all the cross validation sets
for (unsigned fold = 0; fold < m_numberOfFolds; ++fold) {
ClassificationDataset dataTrain = folds.training(fold);
ClassificationDataset dataTest = folds.validation(fold);
//Create attribute tables
//O.K. stores how often label(i) can be found in the dataset
//O.K. TODO: std::vector<unsigned int> is sufficient
boost::unordered_map<std::size_t, std::size_t> cAbove = createCountMatrix(dataTrain);
AttributeTables tables = createAttributeTables(dataTrain.inputs());
//create initial tree for the fold
CARTClassifier<RealVector>::TreeType tree = buildTree(tables, dataTrain, cAbove, 0);
model.setTree(tree);
while(true){
ZeroOneLoss<unsigned int, RealVector> loss;
double errorRate = loss.eval(dataTest.labels(), model(dataTest.inputs()));
if(errorRate < bestErrorRate){
//We have found a subtree that has a smaller error rate when tested!
bestErrorRate = errorRate;
bestTree = tree;
}
if(tree.size()!=1) break;
pruneTree(tree);
model.setTree(tree);
}
}
SHARK_CHECK(bestTree.size() > 0, "We should never set a tree that is empty.");
model.setTree(bestTree);
}
示例6: sample_theta_vectors_from_count_vectors
void sample_theta_vectors_from_count_vectors() {
ModelType model;
model.read(modelF);
calcExpectedEffectiveLengths<ModelType>(model);
int num_threads = min(nThreads, nCV);
buffer = new Buffer(nMB, nSamples, cvlen, tmpF);
paramsArray = new Params[num_threads];
threads = new pthread_t[num_threads];
char inpF[STRLEN];
for (int i = 0; i < num_threads; i++) {
paramsArray[i].no = i;
sprintf(inpF, "%s%d", cvsF, i);
paramsArray[i].fi = fopen(inpF, "r");
paramsArray[i].engine = engineFactory::new_engine();
paramsArray[i].mw = model.getMW();
}
/* set thread attribute to be joinable */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (int i = 0; i < num_threads; i++) {
rc = pthread_create(&threads[i], &attr, &sample_theta_from_c, (void*)(¶msArray[i]));
pthread_assert(rc, "pthread_create", "Cannot create thread " + itos(i) + " (numbered from 0) in sample_theta_vectors_from_count_vectors!");
}
for (int i = 0; i < num_threads; i++) {
rc = pthread_join(threads[i], &status);
pthread_assert(rc, "pthread_join", "Cannot join thread " + itos(i) + " (numbered from 0) in sample_theta_vectors_from_count_vectors!");
}
/* destroy attribute */
pthread_attr_destroy(&attr);
delete[] threads;
for (int i = 0; i < num_threads; i++) {
fclose(paramsArray[i].fi);
delete paramsArray[i].engine;
}
delete[] paramsArray;
delete buffer; // Must delete here, force the content left in the buffer be written into the disk
if (verbose) { printf("Sampling is finished!\n"); }
}
示例7: train
//Train model with a regression dataset
void CARTTrainer::train(ModelType& model, RegressionDataset const& dataset)
{
//Store the number of input dimensions
m_inputDimension = inputDimension(dataset);
//Pass input dimension (i.e., number of attributes) to tree model
model.setInputDimension(m_inputDimension);
//Store the size of the labels
m_labelDimension = labelDimension(dataset);
// create cross-validation folds
RegressionDataset set=dataset;
CVFolds<RegressionDataset > folds = createCVSameSize(set, m_numberOfFolds);
double bestErrorRate = std::numeric_limits<double>::max();
CARTClassifier<RealVector>::TreeType bestTree;
for (unsigned fold = 0; fold < m_numberOfFolds; ++fold){
//Run through all the cross validation sets
RegressionDataset dataTrain = folds.training(fold);
RegressionDataset dataTest = folds.validation(fold);
std::size_t numTrainElements = dataTrain.numberOfElements();
AttributeTables tables = createAttributeTables(dataTrain.inputs());
std::vector < RealVector > labels(numTrainElements);
boost::copy(dataTrain.labels().elements(),labels.begin());
//Build tree form this fold
CARTClassifier<RealVector>::TreeType tree = buildTree(tables, dataTrain, labels, 0, dataTrain.numberOfElements());
//Add the tree to the model and prune
model.setTree(tree);
while(true){
//evaluate the error of current tree
SquaredLoss<> loss;
double error = loss.eval(dataTest.labels(), model(dataTest.inputs()));
if(error < bestErrorRate){
//We have found a subtree that has a smaller error rate when tested!
bestErrorRate = error;
bestTree = tree;
}
if(tree.size() == 1) break;
pruneTree(tree);
model.setTree(tree);
}
}
SHARK_CHECK(bestTree.size() > 0, "We should never set a tree that is empty.");
model.setTree(bestTree);
}
示例8: get_metric
agent_framework::model::Metric get_metric(const ModelType<TYPE>& resource, const ResourceSensorPtr resource_sensor) {
const auto metrics = agent_framework::module::get_manager<agent_framework::model::Metric>().get_entries(
[&resource, &resource_sensor](const agent_framework::model::Metric& metric) -> bool {
return metric.get_component_type() == resource.get_component()
&& metric.get_component_uuid() == resource.get_uuid()
&& metric.get_metric_definition_uuid() == resource_sensor->get_definition().get_uuid();
}
);
if (metrics.size() != 1) {
throw std::runtime_error("Invalid number of Metrics (" + std::to_string(metrics.size()) + ") for "
+ resource_sensor->get_definition().get_metric_jsonptr() + " reading for "
+ resource.get_component().to_string() + " with uuid " + resource.get_uuid() );
}
return metrics.front();
}
示例9: calcExpectedEffectiveLengths
void calcExpectedEffectiveLengths(ModelType& model) {
int lb, ub, span;
double *pdf = NULL, *cdf = NULL, *clen = NULL; // clen[i] = sigma_{j=1}^{i}pdf[i]*(lb+i)
model.getGLD().copyTo(pdf, cdf, lb, ub, span);
clen = new double[span + 1];
clen[0] = 0.0;
for (int i = 1; i <= span; i++) {
clen[i] = clen[i - 1] + pdf[i] * (lb + i);
}
eel.clear();
eel.resize(M + 1, 0.0);
for (int i = 1; i <= M; i++) {
int totLen = refs.getRef(i).getTotLen();
int fullLen = refs.getRef(i).getFullLen();
int pos1 = max(min(totLen - fullLen + 1, ub) - lb, 0);
int pos2 = max(min(totLen, ub) - lb, 0);
if (pos2 == 0) { eel[i] = 0.0; continue; }
eel[i] = fullLen * cdf[pos1] + ((cdf[pos2] - cdf[pos1]) * (totLen + 1) - (clen[pos2] - clen[pos1]));
assert(eel[i] >= 0);
if (eel[i] < MINEEL) { eel[i] = 0.0; }
}
delete[] pdf;
delete[] cdf;
delete[] clen;
}
示例10: verifyPlaneSac
void verifyPlaneSac (ModelType & model, SacType & sac, unsigned int inlier_number = 2000, float tol = 1e-1f,
float refined_tol = 1e-1f, float proj_tol = 1e-3f)
{
// Algorithm tests
bool result = sac.computeModel ();
ASSERT_EQ (result, true);
std::vector<int> sample;
sac.getModel (sample);
EXPECT_EQ (int (sample.size ()), 3);
std::vector<int> inliers;
sac.getInliers (inliers);
EXPECT_GE (int (inliers.size ()), inlier_number);
Eigen::VectorXf coeff;
sac.getModelCoefficients (coeff);
EXPECT_EQ (int (coeff.size ()), 4);
EXPECT_NEAR (coeff[0]/coeff[3], plane_coeffs_[0], tol);
EXPECT_NEAR (coeff[1]/coeff[3], plane_coeffs_[1], tol);
EXPECT_NEAR (coeff[2]/coeff[3], plane_coeffs_[2], tol);
Eigen::VectorXf coeff_refined;
model->optimizeModelCoefficients (inliers, coeff, coeff_refined);
EXPECT_EQ (int (coeff_refined.size ()), 4);
EXPECT_NEAR (coeff_refined[0]/coeff_refined[3], plane_coeffs_[0], refined_tol);
EXPECT_NEAR (coeff_refined[1]/coeff_refined[3], plane_coeffs_[1], refined_tol);
// This test fails in Windows (VS 2010) -- not sure why yet -- relaxing the constraint from 1e-2 to 1e-1
// This test fails in MacOS too -- not sure why yet -- disabling
//EXPECT_NEAR (coeff_refined[2]/coeff_refined[3], plane_coeffs_[2], refined_tol);
// Projection tests
PointCloud<PointXYZ> proj_points;
model->projectPoints (inliers, coeff_refined, proj_points);
EXPECT_NEAR (proj_points.points[20].x, 1.1266, proj_tol);
EXPECT_NEAR (proj_points.points[20].y, 0.0152, proj_tol);
EXPECT_NEAR (proj_points.points[20].z, -0.0156, proj_tol);
EXPECT_NEAR (proj_points.points[30].x, 1.1843, proj_tol);
EXPECT_NEAR (proj_points.points[30].y, -0.0635, proj_tol);
EXPECT_NEAR (proj_points.points[30].z, -0.0201, proj_tol);
EXPECT_NEAR (proj_points.points[50].x, 1.0749, proj_tol);
EXPECT_NEAR (proj_points.points[50].y, -0.0586, proj_tol);
EXPECT_NEAR (proj_points.points[50].z, 0.0587, refined_tol);
}
示例11: viewmodel
void viewmodel(ModelType & model, ClassDecoder * classdecoder, ClassEncoder * classencoder, bool print, bool report, bool nocoverage, bool histogram , bool query, const string dorelations, bool doinstantiate, bool info, bool printreverseindex, int cooc, double coocthreshold = 0.1) {
cerr << "Generating desired views..." << endl;
if (print) {
if (classdecoder == NULL) {
cerr << "ERROR: Unable to print model, no class file specified (--classfile)" << endl;
} else {
model.print(&cout, *classdecoder, doinstantiate);
}
}
if (printreverseindex) {
model.printreverseindex(&cout, *classdecoder);
}
if (report) {
model.report(&cout, nocoverage);
}
if (histogram) {
model.histogram(&cout);
}
if (cooc == 2) {
model.outputcooc_npmi(&cout, *classdecoder,coocthreshold);
} else if (cooc == 1) {
model.outputcooc(&cout, *classdecoder,coocthreshold);
}
if (query) {
if (classencoder == NULL) {
cerr << "ERROR: Unable to query model, no class encoder specified (--classfile)" << endl;
} else {
querymodel<ModelType>(model, classencoder, classdecoder, dorelations, doinstantiate);
}
} else if (!dorelations.empty()) {
bool first = true;
for (typename ModelType::iterator iter = model.begin(); iter != model.end(); iter++) {
cout << iter->first.tostring(*classdecoder) << endl;
const PatternPointer pp = iter->first;
model.outputrelations(pp, *classdecoder, &cout, dorelations == "all" ? "" : dorelations,first);
first = false;
}
}
if (info) {
model.info(&cout);
}
}
示例12: querymodel
void querymodel(ModelType & model, ClassEncoder * classencoder, ClassDecoder * classdecoder, string dorelations, bool doinstantiate, bool repeat = true) {
const bool allowunknown = true;
unsigned char buffer[65536];
uint32_t linenum = 0;
std::string line;
cerr << "Colibri Patternmodeller -- Interactive query mode." << endl;
cerr << " Type ctrl-D to quit, type X to switch between exact mode and extensive mode (default: extensive mode)." << endl;
bool exact = false;
do {
linenum++;
cerr << linenum << ">> ";
getline(cin,line);
if ((line == "X") || (line == "X\n")) {
exact = !exact;
if (exact) {
cerr << "Switched to Exact mode - Only exact matches will be shown now" << endl;
} else {
cerr << "Switched to Extensive mode - Input will be scanned for all matching patterns" << endl;
}
} else if (!line.empty()) {
const int buffersize = classencoder->encodestring(line, buffer, allowunknown);
Pattern linepattern = Pattern(buffer, buffersize);
if (exact) {
processquerypattern<ModelType>(model,classdecoder, linepattern, dorelations, doinstantiate);
} else {
vector<pair<Pattern, int> > patterns = model.getpatterns(linepattern);
if (model.has(linepattern)) {
const IndexReference ref = IndexReference(linenum,0);
//process and output instance
cout << ref.sentence << ':' << (int) ref.token << "\t";
processquerypattern<ModelType>(model, classdecoder, linepattern, dorelations, doinstantiate);
}
for (vector<pair<Pattern,int> >::iterator iter = patterns.begin(); iter != patterns.end(); iter++) {
const Pattern pattern = iter->first;
const IndexReference ref = IndexReference(linenum,iter->second);
//process and output instance
cout << ref.sentence << ':' << (int) ref.token << "\t";
processquerypattern<ModelType>(model, classdecoder, pattern, dorelations, doinstantiate);
}
}
}
} while (!cin.eof() && (repeat));
}
示例13: train
void NormalizeComponentsWhitening::train(ModelType& model, UnlabeledData<RealVector> const& input){
std::size_t dc = dataDimension(input);
SHARK_CHECK(input.numberOfElements() >= dc + 1, "[NormalizeComponentsWhitening::train] input needs to contain more points than there are input dimensions");
SHARK_CHECK(m_targetVariance > 0.0, "[NormalizeComponentsWhitening::train] target variance must be positive");
// dense model with bias having input and output dimension equal to data dimension
model.setStructure(dc, dc, true);
RealVector mean;
RealMatrix covariance;
meanvar(input, mean, covariance);
RealMatrix whiteningMatrix = createWhiteningMatrix(covariance);
whiteningMatrix *= std::sqrt(m_targetVariance);
RealVector offset = -prod(trans(whiteningMatrix),mean);
model.setStructure(RealMatrix(trans(whiteningMatrix)), offset);
}
示例14: Render
void Painter::Render(D3D* d3d, Frustum* frustum, Viewport* viewport,
D3DXMATRIX world, D3DXMATRIX view, D3DXMATRIX projection, D3DXMATRIX ortho)
{
std::sort(z.begin(), z.end(), Compare);
for( vector<BaseType*>::iterator p=z.begin(); p!=z.end(); ++p)
{
//process(*p); RENDER BACK TO FRONT
//FRONT = negatives
//BACK = positives
//sort list greatest to least so back renders first
BaseType* base = *p;
int type = base->GetType();
if (type == 1)
{
ModelType* model = (ModelType*)base;
model->transform = &xforce(*model->transform, Rad);
model->Render(d3d->GetDeviceContext(), frustum, viewport);
}
if (type == 2)
{
TextType* text = (TextType*)base;
text->Render(d3d->GetDeviceContext(), viewport);
}
if (type == 3)
{
BitmapType* bitmap = (BitmapType*)base;
bitmap->transform = &xforce(*bitmap->transform, Rad);
bitmap->Render(d3d, viewport);
}
/*if (type == 4)
{
TransformType* transform = (TransformType*)base;
transform->Render(d3d, world, view, projection, ortho);
}*/
}
return;
}
示例15: getComponentOptions
ClassNodeDrawOptions ClassGraph::getComponentOptions(ModelType const &type,
ClassNodeDrawOptions const &options)
{
ClassNodeDrawOptions compOptions = options;
bool mainComponent = false;
if(mNodes.size() > FIRST_CLASS_INDEX)
{
ModelType const *mainType = mNodes[FIRST_CLASS_INDEX].getType();
ModelClassifier const *mainClass = mainType->getClass();
ModelClassifier const *testClass = type.getClass();
if(mainClass && testClass)
{
ModelModule const *mainModule = mainClass->getModule();
ModelModule const *testModule = testClass->getModule();
if(mainModule && testModule)
{
FilePath mainFp(mainModule->getName(), FP_File);
FilePath fp(testClass->getModule()->getName(), FP_File);
if(mainFp.getDrivePath() == fp.getDrivePath())
{
mainComponent = true;
}
}
}
}
else
{
mainComponent = true;
}
if(!mainComponent)
{
compOptions.drawAttrTypes = false;
compOptions.drawAttributes = false;
compOptions.drawOperParams = false;
compOptions.drawOperations = false;
compOptions.drawPackageName = true;
}
return compOptions;
}