Commit fe06805f authored by Brice Videau's avatar Brice Videau
Browse files

Added introspection for hyperparameters.

parent f50bceec
......@@ -26,6 +26,13 @@ ccs_create_numerical_hyperparameter(const char *name,
void *user_data,
ccs_hyperparameter_t *hyperparameter_ret);
extern ccs_result_t
ccs_numerical_hyperparameter_get_parameters(ccs_hyperparameter_t hyperparameter,
ccs_numeric_type_t *data_type_ret,
ccs_numeric_t *lower_ret,
ccs_numeric_t *upper_ret,
ccs_numeric_t *quantization_ret);
extern ccs_result_t
ccs_create_categorical_hyperparameter(const char *name,
size_t num_possible_values,
......@@ -34,6 +41,12 @@ ccs_create_categorical_hyperparameter(const char *name,
void *user_data,
ccs_hyperparameter_t *hyperparameter_ret);
extern ccs_result_t
ccs_categorical_hyperparameter_get_values(ccs_hyperparameter_t hyperparameter,
size_t num_possible_values,
ccs_datum_t *possible_values,
size_t *num_possible_values_ret);
extern ccs_result_t
ccs_create_ordinal_hyperparameter(const char *name,
size_t num_possible_values,
......@@ -42,6 +55,12 @@ ccs_create_ordinal_hyperparameter(const char *name,
void *user_data,
ccs_hyperparameter_t *hyperparameter_ret);
extern ccs_result_t
ccs_ordinal_hyperparameter_get_values(ccs_hyperparameter_t hyperparameter,
size_t num_possible_values,
ccs_datum_t *possible_values,
size_t *num_possible_values_ret);
extern ccs_result_t
ccs_ordinal_hyperparameter_compare_values(ccs_hyperparameter_t hyperparameter,
ccs_datum_t value1,
......
......@@ -5,7 +5,7 @@
struct _ccs_hyperparameter_categorical_data_s {
_ccs_hyperparameter_common_data_t common_data;
ccs_int_t num_possible_values;
size_t num_possible_values;
_ccs_hash_datum_t *possible_values;
_ccs_hash_datum_t *hash;
};
......@@ -60,7 +60,7 @@ _ccs_hyperparameter_categorical_samples(_ccs_hyperparameter_data_t *data,
} else {
size_t found = 0;
for(size_t i = 0; i < num_values; i++)
if (vs[i] >= 0 && vs[i] < d->num_possible_values)
if (vs[i] >= 0 && (size_t)vs[i] < d->num_possible_values)
values[found++] = d->possible_values[vs[i]].d;
vs = NULL;
size_t coeff = 2;
......@@ -72,7 +72,7 @@ _ccs_hyperparameter_categorical_samples(_ccs_hyperparameter_data_t *data,
err = ccs_distribution_samples(distribution, rng,
buff_sz, (ccs_numeric_t *)vs);
for(size_t i = 0; i < buff_sz && found < num_values; i++)
if (vs[i] >= 0 && vs[i] < d->num_possible_values)
if (vs[i] >= 0 && (size_t)vs[i] < d->num_possible_values)
values[found++] = d->possible_values[vs[i]].d;
coeff <<= 1;
free(vs);
......@@ -196,4 +196,30 @@ ccs_create_categorical_hyperparameter(const char *name,
return CCS_SUCCESS;
}
extern ccs_result_t
ccs_categorical_hyperparameter_get_values(ccs_hyperparameter_t hyperparameter,
size_t num_possible_values,
ccs_datum_t *possible_values,
size_t *num_possible_values_ret) {
if (!hyperparameter || !hyperparameter->data)
return -CCS_INVALID_OBJECT;
if (num_possible_values && !possible_values)
return -CCS_INVALID_VALUE;
if (!possible_values && !num_possible_values_ret)
return -CCS_INVALID_VALUE;
_ccs_hyperparameter_categorical_data_t *d =
(_ccs_hyperparameter_categorical_data_t *)hyperparameter->data;
if (possible_values) {
if (num_possible_values < d->num_possible_values)
return -CCS_INVALID_VALUE;
for (size_t i = 0; i < d->num_possible_values; i++)
possible_values[i] = d->possible_values[i].d;
for (size_t i = num_possible_values; i < d->num_possible_values; i++)
possible_values[i] = ccs_none;
}
if (num_possible_values_ret)
*num_possible_values_ret = d->num_possible_values;
return CCS_SUCCESS;
}
......@@ -189,3 +189,28 @@ ccs_create_numerical_hyperparameter(const char *name,
return CCS_SUCCESS;
}
ccs_result_t
ccs_numerical_hyperparameter_get_parameters(ccs_hyperparameter_t hyperparameter,
ccs_numeric_type_t *data_type_ret,
ccs_numeric_t *lower_ret,
ccs_numeric_t *upper_ret,
ccs_numeric_t *quantization_ret) {
if (!hyperparameter || !hyperparameter->data)
return -CCS_INVALID_OBJECT;
if (!data_type_ret && !lower_ret && !upper_ret && !quantization_ret)
return -CCS_INVALID_VALUE;
_ccs_hyperparameter_numerical_data_t *d =
(_ccs_hyperparameter_numerical_data_t *)hyperparameter->data;
if (data_type_ret)
*data_type_ret = d->common_data.interval.type;
if (lower_ret)
*lower_ret = d->common_data.interval.lower;
if (upper_ret)
*upper_ret = d->common_data.interval.upper;
if (quantization_ret)
*quantization_ret = d->quantization;
return CCS_SUCCESS;
}
......@@ -5,7 +5,7 @@
struct _ccs_hyperparameter_ordinal_data_s {
_ccs_hyperparameter_common_data_t common_data;
ccs_int_t num_possible_values;
size_t num_possible_values;
_ccs_hash_datum_t *possible_values;
_ccs_hash_datum_t *hash;
};
......@@ -60,7 +60,7 @@ _ccs_hyperparameter_ordinal_samples(_ccs_hyperparameter_data_t *data,
} else {
size_t found = 0;
for(size_t i = 0; i < num_values; i++)
if (vs[i] >= 0 && vs[i] < d->num_possible_values)
if (vs[i] >= 0 && (size_t)vs[i] < d->num_possible_values)
values[found++] = d->possible_values[vs[i]].d;
vs = NULL;
size_t coeff = 2;
......@@ -72,7 +72,7 @@ _ccs_hyperparameter_ordinal_samples(_ccs_hyperparameter_data_t *data,
err = ccs_distribution_samples(distribution, rng,
buff_sz, (ccs_numeric_t *)vs);
for(size_t i = 0; i < buff_sz && found < num_values; i++)
if (vs[i] >= 0 && vs[i] < d->num_possible_values)
if (vs[i] >= 0 && (size_t)vs[i] < d->num_possible_values)
values[found++] = d->possible_values[vs[i]].d;
coeff <<= 1;
free(vs);
......@@ -221,3 +221,30 @@ ccs_create_ordinal_hyperparameter(const char *name,
*hyperparameter_ret = hyperparam;
return CCS_SUCCESS;
}
extern ccs_result_t
ccs_ordinal_hyperparameter_get_values(ccs_hyperparameter_t hyperparameter,
size_t num_possible_values,
ccs_datum_t *possible_values,
size_t *num_possible_values_ret) {
if (!hyperparameter || !hyperparameter->data)
return -CCS_INVALID_OBJECT;
if (num_possible_values && !possible_values)
return -CCS_INVALID_VALUE;
if (!possible_values && !num_possible_values_ret)
return -CCS_INVALID_VALUE;
_ccs_hyperparameter_ordinal_data_t *d =
(_ccs_hyperparameter_ordinal_data_t *)hyperparameter->data;
if (possible_values) {
if (num_possible_values < d->num_possible_values)
return -CCS_INVALID_VALUE;
for (size_t i = 0; i < d->num_possible_values; i++)
possible_values[i] = d->possible_values[i].d;
for (size_t i = num_possible_values; i < d->num_possible_values; i++)
possible_values[i] = ccs_none;
}
if (num_possible_values_ret)
*num_possible_values_ret = d->num_possible_values;
return CCS_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment