const char* CalculateWeights(double GeneCutoff, double GeneExponent, char GeneDist, double ArrayCutoff, double ArrayExponent, char ArrayDist) { double* geneweight = NULL; double* arrayweight = NULL; if (GeneCutoff && GeneExponent && GeneDist) { geneweight = calculate_weights(_rows, _columns, _data, _mask, _arrayweight, 0, GeneDist, GeneCutoff, GeneExponent); if (!geneweight) return "Insufficient memory to calculate the row weights"; } if (ArrayCutoff && ArrayExponent && ArrayDist) { arrayweight = calculate_weights(_rows, _columns, _data, _mask, _geneweight, 1, ArrayDist, ArrayCutoff, ArrayExponent); if (!arrayweight) { if (geneweight) free(geneweight); return "Insufficient memory to calculate the column weights"; } } if (geneweight) { free(_geneweight); _geneweight = geneweight; } if (arrayweight) { free(_arrayweight); _arrayweight = arrayweight; } return NULL; }
bool lowest(const ContainerType& x, const ContainerType& y, size_t n, ValueType current_x, //xs ValueType& ys, size_t nleft, size_t nright, ContainerType& weights, // vector w bool use_resid_weights, // userw const ContainerType& resid_weights) { ValueType h; size_t nrt; // rightmost pt (may be greater than nright because of ties) h = std::max(current_x - x[nleft], x[nright] - current_x); // Calculate the weights for the regression in this neighborhood. // Determine if at least some weights are positive, so a regression // is ok. bool fit_ok = calculate_weights(x, n, current_x, use_resid_weights, nleft, resid_weights, weights, nrt, h); if (!fit_ok) { return fit_ok; } // If it is ok to fit, run the weighted least squares regression calculate_y_fit(x, y, current_x, n, nleft, nrt, h, ys, weights); return fit_ok; }
/** * @brief Calculates thermal flow for a given scene. */ int calculate(cpu_system_t* system, thermal_equation::task_t* task) { calculate_weights(system->scene, system->face_areas, task->temperatures, system->emission_task); int r = 0; if ((r = emission::system_calculate(system->emission_calculator, system->emission_task)) < 0) return r; // now we have nearest intersection face for every ray in task (if intersection was occurred) // calculate form factors between meshes const int n_meshes = system->scene->n_meshes; malley_emission::task_t* emission_task = system->emission_task; const ray_caster::task_t* ray_caster_task = emission_task->rays; if (ray_caster_task == 0) return THERMAL_EQUATION_OK; int n_ray = 0; for (int m = 0; m != n_meshes; ++m) { const subject::mesh_t& mesh = system->scene->meshes[m]; const subject::material_t& material = mesh_material(system->scene, m); const float T = task->temperatures[m]; const float power_density = sigma * (T * T * T * T); const float front_density = power_density * material.front.emissivity; const float rear_density = power_density * material.rear.emissivity; for (int f = mesh.first_idx; f != mesh.first_idx + mesh.n_faces; ++f) { const float front_emission = front_density * system->face_areas[f]; const float rear_emission = rear_density * system->face_areas[f]; task->emission[m] += front_emission + rear_emission; const int face_rays_front = emitted_front(emission_task, f); const int face_rays_rear = emitted_rear(emission_task, f); const int face_rays = face_rays_front + face_rays_rear; for (int j = 0; j != face_rays && n_ray < ray_caster_task->n_tasks; ++j, ++n_ray) { if (ray_caster_task->hit_face[n_ray]) { const int hit_face_idx = ray_caster_task->hit_face[n_ray] - system->emission_scene.faces; const int hit_mesh_idx = face2mesh(system, hit_face_idx); // @note Accepting material properties (like absorbance) does not matter. It should handled by emission and ray casting modules. const float ray_power = j < face_rays_front ? (front_emission / face_rays_front) : (rear_emission / face_rays_rear); task->absorption[hit_mesh_idx] += ray_power; } } } } ray_caster::task_free(emission_task->rays); emission_task->rays = 0; return THERMAL_EQUATION_OK; }
std::vector<double> CanonicalAverager::calculate_weights(const std::vector<double> &energies, const CGE &cge, double beta) { // Assume that the CGE only has one dimension (which is the only thing implemented at the moment) assert(cge.get_ge().get_current_histogram().get_shape().size() == 1); return calculate_weights(energies, cge.get_binner(), cge.get_ge().get_estimate().get_lnG(), cge.get_ge().get_estimate().get_lnG_support(), beta); }
std::vector<double> CanonicalAverager::calculate_weights(const std::vector<double> &energies, const DArray &binning, const DArray &lnG, const BArray &lnG_support, double beta) { NonUniformBinner binner(binning); return calculate_weights(energies, binner, lnG, lnG_support, beta); }