starting to develop a c# wrapper for xgboost

This commit is contained in:
giuliohome 2014-08-30 00:36:01 +02:00
parent f3136c2d92
commit 6c3bc36a25
4 changed files with 213 additions and 0 deletions

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Le informazioni generali relative a un assembly sono controllate dal seguente
// set di attributi. Per modificare le informazioni associate a un assembly
// occorre quindi modificare i valori di questi attributi.
[assembly: AssemblyTitle("xgboost_sharp_wrapper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("xgboost_sharp_wrapper")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Se si imposta ComVisible su false, i tipi in questo assembly non saranno visibili
// ai componenti COM. Se è necessario accedere a un tipo in questo assembly da
// COM, impostare su true l'attributo ComVisible per tale tipo.
[assembly: ComVisible(false)]
// Se il progetto viene esposto a COM, il GUID che segue verrà utilizzato per creare l'ID della libreria dei tipi
[assembly: Guid("accc4026-fa8e-41d8-aaa8-1ca69c2b2db5")]
// Le informazioni sulla versione di un assembly sono costituite dai seguenti quattro valori:
//
// Numero di versione principale
// Numero di versione secondario
// Numero build
// Revisione
//
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// utilizzando l'asterisco (*) come descritto di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace xgboost_sharp_wrapper
{
public class xgboost
{
private const string dll_path="..\\x64\\Release\\";
[DllImport(dll_path+"xgboost_wrapper.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern IntPtr XGDMatrixCreateFromFile(string fname, int silent);
public IntPtr SharpXGDMatrixCreateFromFile(string fname, int silent)
{
return XGDMatrixCreateFromFile(fname, silent);
}
[DllImport(dll_path + "xgboost_wrapper.dll")]
public static extern IntPtr XGBoosterCreate(IntPtr[] dmats, System.UInt32 len);
[DllImport(dll_path + "xgboost_wrapper.dll")]
public static extern void XGBoosterUpdateOneIter(IntPtr handle, int iter, IntPtr dtrain);
[DllImport(dll_path + "xgboost_wrapper.dll")]
public static extern string XGBoosterEvalOneIter(IntPtr handle, int iter, IntPtr[] dmats,
string[] evnames, System.UInt32 len);
/*!
* \brief make prediction based on dmat
* \param handle handle
* \param dmat data matrix
* \param output_margin whether only output raw margin value
* \param len used to store length of returning result
*/
[DllImport(dll_path + "xgboost_wrapper.dll")]
public static extern Double[] XGBoosterPredict(IntPtr handle, IntPtr dmat, int output_margin, System.UInt32 len);
/*!
* \brief load model from existing file
* \param handle handle
* \param fname file name
*/
[DllImport(dll_path + "xgboost_wrapper.dll")]
public static extern void XGBoosterLoadModel(IntPtr handle, string fname);
/*!
* \brief save model into existing file
* \param handle handle
* \param fname file name
*/
[DllImport(dll_path + "xgboost_wrapper.dll")]
public static extern void XGBoosterSaveModel(IntPtr handle, string fname);
/*!
* \brief dump model, return array of strings representing model dump
* \param handle handle
* \param fmap name to fmap can be empty string
* \param out_len length of output array
* \return char *data[], representing dump of each model
*/
[DllImport(dll_path + "xgboost_wrapper.dll")]
public static extern string XGBoosterDumpModel(IntPtr handle, string fmap,
System.UInt32 out_len);
}
}

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>xgboost_sharp_wrapper</RootNamespace>
<AssemblyName>xgboost_sharp_wrapper</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="xgboost.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,38 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2013 for Windows Desktop
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xgboost_sharp_wrapper", "xgboost_sharp_wrapper.csproj", "{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "kaggle_higgs_demo", "..\kaggle_higgs_demo\kaggle_higgs_demo.csproj", "{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}.Debug|x64.ActiveCfg = Debug|x64
{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}.Debug|x64.Build.0 = Debug|x64
{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}.Release|Any CPU.Build.0 = Release|Any CPU
{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}.Release|x64.ActiveCfg = Release|x64
{2D0E7F78-53DD-4501-8BD9-69E21A5051E3}.Release|x64.Build.0 = Release|x64
{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}.Debug|x64.ActiveCfg = Debug|x64
{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}.Debug|x64.Build.0 = Debug|x64
{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}.Release|Any CPU.Build.0 = Release|Any CPU
{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}.Release|x64.ActiveCfg = Release|x64
{2EB1B15E-B7CA-494A-B4DC-BF56897A3F2F}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal