// [[Rcpp::depends(BH)]] // [[Rcpp::depends(RcppArmadillo)]] arma::mat intervals(arma::mat& means, const arma::mat& sds, const arma::vec& probs, unsigned int n_ahead) { boost::math::tools::eps_tolerance<double> tol; arma::mat intv(n_ahead, probs.n_elem); for (unsigned int i = 0; i < n_ahead; i++) { double lower = means.col(i).min() - 2 * sds.col(i).max(); double upper = means.col(i).max() + 2 * sds.col(i).max(); for (unsigned int j = 0; j < probs.n_elem; j++) { boost::uintmax_t max_iter = 1000; objective_gaussian f(means.col(i), sds.col(i), probs(j)); std::pair<double, double> r = boost::math::tools::bisect(f, lower, upper, tol, max_iter); if (!tol(r.first, r.second) || (max_iter >= 1000)) { max_iter = 10000; r = boost::math::tools::bisect(f, 1000 * lower, 1000 * upper, tol, max_iter); } intv(i, j) = r.first + (r.second - r.first) / 2.0; lower = intv(i, j); } } return intv; }
void zs_project_to_end_axis(intv_set &_retvalue, zone_set &zs){ intv_set temp; for (auto z : zs){ temp.push_back(intv(-zn_value_bound(z[2]), zn_value_bound(z[6]))); } zs_merge_intervals(_retvalue, temp); }
IntervalVector Affine2Vector::itv() const { assert(!is_empty()); IntervalVector intv(_n); for (int i = 0; i < _n; i++) { intv[i] = (*this)[i].itv(); } return intv; }
TEST(ForeachFilteredIntervalPointNeg, ForeachAlgos) { region_interval intv(5, 3, 7); std::vector<int> expected {4,5,6}; std::vector<int> result; foreach_filtered_interval_point(intv, 15, -4, [&](cv::Point pt) { EXPECT_EQ(5, pt.y); result.push_back(pt.x); }); EXPECT_TRUE(std::equal(expected.begin(), expected.end(), result.begin(), result.end())); }
TEST(ForeachWarpedIntervalPoint, ForeachAlgos) { region_interval intv(5, 10, 15); std::vector<int> expected {12,13,14}; std::vector<int> result; foreach_warped_interval_point(intv, 15, 2, [&](cv::Point pt) { EXPECT_EQ(5, pt.y); result.push_back(pt.x); }); EXPECT_TRUE(std::equal(expected.begin(), expected.end(), result.begin(), result.end())); }
tahoe_ioconf() { register struct device *dp, *mp, *np; register int vba_n, slave; FILE *fp; fp = fopen(path("ioconf.c"), "w"); if (fp == 0) { perror(path("ioconf.c")); exit(1); } fprintf(fp, "#include \"sys/param.h\"\n"); fprintf(fp, "#include \"tahoe/include/pte.h\"\n"); fprintf(fp, "#include \"sys/buf.h\"\n"); fprintf(fp, "#include \"sys/map.h\"\n"); fprintf(fp, "\n"); fprintf(fp, "#include \"tahoe/vba/vbavar.h\"\n"); fprintf(fp, "\n"); fprintf(fp, "#define C (caddr_t)\n\n"); /* * Now generate interrupt vectors for the versabus */ for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (mp == 0 || mp == TO_NEXUS || !eq(mp->d_name, "vba")) continue; if (dp->d_vec != 0) { struct idlst *ip; fprintf(fp, "extern struct vba_driver %sdriver;\n", dp->d_name); fprintf(fp, "extern "); ip = dp->d_vec; for (;;) { fprintf(fp, "X%s%d()", ip->id, dp->d_unit); ip = ip->id_next; if (ip == 0) break; fprintf(fp, ", "); } fprintf(fp, ";\n"); fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name, dp->d_unit); ip = dp->d_vec; for (;;) { fprintf(fp, "X%s%d", ip->id, dp->d_unit); ip = ip->id_next; if (ip == 0) break; fprintf(fp, ", "); } fprintf(fp, ", 0 } ;\n"); } else if (dp->d_type == DRIVER) /* devices w/o interrupts */ fprintf(fp, "extern struct vba_driver %sdriver;\n", dp->d_name); } fprintf(fp, "\nstruct vba_ctlr vbminit[] = {\n"); fprintf(fp, "/*\t driver,\tctlr,\tvbanum,\talive,\tintr,\taddr */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 || !eq(mp->d_name, "vba")) continue; if (dp->d_vec == 0) { printf("must specify vector for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr == 0) { printf("must specify csr address for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) { printf("drives need their own entries; dont "); printf("specify drive or slave for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_flags) { printf("controllers (e.g. %s%d) ", dp->d_name, dp->d_unit); printf("don't have flags, only devices do\n"); continue; } fprintf(fp, "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0x%x },\n", dp->d_name, dp->d_unit, qu(mp->d_unit), dp->d_name, dp->d_unit, dp->d_addr); } fprintf(fp, "\t0\n};\n"); /* versabus devices */ fprintf(fp, "\nstruct vba_device vbdinit[] = {\n"); fprintf(fp, "\t/* driver, unit, ctlr, vbanum, slave, intr, addr, dk, flags*/\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 || mp == TO_NEXUS || mp->d_type == MASTER || eq(mp->d_name, "mba")) continue; np = mp->d_conn; if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba")) continue; np = 0; if (eq(mp->d_name, "vba")) { if (dp->d_vec == 0) printf( "Warning, no interrupt vector specified for device %s%d\n", dp->d_name, dp->d_unit); if (dp->d_addr == 0) { printf("must specify csr for device %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) { printf("drives/slaves can be specified "); printf("only for controllers, "); printf("not for device %s%d\n", dp->d_name, dp->d_unit); continue; } vba_n = mp->d_unit; slave = QUES; } else { if ((np = mp->d_conn) == 0) { printf("%s%d isn't connected to anything ", mp->d_name, mp->d_unit); printf(", so %s%d is unattached\n", dp->d_name, dp->d_unit); continue; } vba_n = np->d_unit; if (dp->d_drive == UNKNOWN) { printf("must specify ``drive number'' "); printf("for %s%d\n", dp->d_name, dp->d_unit); continue; } /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */ /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */ if (dp->d_slave != UNKNOWN) { printf("slave numbers should be given only "); printf("for massbus tapes, not for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_vec != 0) { printf("interrupt vectors should not be "); printf("given for drive %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr != 0) { printf("csr addresses should be given only "); printf("on controllers, not on %s%d\n", dp->d_name, dp->d_unit); continue; } slave = dp->d_drive; } fprintf(fp, "\t{ &%sdriver, %2d, %s,", eq(mp->d_name, "vba") ? dp->d_name : mp->d_name, dp->d_unit, eq(mp->d_name, "vba") ? " -1" : qu(mp->d_unit)); fprintf(fp, " %s, %2d, %s, C 0x%-6x, %d, 0x%x },\n", qu(vba_n), slave, intv(dp), dp->d_addr, dp->d_dk, dp->d_flags); } fprintf(fp, "\t0\n};\n"); pseudo_ioconf(fp); (void) fclose(fp); }
vax_ioconf() { register struct device *dp, *mp, *np; register int uba_n, slave; FILE *fp; fp = fopen(path("ioconf.c"), "w"); if (fp == 0) { perror(path("ioconf.c")); exit(1); } fprintf(fp, "#include \"vax/include/pte.h\"\n"); fprintf(fp, "#include \"sys/param.h\"\n"); fprintf(fp, "#include \"sys/buf.h\"\n"); fprintf(fp, "#include \"sys/map.h\"\n"); fprintf(fp, "\n"); fprintf(fp, "#include \"vax/mba/mbavar.h\"\n"); fprintf(fp, "#include \"vax/uba/ubavar.h\"\n\n"); fprintf(fp, "\n"); fprintf(fp, "#define C (caddr_t)\n\n"); /* * First print the mba initialization structures */ if (seen_mba) { for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (mp == 0 || mp == TO_NEXUS || !eq(mp->d_name, "mba")) continue; fprintf(fp, "extern struct mba_driver %sdriver;\n", dp->d_name); } fprintf(fp, "\nstruct mba_device mbdinit[] = {\n"); fprintf(fp, "\t/* Device, Unit, Mba, Drive, Dk */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_unit == QUES || mp == 0 || mp == TO_NEXUS || !eq(mp->d_name, "mba")) continue; if (dp->d_addr) { printf("can't specify csr address on mba for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_vec != 0) { printf("can't specify vector for %s%d on mba\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive == UNKNOWN) { printf("drive not specified for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_slave != UNKNOWN) { printf("can't specify slave number for %s%d\n", dp->d_name, dp->d_unit); continue; } fprintf(fp, "\t{ &%sdriver, %d, %s,", dp->d_name, dp->d_unit, qu(mp->d_unit)); fprintf(fp, " %s, %d },\n", qu(dp->d_drive), dp->d_dk); } fprintf(fp, "\t0\n};\n\n"); /* * Print the mbsinit structure * Driver Controller Unit Slave */ fprintf(fp, "struct mba_slave mbsinit [] = {\n"); fprintf(fp, "\t/* Driver, Ctlr, Unit, Slave */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { /* * All slaves are connected to something which * is connected to the massbus. */ if ((mp = dp->d_conn) == 0 || mp == TO_NEXUS) continue; np = mp->d_conn; if (np == 0 || np == TO_NEXUS || !eq(np->d_name, "mba")) continue; fprintf(fp, "\t{ &%sdriver, %s", mp->d_name, qu(mp->d_unit)); fprintf(fp, ", %2d, %s },\n", dp->d_unit, qu(dp->d_slave)); } fprintf(fp, "\t0\n};\n\n"); } /* * Now generate interrupt vectors for the unibus */ for (dp = dtab; dp != 0; dp = dp->d_next) { if (dp->d_vec != 0) { struct idlst *ip; mp = dp->d_conn; if (mp == 0 || mp == TO_NEXUS || (!eq(mp->d_name, "uba") && !eq(mp->d_name, "bi"))) continue; fprintf(fp, "extern struct uba_driver %sdriver;\n", dp->d_name); fprintf(fp, "extern "); ip = dp->d_vec; for (;;) { fprintf(fp, "X%s%d()", ip->id, dp->d_unit); ip = ip->id_next; if (ip == 0) break; fprintf(fp, ", "); } fprintf(fp, ";\n"); fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name, dp->d_unit); ip = dp->d_vec; for (;;) { fprintf(fp, "X%s%d", ip->id, dp->d_unit); ip = ip->id_next; if (ip == 0) break; fprintf(fp, ", "); } fprintf(fp, ", 0 } ;\n"); } } fprintf(fp, "\nstruct uba_ctlr ubminit[] = {\n"); fprintf(fp, "/*\t driver,\tctlr,\tubanum,\talive,\tintr,\taddr */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 || !eq(mp->d_name, "uba")) continue; if (dp->d_vec == 0) { printf("must specify vector for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr == 0) { printf("must specify csr address for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) { printf("drives need their own entries; dont "); printf("specify drive or slave for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_flags) { printf("controllers (e.g. %s%d) ", dp->d_name, dp->d_unit); printf("don't have flags, only devices do\n"); continue; } fprintf(fp, "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0%o },\n", dp->d_name, dp->d_unit, qu(mp->d_unit), dp->d_name, dp->d_unit, dp->d_addr); } fprintf(fp, "\t0\n};\n"); /* unibus devices */ fprintf(fp, "\nstruct uba_device ubdinit[] = {\n"); fprintf(fp, "\t/* driver, unit, ctlr, ubanum, slave, intr, addr, dk, flags*/\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 || mp == TO_NEXUS || mp->d_type == MASTER || eq(mp->d_name, "mba")) continue; np = mp->d_conn; if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba")) continue; np = 0; if (eq(mp->d_name, "uba")) { if (dp->d_vec == 0) { printf("must specify vector for device %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr == 0) { printf("must specify csr for device %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) { printf("drives/slaves can be specified "); printf("only for controllers, "); printf("not for device %s%d\n", dp->d_name, dp->d_unit); continue; } uba_n = mp->d_unit; slave = QUES; } else { if ((np = mp->d_conn) == 0) { printf("%s%d isn't connected to anything ", mp->d_name, mp->d_unit); printf(", so %s%d is unattached\n", dp->d_name, dp->d_unit); continue; } uba_n = np->d_unit; if (dp->d_drive == UNKNOWN) { printf("must specify ``drive number'' "); printf("for %s%d\n", dp->d_name, dp->d_unit); continue; } /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */ /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */ if (dp->d_slave != UNKNOWN) { printf("slave numbers should be given only "); printf("for massbus tapes, not for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_vec != 0) { printf("interrupt vectors should not be "); printf("given for drive %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr != 0) { printf("csr addresses should be given only "); printf("on controllers, not on %s%d\n", dp->d_name, dp->d_unit); continue; } slave = dp->d_drive; } fprintf(fp, "\t{ &%sdriver, %2d, %s,", eq(mp->d_name, "uba") ? dp->d_name : mp->d_name, dp->d_unit, eq(mp->d_name, "uba") ? " -1" : qu(mp->d_unit)); fprintf(fp, " %s, %2d, %s, C 0%-6o, %d, 0x%x },\n", qu(uba_n), slave, intv(dp), dp->d_addr, dp->d_dk, dp->d_flags); } fprintf(fp, "\t0\n};\n"); pseudo_ioconf(fp); (void) fclose(fp); }
int ConfigIni::intv(const string prop) { return intv(prop, -1); }
//vis_effect -v _validation_set_ -r _attr_file_ -f _feature_ [-m _model_file_name_] [-o _output_file_name_] //[-q _#quantile_values_] int main(int argc, char* argv[]) { try{ //0. Set log file LogStream clog; clog << "\n-----\nvis_effect "; for(int argNo = 1; argNo < argc; argNo++) clog << argv[argNo] << " "; clog << "\n\n"; //1. Set default values of parameters string modelFName = "model.bin"; //name of the input file for the model string outFName; //name of the output file for predictions int quantN = 10; //number of quantile point values to plot TrainInfo ti; string attrName; // partial dependence attribute name //2. Set parameters from command line //check that the number of arguments is even (flags + value pairs) if(argc % 2 == 0) throw INPUT_ERR; //convert input parameters to string from char* stringv args(argc); for(int argNo = 0; argNo < argc; argNo++) args[argNo] = string(argv[argNo]); //parse and save input parameters //indicators of presence of required flags in the input bool hasVal = false; bool hasAttr = false; bool hasFeature = false; for(int argNo = 1; argNo < argc; argNo += 2) { if(!args[argNo].compare("-m")) modelFName = args[argNo + 1]; else if(!args[argNo].compare("-o")) outFName = args[argNo + 1]; else if(!args[argNo].compare("-v")) { ti.validFName = args[argNo + 1]; hasVal = true; } else if(!args[argNo].compare("-r")) { ti.attrFName = args[argNo + 1]; hasAttr = true; } else if(!args[argNo].compare("-f")) { attrName = args[argNo + 1]; hasFeature = true; } else if(!args[argNo].compare("-q")) quantN = atoi(argv[argNo + 1]); else throw INPUT_ERR; } if(!(hasVal && hasAttr && hasFeature)) throw INPUT_ERR; //2. Load data INDdata data(ti.trainFName.c_str(), ti.validFName.c_str(), ti.testFName.c_str(), ti.attrFName.c_str()); CGrove::setData(data); CTreeNode::setData(data); int attrId = data.getAttrId(attrName); if(!data.isActive(attrId)) throw ATTR_NAME_ERR; //3. Calculate and output data for feature effect plot outEffects(data, intv(1,attrId), quantN, modelFName, outFName); if(outFName.size() == 0) outFName = attrName + ".effect.txt"; clog << "Partial dependence function values are saved into file " << outFName << ".\n"; }catch(TE_ERROR err){ te_errMsg((TE_ERROR)err); return 1; }catch(AG_ERROR err){ ErrLogStream errlog; switch(err) { case INPUT_ERR: errlog << "Usage: -v _validation_set_ -r _attr_file_ -f _feature_ [-m _model_file_name_] " << "[-o _output_file_name_] [-q _#quantile_values_]\n"; break; case ATTR_NAME_ERR: errlog << "Error: attribute name misspelled or the attribute is not active.\n"; break; default: throw err; } return 1; }catch(exception &e){ ErrLogStream errlog; string errstr(e.what()); errlog << "Error: " << errstr << "\n"; return 1; }catch(...){ string errstr = strerror(errno); ErrLogStream errlog; errlog << "Error: " << errstr << "\n"; return 1; } return 0; }
static void ra2ppm2( /* convert Radiance picture to Pixmap (2-byte) */ int binary, int grey ) { COLOR *scanin; double mult, d; register int x; int y; /* allocate scanline */ scanin = (COLOR *)malloc(xmax*sizeof(COLOR)); if (scanin == NULL) quiterr("out of memory in ra2ppm2"); if (bradj) mult = pow(2., (double)bradj); /* convert image */ for (y = ymax-1; y >= 0; y--) { if (freadscan(scanin, xmax, stdin) < 0) quiterr("error reading Radiance picture"); for (x = bradj?xmax:0; x--; ) scalecolor(scanin[x], mult); for (x = grey?xmax:0; x--; ) colval(scanin[x],GRN) = bright(scanin[x]); d = 1./gamcor; for (x = (d>1.01)|(d<0.99)?xmax:0; x--; ) { colval(scanin[x],GRN) = pow(colval(scanin[x],GRN), d); if (!grey) { colval(scanin[x],RED) = pow(colval(scanin[x],RED), d); colval(scanin[x],BLU) = pow(colval(scanin[x],BLU), d); } } if (grey) if (binary) for (x = 0; x < xmax; x++) putby2(intv(colval(scanin[x],GRN)), stdout); else for (x = 0; x < xmax; x++) printf("%u\n", intv(colval(scanin[x],GRN))); else if (binary) for (x = 0; x < xmax; x++) { putby2(intv(colval(scanin[x],RED)), stdout); putby2(intv(colval(scanin[x],GRN)), stdout); putby2(intv(colval(scanin[x],BLU)), stdout); } else for (x = 0; x < xmax; x++) printf("%u %u %u\n", intv(colval(scanin[x],RED)), intv(colval(scanin[x],GRN)), intv(colval(scanin[x],BLU))); if (ferror(stdout)) quiterr("error writing Pixmap"); } /* free scanline */ free((void *)scanin); }