int OrientationSaliencyMap::calculate() { calculated = false; int rt_code = checkParameters(); if(rt_code != AM_OK) return(rt_code); printf("[INFO]: %s: Computation started.\n",mapName.c_str()); cv::Mat image_cur; image.copyTo(image_cur); image_cur.convertTo(image_cur,CV_32F,1.0f/255); cv::Mat image_gray; cv::cvtColor(image_cur,image_gray,CV_BGR2GRAY); cv::blur(image_gray,image_gray,cv::Size(filter_size,filter_size)); orientationMap(image_gray,width,height,angle,max_sum,bandwidth,map); cv::blur(map,map,cv::Size(filter_size,filter_size)); v4r::normalize(map,normalization_type); calculated = true; printf("[INFO]: %s: Computation succeed.\n",mapName.c_str()); return(AM_OK); }
Texture2DResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<0, Texture2D>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; TextureInternalFormat tf; TextureFormat f; PixelType t; Texture::Parameters params; Buffer::Parameters s; int w; int h; try { checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,minLod,maxLod,compare,borderType,borderr,borderg,borderb,bordera,maxAniso,width,height,"); getIntParameter(desc, e, "width", &w); getIntParameter(desc, e, "height", &h); getParameters(desc, e, tf, f, t); getParameters(desc, e, params); s.compressedSize(desc->getSize()); init(w, h, tf, f, t, params, s, CPUBuffer(desc->getData())); desc->clearData(); } catch (...) { desc->clearData(); throw exception(); } }
ParticleProducerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<50, ParticleProducer>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; checkParameters(desc, e, "name,storage,"); ptr<ParticleStorage> storage = manager->loadResource(getParameter(desc, e, "storage")).cast<ParticleStorage>(); const TiXmlNode *n = e->FirstChild(); while (n != NULL) { const TiXmlElement *f = n->ToElement(); if (f == NULL) { n = n->NextSibling(); continue; } ptr<ParticleLayer> l = manager->loadResource(desc, f).cast<ParticleLayer>(); if (l != NULL) { addLayer(l); } else { if (Logger::WARNING_LOGGER != NULL) { log(Logger::WARNING_LOGGER, desc, f, "Unknown scene node element '" + f->ValueStr() + "'"); } } n = n->NextSibling(); } init(storage); }
ForestOrthoLayerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<40, ForestOrthoLayer> (manager, name, desc) { e = e == NULL ? desc->descriptor : e; ptr<GraphProducer>graphProducer; int displayLevel = 0; vec4f color = vec4f((float)30/255,(float)62/255,(float)45/255, 1.0f); checkParameters(desc, e, "name,graph,renderProg,level,color,quality,"); string g = getParameter(desc, e, "graph"); graphProducer = manager->loadResource(g).cast<GraphProducer>(); if (e->Attribute("level") != NULL) { getIntParameter(desc, e, "level", &displayLevel); } if (e->Attribute("quality") != NULL) { quality = strcmp(e->Attribute("quality"), "true") == 0; } if (e->Attribute("color") != NULL) { string c = getParameter(desc, e, "color") + ","; string::size_type start = 0; string::size_type index; for (int i = 0; i < 3; i++) { index = c.find(',', start); color[i] = (float) atof(c.substr(start, index - start).c_str()) / 255; start = index + 1; } } ptr<Program> layerProgram = manager->loadResource(getParameter(desc, e, "renderProg")).cast<Program>(); init(graphProducer, layerProgram, displayLevel, quality, color); }
TerrainNodeResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<0, TerrainNode>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; float size; float zmin; float zmax; ptr<Deformation> deform; float splitFactor; int maxLevel; checkParameters(desc, e, "name,size,zmin,zmax,deform,radius,splitFactor,horizonCulling,maxLevel,"); getFloatParameter(desc, e, "size", &size); getFloatParameter(desc, e, "zmin", &zmin); getFloatParameter(desc, e, "zmax", &zmax); if (e->Attribute("deform") != NULL && strcmp(e->Attribute("deform"), "sphere") == 0) { deform = new SphericalDeformation(size); } if (e->Attribute("deform") != NULL && strcmp(e->Attribute("deform"), "cylinder") == 0) { float radius; getFloatParameter(desc, e, "radius", &radius); deform = new CylindricalDeformation(radius); } if (deform == NULL) { deform = new Deformation(); } getFloatParameter(desc, e, "splitFactor", &splitFactor); getIntParameter(desc, e, "maxLevel", &maxLevel); ptr<TerrainQuad> root = new TerrainQuad(NULL, NULL, 0, 0, -size, -size, 2.0 * size, zmin, zmax); init(deform, root, splitFactor, maxLevel); if (e->Attribute("horizonCulling") != NULL && strcmp(e->Attribute("horizonCulling"), "false") == 0) { horizonCulling = false; } }
int OrientationSaliencyMap::calculatePyramidSimple() { calculated = false; int rt_code = checkParameters(); if(rt_code != AM_OK) return(rt_code); printf("[INFO]: %s: Computation Simple pyramid started.\n",mapName.c_str()); SimplePyramid::Ptr pyramid( new SimplePyramid() ); pyramid->setStartLevel(0); pyramid->setMaxLevel(6); pyramid->setSMLevel(0); pyramid->setWidth(width); pyramid->setHeight(height); pyramid->setNormalizationType(normalization_type); cv::Mat image_cur; image.copyTo(image_cur); image_cur.convertTo(image_cur,CV_32F,1.0f/255); cv::Mat image_gray; cv::cvtColor(image_cur,image_gray,CV_BGR2GRAY); pyramid->setImage(image_gray); pyramid->buildPyramid(); pyramid->print(); combinePyramid(pyramid); calculated = true; printf("[INFO]: %s: Pyramid computation succeed.\n",mapName.c_str()); return(AM_OK); }
void dspWoHistoryByNumber::sFillList() { if (!checkParameters()) { _wo->clear(); return; } QString sql( "SELECT wo_id, wo_subnumber, item_number," " (item_descrip1 || ' ' || item_descrip2)," " wo_status, warehous_code," " formatQty(wo_qtyord) AS ordered," " formatQty(wo_qtyrcv) AS received," " formatDate(wo_startdate) AS startdate," " formatDate(wo_duedate) AS duedate," " formatCost(wo_postedvalue) " "FROM wo, itemsite, warehous, item " "WHERE ( (wo_itemsite_id=itemsite_id)" " AND (itemsite_item_id=item_id)" " AND (itemsite_warehous_id=warehous_id)" " AND (wo_number=:wo_number)" ); if (_showOnlyTopLevel->isChecked()) sql += " AND ( (wo_ordtype<>'W') OR (wo_ordtype IS NULL) )"; sql += ") " "ORDER BY wo_subnumber;"; q.prepare(sql); q.bindValue(":wo_number", _woNumber->text().toInt()); q.exec(); _wo->populate(q); }
sExpression *apply(sExpression *procOrLambda, sExpression *argument, sEnvironment *env){ if(isPrimitiveProc(procOrLambda)) { sProc *cfunc = toProc(procOrLambda); return applyProc(cfunc, argument); } else if(isLambdaType(procOrLambda)) { sLambda *lambd = toLambda(procOrLambda); sList *body = lambd->body; sList *arguments; sList *parameters; if(isList(argument)){ //可変長引数のため parameters = checkParameters(lambd->parameters, toList(argument)); arguments = checkArguments(parameters, toList(argument), lambd->isVarArgument); }else{ parameters = lambd->parameters; arguments = toList(cons(argument, &sNull)); } sEnvironment *env = extendEnvironment(parameters, arguments, lambd->frame); if(isList(car(body))){ return evalSequence(body, env); }else{ return eval(newExp(body, LIST_TAG), env); } } return &sNull; }
void dspBriefSalesHistoryByCustomerType::sFillList() { _sohist->clear(); if (!checkParameters()) return; QString sql( "SELECT custtype_id, custtype_code, cust_name," " cohist_ordernumber, cohist_invcnumber," " formatDate(cohist_orderdate) AS f_orderdate," " formatDate(cohist_invcdate) AS f_invcdate," " SUM(round(cohist_qtyshipped * cohist_unitprice,2)) AS extended," " formatMoney(SUM(round(cohist_qtyshipped * cohist_unitprice,2))) AS f_extended " "FROM cohist, cust, custtype, itemsite, item " "WHERE ( (cohist_itemsite_id=itemsite_id)" " AND (itemsite_item_id=item_id)" " AND (cohist_cust_id=cust_id)" " AND (cust_custtype_id=custtype_id)" " AND (cohist_invcdate BETWEEN :startDate AND :endDate)" ); if (_warehouse->isSelected()) sql += " AND (itemsite_warehous_id=:warehous_id)"; if (_customerType->isSelected()) sql += " AND (custtype_id=:custtype_id)"; else if (_customerType->isPattern()) sql += " AND (custtype_code ~ :custtype_pattern)"; sql += ") " "GROUP BY custtype_id, custtype_code, cust_name," " cohist_ordernumber, cohist_invcnumber," " cohist_orderdate, cohist_invcdate " "ORDER BY cohist_invcdate, cohist_orderdate;"; q.prepare(sql); _dates->bindValue(q); _warehouse->bindValue(q); _customerType->bindValue(q); q.exec(); if (q.first()) { double totalSales = 0.0; do { new XListViewItem( _sohist, _sohist->lastItem(), q.value("custtype_id").toInt(), q.value("custtype_code"), q.value("cust_name"), q.value("cohist_ordernumber"), q.value("cohist_invcnumber"), q.value("f_orderdate"), q.value("f_invcdate"), q.value("f_extended") ); totalSales += q.value("extended").toDouble(); } while (q.next()); new XListViewItem( _sohist, _sohist->lastItem(), -1, "", "", "", "", "", tr("Totals"), formatMoney(totalSales) ); } }
static xbt_dynar_t initDynamicThrottling(int *argc, char *argv[]) { /* Initialize SD */ SD_init(argc, argv); /* Check parameters */ checkParameters(*argc,argv); /* Create environment */ SD_create_environment(argv[1]); /* Load DAX file */ xbt_dynar_t dax = SD_daxload(argv[2]); // createDottyFile(dax, argv[2]); // Schedule DAX fprintf(stdout, "Scheduling DAX...\n"); scheduleDAX(dax); fprintf(stdout, "DAX scheduled\n"); xbt_dynar_t ret = SD_simulate(-1); xbt_dynar_free(&ret); fprintf(stdout, "Simulation end. Time: %f\n", SD_get_clock()); return dax; }
Texture3DResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<0, Texture3D>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; TextureInternalFormat tf; TextureFormat f; PixelType t; Texture::Parameters params; Buffer::Parameters s; int w; int h; int d; try { checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,wrapr,minLod,maxLod,width,height,depth,"); getIntParameter(desc, e, "width", &w); getIntParameter(desc, e, "height", &h); getIntParameter(desc, e, "depth", &d); if (h % d != 0) { if (Logger::ERROR_LOGGER != NULL) { log(Logger::ERROR_LOGGER, desc, e, "Inconsistent 'height' and 'depth' attributes"); } throw exception(); } getParameters(desc, e, tf, f, t); getParameters(desc, e, params); s.compressedSize(desc->getSize()); init(w, h / d, d, tf, f, t, params, s, CPUBuffer(desc->getData())); desc->clearData(); } catch (...) { desc->clearData(); throw exception(); } }
HydroFlowProducerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<30, HydroFlowProducer>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; ptr<TileCache> cache; ptr<GraphProducer> graphs; int displayTileSize = 192; float slip = 1.0f; float searchRadiusFactor = 1.0f; float potentialDelta = 0.01f; int minLevel = 0; checkParameters(desc, e, "name,cache,graphs,displayTileSize,slip,searchRadiusFactor, potentialDelta,minLevel,"); cache = manager->loadResource(getParameter(desc, e, "cache")).cast<TileCache>(); graphs = manager->loadResource(getParameter(desc, e, "graphs")).cast<GraphProducer>(); if (e->Attribute("displayTileSize") != NULL) { getIntParameter(desc, e, "displayTileSize", &displayTileSize); } if (e->Attribute("slip") != NULL) { getFloatParameter(desc, e, "slip", &slip); } if (e->Attribute("searchRadiusFactor") != NULL) { getFloatParameter(desc, e, "searchRadiusFactor", &searchRadiusFactor); } if (e->Attribute("potentialDelta") != NULL) { getFloatParameter(desc, e, "potentialDelta", &potentialDelta); } if (e->Attribute("minLevel") != NULL) { getIntParameter(desc, e, "minLevel", &minLevel); } init(graphs, cache, displayTileSize, slip, searchRadiusFactor, potentialDelta, minLevel); }
void rptCustomerARHistory::sPrint() { if(!checkParameters()) return; ParameterList params; params.append("cust_id", _cust->id()); _dates->appendValue(params); orReport report("CustomerARHistory", params); if (report.isValid()) report.print(); else { report.reportError(this); reject(); } if (_captive) accept(); else { _cust->setId(-1); _cust->setFocus(); } }
void rptSalesHistoryByBilltoName::sPrint() { if(!checkParameters()) return; ParameterList params; params.append("billToName", _billtoName->text().upper().stripWhiteSpace()); _productCategory->appendValue(params); _warehouse->appendValue(params); _dates->appendValue(params); if(_showCosts->isChecked()) params.append("showCosts"); if(_showPrices->isChecked()) params.append("showPrices"); orReport report("SalesHistoryByBilltoName", params); if (report.isValid()) report.print(); else { report.reportError(this); reject(); } if(_captive) accept(); else { _billtoName->clear(); _billtoName->setFocus(); } }
LifeCycleParticleLayerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<50, LifeCycleParticleLayer>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; checkParameters(desc, e, "name,fadeInDelay,fadeOutDelay,activeDelay,unit,"); float fadeInDelay = 5.0f; float fadeOutDelay = 5.0f; float activeDelay = 30.0f; float unit = 1000000.0f; // delays are converted into seconds. if (e->Attribute("unit") != NULL) { if (strcmp(e->Attribute("unit"), "s") == 0) { unit = 1000000.0f; } else if (strcmp(e->Attribute("unit"), "ms") == 0) { unit = 1000.0f; } else if (strcmp(e->Attribute("unit"), "us") == 0) { unit = 10.f; } } //delays are taken in seconds getFloatParameter(desc, e, "fadeInDelay", &fadeInDelay); getFloatParameter(desc, e, "fadeOutDelay", &fadeOutDelay); getFloatParameter(desc, e, "activeDelay", &activeDelay); init(fadeInDelay * unit, activeDelay * unit, fadeOutDelay * unit); }
void dspLaborVarianceByItem::sFillList() { if (!checkParameters()) return; QString sql( "SELECT woopervar_id, formatDate(woopervar_posted)," " woopervar_seqnumber, wrkcnt_code," " formatTime(woopervar_stdsutime)," " formatTime(woopervar_stdrntime)," " formatTime(woopervar_sutime)," " formatTime(woopervar_rntime)," " formattime(woopervar_sutime - woopervar_stdsutime)," " formattime(woopervar_rntime - woopervar_stdrntime) " "FROM woopervar, itemsite, wrkcnt " "WHERE ( (woopervar_parent_itemsite_id=itemsite_id)" " AND (woopervar_wrkcnt_id=wrkcnt_id)" " AND (itemsite_item_id=:item_id)" " AND (woopervar_posted BETWEEN :startDate AND :endDate)" ); if (_warehouse->isSelected()) sql += " AND (itemsite_warehous_id=:warehous_id)"; sql += ") " "ORDER BY woopervar_posted DESC, woopervar_seqnumber;"; q.prepare(sql); _dates->bindValue(q); _warehouse->bindValue(q); q.bindValue(":undefined", tr("Undefined")); q.bindValue(":item_id", _item->id()); q.exec(); _woopervar->populate(q); }
void dspSummarizedSalesBySalesRep::sFillList() { if (!checkParameters()) return; QString sql( "SELECT salesrep_id, (salesrep_number || '-' || salesrep_name)," " formatDate(MIN(cohist_invcdate)), formatDate(MAX(cohist_invcdate))," " formatQty(SUM(cohist_qtyshipped))," " formatMoney(SUM(round(cohist_qtyshipped * cohist_unitprice,2))) " "FROM cohist, itemsite, item, salesrep " "WHERE ( (cohist_itemsite_id=itemsite_id)" " AND (itemsite_item_id=item_id)" " AND (cohist_salesrep_id=salesrep_id)" " AND (cohist_invcdate BETWEEN :startDate AND :endDate)" ); if (_productCategory->isSelected()) sql += " AND (item_prodcat_id=:prodcat_id)"; else if (_productCategory->isPattern()) sql += " AND (item_prodcat_id IN (SELECT prodcat_id FROM prodcat WHERE (prodcat_code ~ :prodcat_pattern)))"; if (_warehouse->isSelected()) sql += " AND (itemsite_warehous_id=:warehous_id)"; sql += ") " "GROUP BY salesrep_number, salesrep_id, salesrep_name"; q.prepare(sql); _warehouse->bindValue(q); _productCategory->bindValue(q); _dates->bindValue(q); q.exec(); _sohist->populate(q); }
bool Client::initialize(int ac, const char **av) { struct sockaddr_in s_in; struct protoent *pe; int port; std::string ip; if (!checkParameters(ac, av, port)) return false; ac < 3 ? ip = "127.0.0.1" : ip = av[4]; if (!(pe = getprotobyname("TCP"))) return false; if ((_fd = socket(AF_INET, SOCK_STREAM, pe->p_proto)) == -1) return false; s_in.sin_family = AF_INET; s_in.sin_port = htons(port); s_in.sin_addr.s_addr = inet_addr(ip.c_str()); std::cout << "Trying to connect with ip : " << ip << " and port : " << port << std::endl; if (connect(_fd, (struct sockaddr *)&s_in, sizeof(s_in)) == -1) { std::cout << "Error : Connection failed\n"; return false; } std::cout << "Connection Success !\n"; return true; }
void dspBookingsByItem::sFillList() { if (!checkParameters()) return; QString sql( "SELECT coitem_id, cohead_number," " formatDate(cohead_orderdate)," " cust_number, cust_name," " formatQty(coitem_qtyord)," " formatSalesPrice(coitem_price)," " formatMoney((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) " "FROM coitem, cohead, cust, itemsite, item " "WHERE ((coitem_cohead_id=cohead_id)" " AND (cohead_cust_id=cust_id)" " AND (coitem_itemsite_id=itemsite_id)" " AND (coitem_status <> 'X')" " AND (itemsite_item_id=item_id)" " AND (item_id=:item_id)" " AND (cohead_orderdate BETWEEN :startDate AND :endDate)" ); if (_warehouse->isSelected()) sql += " AND (itemsite_warehous_id=:warehous_id)"; sql += ") " "ORDER BY cohead_orderdate;"; q.prepare(sql); _warehouse->bindValue(q); _dates->bindValue(q); q.bindValue(":item_id", _item->id()); q.exec(); _soitem->populate(q); }
WaterElevationLayerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<40, WaterElevationLayer> (manager, name, desc) { e = e == NULL ? desc->descriptor : e; ptr<GraphProducer> graphProducer; ptr<TileProducer> elevations; int displayLevel = 0; bool quality = true; bool deform = false; checkParameters(desc, e, "name,graph,renderProg,fillProg,level,cpuElevations,quality,deform,"); string g = getParameter(desc, e, "graph"); graphProducer = manager->loadResource(g).cast<GraphProducer>(); string r = getParameter(desc, e, "cpuElevations"); elevations = manager->loadResource(r).cast<TileProducer>(); if (e->Attribute("level") != NULL) { getIntParameter(desc, e, "level", &displayLevel); } if (e->Attribute("quality") != NULL) { quality = strcmp(e->Attribute("quality"), "true") == 0; } if (e->Attribute("deform") != NULL) { deform = strcmp(e->Attribute("deform"), "true") == 0; } ptr<Program> layerProgram = manager->loadResource(getParameter(desc, e, "renderProg")).cast<Program>(); ptr<Program> fillProg = manager->loadResource(getParameter(desc, e, "fillProg")).cast<Program>(); init(graphProducer, layerProgram, fillProg, elevations, displayLevel, quality, deform); }
void dspSummarizedSalesByCustomerType::sFillList() { _sohist->clear(); if (!checkParameters()) return; QString sql( "SELECT custtype_id, custtype_code, warehous_code," " formatSalesPrice(minprice) AS f_minprice," " formatSalesPrice(maxprice) AS f_maxprice," " formatSalesPrice(avgprice) AS f_avgprice," " formatQty(totalunits) AS f_totalunits," " formatQty(totalsales) AS f_totalsales, totalsales " "FROM ( SELECT custtype_id, custtype_code, warehous_code," " MIN(cohist_unitprice) AS minprice, MAX(cohist_unitprice) AS maxprice," " AVG(cohist_unitprice) AS avgprice, SUM(cohist_qtyshipped) AS totalunits," " SUM(round(cohist_qtyshipped * cohist_unitprice,2)) AS totalsales " " FROM cohist, cust, custtype, itemsite, item, warehous " " WHERE ( (cohist_cust_id=cust_id)" " AND (cust_custtype_id=custtype_id)" " AND (cohist_itemsite_id=itemsite_id)" " AND (itemsite_item_id=item_id)" " AND (itemsite_warehous_id=warehous_id)" " AND (cohist_invcdate BETWEEN :startDate AND :endDate)" ); if (_warehouse->isSelected()) sql += "AND (warehous_id=:warehous_id)"; if (_customerType->isSelected()) sql += " AND (custtype_id=:custtype_id)"; else if (_customerType->isPattern()) sql += " AND (custtype_code ~ :custtype_pattern)"; sql += ") " "GROUP BY custtype_id, custtype_code, warehous_code ) AS data " "ORDER BY custtype_code, warehous_code;"; q.prepare(sql); _warehouse->bindValue(q); _customerType->bindValue(q); _dates->bindValue(q); q.exec(); _sohist->populate(q); if (q.first()) { double totalSales = 0.0; do totalSales += q.value("totalsales").toDouble(); while (q.next()); new XTreeWidgetItem(_sohist, _sohist->topLevelItem(_sohist->topLevelItemCount() - 1), -1, QVariant(tr("Totals")), "", "", "", "", "", formatMoney(totalSales) ); } }
/* call as model = mexsvmlearn(data,labels,options) */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { DOC **docs; /* hold a test example */ double *target; /* hold labels */ WORD *words; /* the words read from the example */ long rows, cols; /* the number of rows and cols in the test data */ double dist, doc_label, costfactor; double *err,*pred; long int correct=0, incorrect=0, none=0,i; MODEL *model; checkParameters(nlhs, plhs, nrhs, prhs); global_init( ); /* load model parameters from the "model" parameter */ model = restore_model((mxArray *)prhs[2]); rows = mxGetM(prhs[0]); cols = mxGetN(prhs[0]); /* load the testing arrays into docs */ mexToDOC((mxArray *)prhs[0], (mxArray *)prhs[1], &docs, &target, NULL, NULL); /* setup output environment */ plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); plhs[1] = mxCreateDoubleMatrix(rows,1,mxREAL); err = mxGetPr(plhs[0]); pred = mxGetPr(plhs[1]); /* classify examples */ for (i = 0; i < rows; i++) { dist = classify_example(model, docs[i]); pred[i] = dist; if (dist > 0) { if (target[i] > 0) correct++; else incorrect++; } else { if (target[i] < 0) correct++; else incorrect++; } if ((int)(0.1+(target[i] * target[i]))!=1) none++; } err[0] = incorrect / (double) rows; global_destroy( ); }
Real blackFormulaImpliedStdDev(Option::Type optionType, Real strike, Real forward, Real blackPrice, Real discount, Real displacement, Real guess, Real accuracy, Natural maxIterations) { checkParameters(strike, forward, displacement); QL_REQUIRE(discount>0.0, "discount (" << discount << ") must be positive"); QL_REQUIRE(blackPrice>=0.0, "option price (" << blackPrice << ") must be non-negative"); // check the price of the "other" option implied by put-call paity Real otherOptionPrice = blackPrice - optionType*(forward-strike)*discount; QL_REQUIRE(otherOptionPrice>=0.0, "negative " << Option::Type(-1*optionType) << " price (" << otherOptionPrice << ") implied by put-call parity. No solution exists for " << optionType << " strike " << strike << ", forward " << forward << ", price " << blackPrice << ", deflator " << discount); // solve for the out-of-the-money option which has // greater vega/price ratio, i.e. // it is numerically more robust for implied vol calculations if (optionType==Option::Put && strike>forward) { optionType = Option::Call; blackPrice = otherOptionPrice; } if (optionType==Option::Call && strike<forward) { optionType = Option::Put; blackPrice = otherOptionPrice; } strike = strike + displacement; forward = forward + displacement; if (guess==Null<Real>()) guess = blackFormulaImpliedStdDevApproximation( optionType, strike, forward, blackPrice, discount, displacement); else QL_REQUIRE(guess>=0.0, "stdDev guess (" << guess << ") must be non-negative"); BlackImpliedStdDevHelper f(optionType, strike, forward, blackPrice/discount); NewtonSafe solver; solver.setMaxEvaluations(maxIterations); Real minSdtDev = 0.0, maxStdDev = 24.0; // 24 = 300% * sqrt(60) Real stdDev = solver.solve(f, accuracy, guess, minSdtDev, maxStdDev); QL_ENSURE(stdDev>=0.0, "stdDev (" << stdDev << ") must be non-negative"); return stdDev; }
UpdateTerrainTaskResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<40, UpdateTerrainTask>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; checkParameters(desc, e, "name,"); string n = getParameter(desc, e, "name"); init(QualifiedName(n)); }
void dspBriefSalesHistoryByCustomer::sFillList() { _sohist->clear(); if (!checkParameters()) return; QString sql( "SELECT cohist_ordernumber, cohist_ponumber, cohist_invcnumber," " formatDate(cohist_orderdate) AS f_orderdate," " formatDate(cohist_invcdate, 'Return') AS f_invcdate," " SUM(round(cohist_qtyshipped * cohist_unitprice,2)) AS extended," " formatMoney(SUM(round(cohist_qtyshipped * cohist_unitprice,2))) AS f_extended " "FROM cohist, itemsite, item " "WHERE ( (cohist_itemsite_id=itemsite_id)" " AND (itemsite_item_id=item_id)" " AND (cohist_invcdate BETWEEN :startDate AND :endDate)" " AND (cohist_cust_id=:cust_id)" ); if (_warehouse->isSelected()) sql += " AND (itemsite_warehous_id=:warehous_id)"; if (_productCategory->isSelected()) sql += " AND (item_prodcat_id=:prodcat_id)"; else if (_productCategory->isPattern()) sql += " AND (item_prodcat_id IN (SELECT prodcat_id FROM prodcat WHERE (prodcat_code ~ :prodcat_pattern)))"; sql += ") " "GROUP BY cohist_ordernumber, cohist_ponumber, cohist_invcnumber," " cohist_orderdate, cohist_invcdate " "ORDER BY cohist_invcdate, cohist_orderdate;"; q.prepare(sql); _dates->bindValue(q); q.bindValue(":cust_id", _cust->id()); _warehouse->bindValue(q); _productCategory->bindValue(q); q.exec(); if (q.first()) { double totalSales = 0.0; XTreeWidgetItem *last = 0; do { last = new XTreeWidgetItem( _sohist, last, -1, q.value("cohist_ordernumber"), q.value("cohist_ponumber"), q.value("cohist_invcnumber"), q.value("f_orderdate"), q.value("f_invcdate"), q.value("f_extended") ); totalSales += q.value("extended").toDouble(); } while (q.next()); XTreeWidgetItem *totals = new XTreeWidgetItem(_sohist, last, -1, QVariant(tr("Totals"))); totals->setText(5, formatMoney(totalSales)); } }
void dspWoHistoryByItem::sFillList() { if (!checkParameters()) return; _wo->clear(); QString sql( "SELECT wo_id," " formatWONumber(wo_id) AS wonumber," " wo_status, warehous_code," " formatQty(wo_qtyord) AS qtyord," " formatQty(wo_qtyrcv) AS qtyrcv," " formatDate(wo_startdate) AS startdate," " formatDate(wo_duedate) AS duedate," " ( (wo_startdate <= CURRENT_DATE) AND (wo_status IN ('O','E','S','R')) ) AS latestart," " (wo_duedate <= CURRENT_DATE) AS latedue," " formatCost(wo_postedvalue) AS value " "FROM wo, itemsite, warehous " "WHERE ((wo_itemsite_id=itemsite_id)" " AND (itemsite_warehous_id=warehous_id)" " AND (itemsite_item_id=:item_id)" " AND (wo_duedate BETWEEN :startDate AND :endDate)" ); if (_showOnlyTopLevel->isChecked()) sql += " AND ( (wo_ordtype<>'W') OR (wo_ordtype IS NULL) )"; if (_warehouse->isSelected()) sql += " AND (itemsite_warehous_id=:warehous_id)"; sql += ") " "ORDER BY wo_startdate DESC, wo_number, wo_subnumber;"; q.prepare(sql); _dates->bindValue(q); _warehouse->bindValue(q); q.bindValue(":item_id", _item->id()); q.exec(); XTreeWidgetItem *last = 0; while (q.next()) { last = new XTreeWidgetItem( _wo, last, q.value("wo_id").toInt(), q.value("wonumber"), q.value("wo_status"), q.value("warehous_code"), q.value("qtyord"), q.value("qtyrcv"), q.value("startdate"), q.value("duedate") ); if (q.value("latestart").toBool()) last->setTextColor(5, "red"); if (q.value("latedue").toBool()) last->setTextColor(6, "red"); if (_showCost->isChecked()) last->setText(7, q.value("value").toString()); } }
RPCMethod::ParameterError::Enum RPCMethod::checkParameters(std::shared_ptr<std::vector<BaseLib::PVariable>> parameters, std::vector<std::vector<BaseLib::VariableType>> types) { RPCMethod::ParameterError::Enum error = RPCMethod::ParameterError::Enum::wrongCount; for(std::vector<std::vector<BaseLib::VariableType>>::iterator i = types.begin(); i != types.end(); ++i) { RPCMethod::ParameterError::Enum result = checkParameters(parameters, *i); if(result == RPCMethod::ParameterError::Enum::noError) return result; if(result != RPCMethod::ParameterError::Enum::wrongCount) error = result; //Priority of type error is higher than wrong count } return error; }
int BaseFilter::performAction() { //check if selected entities are good int check_result = checkSelected(); if (check_result != 1) { throwError(check_result); return check_result; } //if dialog is needed open the dialog int dialog_result = openInputDialog(); if (dialog_result < 1) { if (dialog_result<0) throwError(dialog_result); else dialog_result = 1; //the operation is canceled by the user, no need to throw an error! return dialog_result; } //get the parameters from the dialog getParametersFromDialog(); //are the given parameters ok? int par_status = checkParameters(); if (par_status != 1) { throwError(par_status); return par_status; } //if so go ahead with start() int start_status = start(); if (start_status != 1) { throwError(start_status); return start_status; } //if we have an output dialog is time to show it int out_dialog_result = openOutputDialog(); if (out_dialog_result < 1) { if (out_dialog_result<0) throwError(out_dialog_result); else out_dialog_result = 1; //the operation is canceled by the user, no need to throw an error! return out_dialog_result; //maybe some filter could ask the user if he wants to ac } return 1; }
CPUElevationProducerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) : ResourceTemplate<3, CPUElevationProducer>(manager, name, desc) { e = e == NULL ? desc->descriptor : e; ptr<TileCache> cache; ptr<TileProducer> residuals; checkParameters(desc, e, "name,cache,residuals,"); cache = manager->loadResource(getParameter(desc, e, "cache")).cast<TileCache>(); residuals = manager->loadResource(getParameter(desc, e, "residuals")).cast<TileProducer>(); init(cache, residuals); }
void dspPendingAvailability::sFillList() { if (!checkParameters()) return; _items->clear(); QString sql( "SELECT itemsite_id, bomitem_seqnumber, item_number, item_descrip, uom_name," " pendalloc, (totalalloc + pendalloc) AS totalalloc," " qoh, (qoh + ordered - (totalalloc + pendalloc)) AS totalavail," " reorderlevel," " 'qty' AS pendalloc_xtnumericrole," " 'qty' AS totalalloc_xtnumericrole," " 'qty' AS qoh_xtnumericrole," " 'qty' AS totalavail_xtnumericrole," " CASE WHEN (qoh < pendalloc) THEN 'error' END AS qoh_qtforegroundrole," " CASE WHEN ((qoh + ordered - (totalalloc + pendalloc)) < reorderlevel) THEN 'error'" " WHEN ((qoh + ordered - (totalalloc + pendalloc)) = reorderlevel) THEN 'warning'" " END AS totalavail_qtforegroundrole " "FROM ( SELECT itemsite_id, bomitem_seqnumber, item_number," " (item_descrip1 || ' ' || item_descrip2) AS item_descrip, uom_name," " ((itemuomtouom(bomitem_item_id, bomitem_uom_id, NULL," " (bomitem_qtyfxd + bomitem_qtyper * :buildQty) * (1 + bomitem_scrap)))) AS pendalloc," " qtyAllocated(itemsite_id, DATE(:buildDate)) AS totalalloc," " noNeg(itemsite_qtyonhand) AS qoh," " qtyOrdered(itemsite_id, DATE(:buildDate)) AS ordered," " CASE WHEN(itemsite_useparams) THEN itemsite_reorderlevel ELSE 0.0 END AS reorderlevel" " FROM itemsite, item, bomitem(:item_id), uom " " WHERE ( (bomitem_item_id=itemsite_item_id)" " AND (itemsite_item_id=item_id)" " AND (item_inv_uom_id=uom_id)" " AND (itemsite_warehous_id=:warehous_id)" ); if (_effective->isNull()) sql += " AND (CURRENT_DATE BETWEEN bomitem_effective AND (bomitem_expires-1))) ) AS data "; else sql += " AND (:effective BETWEEN bomitem_effective AND (bomitem_expires-1))) ) AS data "; if (_showShortages->isChecked()) sql += "WHERE ((qoh + ordered - (totalalloc + pendalloc)) < 0) "; sql += "ORDER BY bomitem_seqnumber"; q.prepare(sql); q.bindValue(":buildQty", _qtyToBuild->toDouble()); q.bindValue(":buildDate", _buildDate->date()); q.bindValue(":warehous_id", _warehouse->id()); q.bindValue(":item_id", _item->id()); q.bindValue(":effective", _effective->date()); q.exec(); _items->populate(q); }