AI-XGBoost

 view release on metacpan or  search on metacpan

lib/AI/XGBoost/CAPI/RAW.pm  view on Meta::CPAN


$ffi->attach( XGDMatrixSetFloatInfo => [qw(opaque string float[] uint64)] => 'int' );

$ffi->attach( XGDMatrixSetUIntInfo => [qw(opaque string uint32* uint64)] => 'int' );

$ffi->attach( XGDMatrixSetGroup => [qw(opaque uint32* uint64)] => 'int' );

$ffi->attach( XGDMatrixGetFloatInfo => [qw(opaque string uint64* opaque*)] => 'int' );

$ffi->attach( XGDMatrixGetUIntInfo => [qw(opaque string uint64* opaque*)] => 'int' );

$ffi->attach( XGDMatrixFree => [qw(opaque)] => 'int' );

$ffi->attach( XGBoosterCreate => [qw(opaque[] uint64 opaque*)] => 'int' );

$ffi->attach( XGBoosterFree => [qw(opaque)] => 'int' );

$ffi->attach( XGBoosterSetParam => [qw(opaque string string)] => 'int' );

$ffi->attach( XGBoosterBoostOneIter => [qw(opaque opaque float[] float[] uint64)] => 'int' );

$ffi->attach( XGBoosterUpdateOneIter => [qw(opaque int opaque)] => 'int' );

$ffi->attach( XGBoosterEvalOneIter => [qw(opaque int opaque[] opaque[] uint64 opaque*)] => 'int' );

$ffi->attach( XGBoosterPredict => [qw(opaque opaque int uint uint64* opaque*)] => 'int' );

$ffi->attach( XGBoosterLoadModel => [qw(opaque string)] => 'int' );

$ffi->attach( XGBoosterSaveModel => [qw(opaque string)] => 'int' );

$ffi->attach( XGBoosterLoadModelFromBuffer => [qw(opaque opaque uint64)] => 'int' );

$ffi->attach( XGBoosterGetModelRaw => [qw(opaque uint64* opaque*)] => 'int' );

$ffi->attach( XGBoosterDumpModel => [qw(opaque string int uint64* opaque*)] => 'int' );

$ffi->attach( XGBoosterDumpModelEx => [qw(opaque string int string uint64* opaque*)] => 'int' );

$ffi->attach( XGBoosterDumpModelWithFeatures => [qw(opaque int opaque[] opaque[] int uint64* opaque*)] => 'int' );

$ffi->attach(
           XGBoosterDumpModelExWithFeatures => [qw(opaque int opaque[] opaque[] int string uint64* opaque*)] => 'int' );

$ffi->attach( XGBoosterSetAttr => [qw(opaque string string)] => 'int' );

$ffi->attach( XGBoosterGetAttr => [qw(opaque string opaque* int*)] => 'int' );

$ffi->attach( XGBoosterGetAttrNames => [qw(opaque uint64* opaque*)] => 'int' );

$ffi->attach( XGBoosterLoadRabitCheckpoint => [qw(opaque int)] => 'int' );

$ffi->attach( XGBoosterSaveRabitCheckpoint => [qw(opaque)] => 'int' );

1;

__END__

=pod

=encoding utf-8

=head1 NAME

AI::XGBoost::CAPI::RAW - Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost

=head1 VERSION

version 0.11

=head1 SYNOPSIS

 use 5.010;
 use AI::XGBoost::CAPI::RAW;
 use FFI::Platypus;
 
 my $silent = 0;
 my ($dtrain, $dtest) = (0, 0);
 
 AI::XGBoost::CAPI::RAW::XGDMatrixCreateFromFile('agaricus.txt.test', $silent, \$dtest);
 AI::XGBoost::CAPI::RAW::XGDMatrixCreateFromFile('agaricus.txt.train', $silent, \$dtrain);
 
 my ($rows, $cols) = (0, 0);
 AI::XGBoost::CAPI::RAW::XGDMatrixNumRow($dtrain, \$rows);
 AI::XGBoost::CAPI::RAW::XGDMatrixNumCol($dtrain, \$cols);
 say "Dimensions: $rows, $cols";
 
 my $booster = 0;
 
 AI::XGBoost::CAPI::RAW::XGBoosterCreate( [$dtrain] , 1, \$booster);
 
 for my $iter (0 .. 10) {
     AI::XGBoost::CAPI::RAW::XGBoosterUpdateOneIter($booster, $iter, $dtrain);
 }
 
 my $out_len = 0;
 my $out_result = 0;
 
 AI::XGBoost::CAPI::RAW::XGBoosterPredict($booster, $dtest, 0, 0, \$out_len, \$out_result);
 my $ffi = FFI::Platypus->new();
 my $predictions = $ffi->cast(opaque => "float[$out_len]", $out_result);
 
 #say join "\n", @$predictions;
 
 AI::XGBoost::CAPI::RAW::XGBoosterFree($booster);
 AI::XGBoost::CAPI::RAW::XGDMatrixFree($dtrain);
 AI::XGBoost::CAPI::RAW::XGDMatrixFree($dtest);

=head1 DESCRIPTION

Wrapper for the C API.

The doc for the methods is extracted from doxygen comments: https://github.com/dmlc/xgboost/blob/master/include/xgboost/c_api.h

=head1 FUNCTIONS

=head2 XGBGetLastError

Get string message of the last error

All functions in this file will return 0 when success



( run in 0.573 second using v1.01-cache-2.11-cpan-5837b0d9d2c )