public int optimize(double[] x, double C, bool orthant) { const long msize = 5; var size = x.LongLength - 1; if (w == null || w.LongLength == 0) { iflag_ = 0; w = new CRFLite.Utils.FixedBigArray <double>(size * (2 * msize + 1) + 2 * msize, 1); diag = new double[size + 1]; if (orthant == true) { xi = new double[size + 1]; v = new double[size + 1]; } } if (orthant == true) { pseudo_gradient(x, C); } else { v = expected; } lbfgs_optimize(msize, x, orthant, C); if (iflag_ < 0) { Console.WriteLine("routine stops with unexpected error"); return(-1); } return(iflag_); }
//Generate feature string and its id list public void GenerateLexicalIdList(out IList <string> keyList, out IList <int> valList) { var fixArrayKey = new CRFLite.Utils.FixedBigArray <string>(Size, 0); keyList = fixArrayKey; var fixArrayValue = new CRFLite.Utils.FixedBigArray <int>(Size, 0); valList = fixArrayValue; Parallel.For(0, arrayFeatureFreqSize, parallelOption, i => { fixArrayKey[i] = arrayFeatureFreq[i].strFeature; fixArrayValue[i] = (int)(arrayFeatureFreq[i].value); }); }
private double ddot_(long size, CRFLite.Utils.FixedBigArray <double> dx, long dx_idx, CRFLite.Utils.FixedBigArray <double> dy, long dy_idx) { double ret = 0.0f; Parallel.For <double>(0, size, parallelOption, () => 0, (i, loop, subtotal) => { subtotal += dx[i + dx_idx] * dy[i + dy_idx]; return(subtotal); }, (subtotal) => // lock free accumulator { double initialValue; double newValue; do { initialValue = ret; // read current value newValue = initialValue + subtotal; //calculate new value }while (initialValue != Interlocked.CompareExchange(ref ret, newValue, initialValue)); }); return(ret); }