void test_simplex_fit(){ double **a; int dim=2; a = allocateDoubleMatrix(dim+1,dim); a[0][0]=0.9; a[0][1]=0.9; a[1][0]=0.9; a[1][1]=1.1; a[2][0]=1.1; a[2][1]=0.9; double x[]={1.707106,2.490711,3.605550,4.297620,5.656853}; double y[]={12.500000,4.166667,31.250000,81.250000,112.500000}; simplex_fit (a, dim, x, y, 5, test_linear_model_2); }
int simplex_from_vertex(const vertex_t *v, double percent, simplex_t *s) { int i, j; vertex_t *size = vertex_alloc(); if (!size) return -1; if (vertex_percent(size, percent / 2) != 0) { vertex_free(size); return -1; } /* Generate a simplex of unit length. */ unit_simplex(s); /* Pseudo-randomly rotate the unit simplex. */ rotate(s); /* Grow and translate the simplex. */ for (i = 0; i <= N; ++i) { for (j = 0; j < N; ++j) { s->vertex[i]->term[j] *= size->term[j]; s->vertex[i]->term[j] += v->term[j]; } } if (simplex_fit(s) != 0) { vertex_free(size); return -1; } /* Fill any remaining points with random vertices. */ for (i = N+1; i < s->len; ++i) vertex_rand(s->vertex[i]); vertex_free(size); return 0; }