58 float (*samples)[
D],
uint16_t count,
bool use_bias,
float *params,
float *fit_error __attribute__((unused)))
66 float errors[n_iterations];
70 float subset_params[n_iterations][D_1];
78 for (
int i = 0; i < n_iterations; i++) {
85 subset_targets[j] = targets[indices_subset[j]];
86 for (
int k = 0; k <
D; k++) {
87 subset_samples[j][k] = samples[indices_subset[j]][k];
98 for (
int j = 0; j < count; j++) {
100 prediction =
predict_value(samples[j], subset_params[i],
D, use_bias);
101 err = fabsf(prediction - targets[j]);
103 err = (err > error_threshold) ? error_threshold : err;
110 float min_err = errors[0];
112 for (
int i = 1; i < n_iterations; i++) {
113 if (errors[i] < min_err) {
120 for (
int d = 0; d < D_1; d++) {
121 params[d] = subset_params[min_ind][d];
138 for (
int w = 0; w <
D; w++) {
163 bool picked_number =
false;
164 while (!picked_number) {
165 index = rand() % count;
167 for (
int k = 0; k < j; k++) {
168 if (indices_subset[k] == index) {
174 indices_subset[j] = index;
175 picked_number =
true;
float predict_value(float *sample, float *weights, int D, bool use_bias)
Predict the value of a sample with linear weights.
void get_indices_without_replacement(int *indices_subset, int n_samples, int count)
Get indices without replacement.
void RANSAC_linear_model(int n_samples, int n_iterations, float error_threshold, float *targets, int D, float(*samples)[D], uint16_t count, bool use_bias, float *params, float *fit_error)
Perform RANSAC to fit a linear model.
Perform Random Sample Consensus (RANSAC), a robust fitting method.
Paparazzi floating point algebra.
void fit_linear_model(float *targets, int D, float(*samples)[D], uint16_t count, bool use_bias, float *params, float *fit_error)
Fit a linear model from samples to target values.
Matrix decompositions in floating point.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.