private float[] GetFloatInfo(string field) { ulong lenULong; IntPtr result; int output = XGBOOST_NATIVE_METHODS.XGDMatrixGetFloatInfo(_handle, field, out lenULong, out result); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } int len = unchecked ((int)lenULong); float[] floatInfo = new float[len]; for (int i = 0; i < len; i++) { byte[] floatBytes = new byte[4]; floatBytes[0] = Marshal.ReadByte(result, 4 * i + 0); floatBytes[1] = Marshal.ReadByte(result, 4 * i + 1); floatBytes[2] = Marshal.ReadByte(result, 4 * i + 2); floatBytes[3] = Marshal.ReadByte(result, 4 * i + 3); float f = BitConverter.ToSingle(floatBytes, 0); floatInfo[i] = f; } return(floatInfo); }
public string[] DumpModelEx(string fmap, int with_stats, string format) { int length; string[] dumpStr; XGBOOST_NATIVE_METHODS.XGBoosterDumpModel(handle, fmap, with_stats, out length, out dumpStr); return(dumpStr); }
public void Update(DMatrix train, int iter) { var output = XGBOOST_NATIVE_METHODS.XGBoosterUpdateOneIter(Handle, iter, train.Handle); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } XGBOOST_NATIVE_METHODS.XGDMatrixFree(handle); disposed = true; }
public void SetParameter(string name, string val) { int output = XGBOOST_NATIVE_METHODS.XGBoosterSetParam(handle, name, val); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } }
private void SetFloatInfo(string field, float[] floatInfo) { ulong len = (ulong)floatInfo.Length; int output = XGBOOST_NATIVE_METHODS.XGDMatrixSetFloatInfo(_handle, field, floatInfo, len); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } }
public Booster(DMatrix train) { var dmats = new[] { train.Handle }; var len = unchecked ((ulong)dmats.Length); var output = XGBOOST_NATIVE_METHODS.XGBoosterCreate(dmats, len, out handle); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } }
public Booster(string fileName, int silent = 1) { IntPtr tempPtr; var newBooster = XGBOOST_NATIVE_METHODS.XGBoosterCreate(null, 0, out tempPtr); var output = XGBOOST_NATIVE_METHODS.XGBoosterLoadModel(tempPtr, fileName); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } handle = tempPtr; }
public float[] Predict(DMatrix test) { ulong predsLen; IntPtr predsPtr; var output = XGBOOST_NATIVE_METHODS.XGBoosterPredict( handle, test.Handle, normalPrediction, 0, out predsLen, out predsPtr); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } return(GetPredictionsArray(predsPtr, predsLen)); }
public Booster(IDictionary <string, object> parameters, DMatrix train) { var dmats = new[] { train.Handle }; var len = unchecked ((ulong)dmats.Length); var output = XGBOOST_NATIVE_METHODS.XGBoosterCreate(dmats, len, out handle); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } SetParameters(parameters); }
public DMatrix(float[] data1D, ulong nrows, ulong ncols, float[] labels = null) { int output = XGBOOST_NATIVE_METHODS.XGDMatrixCreateFromMat(data1D, nrows, ncols, Missing, out _handle); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } if (labels != null) { Label = labels; } }
// Dispose pattern from MSDN documentation protected virtual void Dispose(bool disposing) { if (disposed) { return; } int output = XGBOOST_NATIVE_METHODS.XGDMatrixFree(_handle); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } disposed = true; }
public DMatrix(float[][] data, float[] labels = null) { float[] data1D = Flatten2DArray(data); ulong nrows = unchecked ((ulong)data.Length); ulong ncols = unchecked ((ulong)data[0].Length); int output = XGBOOST_NATIVE_METHODS.XGDMatrixCreateFromMat(data1D, nrows, ncols, Missing, out _handle); if (output == -1) { throw new DllFailException(XGBOOST_NATIVE_METHODS.XGBGetLastError()); } if (labels != null) { Label = labels; } }
public string[] DumpModelEx(string fmap, int with_stats, string format) { int length; IntPtr treePtr; var intptrSize = IntPtr.Size; XGBOOST_NATIVE_METHODS.XGBoosterDumpModel(handle, fmap, with_stats, out length, out treePtr); var trees = new string[length]; int readSize = 0; var handle2 = GCHandle.Alloc(treePtr, GCHandleType.Pinned); //iterate through the length of the tree ensemble and pull the strings out from the returned pointer's array of pointers. prepend python's api convention of adding booster[i] to the beginning of the tree for (var i = 0; i < length; i++) { var ipt1 = Marshal.ReadIntPtr(Marshal.ReadIntPtr(handle2.AddrOfPinnedObject()), intptrSize * i); string s = Marshal.PtrToStringAnsi(ipt1); trees[i] = string.Format("booster[{0}]\n{1}", i, s); var bytesToRead = (s.Length * 2) + IntPtr.Size; readSize += bytesToRead; } handle2.Free(); return(trees); }
public void Save(string fileName) { XGBOOST_NATIVE_METHODS.XGBoosterSaveModel(handle, fileName); }