10 #define DEFAULT_PARAM "-t 2 -c 100" 13 #define DrawLine(dc,x1,y1,x2,y2,c) \ 15 HPEN hpen = CreatePen(PS_SOLID,0,c); \ 16 HPEN horig = SelectPen(dc,hpen); \ 17 MoveToEx(dc,x1,y1,NULL); \ 19 SelectPen(dc,horig); \ 56 LRESULT CALLBACK
WndProc(HWND, UINT, WPARAM, LPARAM);
58 int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
59 PSTR szCmdLine,
int iCmdShow)
61 static char szAppName[] =
"SvmToy";
65 wndclass.cbSize =
sizeof(wndclass);
66 wndclass.style = CS_HREDRAW | CS_VREDRAW;
68 wndclass.cbClsExtra = 0;
69 wndclass.cbWndExtra = 0;
70 wndclass.hInstance = hInstance;
71 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
72 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
73 wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
74 wndclass.lpszMenuName = NULL;
75 wndclass.lpszClassName = szAppName;
76 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
78 RegisterClassEx(&wndclass);
95 CreateWindow(
"button",
"Change", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
97 CreateWindow(
"button",
"Run", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
99 CreateWindow(
"button",
"Clear", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
101 CreateWindow(
"button",
"Save", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
103 CreateWindow(
"button",
"Load", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
106 edit = CreateWindow(
"edit", NULL, WS_CHILD | WS_VISIBLE,
121 while (GetMessage(&msg, NULL, 0, 0)) {
122 TranslateMessage(&msg);
123 DispatchMessage(&msg);
130 OPENFILENAME OpenFileName;
131 memset(&OpenFileName,0,
sizeof(OpenFileName));
134 OpenFileName.lStructSize =
sizeof(OPENFILENAME);
135 OpenFileName.hwndOwner = hWnd;
136 OpenFileName.lpstrFile = filename;
137 OpenFileName.nMaxFile = len;
138 OpenFileName.Flags = 0;
140 return save?GetSaveFileName(&OpenFileName):GetOpenFileName(&OpenFileName);
153 else if(v==2)
return brush2;
160 rect.left = int(p.
x*
XLEN);
161 rect.top = int(p.
y*
YLEN);
162 rect.right = int(p.
x*
XLEN) + 3;
163 rect.bottom = int(p.
y*
YLEN) + 3;
201 Edit_GetLine(
edit, 0, str,
sizeof(str));
205 while (*p && *p !=
'-')
223 param.
gamma = atof(p);
226 param.
coef0 = atof(p);
254 while(*p && !isspace(*p)) ++p;
264 prob.
y =
new double[prob.
l];
279 x_space[2 * i].
index = 1;
280 x_space[2 * i].
value = q->x;
281 x_space[2 * i + 1].
index = -1;
282 prob.
x[i] = &x_space[2 * i];
291 int *j =
new int[
XLEN];
293 for (i = 0; i <
XLEN; i++)
295 x[0].
value = (double) i / XLEN;
302 int p = (int)(param.
p *
YLEN);
303 for(
int i=1; i <
XLEN; i++)
336 x_space[3 * i].
index = 1;
337 x_space[3 * i].
value = q->x;
338 x_space[3 * i + 1].
index = 2;
339 x_space[3 * i + 1].
value = q->y;
340 x_space[3 * i + 2].
index = -1;
341 prob.
x[i] = &x_space[3 * i];
342 prob.
y[i] = q->value;
352 for (i = 0; i <
XLEN; i++)
353 for (j = 0; j <
YLEN; j++) {
354 x[0].
value = (double) i / XLEN;
355 x[1].
value = (double) j / YLEN;
372 LRESULT CALLBACK
WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
380 int x = LOWORD(lParam);
381 int y = HIWORD(lParam);
389 hdc = BeginPaint(hwnd, &ps);
396 int id = LOWORD(wParam);
413 FILE *fp = fopen(filename,
"w");
416 Edit_GetLine(
edit, 0, str,
sizeof(str));
418 const char* svm_type_str = strstr(p,
"-s ");
419 int svm_type =
C_SVC;
420 if(svm_type_str != NULL)
421 sscanf(svm_type_str,
"-s %d", &svm_type);
428 fprintf(fp,
"%f 1:%f\n", p->y, p->x);
433 fprintf(fp,
"%d 1:%f 2:%f\n", p->value, p->x, p->y);
445 FILE *fp = fopen(filename,
"r");
450 while(fgets(buf,
sizeof(buf),fp))
454 if(sscanf(buf,
"%d%*d:%lf%*d:%lf",&v,&x,&y)==3)
459 else if(sscanf(buf,
"%lf%*d:%lf",&y,&x)==2)
481 return DefWindowProc(hwnd, iMsg, wParam, lParam);
void button_run_clicked()
struct svm_parameter param
def svm_train(arg1, arg2=None, arg3=None)
int getfilename(HWND hWnd, char *filename, int len, int save)
void draw_point(const point &p)
TFSIMD_FORCE_INLINE const tfScalar & y() const
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
def svm_predict(y, x, m, options="")
void svm_free_and_destroy_model(svm_model **model_ptr_ptr)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
#define DrawLine(dc, x1, y1, x2, y2, c)
HBRUSH choose_brush(int v)
struct svm_node * x_space