本文整理汇总了C++中Metric类的典型用法代码示例。如果您正苦于以下问题:C++ Metric类的具体用法?C++ Metric怎么用?C++ Metric使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Metric类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_metric
Metric Filler::get_metric(double x,double y,double z,GEntity* ge){
Metric m;
SMetric3 temp;
SVector3 v1,v2,v3;
Field* field;
FieldManager* manager;
v1 = SVector3(1.0,0.0,0.0);
v2 = SVector3(0.0,1.0,0.0);
v3 = SVector3(0.0,0.0,1.0);
manager = ge->model()->getFields();
if(manager->getBackgroundField()>0){
field = manager->get(manager->getBackgroundField());
if(field){
(*field)(x,y,z,temp,ge);
}
}
m.set_m11(v1.x());
m.set_m21(v1.y());
m.set_m31(v1.z());
m.set_m12(v2.x());
m.set_m22(v2.y());
m.set_m32(v2.z());
m.set_m13(v3.x());
m.set_m23(v3.y());
m.set_m33(v3.z());
return m;
}
示例2: get_metv
/**
* \details Calculates incusive and exclusive values for every metric.
*/
void AggrCube::get_met_tree(vector<double>& excl_sevv,
vector<double>& incl_sevv,
inclmode cnode_mode,
inclmode sys_mode,
Cnode* cnode,
Sysres* sys) const
{
const vector<Metric*>& metrics = get_metv();
size_t num_metrics = metrics.size();
excl_sevv.resize(num_metrics);
incl_sevv.resize(num_metrics);
#pragma omp parallel
{
#pragma omp for
for (size_t i = 0; i < num_metrics; ++i)
incl_sevv[i] = get_vcsev(INCL, cnode_mode, sys_mode, metrics[i], cnode, sys);
#pragma omp for
for (size_t i = 0; i < num_metrics; ++i) {
Metric* met = metrics[i];
double result = incl_sevv[i];
for (unsigned int j = 0; j < met->num_children(); ++j)
result -= incl_sevv[met->get_child(j)->get_id()];
excl_sevv[i] = result;
}
}
}
示例3: metricToJson
json::Object metricToJson(const Metric& metric)
{
json::Object metricJson = metricBaseToJson(metric);
metricJson["name"] = metric.data().name;
metricJson["value"] = metric.data().value;
return metricJson;
}
示例4: TEST_F
TEST_F(HIST_PERC_Fixture,TestPercentilesMany)
{
bool failure = false;
try {
factory->process("create percentiles aaa with time_window=30 collect_period=10 ps=50:90:99:99.9");
}
catch(std::runtime_error& ex) {
cout << "Failed: " << ex.what() << endl;
failure = true;
}
catch(...) {
failure = true;
}
ASSERT_FALSE(failure);
Dataset* dataset = Dataset::open(path, CWSE_DATA_ACCESS_READ_ONLY);
try {
uint16_t ids[4];
ids[0] = dataset->findColumn("aaa.50");
ids[1] = dataset->findColumn("aaa.90");
ids[2] = dataset->findColumn("aaa.99");
ids[3] = dataset->findColumn("aaa.99.9");
for (int i=0; i < 4; i++) {
ASSERT_TRUE(ids[i] != CWSE_INVALID_COLUMN_ID);
ASSERT_EQ(0, dataset->get(ids[i]));
}
Metric* metric = factory->find("aaa");
ASSERT_FALSE(metric == NULL);
Percentiles* p = dynamic_cast<Percentiles*>(metric);
ASSERT_FALSE(p == NULL);
p->resetNextTimePoint(10);
for (int i=1; i <= 100; i++) {
metric->update(i);
}
p->onTimeTick(10);
ASSERT_EQ(50.5, dataset->get(ids[0]));
ASSERT_EQ(90.5, dataset->get(ids[1]));
ASSERT_EQ(99.5, dataset->get(ids[2]));
ASSERT_EQ(100, dataset->get(ids[3]));
}
catch(std::runtime_error& ex) {
cout << "Failed: " << ex.what() << endl;
failure = true;
}
catch(...) {
delete dataset;
ASSERT_TRUE(false);
}
delete dataset;
}
示例5: infinity_distance
double infinity_distance(SPoint3 p1,SPoint3 p2,Metric m){
double distance;
double x1,y1,z1;
double x2,y2,z2;
double a,b,c,d,e,f,g,h,i;
a = m.get_m11();
b = m.get_m21();
c = m.get_m31();
d = m.get_m12();
e = m.get_m22();
f = m.get_m32();
g = m.get_m13();
h = m.get_m23();
i = m.get_m33();
x1 = a*p1.x() + b*p1.y() + c*p1.z();
y1 = d*p1.x() + e*p1.y() + f*p1.z();
z1 = g*p1.x() + h*p1.y() + i*p1.z();
x2 = a*p2.x() + b*p2.y() + c*p2.z();
y2 = d*p2.x() + e*p2.y() + f*p2.z();
z2 = g*p2.x() + h*p2.y() + i*p2.z();
distance = std::max(std::max(fabs(x2-x1),fabs(y2-y1)),fabs(z2-z1));
return distance;
}
示例6: newMetric
void
StatsD::publishAggregateMetrics()
{
for( AggregateMetricList::iterator itr = m_aggregate_metrics.begin();
itr != m_aggregate_metrics.end();
itr++ )
{
Metric *metric = newMetric(itr->second);
metric->convertToNonAggregateValue();
publishMetric(*metric);
delete metric;
}
}
示例7: getGoldActions
void Segmentor::getGoldActions(const vector<Instance>& vecInsts, vector<vector<CAction> >& vecActions){
vecActions.clear();
static Metric eval;
#if USE_CUDA==1
static CStateItem<gpu> state[m_classifier.MAX_SENTENCE_SIZE];
#else
static CStateItem<cpu> state[m_classifier.MAX_SENTENCE_SIZE];
#endif
static vector<string> output;
static CAction answer;
eval.reset();
static int numInstance, actionNum;
vecActions.resize(vecInsts.size());
for (numInstance = 0; numInstance < vecInsts.size(); numInstance++) {
const Instance &instance = vecInsts[numInstance];
actionNum = 0;
state[actionNum].initSentence(&instance.chars);
state[actionNum].clear();
while (!state[actionNum].IsTerminated()) {
state[actionNum].getGoldAction(instance.words, answer);
vecActions[numInstance].push_back(answer);
state[actionNum].move(state+actionNum+1, answer);
actionNum++;
}
if(actionNum-1 != instance.charsize()) {
std::cout << "action number is not correct, please check" << std::endl;
}
state[actionNum].getSegResults(output);
instance.evaluate(output, eval);
if (!eval.bIdentical()) {
std::cout << "error state conversion!" << std::endl;
exit(0);
}
if ((numInstance + 1) % m_options.verboseIter == 0) {
cout << numInstance + 1 << " ";
if ((numInstance + 1) % (40 * m_options.verboseIter) == 0)
cout << std::endl;
cout.flush();
}
if (m_options.maxInstance > 0 && numInstance == m_options.maxInstance)
break;
}
}
示例8: main
int main(void)
{
Metric mc;
mc.subwinSize = Size3(16,16,1);
mc.subwinStep = Size3(16,16,1);
string scorefilepath = "/modules/Site/grantest_output.txt";
mc.searchPath = "/data/totest/gran/";
mc.subsample = true;
mc.changeWin = false;
//cout<<mc.subwinSize<<endl;
mc.trainGranularity(mc.searchPath,scorefilepath);
return 0;
}
示例9: mypath
bool
TextWriter::writeCommon(const Metric& metric)
{
std::ostringstream path;
for (uint32_t i=0; i<_path.size(); ++i) {
path << _path[i] << ".";
}
std::string mypath(path.str());
path << metric.getMangledName();
if (_regex.match(path.str())) {
if (metric.used() || _verbose) {
_out << "\n" << mypath;
return true;
}
}
return false;
}
示例10: thundersvm_predict_sub
void thundersvm_predict_sub(DataSet& predict_dataset, CMDParser& parser, char* model_file_path, char* output_file_path){
fstream file;
file.open(model_file_path, std::fstream::in);
string feature, svm_type;
file >> feature >> svm_type;
CHECK_EQ(feature, "svm_type");
SvmModel *model = nullptr;
Metric *metric = nullptr;
if (svm_type == "c_svc") {
model = new SVC();
metric = new Accuracy();
} else if (svm_type == "nu_svc") {
model = new NuSVC();
metric = new Accuracy();
} else if (svm_type == "one_class") {
model = new OneClassSVC();
//todo determine a metric
} else if (svm_type == "epsilon_svr") {
model = new SVR();
metric = new MSE();
} else if (svm_type == "nu_svr") {
model = new NuSVR();
metric = new MSE();
}
#ifdef USE_CUDA
CUDA_CHECK(cudaSetDevice(parser.gpu_id));
#endif
model->set_max_memory_size_Byte(parser.param_cmd.max_mem_size);
model->load_from_file(model_file_path);
file.close();
file.open(output_file_path, fstream::out);
vector<float_type> predict_y;
predict_y = model->predict(predict_dataset.instances(), -1);
for (int i = 0; i < predict_y.size(); ++i) {
file << predict_y[i] << std::endl;
}
file.close();
if (metric) {
LOG(INFO) << metric->name() << " = " << metric->score(predict_y, predict_dataset.y());
}
}
示例11: remove
inline Future<Nothing> remove(const Metric& metric)
{
// The metrics process is instantiated in `process::initialize`.
process::initialize();
return dispatch(
internal::metrics,
&internal::MetricsProcess::remove,
metric.name());
}
示例12: getGoldActions
void Segmentor::getGoldActions(const vector<Instance>& vecInsts, vector<vector<CAction> >& vecActions) {
vecActions.clear();
static Metric segEval, posEval;
static CStateItem state[m_classifier.MAX_SENTENCE_SIZE];
static CResult output;
static CAction answer;
segEval.reset();
posEval.reset();
static int numInstance, actionNum;
vecActions.resize(vecInsts.size());
for (numInstance = 0; numInstance < vecInsts.size(); numInstance++) {
const Instance &instance = vecInsts[numInstance];
actionNum = 0;
state[actionNum].initSentence(&instance.chars, &instance.candidateLabels);
state[actionNum].clear();
while (!state[actionNum].IsTerminated()) {
state[actionNum].getGoldAction(instance, m_classifier.fe._postagAlphabet, answer);
vecActions[numInstance].push_back(answer);
state[actionNum].move(state + actionNum + 1, answer, m_classifier.fe._postagAlphabet);
actionNum++;
}
if (actionNum - 1 != instance.charsize()) {
std::cout << "action number is not correct, please check" << std::endl;
}
state[actionNum].getSegPosResults(output);
instance.evaluate(output, segEval, posEval);
if (!segEval.bIdentical() || !posEval.bIdentical()) {
std::cout << "error state conversion!" << std::endl;
std::cout << "output instance:" << std::endl;
for (int tmpK = 0; tmpK < instance.words.size(); tmpK++) {
std::cout << instance.words[tmpK] << "_" << instance.postags[tmpK] << " ";
}
std::cout << std::endl;
std::cout << "predicated instance:" << std::endl;
for (int tmpK = 0; tmpK < output.size(); tmpK++) {
std::cout << output.words[tmpK] << "_" << output.postags[tmpK] << " ";
}
std::cout << std::endl;
exit(0);
}
if ((numInstance + 1) % m_options.verboseIter == 0) {
cout << numInstance + 1 << " ";
if ((numInstance + 1) % (40 * m_options.verboseIter) == 0)
cout << std::endl;
cout.flush();
}
if (m_options.maxInstance > 0 && numInstance == m_options.maxInstance)
break;
}
}
示例13: assure
void
VirtualPathSelection::createPeerLink(const wns::service::dll::UnicastAddress myself,
const wns::service::dll::UnicastAddress peer,
const Metric linkMetric)
{
if(useStaticPS)
{
if (wns::simulator::getEventScheduler()->getTime() > staticPSsnapshotTimeout)
{
return;
}
}
assure(mapper.knows(myself), "myself (" << myself << ") is not a known address");
assure(mapper.knows(peer), "peer (" << peer << ") is not a known address");
assure(isMeshPoint(myself) , "myself (" << myself << ") is not a known MP");
assure(isMeshPoint(peer), "peer (" << peer << ") is not a known MP");
assure(linkMetric.isNotInf(), "createPeerLink with metric == inf");
if(isPortal(myself) && isPortal(peer))
{
MESSAGE_SINGLE(NORMAL, logger, "createPeerLink: Ignore wireless link between " << myself << " and " << peer << ", both are portals");
}
else
{
int myselfId = mapper.get(myself);
int peerId = mapper.get(peer);
assure(linkCosts[myselfId][peerId].isInf(), "createPeerLink with already known linkCosts");
Metric newLinkMetric = linkMetric;
if(preKnowledgeCosts[myselfId][peerId].isNotInf())
{
newLinkMetric = newLinkMetric * (1.0-preKnowledgeAlpha) + preKnowledgeCosts[myselfId][peerId] * preKnowledgeAlpha;
MESSAGE_SINGLE(NORMAL, logger, "createPeerLink: " << myself << "->" << peer << " has preKnowledge of " << preKnowledgeCosts[myselfId][peerId] << ", " << linkMetric << "->" << newLinkMetric);
}
linkCosts[myselfId][peerId] = newLinkMetric;
MESSAGE_SINGLE(NORMAL, logger, "createPeerLink: " << myself << " --> " << peer << " costs " << linkCosts[myselfId][peerId]);
pathMatrixIsConsistent = false;
onNewPathSelectionEntry();
}
}
示例14: otherInsts
void Segmentor::train(const string& trainFile, const string& devFile, const string& testFile, const string& modelFile, const string& optionFile, const string& lexiconFile) {
if (optionFile != "")
m_options.load(optionFile);
m_options.showOptions();
vector<Instance> trainInsts, devInsts, testInsts;
m_pipe.readInstances(trainFile, trainInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
if (devFile != "")
m_pipe.readInstances(devFile, devInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
if (testFile != "")
m_pipe.readInstances(testFile, testInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
vector<vector<Instance> > otherInsts(m_options.testFiles.size());
for (int idx = 0; idx < m_options.testFiles.size(); idx++) {
m_pipe.readInstances(m_options.testFiles[idx], otherInsts[idx], m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
}
createAlphabet(trainInsts);
m_classifier.init(m_options.delta);
m_classifier.setDropValue(m_options.dropProb);
vector<vector<CAction> > trainInstGoldactions;
getGoldActions(trainInsts, trainInstGoldactions);
double bestPostagFmeasure = 0;
int inputSize = trainInsts.size();
std::vector<int> indexes;
for (int i = 0; i < inputSize; ++i)
indexes.push_back(i);
static Metric eval;
static Metric segMetric_dev, segMetric_test;
static Metric postagMetric_dev, postagMetric_test;
int maxIter = m_options.maxIter * (inputSize / m_options.batchSize + 1);
int oneIterMaxRound = (inputSize + m_options.batchSize - 1) / m_options.batchSize;
std::cout << "maxIter = " << maxIter << std::endl;
int devNum = devInsts.size(), testNum = testInsts.size();
static vector<CResult> decodeInstResults;
static CResult curDecodeInst;
static bool bCurIterBetter;
static vector<Instance > subInstances;
static vector<vector<CAction> > subInstGoldActions;
for (int iter = 0; iter < maxIter; ++iter) {
std::cout << "##### Iteration " << iter << std::endl;
srand(iter);
random_shuffle(indexes.begin(), indexes.end());
std::cout << "random: " << indexes[0] << ", " << indexes[indexes.size() - 1] << std::endl;
bool bEvaluate = false;
if (m_options.batchSize == 1) {
eval.reset();
bEvaluate = true;
for (int idy = 0; idy < inputSize; idy++) {
subInstances.clear();
subInstGoldActions.clear();
subInstances.push_back(trainInsts[indexes[idy]]);
subInstGoldActions.push_back(trainInstGoldactions[indexes[idy]]);
double cost = m_classifier.train(subInstances, subInstGoldActions);
eval.overall_label_count += m_classifier._eval.overall_label_count;
eval.correct_label_count += m_classifier._eval.correct_label_count;
if ((idy + 1) % (m_options.verboseIter * 10) == 0) {
std::cout << "current: " << idy + 1 << ", Cost = " << cost << ", Correct(%) = " << eval.getAccuracy() << std::endl;
}
m_classifier.updateParams(m_options.regParameter, m_options.adaAlpha, m_options.adaEps);
}
std::cout << "current: " << iter + 1 << ", Correct(%) = " << eval.getAccuracy() << std::endl;
}
else {
if (iter == 0)
eval.reset();
subInstances.clear();
subInstGoldActions.clear();
for (int idy = 0; idy < m_options.batchSize; idy++) {
subInstances.push_back(trainInsts[indexes[idy]]);
subInstGoldActions.push_back(trainInstGoldactions[indexes[idy]]);
}
double cost = m_classifier.train(subInstances, subInstGoldActions);
eval.overall_label_count += m_classifier._eval.overall_label_count;
eval.correct_label_count += m_classifier._eval.correct_label_count;
if ((iter + 1) % (m_options.verboseIter) == 0) {
std::cout << "current: " << iter + 1 << ", Cost = " << cost << ", Correct(%) = " << eval.getAccuracy() << std::endl;
eval.reset();
bEvaluate = true;
}
m_classifier.updateParams(m_options.regParameter, m_options.adaAlpha, m_options.adaEps);
}
if (bEvaluate && devNum > 0) {
bCurIterBetter = false;
if (!m_options.outBest.empty())
//.........这里部分代码省略.........
示例15: thundersvm_train_sub
//void DataSet_load_from_python(DataSet *dataset, float *y, char **x, int len) {dataset->load_from_python(y, x, len);}
void thundersvm_train_sub(DataSet& train_dataset, CMDParser& parser, char* model_file_path){
SvmModel *model = nullptr;
switch (parser.param_cmd.svm_type) {
case SvmParam::C_SVC:
model = new SVC();
break;
case SvmParam::NU_SVC:
model = new NuSVC();
break;
case SvmParam::ONE_CLASS:
model = new OneClassSVC();
break;
case SvmParam::EPSILON_SVR:
model = new SVR();
break;
case SvmParam::NU_SVR:
model = new NuSVR();
break;
}
//todo add this to check_parameter method
if (parser.param_cmd.svm_type == SvmParam::NU_SVC) {
train_dataset.group_classes();
for (int i = 0; i < train_dataset.n_classes(); ++i) {
int n1 = train_dataset.count()[i];
for (int j = i + 1; j < train_dataset.n_classes(); ++j) {
int n2 = train_dataset.count()[j];
if (parser.param_cmd.nu * (n1 + n2) / 2 > min(n1, n2)) {
printf("specified nu is infeasible\n");
return;
}
}
}
}
if (parser.param_cmd.kernel_type != SvmParam::LINEAR)
if (!parser.gamma_set) {
parser.param_cmd.gamma = 1.f / train_dataset.n_features();
}
#ifdef USE_CUDA
CUDA_CHECK(cudaSetDevice(parser.gpu_id));
#endif
vector<float_type> predict_y, test_y;
if (parser.do_cross_validation) {
predict_y = model->cross_validation(train_dataset, parser.param_cmd, parser.nr_fold);
} else {
model->train(train_dataset, parser.param_cmd);
model->save_to_file(model_file_path);
LOG(INFO) << "evaluating training score";
predict_y = model->predict(train_dataset.instances(), -1);
//predict_y = model->predict(train_dataset.instances(), 10000);
//test_y = train_dataset.y();
}
Metric *metric = nullptr;
switch (parser.param_cmd.svm_type) {
case SvmParam::C_SVC:
case SvmParam::NU_SVC: {
metric = new Accuracy();
break;
}
case SvmParam::EPSILON_SVR:
case SvmParam::NU_SVR: {
metric = new MSE();
break;
}
case SvmParam::ONE_CLASS: {
}
}
if (metric) {
LOG(INFO) << metric->name() << " = " << metric->score(predict_y, train_dataset.y()) << std::endl;
}
return;
}