/** * {@inheritDoc} */ public override Tuple Decode(int[] encoded, string parentFieldName) { //Debug.Assert(ArrayUtils.All(encoded, new Condition.Adapter<Integer>() { // public boolean eval(int i) // { // return i <= 1; // } //}); Debug.Assert(ArrayUtils.All(encoded, n => n <= 1)); //overlaps = (self.sdrs * encoded[0:self.n]).sum(axis=1) int[] overlap = new int[_sdrByCategory.Count]; for (int i = 0; i < _sdrByCategory.Count; i++) { int[] sdr = _sdrByCategory.GetSdr(i); for (int j = 0; j < sdr.Length; j++) { if (sdr[j] == encoded[j] && encoded[j] == 1) { overlap[i]++; } } } LOG.Debug("Overlaps for decoding:"); if (LOG.IsDebugEnabled) { int inx = 0; foreach (string category in _sdrByCategory.Keys) { LOG.Debug(overlap[inx] + " " + category); inx++; } } //matchingCategories = (overlaps > self.thresholdOverlap).nonzero()[0] int[] matchingCategories = ArrayUtils.Where(overlap, overlaps => overlaps > _thresholdOverlap); //int[] matchingCategories = ArrayUtils.where(overlap, new Condition.Adapter<Integer>() { // @Override // public boolean eval(int overlaps) // { // return overlaps > thresholdOverlap; // } //}); //int[] matchingCategories = overlap.Where(overlaps => overlaps > _thresholdOverlap).ToArray(); StringBuilder resultString = new StringBuilder(); List <MinMax> resultRanges = new List <MinMax>(); string fieldName; foreach (int index in matchingCategories) { if (resultString.Length != 0) { resultString.Append(" "); } resultString.Append(_sdrByCategory.GetCategory(index)); resultRanges.Add(new MinMax(index, index)); } if (string.IsNullOrEmpty(parentFieldName)) { fieldName = GetName() ?? String.Empty; } else { fieldName = string.Format("{0}.{1}", parentFieldName, GetName()); } Map <string, RangeList> fieldsDict = new Map <string, RangeList>(); fieldsDict.Add(fieldName, new RangeList(resultRanges, resultString.ToString())); // return ({fieldName: (resultRanges, resultString)}, [fieldName]) return(new DecodeResult(fieldsDict, new List <string> { fieldName })); }