Пример #1
0
void CallView::refresh()
{
    clear();
    setColumnWidth(1, _eventType2 ? 50:0);

    if (_eventType)
        _headerLabels[0] = _eventType->name();
    if (_eventType2)
        _headerLabels[1] = _eventType2->name();
    setHeaderLabels(_headerLabels);

    if (!_data || !_activeItem) return;

    TraceFunction* f = activeFunction();
    if (!f) return;

    TraceCall* call;
    // In the call lists, we skip cycles to show the real call relations
    TraceCallList l = _showCallers ? f->callers(true) : f->callings(true);

    QList<QTreeWidgetItem*> items;
    for (call=l.first();call;call=l.next())
	if (call->subCost(_eventType)>0)
            items.append(new CallItem(this, 0, call));

    // when inserting, switch off sorting for performance reason
    setSortingEnabled(false);
    addTopLevelItems(items);
    setSortingEnabled(true);
    // enabling sorting switches on the indicator, but we want it off
    header()->setSortIndicatorShown(false);
    // resize to content now (section size still can be interactively changed)
    header()->resizeSections(QHeaderView::ResizeToContents);

    if (!_eventType2)
        setColumnWidth(1, 0);
}
Пример #2
0
int ANN::outputFunction(int opt) {
    double y = activeFunction();
    if (opt==1) {//sigmoid
        if (y>0) {
            return 1;
        } else {
            return 0;
        }
    } else if (opt==2) {//step
        if (y>ThresholdStep) {
            return 1;
        } else {
            return 0;
        }
    } else if (opt==3) {//sign
        if (y>0) {
            return 1;
        } else {
            return -1;
        }
    } else if (opt==4) {//linear
        return y;
    }
}
Пример #3
0
void ANN::annBatch(Training tr, int optFunction) {
	vector<double> deltaW;
	int counter = 0;
    double MSE = 999;
    double pow;
    int oF;
    //isi delta w dengan 0
    for (int i = 0 ; i < listW.size(); i++){
        deltaW.push_back(0);    
    }
	while (counter < MaximumIteration && MSE > Epsilon) {
        cout << "===================" << endl;
        cout << "==== epoch " << counter+1 << " =====" << endl;
        cout << "===================" << endl;
        
        cout << "  x0  x1  x2  x3  x4       w0       w1       w2       w3       w4        y        o        t  deltaW0  deltaW1  deltaW2  deltaW3  deltaW4";
//        cout << "  x0  x1  x2       w0       w1       w2        y        o        t  deltaW0  deltaW1  deltaW2";
        cout << endl;
        //satu batch
        MSE = 0;
		for (int i = 0; i < tr.getNumberData() ; i++){
            for (int j=0; j<listX.size(); j++) {
                printf("%4d", listX[j]);
            }
            for (int j=0; j<listW.size(); j++) {
                printf("%9.2f", listW[j]);
            }
            
            oF = outputFunction(optFunction);
            printf("%9.2f", activeFunction());
            printf("%9d", oF);
            printf("%9d", tr.getDataValueConverted(i, tr.getTargetAttribute()));
            
			for (int j = 0 ; j < listW.size() ; j++){
                deltaW[j] = deltaW[j] + LearningRate * (tr.getDataValueConverted(i, tr.getTargetAttribute()) - oF) * listX[j];
			}                                               
            
            if (i+1<tr.getNumberData()) {
                for (int j=0; j<listX.size(); j++) {
                    if (j>0) {
                        listX[j] = tr.getDataValueConverted(i+1, tr.getAttribute(j-1));
                    } else {
                        listX[j] = 1;
                    }
                }
            } else {
                for (int j=0; j<listX.size(); j++) {
                    if (j>0) {
                        listX[j] = tr.getDataValueConverted(0, tr.getAttribute(j-1));
                    } else {
                        listX[j] = 1;
                    }
                }
            }
            
            for (int j=0; j<deltaW.size(); j++) {
                printf("%9.2f", deltaW[j]);
            }
            cout << endl;
            
            pow = tr.getDataValueConverted(i, tr.getTargetAttribute()) - oF ;
			pow = pow * pow;
			MSE = MSE + pow;
		}
        
        MSE = (MSE / tr.getNumberData());
        cout << "MSE : " << MSE << endl;
        cout << endl;
        
		//update
		for (int i = 0 ; i < listW.size() ; i++){
			listW[i] = listW[i] + deltaW[i];
		}               
        
        //isi delta w dengan 0
        for (int i = 0 ; i < listW.size(); i++){
            //deltaW.push_back(0);
            deltaW[i] = 0;
        }
        
		counter++;
	}	
}