//begin public methods unsigned int Random::calibrate(){ unsigned int* bins = (unsigned int*)malloc(BINS_SIZE * sizeof(unsigned int)); //set all value counts to zero for(int i = 0; i < BINS_SIZE; i++) { bins[i] = 0; } //loop until i equals the calibration sample size for(unsigned int i = 0; i < CALIBRATION_SIZE; i++) { //get a sample byte adc_byte = read_input(); //add one count to the bin of the sample value bins[adc_byte]++; } //find the threshold _threshold = find_threshold(bins); free(bins); return _threshold; }
int main(int argc, char ** argv) { // argument parsing if (argc < 2) { std::cout << "Usage: " << argv[0] << " mb" << std::endl; return 1; } tpie::sysinfo si; std::cout << si << '\n'; size_t mb; std::stringstream ss(argv[1]); ss >> mb; std::cout << si.custominfo("Data (MB)", mb) << std::endl; std::vector<test_t> data(mb*1024*1024/sizeof(test_t)); // program tpie::tpie_init(); size_t center = thresholdMax/2; size_t radius = thresholdMax/2; do { center = find_threshold(center, radius, data); radius = radius/2; } while (radius >= thresholdInc); tpie::tpie_finish(); return 0; }
static ssize_t store_volt_thres(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { unsigned long volt; int pos, ret; struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); if (kstrtoul(buf, 10, &volt)) return -EINVAL; pos = find_threshold(volt_thresholds, volt); if (pos < 0) return -EINVAL; /* * The voltage thresholds are in descending order in VWARN*_CFG * registers. So calculate 'pos' by substracting from NUM_THRESHOLDS. */ pos = NUM_THRESHOLDS - pos - 1; /* * Since VWARN*_CFG are consecutive registers, calculate the * required register address using s_attr->nr. */ ret = set_threshold(VWARN1_CFG + s_attr->nr, pos); return ret ? ret : count; }
static ssize_t store_curr_thres(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { unsigned long curnt; int pos, ret; struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); if (kstrtoul(buf, 10, &curnt)) return -EINVAL; pos = find_threshold(curr_thresholds, curnt); if (pos < 0) return -EINVAL; /* * Since VCC_CFG and VNN_CFG are consecutive registers, calculate the * required register address using s_attr->nr. */ ret = set_threshold(MAXVCC_CFG + s_attr->nr, pos); return ret ? ret : count; }
/* * Make an initial guess about the key */ void first_guess(timing_data * data, unsigned char * key_guess){ int i, j, u, v; int votes[KEY_LENGTH][256]; memset(votes, 0, sizeof(votes)); for(i = 0; i < KEY_LENGTH; i++) for(j = i + 1; j < KEY_LENGTH; j++){ if( i % 4 == j % 4){ double x = find_threshold(VOTE_LIMIT, data->cost[i][j], 0, 255, 0, 255); for(u = 0; u < 256; u++) for(v = 0; v < 256; v++) if(data->cost[i][j][u][v] < x){ votes[i][u]++; votes[j][v]++; } } } for(i = 0; i < KEY_LENGTH; i++){ u = find_max(votes[i], 256); key_guess[i] = u; } }
KdTreeNode* KdTree::build(size_t* index_list, size_t index_size, size_t depth) { // end of recursion if (index_size == 0) return NULL; // create new node KdTreeNode* node = new KdTreeNode(); // reach max depht or only one point left // then set as leaf if (index_size == 1 || depth >= MAX_TREE_DEPTH) { // set node type node->type = KdTreeNodeType::LEAF; // store references or points node->left.data_size = index_size; node->right.data_ref = new size_t[index_size]; for (size_t i = 0; i < index_size; ++i) node->right.data_ref[i] = index_list[i]; return node; } // set node type node->type = KdTreeNodeType::BRANCH; // find splitting axis node->split_axis = find_longest_axis(index_list, index_size); // find the threshold node->threshold = find_threshold(index_list, index_size, node->split_axis); // find reference data for left and right nodes std::vector<size_t> left_data_list; std::vector<size_t> right_data_list; for (size_t i = 0; i < index_size; ++i) { if (data_list[index_list[i]]->get_val(node->split_axis) < node->threshold) left_data_list.push_back(index_list[i]); else right_data_list.push_back(index_list[i]); } // copy the size of the data size_t left_index_size = left_data_list.size(); size_t right_index_size = right_data_list.size(); // create index_list for left and right nodes // overwrite the index_list size_t* left_index_list = index_list; size_t* right_index_list = index_list + left_index_size; // copy to new value list to new data_list for (size_t i = 0; i < left_index_size; ++i) left_index_list[i] = left_data_list[i]; for (size_t i = 0; i < right_index_size; ++i) right_index_list[i] = right_data_list[i]; // recursive node->left.node = build(left_index_list, left_index_size, depth + 1); node->right.node = build(right_index_list, right_index_size, depth + 1); return node; }
EdgeSet MSConnectivityScore::get_connected_pairs() const { NNGraph g = find_threshold(); EdgeSet edges = get_all_edges(g); return edges; }
int main (int argc, char **argv) { heapelement_t **CDheap=NULL; hashelement_t **CDhash=NULL; phnhashelement_t **CIhash=NULL; dicthashelement_t **dicthash=NULL; int32 cilistsize=0, cdheapsize=0, threshold, tph_list_given, ncd; char *phnlist, *incimdef, *triphnlist, *incdmdef; char *lsnfile, *dictfn, *fillerdictfn, **CIlist=NULL; char *cimdeffn, *alltphnmdeffn, *untiedmdeffn, *countfn; parse_cmd_ln(argc,argv); /* Test all flags before beginning */ cimdeffn = (char *)cmd_ln_access("-ocimdef"); alltphnmdeffn = (char *)cmd_ln_access("-oalltphnmdef"); untiedmdeffn = (char *)cmd_ln_access("-ountiedmdef"); countfn = (char *)cmd_ln_access("-ocountfn"); if (cimdeffn) E_INFO("Will write CI mdef file %s\n",cimdeffn); if (alltphnmdeffn) E_INFO("Will write alltriphone mdef file %s\n",alltphnmdeffn); if (untiedmdeffn) E_INFO("Will write untied mdef file %s\n",untiedmdeffn); if (countfn) E_INFO("Will write triphone counts file %s\n",countfn); if (!cimdeffn && !alltphnmdeffn && !untiedmdeffn && !countfn) E_FATAL("No output mdef files or count files specified!\n"); dictfn = (char *)cmd_ln_access("-dictfn"); fillerdictfn = (char *)cmd_ln_access("-fdictfn"); lsnfile = (char*)cmd_ln_access("-lsnfn"); if ((untiedmdeffn || countfn) && (!lsnfile || !dictfn)) { E_WARN("Either dictionary or transcript file not given!\n"); if (untiedmdeffn) E_WARN("Untied mdef will not be made\n"); if (countfn) E_WARN("Phone counts will not be generated\n"); untiedmdeffn = countfn = NULL; } phnlist = (char *)cmd_ln_access("-phnlstfn"); triphnlist = (char *)cmd_ln_access("-triphnlstfn"); incimdef = (char *)cmd_ln_access("-inCImdef"); incdmdef = (char *)cmd_ln_access("-inCDmdef"); if (!incdmdef && !incimdef && !phnlist && !triphnlist) E_FATAL("No input mdefs or phone list given\n"); if (triphnlist) { if (phnlist) E_WARN("Both -triphnlist %s and -phnlist given.\n",triphnlist); E_WARN("Ignoring -phnlist %s\n",phnlist); phnlist = triphnlist; } tph_list_given = (triphnlist || incdmdef) ? 1 : 0; if (incdmdef) { if (incimdef || phnlist){ E_WARN("Using only input CD mdef %s!\n",incdmdef); E_WARN("Using only triphones from input CD mdef %s!\n",incdmdef); if (incimdef) E_WARN("CImdef %s will be ignored\n",incimdef); if (phnlist) E_WARN("phonelist %s will be ignored\n",phnlist); incimdef = phnlist = NULL; } make_ci_list_cd_hash_frm_mdef(incdmdef,&CIlist,&cilistsize, &CDhash,&ncd); } else{ if (phnlist) make_ci_list_cd_hash_frm_phnlist(phnlist,&CIlist, &cilistsize,&CDhash,&ncd); if (incimdef) { if (CIlist) ckd_free_2d((void**)CIlist); make_ci_list_frm_mdef(incimdef,&CIlist,&cilistsize); } } if (cimdeffn) make_mdef_from_list(cimdeffn,CIlist,cilistsize,NULL,0,argv[0]); if (!tph_list_given && !cimdeffn) { read_dict(dictfn, fillerdictfn, &dicthash); if (CDhash) freehash(CDhash); make_dict_triphone_list (dicthash, &CDhash); } if (alltphnmdeffn){ threshold = -1; make_CD_heap(CDhash,threshold,&CDheap,&cdheapsize); make_mdef_from_list(alltphnmdeffn,CIlist,cilistsize, CDheap,cdheapsize,argv[0]); } if (countfn || untiedmdeffn) count_triphones(lsnfile, dicthash, CDhash, &CIhash); if (countfn){ print_counts(countfn,CIhash,CDhash); } if (untiedmdeffn){ threshold = find_threshold(CDhash); make_CD_heap(CDhash,threshold,&CDheap,&cdheapsize); make_mdef_from_list(untiedmdeffn,CIlist,cilistsize, CDheap,cdheapsize,argv[0]); } return 0; }