Result criticalCellsAreSelfLabelled(VolumeData const& candidate) { CubicalComplex const& complex = candidate.complex; Field const& field = candidate.field; for (int up = 0; up <= 1; ++up) { Labels const labels = markCells(candidate, up); for (Cell v = 0; v < complex.cellIdLimit(); ++v) { if (complex.isCell(v) and field.isCritical(v)) { if (labels.count(v) == 0 or labels.at(v).count(v) < 1) { std::stringstream msg; msg << "Critical cell " << complex.cellPosition(v) << " is not in its own " << (up ? "unstable" : "stable") << " set"; return failure(msg.str()); } else if (labels.at(v).size() > 1) { std::stringstream msg; msg << "Critical cell " << complex.cellPosition(v) << " is in other " << (up ? "unstable" : "stable") << " sets"; return failure(msg.str()); } } } } return success(); }
void PointMatcher<T>::DataPoints::assertConsistency(const std::string& dataName, const int dataRows, const int dataCols, const Labels& labels) const { if (dataRows == 0) { if (dataCols != 0) throw std::runtime_error( (boost::format("Point cloud has degenerate %2% dimensions of rows=0, cols=%1%") % dataCols % dataName).str() ); if (labels.size() > 0) throw std::runtime_error( (boost::format("Point cloud has no %2% data but %1% descriptor labels") % labels.size() % dataName).str() ); } else { if (dataCols != features.cols()) throw std::runtime_error( (boost::format("Point cloud has %1% points in features but %2% points in %3%") % features.cols() % dataCols % dataName).str() ); int descDim(0); for (BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) descDim += it->span; if (dataRows != descDim) throw std::runtime_error( (boost::format("Labels from %3% return %1% total dimensions but there are %2% in the %3% matrix") % descDim % dataRows % dataName).str() ); } }
void PointMatcher<T>::DataPoints::removeField(const std::string& name, Labels& labels, MatrixType& data) const { const unsigned deleteId = getFieldStartingRow(name, labels); const unsigned span = getFieldDimension(name, labels); const unsigned keepAfterId = deleteId + span; const unsigned lastId = data.rows() - 1; const unsigned sizeKeep = data.rows() - keepAfterId; const unsigned nbPoints = data.cols(); // check if the data to be removed at the end if(keepAfterId <= lastId) { data.block(deleteId, 0, sizeKeep, nbPoints) = data.block(keepAfterId, 0, sizeKeep, nbPoints); } //Remove the last rows data.conservativeResize(data.rows()-span, nbPoints); // remove label from the label list for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) { labels.erase(it); break; } } }
Result traversalsAreConsistent(VolumeData const& candidate) { CubicalComplex const& complex = candidate.complex; Field const& field = candidate.field; for (int up = 0; up <= 1; ++up) { Labels const labels = markCells(candidate, up); Field::Vectors V = up ? field.coV() : field.V(); Facets I(complex.xdim(), complex.ydim(), complex.zdim(), up); for (Cell v = 0; v < complex.cellIdLimit(); ++v) { if (not complex.isCell(v)) continue; if (labels.count(v) > 0) { int const n = I.count(v); for (int i = 0; i < n; ++i) { Cell const b = I(v, i); if (not V.defined(b) or V(b) == b) continue; Result r = labelsPropagate(labels, v, V(b), up, complex); if (!r) return r; } } } } return success(); }
Image::Appc getTestImage() const { Image::Appc appc; appc.set_name("foo.com/bar"); Label version; version.set_key("version"); version.set_value("1.0.0"); Label arch; arch.set_key("arch"); arch.set_value("amd64"); Label os; os.set_key("os"); os.set_value("linux"); Labels labels; labels.add_labels()->CopyFrom(version); labels.add_labels()->CopyFrom(arch); labels.add_labels()->CopyFrom(os); appc.mutable_labels()->CopyFrom(labels); return appc; }
//! TR2 metric using SRM(Spatial Relations Matrix) comparison //! returns vector holding pos[0] = match score; pos[1] = mismatch score. vector<float> ShadeShapeMatch::tr2(ShadeShapeRelation &ssrUP, Labels &upLabels, ShadeShapeRelation &ssrDB, Labels &dbLabels, String nStr) { assert(upLabels.size()>0 && dbLabels.size()>0); assert(upLabels.size()==dbLabels.size()); ShadeShapeRelationMatch ssrm; ssrm.srm_match(ssrUP,upLabels,ssrDB,dbLabels,nStr); float matchScore = ssrm.getMatchScore(); float mismatchScore = ssrm.getMismatchScore(); //store the ESG variable data to PrintStream to be printed out later PrintStream esgPS = ssrm.getEsgPrintStream(); if(this->esgPS_Map.find(nStr)==this->esgPS_Map.end()) { this->esgPS_Map[nStr] = esgPS; } //store the entropy variable data to PrintStream to be printed out later PrintStream entropyPS = ssrm.getEntropyPrintStream(); if(this->entropyPS_Map.find(nStr)==this->entropyPS_Map.end()) { this->entropyPS_Map[nStr] = entropyPS; } PrintStream mismatchEntropyPS = ssrm.getMismatchEntropyPrintStream(); if(this->mismatchEntropyPS_Map.find(nStr)==this->mismatchEntropyPS_Map.end()) { this->mismatchEntropyPS_Map[nStr] = mismatchEntropyPS; } PrintStream noEntropyPS = ssrm.getNoEntropyPrintStream(); if(this->noEntropyPS_Map.find(nStr)==this->noEntropyPS_Map.end()) { this->noEntropyPS_Map[nStr] = noEntropyPS; } vector<float> results = {matchScore,mismatchScore}; return results; }
PointMatcher<T>::DataPoints::DataPoints(const Labels& featureLabels, const Labels& descriptorLabels, const size_t pointCount): featureLabels(featureLabels), descriptorLabels(descriptorLabels) { features.resize(featureLabels.totalDim(), pointCount); if(descriptorLabels.totalDim()) descriptors.resize(descriptorLabels.totalDim(), pointCount); }
unsigned PointMatcher<T>::DataPoints::getFieldDimension(const std::string& name, const Labels& labels) const { for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) return it->span; } return 0; }
unsigned PointMatcher<T>::DataPoints::getFieldStartingRow(const std::string& name, const Labels& labels) const { unsigned row(0); for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) return row; row += it->span; } return 0; }
virtual Result<Labels> masterLaunchTaskLabelDecorator( const TaskInfo& taskInfo, const FrameworkInfo& frameworkInfo, const SlaveInfo& slaveInfo) { LOG(INFO) << "Executing 'masterLaunchTaskLabelDecorator' hook"; Labels labels; Label *label = labels.add_labels(); label->set_key(testLabelKey); label->set_value(testLabelValue); return labels; }
bool PointMatcher<T>::DataPoints::fieldExists(const std::string& name, const unsigned dim, const Labels& labels) const { for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) { if (dim == 0 || it->span == dim) return true; else return false; } } return false; }
void OpenCvDetector::train(const Segments& segments, const Labels& labels) { cv::Mat featureMatrix = calculateFeatureMatrix(segments); cv::Mat labelVector(labels.size(), 1, CV_32SC1); for(size_t i = 0; i < labels.size(); i++) { labelVector.at<signed>(i) = labels[i]; } // Dump feature values into file (for analysis with Matlab etc.) dumpFeatureMatrix(featureMatrix, labels); // Implemented by the derived class. trainOnFeatures(featureMatrix, labelVector); }
float ShadeShapeMatch::tr1ForShade(Labels &upLabels, Labels &dbLabels) { assert(upLabels.size()==dbLabels.size()); float numerSum = 0.0; float denomSumUP = 0.0; float denomSumDB = 0.0; map<String,pair<int,float> > upMap = upLabels.getMap(); map<String,pair<int,float> > dbMap = dbLabels.getMap(); for(auto itUP=upMap.begin(), itDB=dbMap.begin(); itUP!=upMap.end(), itDB!=dbMap.end(); itUP++, itDB++) { numerSum += (itUP->second.second * itDB->second.second); denomSumUP += pow(itUP->second.second,2); denomSumDB += pow(itDB->second.second,2); } float denomSum = sqrt(denomSumUP) * sqrt(denomSumDB); float results = numerSum / denomSum; return results; }
Result labelsPropagate( Labels const& labels, Cell const v, Cell const w, bool const upstream, CubicalComplex const& complex) { std::set<Cell> const& lv = labels.at(v); std::set<Cell> const& lw = labels.at(w); std::set<Cell>::const_iterator iter; for (iter = lv.begin(); iter != lv.end(); ++iter) { if (lw.count(*iter) == 0) { std::stringstream msg; msg << (upstream ? "unstable" : "stable") << " sets for cell " << complex.cellPosition(v) << " are not contained in those for " << complex.cellPosition(w) << ": {" << lv << "} vs {" << lw << "}"; return failure(msg.str()); } } return success(); }
RankFixture(size_t fooCnt, size_t barCnt, const Labels &labels) : queryEnv(&indexEnv), rankSetup(factory, indexEnv), mdl(), match_data(), rankProgram(), fooHandles(), barHandles() { for (size_t i = 0; i < fooCnt; ++i) { uint32_t fieldId = indexEnv.getFieldByName("foo")->id(); fooHandles.push_back(mdl.allocTermField(fieldId)); SimpleTermData term; term.setUniqueId(i + 1); term.addField(fieldId).setHandle(fooHandles.back()); queryEnv.getTerms().push_back(term); } for (size_t i = 0; i < barCnt; ++i) { uint32_t fieldId = indexEnv.getFieldByName("bar")->id(); barHandles.push_back(mdl.allocTermField(fieldId)); SimpleTermData term; term.setUniqueId(fooCnt + i + 1); term.addField(fieldId).setHandle(barHandles.back()); queryEnv.getTerms().push_back(term); } labels.inject(queryEnv.getProperties()); rankSetup.setFirstPhaseRank(featureName); rankSetup.setIgnoreDefaultRankFeatures(true); ASSERT_TRUE(rankSetup.compile()); match_data = mdl.createMatchData(); rankProgram = rankSetup.create_first_phase_program(); rankProgram->setup(*match_data, queryEnv); }
virtual Result<Labels> slaveTaskStatusLabelDecorator( const FrameworkID& frameworkId, const TaskStatus& status) { LOG(INFO) << "CalicoHook::task status label decorator"; if (!status.has_executor_id()) { LOG(WARNING) << "CalicoHook:: task status has no valid executor id"; return None(); } const ExecutorID executorId = status.executor_id(); if (!executors->contains(executorId)) { LOG(WARNING) << "CalicoHook:: no valid container id for: " << executorId; return None(); } const ContainerID containerId = executors->at(executorId); if (infos == NULL || !infos->contains(containerId)) { LOG(WARNING) << "CalicoHook:: no valid infos for: " << containerId; return None(); } const Info* info = (*infos)[containerId]; if (info->ipAddress.isNone()) { LOG(WARNING) << "CalicoHook:: no valid IP address"; return None(); } Labels labels; if (status.has_labels()) { labels.CopyFrom(status.labels()); } // Set IPAddress label. Label* label = labels.add_labels(); label->set_key(ipAddressLabelKey); label->set_value(info->ipAddress.get()); LOG(INFO) << "CalicoHook:: added label " << label->key() << ":" << label->value(); return labels; }
void PointMatcher<T>::DataPoints::addField(const std::string& name, const MatrixType& newField, Labels& labels, MatrixType& data) const { const int newFieldDim = newField.rows(); const int newPointCount = newField.cols(); const int pointCount = features.cols(); if (newField.rows() == 0) return; // Replace if the field exists if (fieldExists(name, 0, labels)) { const int fieldDim = getFieldDimension(name, labels); if(fieldDim == newFieldDim) { // Ensure that the number of points in the point cloud and in the field are the same if(pointCount == newPointCount) { const int row = getFieldStartingRow(name, labels); data.block(row, 0, fieldDim, pointCount) = newField; } else { stringstream errorMsg; errorMsg << "The field " << name << " cannot be added because the number of points is not the same. Old point count: " << pointCount << "new: " << newPointCount; throw InvalidField(errorMsg.str()); } } else { stringstream errorMsg; errorMsg << "The field " << name << " already exists but could not be added because the dimension is not the same. Old dim: " << fieldDim << " new: " << newFieldDim; throw InvalidField(errorMsg.str()); } } else // Add at the end if it is a new field { if(pointCount == newPointCount || pointCount == 0) { const int oldFieldDim(data.rows()); const int totalDim = oldFieldDim + newFieldDim; data.conservativeResize(totalDim, newPointCount); data.bottomRows(newFieldDim) = newField; labels.push_back(Label(name, newFieldDim)); } else { stringstream errorMsg; errorMsg << "The field " << name << " cannot be added because the number of points is not the same. Old point count: " << pointCount << " new: " << newPointCount; throw InvalidField(errorMsg.str()); } } }
virtual Result<TaskStatus> slaveTaskStatusDecorator( const FrameworkID& frameworkId, const TaskStatus& status) { LOG(INFO) << "Executing 'slaveTaskStatusDecorator' hook"; Labels labels; // Set one known label. Label* newLabel = labels.add_labels(); newLabel->set_key("bar"); newLabel->set_value("qux"); // Remove label which was set by test. foreach (const Label& oldLabel, status.labels().labels()) { if (oldLabel.key() != "foo") { labels.add_labels()->CopyFrom(oldLabel); } } TaskStatus result; result.mutable_labels()->CopyFrom(labels); // Set an IP address, a network isolation group, and a known label // in network info. This data is later validated by the // 'HookTest.VerifySlaveTaskStatusDecorator' test. NetworkInfo* networkInfo = result.mutable_container_status()->add_network_infos(); // TODO(CD): Deprecated -- remove after 0.27.0. networkInfo->set_ip_address("4.3.2.1"); NetworkInfo::IPAddress* ipAddress = networkInfo->add_ip_addresses(); ipAddress->set_ip_address("4.3.2.1"); networkInfo->add_groups("public"); Label* networkInfoLabel = networkInfo->mutable_labels()->add_labels(); networkInfoLabel->set_key("net_foo"); networkInfoLabel->set_value("net_bar"); return result; }
Labels HookManager::masterLaunchTaskLabelDecorator( const TaskInfo& taskInfo, const FrameworkInfo& frameworkInfo, const SlaveInfo& slaveInfo) { Lock lock(&mutex); Labels labels; foreachpair (const string& name, Hook* hook, availableHooks) { const Result<Labels>& result = hook->masterLaunchTaskLabelDecorator(taskInfo, frameworkInfo, slaveInfo); if (result.isSome()) { labels.MergeFrom(result.get()); } else if (result.isError()) { LOG(WARNING) << "Master label decorator hook failed for module '" << name << "': " << result.error(); } } return labels; }
void Operands::solveMatch(struct s_match m, struct s_operand *op, Labels labels, struct s_status *status) { op->name = m.element; op->operation = m.operation; op->aritOperand = m.operand; op->aritOperandType = TYPE_NONE; op->type = TYPE_LABEL; // if the operand is a label if((m.subtype[TYPE_ADDRESS] || m.subtype[TYPE_LABEL]) && labels.exists(op->name)) op->value = Number::toBin(labels.value(op->name)); // if not, it might be a number else if (Number::exists(op->name)) op->value == Number::toBin(op->name); else throw(eUndefinedLabel); // checks if there is an operation if(op->operation.compare("") != 0) Operands::solveOperation(op, labels, status); }
/** * resolve a operacao aritmetica presente no operando, escrevendo o valor em o->value */ void Operands::solveOperation(t_operand *op,Labels labels,t_status *status) { if(op->operation.compare("") == 0) return; bool opPotentialLabel = false; Number *operand = NULL; if(status != NULL) status->label = (char *)op->aritOperand.c_str(); if(labels.exists(op->aritOperand)) { operand = new Number(Number::toBin(labels.value(op->aritOperand))); } else { try { operand = new Number(op->aritOperand); } catch(e_exception e) { opPotentialLabel = true; } } if(!opPotentialLabel) { Number result(op->value); result.operate(op->operation[0],*operand); op->value = result.toBin(); delete operand; } else { op->aritOperandType = TYPE_LABEL; throw(eUndefinedLabel); } }
virtual Result<Labels> slaveTaskStatusLabelDecorator( const FrameworkID& frameworkId, const TaskStatus& status) { LOG(INFO) << "Executing 'slaveTaskStatusLabelDecorator' hook"; Labels labels; // Set one known label. Label* newLabel = labels.add_labels(); newLabel->set_key("bar"); newLabel->set_value("qux"); // Remove label which was set by test. foreach (const Label& oldLabel, status.labels().labels()) { if (oldLabel.key() != "foo") { labels.add_labels()->CopyFrom(oldLabel); } } return labels; }
typename Eigen::Block<MatrixType> PointMatcher<T>::DataPoints::getViewByName(const std::string& name, const Labels& labels, MatrixType& data, const int viewRow) const { unsigned row(0); for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) { if (viewRow >= 0) { if (viewRow >= int(it->span)) throw InvalidField( (boost::format("Requesting row %1% of field %2% that only has %3% rows") % viewRow % name % it->span).str() ); return data.block(row + viewRow, 0, 1, data.cols()); } else return data.block(row, 0, it->span, data.cols()); } row += it->span; } throw InvalidField("Field " + name + " not found"); }
Result checkLabelCounts( VolumeData const& candidate, int const dim, bool const upstream, int const min = 1, int const max = 1) { CubicalComplex const& complex = candidate.complex; Labels const labels = markCells(candidate, upstream); for (Cell v = 0; v < complex.cellIdLimit(); ++v) { if (complex.isCell(v) and complex.cellDimension(v) == dim) { int const count = labels.count(v) == 0 ? 0 : labels.at(v).size(); if (count < min) { std::stringstream msg; msg << "Cell " << complex.cellPosition(v); if (min == 1) msg << " has no label"; else msg << " has too few labels (" << count << ")"; return failure(msg.str()); } else if (count > max) { std::stringstream msg; msg << "Cell " << complex.cellPosition(v) << " has too many labels (" << count << ")"; return failure(msg.str()); } } } return success(); }
int main(int argc, char **argv) { QApplication app(argc, argv); qApp->setAttribute(Qt::AA_UseHighDpiPixmaps); PixmapPainter pixmapPainter; pixmapPainter.show(); Labels label; label.resize(200, 200); // label.show(); MainWindow mainWindow; // mainWindow.show(); StandardIcons icons; icons.resize(510, 510); // icons.show(); Caching caching; caching.resize(300, 300); // caching.show(); Style style; // style.show(); Fonts fonts; // fonts.show(); IconDrawing iconDrawing; // iconDrawing.show(); Buttons buttons; // buttons.show(); return app.exec(); }
virtual Result<Labels> masterLaunchTaskLabelDecorator( const TaskInfo& taskInfo, const FrameworkInfo& frameworkInfo, const SlaveInfo& slaveInfo) { LOG(INFO) << "Executing 'masterLaunchTaskLabelDecorator' hook"; Labels labels; // Set one known label. Label* newLabel = labels.add_labels(); newLabel->set_key(testLabelKey); newLabel->set_value(testLabelValue); // Remove the 'testRemoveLabelKey' label which was set by the test. foreach (const Label& oldLabel, taskInfo.labels().labels()) { if (oldLabel.key() != testRemoveLabelKey) { labels.add_labels()->CopyFrom(oldLabel); } } return labels; }
// TODO(nnielsen): Split hook tests into multiple modules to avoid // interference. virtual Result<Labels> slaveRunTaskLabelDecorator( const TaskInfo& taskInfo, const ExecutorInfo& executorInfo, const FrameworkInfo& frameworkInfo, const SlaveInfo& slaveInfo) { LOG(INFO) << "Executing 'slaveRunTaskLabelDecorator' hook"; Labels labels; // Set one known label. Label* newLabel = labels.add_labels(); newLabel->set_key("baz"); newLabel->set_value("qux"); // Remove label which was set by test. foreach (const Label& oldLabel, taskInfo.labels().labels()) { if (oldLabel.key() != "foo") { labels.add_labels()->CopyFrom(oldLabel); } } return labels; }
//! compare two labels and fill in missing labels void ShadeShapeMatch::fillMissingLabels(Labels &upLabels, Labels &dbLabels) { map<String,pair<int,float> > &upMap = upLabels.getMap(); map<String,pair<int,float> > &dbMap = dbLabels.getMap(); map<String,int> &upShadeLevelMap = upLabels.getShadeLevelMap(); map<String,int> &dbShadeLevelMap = dbLabels.getShadeLevelMap(); map<String,int> &upShapeNumMap = upLabels.getShapeMap(); map<String,int> &dbShapeNumMap = dbLabels.getShapeMap(); for(auto it=upMap.begin(); it!=upMap.end(); it++) { String label = it->first; if(dbMap.find(label)==dbMap.end()) { dbMap[label] = std::make_pair(0,0.0); dbShadeLevelMap[label] = upLabels.getShadeLevel(label); dbShapeNumMap[label] = upLabels.getShapeNum(label); } } for(auto it=dbMap.begin(); it!=dbMap.end(); it++) { String label = it->first; if(upMap.find(label)==upMap.end()) { upMap[label] = std::make_pair(0,0.0); upShadeLevelMap[label] = dbLabels.getShadeLevel(label); upShapeNumMap[label] = dbLabels.getShapeNum(label); } } }
//! dot product using holder's inequality //! TR1 //! applies shape shift penalties during calculations for the shapes shifted float ShadeShapeMatch::dotProduct(Labels &upLabels, Labels &dbLabels) { ShapeMatch spm; ShadeMatch sdm; if(upLabels.size()!=dbLabels.size()) { cout << "ShapeMatch::dotProduct(): upLabels && dbLabels not same size!!!" << endl; exit(1); } float numerSum = 0.0; float denomSumUP = 0.0; float denomSumDB = 0.0; map<String,pair<int,float> > upMap = upLabels.getMap(); map<String,pair<int,float> > dbMap = dbLabels.getMap(); this->shapeTranslateCount.resize(spm.numOfShapes(),vector<int>(spm.numOfShapes(),0)); // 10 shapes for(auto itUP=upMap.begin(), itDB=dbMap.begin(); itUP!=upMap.end(), itDB!=dbMap.end(); itUP++, itDB++) { String label = itUP->first; float penalty = 1.0; int shapeNum = upLabels.getShapeNum(label); if(shapeNum==-1) shapeNum = dbLabels.getShapeNum(label); if(upLabels.isShapeShifted(label)) { int prevShapeNum = upLabels.getPrevShapeNum(label); if(prevShapeNum>=0 && shapeNum>=0) { penalty = spm.getShiftPenalty(prevShapeNum,shapeNum); } else { printf("ShadeShapeMatch::dotProduct() %s label does not exist!\n",itUP->first.c_str()); printf("PrevShapeNum: %d, :CurrShapeNum: %d\n",prevShapeNum,shapeNum); } } int shadeLevel = upLabels.getShadeLevel(label); float shadeWeight = sdm.applyShadeWeights(shadeLevel); float shapeWeight = spm.applyShapeWeight(shapeNum); numerSum += (itUP->second.second * itDB->second.second) * penalty * shadeWeight * shapeWeight; denomSumUP += pow(itUP->second.second,2); denomSumDB += pow(itDB->second.second,2); } float denomSum = sqrt(denomSumUP) * sqrt(denomSumDB); float results = numerSum / denomSum; return results; }
static Block parse( const Instructions& instructions , const Labels& labels , Address entrypoint ){ Address begin,end; begin = instructions.begin; end = instructions.end; Block block; block.begin = entrypoint; Address address; for( address = entrypoint ; address.word32 <= end.word32 ; address = address.next() ){ Address nextAddress; nextAddress = address.next(); if(labels.contains(nextAddress)){ block.end = address; block.overflows = true; return block; } Instruction instruction; instruction = instructions[address]; switch(Identity::endOf(instruction)){ case Identity::SimpleEnd: block.end = address; block.overflows = false; return block; case Identity::EndWithSlot: block.end = address.next(); block.overflows = false; return block; } } /* It's very, very strange to reach this point in the code. */ block.end = address.previous(); block.overflows = true; return block; }