Algorithm-CRF

 view release on metacpan or  search on metacpan

CRF.xs  view on Meta::CPAN

}
#endif

using namespace CRFPP;

MODULE = Algorithm::CRF		PACKAGE = Algorithm::CRF		

PROTOTYPES: ENABLE

bool
crfpp_learn( templfile, trainfile, modelfile, textmodelfile, maxitr, freq, eta, C, thread_num , shrinking_size, algorithm, convert)
	const char *templfile
	const char *trainfile
	const char *modelfile
	bool textmodelfile
	size_t maxitr
	size_t freq
	double eta
	double C
	unsigned short thread_num
	unsigned short shrinking_size
	int algorithm
	bool convert
    CODE:
CRFPP::Encoder encoder;
    if (thread_num > 1024)
	fprintf (stderr,"#thread is too big\n",encoder.what());
    if (convert) {
	if (! encoder.convert(templfile, trainfile)) {
	    //cerr << encoder.what() << endl;
	    fprintf (stderr,"%s\n",encoder.what());
	    RETVAL = -1;
	}
    } else {
	if (! encoder.learn ( templfile, 
	trainfile, 
	modelfile, 
	textmodelfile, 
	maxitr, 
	freq, 
	eta, 
	C, 
	thread_num,
        shrinking_size,
	algorithm )) {
	    //	cerr << encoder.what() << endl;
	    fprintf (stderr,"%s\n",encoder.what());
	    RETVAL = -1;
	} else
	    RETVAL = 0;
    }
    OUTPUT:
	RETVAL

t/1-crf_learn.t  view on Meta::CPAN

my $s = new Algorithm::CRF;
#ok($s->CRFpp_Learn("-t -c 10.0 template train.data model")==0, "crfpp_learn");
ok(Algorithm::CRF::crfpp_learn("t/template",
	"t/train.data",
	"t/model",
	1, #textmodelfile
	100000, # maxitr
	1, # freq
	0.0001, # eta
	10, # C
	1, # threads
	20, # shrinking_size
        0, # algorithm , 0 for CRF
        0)==0, "CRFPP_LEARN");



( run in 0.982 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )