예제 #1
0
파일: terminal-vga.c 프로젝트: etel/ponyos
void
term_write_char(
		uint32_t val,
		uint16_t x,
		uint16_t y,
		uint32_t fg,
		uint32_t bg,
		uint8_t flags
		) {
	if (val > 128) val = ununicode(val);
	if (fg > 256) {
		fg = best_match(fg);
	}
	if (bg > 256) {
		bg = best_match(bg);
	}
	if (fg > 16) {
		fg = vga_colors[fg];
	}
	if (bg > 16) {
		bg = vga_colors[bg];
	}
	if (fg == 16) fg = 0;
	if (bg == 16) bg = 0;
	placech(val, x, y, (vga_to_ansi[fg] & 0xF) | (vga_to_ansi[bg] << 4));
}
void OptimizedSelectionSGP::iteration(const Dataset& train, const Dataset& test)
{
        Population* new_pop = new Population();

        // Elitism: adding best solution to new population
        unsigned int best_index = cur_pop->best(train).first;
        new_pop->add_solution(new Individual((*cur_pop)[best_index]));

        for (unsigned int i = 1; i < pop_size && budget > 0; ++i)
        {
                double coin = ((double) rand() / RAND_MAX);
                if (coin < mut_rate || budget < pop_size)
                {
                        std::vector<unsigned int> selected = selection(1, train);
                        new_pop->add_solution(mutation((*cur_pop)[selected[0]], train, test));
                }
                else
                {
                        std::vector<unsigned int> selected = selection(1, train);
			Individual ind2 = best_match((*cur_pop)[selected[0]], train);
                        new_pop->add_solution(crossover((*cur_pop)[selected[0]], ind2, train, test));
			budget -= pop_size;
                }
        }

        delete cur_pop;
        cur_pop = new_pop;
}
예제 #3
0
    vector<DMatch> points(
        vector<pair<int, int> > edge_matches,
        Mat &desc1, Mat &desc2,
        vector<vector<int> > &edges1, vector<vector<int> > &edges2,
        double th, double sigma = 0.5
    ) {
        vector<DMatch> matches;
        set<pair<int, int> > S;
        for (size_t i = 0; i < edge_matches.size(); i++) {
            int base_edge_idx = edge_matches[i].first;
            int ref_edge_idx  = edge_matches[i].second;
            vector<Mat> des_1(3), des_2(3);
            for (int k = 0; k < 3; k++) {
                des_1[k] = desc1.row(edges1[base_edge_idx][k]);
                des_2[k] = desc2.row(edges2[ref_edge_idx][k]);
            }

            vector<int> best_match(3);
            vector<double> best_sim(3, -1E30);
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    double _sim = exp(-sum(abs(des_1[j] - des_2[k]))[0] / sigma);

                    if (_sim > best_sim[j]) {
                        best_sim[j] = _sim;
                        best_match[j] = k;
                    }
                }
            }

            for (int j = 0; j < 3; j++) {
                int k = best_match[j];

                int qI = edges1[base_edge_idx][j];
                int tI = edges2[ref_edge_idx][k];

                if (!S.count(make_pair(qI, tI)) && best_sim[j] > th) {
                    double _dist = -sigma * log(best_sim[j]);
                    matches.push_back(DMatch(qI, tI, _dist));
                    S.insert(make_pair(qI, tI));
                }
            }
        }
        return matches;
    }
예제 #4
0
// ////////////////////////////////////////////////////////////////////////////
bool ResolveDll(const std::string &dll_name,
	LocateDllPredicate &dll_predicate, std::string &full_dll_name)
{
	if ((dll_predicate.SearchStartUpDir()) &&
		LocateDll(GetStartUpDirectory(), dll_name, dll_predicate,
		full_dll_name) && (!dll_predicate.IsGlobalPredicate()))
		return(true);

	if ((dll_predicate.SearchCurrentDir()) &&
		LocateDll(OS_GetCurrentDirectory(), dll_name, dll_predicate,
		full_dll_name) && (!dll_predicate.IsGlobalPredicate()))
		return(true);

	if ((dll_predicate.SearchSystemDir()) &&
		LocateDll(OS_GetSystemDirectory(), dll_name, dll_predicate,
		full_dll_name) && (!dll_predicate.IsGlobalPredicate()))
		return(true);

	if ((dll_predicate.SearchWindowsDir()) &&
		LocateDll(OS_GetWindowsDirectory(), dll_name, dll_predicate,
		full_dll_name) && (!dll_predicate.IsGlobalPredicate()))
		return(true);

	MLB::Utility::StringVector dll_list;

	if (LocateDll(LocateDllInPath(dll_name, dll_list), dll_predicate,
		full_dll_name) && (!dll_predicate.IsGlobalPredicate()))
		return(true);

	std::string best_match(dll_predicate.GetBestMatch().file_name_);

	if (!best_match.empty())
		full_dll_name.swap(best_match);
	else
		full_dll_name.clear();

	return(!full_dll_name.empty());
}