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); \ 58 LRESULT CALLBACK
WndProc(HWND, UINT, WPARAM, LPARAM);
60 int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
61 PSTR szCmdLine,
int iCmdShow)
63 static char szAppName[] =
"SvmToy";
67 wndclass.cbSize =
sizeof(wndclass);
68 wndclass.style = CS_HREDRAW | CS_VREDRAW;
70 wndclass.cbClsExtra = 0;
71 wndclass.cbWndExtra = 0;
72 wndclass.hInstance = hInstance;
73 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
74 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
75 wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
76 wndclass.lpszMenuName = NULL;
77 wndclass.lpszClassName = szAppName;
78 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
80 RegisterClassEx(&wndclass);
97 CreateWindow(
"button",
"Change", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
99 CreateWindow(
"button",
"Run", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
101 CreateWindow(
"button",
"Clear", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
103 CreateWindow(
"button",
"Save", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
105 CreateWindow(
"button",
"Load", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
108 edit = CreateWindow(
"edit", NULL, WS_CHILD | WS_VISIBLE,
123 while (GetMessage(&msg, NULL, 0, 0))
125 TranslateMessage(&msg);
126 DispatchMessage(&msg);
133 OPENFILENAME OpenFileName;
134 memset(&OpenFileName, 0,
sizeof(OpenFileName));
137 OpenFileName.lStructSize =
sizeof(OPENFILENAME);
138 OpenFileName.hwndOwner = hWnd;
139 OpenFileName.lpstrFile = filename;
140 OpenFileName.nMaxFile = len;
141 OpenFileName.Flags = 0;
143 return save ? GetSaveFileName(&OpenFileName) : GetOpenFileName(&OpenFileName);
155 if (v == 1)
return brush1;
156 else if (v == 2)
return brush2;
163 rect.left = int(p.
x *
XLEN);
164 rect.top = int(p.
y *
YLEN);
165 rect.right = int(p.
x *
XLEN) + 3;
166 rect.bottom = int(p.
y *
YLEN) + 3;
204 Edit_GetLine(
edit, 0, str,
sizeof(str));
209 while (*p && *p !=
'-')
228 param.
gamma = atof(p);
231 param.
coef0 = atof(p);
259 while (*p && !isspace(*p)) ++p;
269 prob.
y =
new double[prob.
l];
284 x_space[2 * i].
index = 1;
285 x_space[2 * i].
value = q->x;
286 x_space[2 * i + 1].
index = -1;
287 prob.
x[i] = &x_space[2 * i];
296 int *j =
new int[
XLEN];
298 for (i = 0; i <
XLEN; i++)
300 x[0].
value = (double) i / XLEN;
307 int p = (int)(param.
p *
YLEN);
308 for (
int i = 1; i <
XLEN; i++)
341 x_space[3 * i].
index = 1;
342 x_space[3 * i].
value = q->x;
343 x_space[3 * i + 1].
index = 2;
344 x_space[3 * i + 1].
value = q->y;
345 x_space[3 * i + 2].
index = -1;
346 prob.
x[i] = &x_space[3 * i];
347 prob.
y[i] = q->value;
357 for (i = 0; i <
XLEN; i++)
358 for (j = 0; j <
YLEN; j++)
360 x[0].
value = (double) i / XLEN;
361 x[1].
value = (double) j / YLEN;
378 LRESULT CALLBACK
WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
387 int x = LOWORD(lParam);
388 int y = HIWORD(lParam);
396 hdc = BeginPaint(hwnd, &ps);
403 int id = LOWORD(wParam);
421 FILE *fp = fopen(filename,
"w");
424 Edit_GetLine(
edit, 0, str,
sizeof(str));
426 const char* svm_type_str = strstr(p,
"-s ");
427 int svm_type =
C_SVC;
428 if (svm_type_str != NULL)
429 sscanf(svm_type_str,
"-s %d", &svm_type);
436 fprintf(fp,
"%f 1:%f\n", p->y, p->x);
441 fprintf(fp,
"%d 1:%f 2:%f\n", p->value, p->x, p->y);
453 FILE *fp = fopen(filename,
"r");
458 while (fgets(buf,
sizeof(buf), fp))
462 if (sscanf(buf,
"%d%*d:%lf%*d:%lf", &v, &x, &y) == 3)
467 else if (sscanf(buf,
"%lf%*d:%lf", &y, &x) == 2)
489 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)
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