private float[] GetFloatInfo(string field) { ulong lenULong; IntPtr result; int output = XGBoostNative.XGDMatrixGetFloatInfo(_handle, field, out lenULong, out result); if (output == -1) { throw new DllFailException(XGBoostNative.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; XGBoostNative.XGBoosterDumpModel(handle, fmap, with_stats, out length, out dumpStr); return(dumpStr); }
public void Update(DMatrix train, int iter) { var output = XGBoostNative.XGBoosterUpdateOneIter(Handle, iter, train.Handle); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } XGBoostNative.XGDMatrixFree(handle); disposed = true; }
public void LoadModelFromBuffer(byte[] buf) { int output = XGBoostNative.XGBoosterLoadModelFromBuffer(handle, buf, buf.Length); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } }
public void SetParameter(string name, string val) { int output = XGBoostNative.XGBoosterSetParam(handle, name, val); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } }
private void SetFloatInfo(string field, float[] floatInfo) { ulong len = (ulong)floatInfo.Length; int output = XGBoostNative.XGDMatrixSetFloatInfo(_handle, field, floatInfo, len); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } }
public XGBooster(DMatrix train) { var dmats = new[] { train.Handle }; var len = unchecked ((ulong)dmats.Length); var output = XGBoostNative.XGBoosterCreate(dmats, len, out handle); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } }
public XGBooster() { IntPtr tempPtr; var output = XGBoostNative.XGBoosterCreate(null, 0, out tempPtr); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } handle = tempPtr; }
public XGBooster(string fileName, int silent = 1) { IntPtr tempPtr; var newBooster = XGBoostNative.XGBoosterCreate(null, 0, out tempPtr); var output = XGBoostNative.XGBoosterLoadModel(tempPtr, fileName); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } handle = tempPtr; }
public XGBooster(IDictionary <string, object> parameters, DMatrix train) { var dmats = new[] { train.Handle }; var len = unchecked ((ulong)dmats.Length); var output = XGBoostNative.XGBoosterCreate(dmats, len, out handle); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } SetParameters(parameters); }
public float[] Predict(DMatrix test, bool predContribs = false, int ntreeLimit = 0) { ulong predsLen; IntPtr predsPtr; int optionsMask = predContribs ? ContribsOptionMask : NormalOptionMask; var output = XGBoostNative.XGBoosterPredict( handle, test.Handle, optionsMask, ntreeLimit, out predsLen, out predsPtr); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } return(GetPredictionsArray(predsPtr, predsLen)); }
public byte[] GetModelRaw() { int length; IntPtr dumpPtr; int output = XGBoostNative.XGBoosterGetModelRaw(handle, out length, out dumpPtr); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } byte[] modelBytes = new byte[length]; Marshal.Copy(dumpPtr, modelBytes, 0, length); return(modelBytes); }
// Dispose pattern from MSDN documentation protected virtual void Dispose(bool disposing) { if (disposed) { return; } int output = XGBoostNative.XGDMatrixFree(_handle); if (output == -1) { throw new DllFailException(XGBoostNative.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 = XGBoostNative.XGDMatrixCreateFromMat(data1D, nrows, ncols, Missing, out _handle); if (output == -1) { throw new DllFailException(XGBoostNative.XGBGetLastError()); } if (labels != null) { Label = labels; } }
public void Save(string fileName) { XGBoostNative.XGBoosterSaveModel(handle, fileName); }