10 #define DEFAULT_PARAM "-t 2 -c 100"
34 virtual void mousePressEvent( QMouseEvent* );
35 virtual void paintEvent( QPaintEvent* );
57 if(v==1)
return icon1;
58 else if(v==2)
return icon2;
69 const QPixmap& icon = choose_icon(p.
value);
70 buffer_painter.drawPixmap((
int)(p.
x*
XLEN),(
int)(p.
y*
YLEN),icon);
111 const char *p = input_line.text().toAscii().constData();
114 while (*p && *p !=
'-')
163 while(*p && !isspace(*p)) ++p;
200 int *j =
new int[
XLEN];
202 for (i = 0; i <
XLEN; i++)
208 buffer_painter.setPen(
colors[0]);
209 buffer_painter.drawLine(0,0,0,
YLEN-1);
212 for(i = 1; i <
XLEN; i++)
214 buffer_painter.setPen(
colors[0]);
215 buffer_painter.drawLine(i,0,i,
YLEN-1);
217 buffer_painter.setPen(
colors[5]);
218 buffer_painter.drawLine(i-1,j[i-1],i,j[i]);
222 buffer_painter.setPen(
colors[2]);
223 buffer_painter.drawLine(i-1,j[i-1]+p,i,j[i]+p);
225 buffer_painter.setPen(
colors[2]);
226 buffer_painter.drawLine(i-1,j[i-1]-p,i,j[i]-p);
251 prob.
y[i] = q->value;
261 for (i = 0; i <
XLEN; i++)
262 for (j = 0; j <
YLEN ; j++) {
267 buffer_painter.setPen(
colors[(
int)
d]);
268 buffer_painter.drawPoint(i,j);
286 QString filename = QFileDialog::getSaveFileName();
287 if(!filename.isNull())
289 FILE *fp = fopen(filename.toAscii().constData(),
"w");
291 const char *p = input_line.text().toAscii().constData();
292 const char* svm_type_str = strstr(p,
"-s ");
293 int svm_type =
C_SVC;
294 if(svm_type_str != NULL)
295 sscanf(svm_type_str,
"-s %d", &svm_type);
302 fprintf(fp,
"%f 1:%f\n", p->y, p->x);
307 fprintf(fp,
"%d 1:%f 2:%f\n", p->value, p->x, p->y);
315 QString filename = QFileDialog::getOpenFileName();
316 if(!filename.isNull())
318 FILE *fp = fopen(filename.toAscii().constData(),
"r");
323 while(fgets(buf,
sizeof(buf),fp))
327 if(sscanf(buf,
"%d%*d:%lf%*d:%lf",&v,&
x,&y)==3)
332 else if(sscanf(buf,
"%lf%*d:%lf",&y,&
x)==2)
348 #include "svm-toy.moc"
351 :button_change_icon(this)
352 ,button_run(
"Run",this)
353 ,button_clear(
"Clear",this)
354 ,button_save(
"Save",this)
355 ,button_load(
"Load",this)
366 QObject::connect(&
button_run, SIGNAL(clicked()),
this,
368 QObject::connect(&
button_clear, SIGNAL(clicked()),
this,
370 QObject::connect(&
button_save, SIGNAL(clicked()),
this,
372 QObject::connect(&
button_load, SIGNAL(clicked()),
this,
374 QObject::connect(&
input_line, SIGNAL(returnPressed()),
this,
378 setAttribute(Qt::WA_NoBackground);
380 icon1 = QPixmap(4,4);
381 icon2 = QPixmap(4,4);
382 icon3 = QPixmap(4,4);
386 painter.begin(&
icon1);
387 painter.fillRect(0,0,4,4,QBrush(
colors[4]));
390 painter.begin(&
icon2);
391 painter.fillRect(0,0,4,4,QBrush(
colors[5]));
394 painter.begin(&
icon3);
395 painter.fillRect(0,0,4,4,QBrush(
colors[6]));
425 p.drawPixmap(0, 0,
buffer);
428 int main(
int argc,
char* argv[] )
430 QApplication myapp( argc, argv );
433 mywidget->setGeometry( 100, 100,
XLEN,
YLEN+25 );