Skip to content

Commit

Permalink
create ccv_minimize_default_params
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Nov 28, 2014
1 parent 0492ad7 commit 8db7071
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/ccv.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ typedef struct {
double sig;
} ccv_minimize_param_t;

extern const ccv_minimize_param_t ccv_minimize_default_params;

typedef int(*ccv_minimize_f)(const ccv_dense_matrix_t* x, double* f, ccv_dense_matrix_t* df, void*);
void ccv_minimize(ccv_dense_matrix_t* x, int length, double red, ccv_minimize_f func, ccv_minimize_param_t params, void* data);

Expand Down Expand Up @@ -1123,8 +1125,6 @@ typedef struct {
ccv_size_t base;
int range_through;
int step_through;
int active_set;
int wide_set;
} feature;
struct {
float angle;
Expand Down
9 changes: 9 additions & 0 deletions lib/ccv_numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
#include "3rdparty/kissfft/kissf_fftndr.h"
#endif

const ccv_minimize_param_t ccv_minimize_default_params = {
.interp = 0.1,
.extrap = 3.0,
.max_iter = 20,
.ratio = 10.0,
.sig = 0.1,
.rho = 0.05,
};

void ccv_invert(ccv_matrix_t* a, ccv_matrix_t** b, int type)
{
}
Expand Down
14 changes: 3 additions & 11 deletions lib/ccv_scd.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ static int _ccv_scd_feature_logistic_loss(const ccv_dense_matrix_t* x, double* f
return 0;
}

static void _ccv_scd_feature_supervised_train(gsl_rng* rng, ccv_array_t* features, int positive_count, int negative_count, double* pw, double* nw, float* fv, int active_set, int wide_set, double C)
static void _ccv_scd_feature_supervised_train(gsl_rng* rng, ccv_array_t* features, int positive_count, int negative_count, double* pw, double* nw, float* fv, double C)
{
parallel_for(i, features->rnum) {
if ((i + 1) % 31 == 1 || (i + 1) == features->rnum)
Expand All @@ -469,19 +469,11 @@ static void _ccv_scd_feature_supervised_train(gsl_rng* rng, ccv_array_t* feature
.nw = nw,
.fv = fv,
};
ccv_minimize_param_t params = {
.interp = 0.1,
.extrap = 3.0,
.max_iter = 20,
.ratio = 10.0,
.sig = 0.1,
.rho = 0.05,
};
ccv_dense_matrix_t* x = ccv_dense_matrix_new(1, 33, CCV_32F | CCV_C1, 0, 0);
int j;
for (j = 0; j < 33; j++)
x->data.f32[j] = gsl_rng_uniform_pos(rng) * 2 - 1.0;
ccv_minimize(x, 5, 1.0, _ccv_scd_feature_logistic_loss, params, &context);
ccv_minimize(x, 5, 1.0, _ccv_scd_feature_logistic_loss, ccv_minimize_default_params, &context);
for (j = 0; j < 32; j++)
feature->w[j] = x->data.f32[j];
feature->bias = x->data.f32[32];
Expand Down Expand Up @@ -882,7 +874,7 @@ ccv_scd_classifier_cascade_t* ccv_scd_classifier_cascade_new(ccv_array_t* posfil
{
ccv_scd_classifier_t* classifier = z.cascade->classifiers + z.t;
classifier->features = (ccv_scd_feature_t*)ccrealloc(classifier->features, sizeof(ccv_scd_feature_t) * (z.k + 1));
_ccv_scd_feature_supervised_train(rng, z.features, z.positives->rnum, z.negatives->rnum, z.pw, z.nw, z.fv, params.feature.active_set, params.feature.wide_set, params.C);
_ccv_scd_feature_supervised_train(rng, z.features, z.positives->rnum, z.negatives->rnum, z.pw, z.nw, z.fv, params.C);
int best_feature_no = _ccv_scd_best_feature_with_auc(z.s, z.features, z.positives->rnum, z.negatives->rnum, z.fv);
ccv_scd_feature_t best_feature = *(ccv_scd_feature_t*)ccv_array_get(z.features, best_feature_no);
for (i = 0; i < z.positives->rnum + z.negatives->rnum; i++)
Expand Down
9 changes: 1 addition & 8 deletions test/unit/numeric.tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,7 @@ TEST_CASE("minimize rosenbrock")
ccv_dense_matrix_t* x = ccv_dense_matrix_new(1, 2, CCV_64F | CCV_C1, 0, 0);
ccv_zero(x);
int steps = 0;
ccv_minimize_param_t params;
params.interp = 0.1;
params.extrap = 3.0;
params.max_iter = 20;
params.ratio = 10.0;
params.sig = 0.1;
params.rho = 0.05;
ccv_minimize(x, 25, 1.0, rosenbrock, params, &steps);
ccv_minimize(x, 25, 1.0, rosenbrock, ccv_minimize_default_params, &steps);
double dx[2] = { 1, 1 };
REQUIRE_ARRAY_EQ_WITH_TOLERANCE(double, x->data.f64, dx, 2, 1e-6, "the global minimal should be at (1.0, 1.0)");
ccv_matrix_free(x);
Expand Down

0 comments on commit 8db7071

Please sign in to comment.