out.c

来自「C-package of "Long Short-Term Memory" fo」· C语言 代码 · 共 97 行

C
97
字号
/* * $Id: out.c 1272 2007-05-09 16:26:20Z mhe $ * */#include <stdio.h>#include <stdlib.h>#include "lstm.h"#include "out.h"void output_epoch(int examples, int examplesnon) {  double fnp = (examples) ? (double) class_err / (double) examples * 100: 0;  double fpp = (examplesnon) ? (double) classnon_err / (double) examplesnon * 100: 0;  FILE *fp;  double mse = epoch_err/(1.0*training_size);  double roc   = roctrain(training_size);  double rocROCN = rocROCNtrain(training_size);  fp=fopen(outfile, "a");  fprintf(fp,"epochs:%d sequences:%d\n",epoch+1,numb_seq);  fprintf(fp,"MSE:%.6f\n", mse);  fprintf(fp,"false-negative:%d (out of %d positive training examples) %.1f%%\n",class_err, examples, fnp);  fprintf(fp,"false-positive:%d (out of %d negative training examples) %.1f%%\n",classnon_err, examplesnon, fpp);  fprintf(fp,"roc:%.4f\n", roc);  fprintf(fp,"roc%d:%.4f\n", ROCN, rocROCN);  fprintf(fp,"\n");  fclose(fp);}void weight_out(double **W){	FILE *fp;	int i,j;    /* all weights */	fp = fopen(weightfile, "w");	fprintf(fp,"anz:%d\n",numb_seq);	for (i=0;i<ges_mod;i++) {      for (j=0;j<ges_mod;j++) {      	fprintf(fp,"(%.2d,%.2d): %lf ",i,j,W[i][j]);      }      fprintf(fp,"\n");    }    fprintf(fp,"\n");	fclose(fp);    /* effective weights */    fp = fopen("weightsmall.mat", "w");    for (i=in_mod_b+1;i<ges_mod-1;i++) {      for (j=0;j<ges_mod;j++) {        if (W[i][j] < 0) {            fprintf(fp,"(%.3d,%.3d):%3.6lf\t\t",i,j,W[i][j]);        }        else {            fprintf(fp,"(%.3d,%.3d): %4.6lf\t\t",i,j,W[i][j]);        }      }      fprintf(fp,"\n");    }    fprintf(fp,"\n");    fclose(fp);    /* input weights grouped by AA */    fp = fopen("weightsAAgrouped.mat", "w");    for (i = 0; i < in_mod_b; i++) {        fprintf(fp,"%0.8lf", W[in_mod_b + 3][i]);        if (!((i + 1) % AAS)) fprintf(fp,"\n"); else fprintf(fp," ");    }    fprintf(fp,"\n");    fclose(fp);}void write_info(){      printf("Perhaps an error occurred during reading the file\n");      printf("lstmtest.txt ---> stopping the program.\n");      printf("There should be %d input components and\n",in_mod);      printf("%d target components per line. Makes %d real\n",out_mod,in_mod+out_mod);      printf("values per line.\n");      printf("An input sequence ends with a line\n");      printf("where the first value (out of %d values in\n",in_mod+out_mod);      printf("the line) is greater than 10.0\n");      printf("The file ends with an extra line\n");      printf("where the first value (out of %d values in\n",in_mod+out_mod);      printf("the line) is greater than 10.0\n");}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?