syncnet::syncnet(std::vector<std::vector<double> > * input_data, const double connectivity_radius, const bool enable_conn_weight, const initial_type initial_phases) : sync_network(input_data->size(), 1, 0, connection_t::CONNECTION_NONE, initial_type::RANDOM_GAUSSIAN) { equation<double> oscillator_equation = std::bind(&syncnet::phase_kuramoto_equation, this, _1, _2, _3, _4); set_equation(oscillator_equation); oscillator_locations = new std::vector<std::vector<double> >(*input_data); create_connections(connectivity_radius, enable_conn_weight); }
static int fitfit(struct objlist *obj,N_VALUE *inst,N_VALUE *rval,int argc,char **argv) { struct fitlocal *fitlocal; int i,through,dimension,deriv,disp; enum FIT_OBJ_TYPE type; double x,y,x0,y0,converge,wt; struct narray *darray; double *data,*wdata; char *equation,*func,prm[32]; int dnum,num,err,err2,err3; enum FitError rcode; double derror,correlation,pp; int ecode; int weight,anum; if (_exeparent(obj,(char *)argv[1],inst,rval,argc,argv)) return 1; _getobj(obj,"_local",inst,&fitlocal); if (set_equation(obj, inst, fitlocal, NULL)) return 1; equation = g_strdup("undef"); if (equation == NULL) return 1; if (set_equation(obj, inst, fitlocal, equation)) { g_free(equation); return 1; } num=0; derror=0; correlation=0; pp=0; if (_putobj(obj,"number",inst,&num)) return 1; if (_putobj(obj,"error",inst,&derror)) return 1; if (_putobj(obj,"correlation",inst,&correlation)) return 1; for (i = 0; i < 10; i++) { snprintf(prm, sizeof(prm), "%%%02d", i); if (_putobj(obj, prm, inst, &pp)) return 1; } _getobj(obj,"type",inst,&type); _getobj(obj,"through_point",inst,&through); _getobj(obj,"point_x",inst,&x0); _getobj(obj,"point_y",inst,&y0); _getobj(obj,"poly_dimension",inst,&dimension); _getobj(obj,"user_func",inst,&func); _getobj(obj,"derivative",inst,&deriv); _getobj(obj,"converge",inst,&converge); _getobj(obj, "id", inst, &(fitlocal->id)); for (i = 0; i < 10; i++) { snprintf(prm, sizeof(prm), "parameter%d", i); _getobj(obj, prm, inst, &(fitlocal->coe[i])); } _getobj(obj,"display",inst,&disp); if (through && (type == FIT_TYPE_USER)) { error(obj,ERRTHROUGH); return 1; } darray = (struct narray *) (argv[2]); if (arraynum(darray) < 1) return FitError_Small; data=arraydata(darray); anum=arraynum(darray)-1; dnum=nround(data[0]); data += 1; if (dnum == (anum / 2)) { weight = FALSE; wt = 0; /* dummy code to avoid compile warnings */ wdata = NULL; /* dummy code to avoid compile warnings */ } else if (dnum == (anum / 3)) { weight = TRUE; wdata = data + 2 * dnum; } else { error(obj, ERR_INCONSISTENT_DATA_NUM); return 1; } num=0; err2=err3=FALSE; for (i=0;i<dnum;i++) { x=data[i*2]; y=data[i*2+1]; if (weight) { wt = wdata[i]; } err=FALSE; switch (type) { case FIT_TYPE_POW: if (y<=0) err=TRUE; else y=log(y); if (x<=0) err=TRUE; else x=log(x); break; case FIT_TYPE_EXP: if (y<=0) err=TRUE; else y=log(y); break; case FIT_TYPE_LOG: if (x<=0) err=TRUE; else x=log(x); break; case FIT_TYPE_POLY: case FIT_TYPE_USER: /* nothing to do */ break; } if (err) { err2 = TRUE; } else if (weight && (wt <= 0)) { err=TRUE; err3=TRUE; } if (!err) { data[num*2]=x; data[num*2+1]=y; if (weight) { wdata[num] = wt; } num++; } } if (err2) error(obj,ERRLN); if (err3) error(obj,ERRNEGATIVEWEIGHT); if (through) { err=FALSE; switch (type) { case FIT_TYPE_POW: if (y0<=0) err=TRUE; else y0=log(y0); if (x0<=0) err=TRUE; else x0=log(x0); break; case FIT_TYPE_EXP: if (y0<=0) err=TRUE; else y0=log(y0); break; case FIT_TYPE_LOG: if (x0<=0) err=TRUE; else x0=log(x0); break; case FIT_TYPE_POLY: /* nothing to do */ break; case FIT_TYPE_USER: /* never reached */ break; } if (err) { error(obj,ERRPOINT); return 1; } } if (type != FIT_TYPE_USER) { rcode=fitpoly(fitlocal,type,dimension,through,x0,y0,data,num,disp,weight,wdata); } else { rcode=fituser(obj,fitlocal,func,deriv,converge,data,num,disp,weight,wdata); } switch (rcode) { case FitError_Fatal: return 1; break; case FitError_Small: ecode = ERRSMLDATA; break; case FitError_Matrix: ecode = ERRSINGULAR; break; case FitError_Equation: ecode = ERRNOEQS; break; case FitError_Syntax: ecode = ERRSYNTAX; break; case FitError_Range: ecode = ERRRANGE; break; /* case FitError_Convergence: ecode = ERRCONVERGE; break; */ case FitError_Interrupt: ecode = ERRINTERRUPT; break; default: ecode = 0; } if (ecode!=0) { error(obj,ecode); return 1; } if (_putobj(obj,"number",inst,&(fitlocal->num))) return 1; if (_putobj(obj,"error",inst,&(fitlocal->derror))) return 1; if (_putobj(obj,"correlation",inst,&(fitlocal->correlation))) return 1; for (i = 0; i < 10; i++) { snprintf(prm, sizeof(prm), "%%%02d", i); if (_putobj(obj, prm, inst, &(fitlocal->coe[i]))) return 1; } if (set_equation(obj, inst, fitlocal, fitlocal->equation)) return 1; fitlocal->equation = NULL; return 0; }
static int fitput(struct objlist *obj,N_VALUE *inst,N_VALUE *rval, int argc,char **argv) { char *field; char *math; struct fitlocal *fitlocal; MathEquation *code; int rcode; _getobj(obj,"_local",inst,&fitlocal); field=argv[1]; if (strcmp(field,"poly_dimension")==0) { if (*(int *)(argv[2])<1) *(int *)(argv[2])=1; else if (*(int *)(argv[2])>9) *(int *)(argv[2])=9; } else if ((strcmp(field,"user_func")==0) || ((strncmp(field,"derivative",10)==0) && (field[10]!='\0'))) { math=(char *)(argv[2]); if (math!=NULL) { MathEquationParametar *prm; code = ofile_create_math_equation(NULL, 2, FALSE, FALSE, FALSE, FALSE, TRUE); if (code == NULL) { return 1; } rcode = math_equation_parse(code, math); if (rcode) { show_eqn_error(obj, code, math, field, rcode); math_equation_free(code); return 1; } if (math_equation_optimize(code)) { math_equation_free(code); return 1; } prm = math_equation_get_parameter(code, 0, NULL); if (prm == NULL) { math_equation_free(code); return 1; } if (prm->id_max > 9) { error(obj,ERRMANYPARAM); math_equation_free(code); return 1; } } else { code=NULL; } if (field[0]=='u') { math_equation_free(fitlocal->codef); fitlocal->codef = code; } else { math_equation_free(fitlocal->codedf[field[10] - '0']); fitlocal->codedf[field[10] - '0'] = code; } } if (set_equation(obj, inst, fitlocal, NULL)) return 1; return 0; }