public override ValueGetter <RowId> GetIdGetter() { #if (DEBUG) Dictionary <RowId, int> localCache = new Dictionary <RowId, int>(); #endif // We do not change the ID (row to row transform). var getId = _inputCursor.GetIdGetter(); return((ref RowId pos) => { getId(ref pos); if (_shift > 0) { Contracts.Assert(_copy >= 0 && _copy <= _maxReplica); ulong left = pos.Low << _shift; left >>= _shift; left = pos.Low - left; ulong lo = pos.Low << _shift; ulong hi = pos.High << _shift; hi += left >> (64 - _shift); pos = new RowId(lo + (ulong)_copy, hi); #if (DEBUG) if (localCache.ContainsKey(pos)) { throw Contracts.Except("Id already taken: {0}", pos); } #endif } else { Contracts.Assert(_copy == 0); } }); }
public ResampleCursor(ResampleTransform view, RowCursor cursor, Func <int, bool> predicate, float lambda, int?seed, Random rand, Dictionary <RowId, int> cache, int classColumn, TClass classValue) { _view = view; _inputCursor = cursor; _lambda = lambda; uint?useed = seed.HasValue ? (uint)seed.Value : (uint?)null; _rand = rand == null?RandomUtils.Create(useed) : rand; _predicate = predicate; _cache = cache; _maxReplica = cache == null?Math.Max((int)(lambda * 3 + 1), 1) : _cache.Values.Max(); int maxReplica = _maxReplica + 1; _shift = 0; _idGetter = cursor.GetIdGetter(); while (maxReplica > 0) { _shift += 1; maxReplica >>= 1; } _copy = -1; _classValue = classValue; _classGetter = classColumn >= 0 ? _inputCursor.GetGetter <TClass>(classColumn) : null; }
public override ValueGetter <RowId> GetIdGetter() { var getId = _inputCursor.GetIdGetter(); return((ref RowId pos) => { getId(ref pos); }); }
public override ValueGetter <RowId> GetIdGetter() { // We do not change the ID (row to row transform). var getId = _inputCursor.GetIdGetter(); return((ref RowId pos) => { getId(ref pos); }); }
void LoadCache <TClass>(Random rand, RowCursor cur, int classColumn, TClass valueClass, IChannel ch) { _cacheReplica = new Dictionary <RowId, int>(); var hist = new Dictionary <TClass, long>(); var gid = cur.GetIdGetter(); var gcl = cur.GetGetter <TClass>(classColumn); RowId did = default(RowId); TClass cl = default(TClass); long nbIn = 0; long nbOut = 0; int rep; while (cur.MoveNext()) { gcl(ref cl); gid(ref did); if (!hist.ContainsKey(cl)) { hist[cl] = 1; } else { ++hist[cl]; } if (cl.Equals(valueClass)) { rep = NextPoisson(_args.lambda, rand); ++nbIn; } else { rep = 1; ++nbOut; } _cacheReplica[did] = rep; } if (nbIn == 0) { ch.Warning(MessageSensitivity.UserData, "Resample on a condition never happened: nbIn={0} nbOut={1}", nbIn, nbOut); } }
public override ValueGetter <RowId> GetIdGetter() { return(_trailingCursor.GetIdGetter()); }
public override ValueGetter <DataViewRowId> GetIdGetter() { return(_input.GetIdGetter()); }
public override ValueGetter <UInt128> GetIdGetter() { return(_trailingCursor.GetIdGetter()); }
public override ValueGetter <RowId> GetIdGetter() { return(_inputCursor.GetIdGetter()); }