Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50ee33c

Browse files
author
Alena Rybakina
committed
Add aqo_k as custom parameter to define few number of features
for prediction. Its default value is 3. Queries can contain a more number of features than 3 especially generic queries. Also add predict_a_few_neibours parameter for switch avalable to predict a few neibors than 3. It is done for not to change the previous logic of the code
1 parent 34ee3be commit 50ee33c

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

aqo.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ bool force_collect_stat;
4848
*/
4949
bool aqo_show_hash;
5050
bool aqo_show_details;
51+
bool aqo_predict_with_few_neighbors;
5152

5253
/* GUC variables */
5354
static const struct config_enum_entry format_options[] = {
@@ -72,7 +73,7 @@ int auto_tuning_infinite_loop = 8;
7273
/* Machine learning parameters */
7374

7475
/* The number of nearest neighbors which will be chosen for ML-operations */
75-
int aqo_k = 3;
76+
int aqo_k;
7677
double log_selectivity_lower_bound = -30;
7778

7879
/*
@@ -237,6 +238,29 @@ _PG_init(void)
237238
NULL
238239
);
239240

241+
DefineCustomIntVariable("aqo.k_neighbors_threshold",
242+
"Set the threshold of number of neighbors for predicting.",
243+
NULL,
244+
&aqo_k,
245+
3,
246+
1, INT_MAX / 1000,
247+
PGC_USERSET,
248+
0,
249+
NULL,
250+
NULL,
251+
NULL);
252+
253+
DefineCustomBoolVariable("aqo.predict_with_few_neighbors",
254+
"Make prediction with less neighbors than we should have.",
255+
NULL,
256+
&aqo_predict_with_few_neighbors,
257+
true,
258+
PGC_USERSET,
259+
0,
260+
NULL,
261+
lc_assign_hook,
262+
NULL);
263+
240264
prev_shmem_startup_hook = shmem_startup_hook;
241265
shmem_startup_hook = aqo_init_shmem;
242266
prev_planner_hook = planner_hook;

aqo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ extern double auto_tuning_exploration;
211211
extern int auto_tuning_max_iterations;
212212
extern int auto_tuning_infinite_loop;
213213
extern double auto_tuning_convergence_error;
214+
extern bool aqo_predict_with_few_neighbors;
214215

215216
/* Machine learning parameters */
216217

machine_learning.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ OkNNr_predict(OkNNrdata *data, double *features)
158158

159159
Assert(data != NULL);
160160

161+
if (!aqo_predict_with_few_neighbors && data->rows < aqo_k)
162+
return -1.;
163+
161164
for (i = 0; i < data->rows; ++i)
162165
distances[i] = fs_distance(data->matrix[i], features, data->cols);
163166

0 commit comments

Comments
 (0)