示例#1
0
int main(int * argc, char ** argv){
    initialize_unit();
    while(1){
        calc_error(input_data, output_data);
        back_propagation(); 
        if(check_loop())break;
   }

    release_unit();
}
示例#2
0
void network::SGD(train_couple* mini_batch, int batch_size, double eta,int n)
{
	matrix* X=extract_X(mini_batch,batch_size);
	matrix* Y=extract_Y(mini_batch,batch_size);

	matrix* Gw_sum=prepare_Gw();
	matrix* Gb_sum=prepare_Gb();

	for (int i=0; i<batch_size; i++){
		matrix* Gw=prepare_Gw();
		matrix* Gb=prepare_Gb();

		back_propagation(X[i],Y[i],Gw,Gb);

		for (int l=0; l<layers_count; l++){
			Gw_sum[l]=Gw_sum[l]+Gw[l];
			Gb_sum[l]=Gb_sum[l]+Gb[l];

		}
		delete [] Gw;
		delete [] Gb;
	}

	/////Averaging
	for (int l=0; l<layers_count; l++){
		Gw_sum[l]=Gw_sum[l]*(n/batch_size);
		Gb_sum[l]=Gb_sum[l]*(n/batch_size);
	}

	for (int l=0; l<layers_count; l++){
		w[l]=w[l]-eta*Gw_sum[l] ;
		b[l]=b[l]-eta*Gb_sum[l] ;
	}

	delete [] X;
	delete [] Y;
	delete [] Gw_sum;
	delete [] Gb_sum;
}