Example #1
0
void kmeans::process(const dataset & p_data, const index_sequence & p_indexes, cluster_data & p_result) {
    m_ptr_data = &p_data;
    m_ptr_indexes = &p_indexes;

    m_ptr_result = (kmeans_data *) &p_result;

    if (p_data[0].size() != m_initial_centers[0].size()) {
        throw std::invalid_argument("Dimension of the input data and dimension of the initial cluster centers must be the same.");
    }

    m_ptr_result->centers().assign(m_initial_centers.begin(), m_initial_centers.end());

    if (m_ptr_result->is_observed()) {
        cluster_sequence sequence;
        update_clusters(m_initial_centers, sequence);

        m_ptr_result->evolution_centers().push_back(m_initial_centers);
        m_ptr_result->evolution_clusters().push_back(sequence);
    }

    double current_change = std::numeric_limits<double>::max();

    for(std::size_t iteration = 0; iteration < m_itermax && current_change > m_tolerance; iteration++) {
        update_clusters(m_ptr_result->centers(), m_ptr_result->clusters());
        current_change = update_centers(m_ptr_result->clusters(), m_ptr_result->centers());

        if (m_ptr_result->is_observed()) {
            m_ptr_result->evolution_centers().push_back(m_ptr_result->centers());
            m_ptr_result->evolution_clusters().push_back(m_ptr_result->clusters());
        }
    }

    calculate_total_wce();
}
Example #2
0
void xmeans::improve_parameters(std::vector<std::vector<unsigned int> *> * improved_clusters, std::vector<std::vector<double> > * improved_centers, const std::vector<unsigned int> * const available_indexes) {
	double current_change = std::numeric_limits<double>::max();

	while(current_change > tolerance) {
		update_clusters(improved_clusters, improved_centers, available_indexes);
		current_change = update_centers(improved_clusters, improved_centers);
	}
}
Example #3
0
void kmeans::process(void) {
	double current_change = std::numeric_limits<double>::max();

	while(current_change > tolerance) {
		update_clusters();
		current_change = update_centers();
	}
}
void pi_pi_eng(struct atomgrp *ag, double *energy, struct pi_pi_setup *pps_rec,
		struct pi_pi_setup *pps_lig, double weight)
{
	update_centers(pps_rec, ag);
	update_centers(pps_lig, ag);

	for (int i = 0; i < pps_rec->npseudoatoms; i++) {
		struct pi_pi_pseudoatom *par = &(pps_rec->pseudoatoms[i]);
		for (int j = 0; j < pps_lig->npseudoatoms; j++) {
			struct pi_pi_pseudoatom *pal = &(pps_lig->pseudoatoms[j]);
			double dsq = _mol_sq(par->center.X - pal->center.X) +
				_mol_sq(par->center.Y - pal->center.Y) +
				_mol_sq(par->center.Z - pal->center.Z);

			if (dsq < (PI_PI_DIST_CUTOFF * PI_PI_DIST_CUTOFF)) {
				//fprintf(stderr, "%f\n", dsq);
				(*energy) += pi_pi_pairwise_eng(ag, par, pal, weight);
			}
		}
	}

}