@ -511,6 +511,95 @@ double set_ocas_model(int refc,int answerind,double *W,double W0,int numfeatures
return ( W0 ) ;
}
/*double load_model(register int *posAp,register int *negAp,register double *W,register int refc,register int answerind,register int numfeatures)
{
int j ;
FILE * fp ;
double perc ;
char modelname [ 512 ] ;
# ifdef __APPLE__
sprintf ( modelname , " /Volumes/SSD/models/%s_%d.A%c%c " , CONTRACTS [ refc ] , numfeatures , ( answerind / 10 ) + ' 0 ' , ( answerind % 10 ) + ' 0 ' ) ;
# else
sprintf ( modelname , " /media/raptor/models/%s_%d.A%c%c " , CONTRACTS [ refc ] , numfeatures , ( answerind / 10 ) + ' 0 ' , ( answerind % 10 ) + ' 0 ' ) ;
# endif
if ( ( fp = fopen ( modelname , " rb " ) ) ! = 0 )
{
//printf("load file\n");
j = ( int ) fread ( W , sizeof ( * W ) , numfeatures + 1 , fp ) ;
//fread(&W0,1,sizeof(W0),fp);
if ( fread ( & perc , 1 , sizeof ( perc ) , fp ) = = sizeof ( perc ) )
j + + ;
if ( fread ( posAp , 1 , sizeof ( * posAp ) , fp ) = = sizeof ( * posAp ) )
j + + ;
if ( fread ( negAp , 1 , sizeof ( * negAp ) , fp ) = = sizeof ( * negAp ) )
j + + ;
fclose ( fp ) ;
//printf("loaded %s bias %9.6f | %5.2f%%\n",modelname,W[numfeatures],perc);
return ( perc ) ;
}
# ifndef DISABLE_EXISTINGMODEL
else if ( 0 )
{
sprintf ( modelname , " /media/raptor/models/%s_%d.A%c%c " , CONTRACTS [ 0 ] , numfeatures , ( answerind / 10 ) + ' 0 ' , ( answerind % 10 ) + ' 0 ' ) ;
if ( ( fp = fopen ( modelname , " rb " ) ) ! = 0 )
{
j = ( int ) fread ( W , sizeof ( * W ) , numfeatures + 1 , fp ) ;
if ( fread ( & perc , 1 , sizeof ( perc ) , fp ) = = sizeof ( perc ) )
j + + ;
if ( fread ( posAp , 1 , sizeof ( * posAp ) , fp ) = = sizeof ( * posAp ) )
j + + ;
if ( fread ( negAp , 1 , sizeof ( * negAp ) , fp ) = = sizeof ( * negAp ) )
j + + ;
fclose ( fp ) ;
printf ( " Using backup model for %s loaded %s bias %9.6f | %5.2f%% \n " , CONTRACTS [ refc ] , modelname , W [ numfeatures ] , perc ) ;
return ( perc * .9 ) ;
}
}
# endif
else printf ( " couldn't load (%s) \ n " ,modelname) ;
return ( - 1 ) ;
}
int save_model ( int refc , int answerind , double * W , int numfeatures , double W0 , double perc , int posA , int negA )
{
FILE * fp ;
char modelname [ 512 ] ;
sprintf ( modelname , " /media/raptor/models/%s_%d.A%c%c " , CONTRACTS [ refc ] , numfeatures , ( answerind / 10 ) + ' 0 ' , ( answerind % 10 ) + ' 0 ' ) ;
//printf("modelname.%s m.%p predabs %f\n",modelname,m,predabs);
if ( ( fp = fopen ( modelname , " wb " ) ) ! = 0 )
{
//printf("save %s %.f%% posA.%d negA.%d\n",modelname,perc,posA,negA);
fwrite ( W , sizeof ( * W ) , numfeatures , fp ) ;
fwrite ( & W0 , 1 , sizeof ( W0 ) , fp ) ;
fwrite ( & perc , 1 , sizeof ( perc ) , fp ) ;
fwrite ( & posA , 1 , sizeof ( posA ) , fp ) ;
fwrite ( & negA , 1 , sizeof ( negA ) , fp ) ;
fclose ( fp ) ;
return ( 0 ) ;
}
return ( - 1 ) ;
}
double set_ocas_model ( int refc , int answerind , double * W , double W0 , int numfeatures , int firstweekind , int len , int bad , double dist , double predabs , int posA , int negA , double answerabs , double aveanswer )
{
double fileperc , perc = ( 100. * ( double ) ( len - bad ) ) / len ;
# ifndef DISABLE_EXISTINGMODEL
int _posA , _negA ;
double tmpW [ MAX_OCAS_FEATURES + 2 ] , fileperc ;
if ( ( fileperc = load_model ( & _posA , & _negA , tmpW , refc_to_c ( refc ) , answerind , numfeatures ) ) > perc )
{
if ( ( _posA + _negA ) ! = 0 & & _posA > = posA & & _negA > = negA )
{
memcpy ( W , tmpW , sizeof ( * W ) * numfeatures ) ;
printf ( " %s.A%02d numfeatures.%d posA.%d negA.%d saved model %f is better than %f +A%d -A%d \n " , CONTRACTS [ refc ] , answerind , numfeatures , _posA , _negA , fileperc , perc , posA , negA ) ;
return ( tmpW [ numfeatures ] ) ;
}
}
# endif
save_model ( refc , answerind , W , numfeatures , W0 , perc , posA , negA ) ;
return ( W0 ) ;
} */
# ifndef _WIN
# include "tradebots_SVM.h"
# endif