public int PredictionEnTransformXor(Foreseer foreseer) { IntField orig = this.Clone(); foreseer.Initialize(orig); int wrongPredictions = 0; int p = 0; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++, p++) { int predicted = foreseer.Foresee(orig, x, y); Data[p] = orig.Data[p] ^ predicted; if (Data[p] != 0) { wrongPredictions++; } foreseer.Learn(orig, x, y, orig.Data[p], predicted); } } return(wrongPredictions); }
public override int Foresee(IntField image, int x, int y) { _curArea = ExtractArea(image, x, y); if (_curArea == null) { return(_fallback.Foresee(image, x, y)); } if (_history.ContainsKey(_curArea)) { return(_history[_curArea].Predicted()); } else { return(_fallback.Foresee(image, x, y)); } }
public override int Foresee(IntField image, int x, int y) { _curArea = ExtractArea(image, x, y, out _curMostFreqSymbol, out _curSecondFreqSymbol); if (_curArea == null) { return(_fallback.Foresee(image, x, y)); } if (_history.ContainsKey(_curArea)) { return(_history[_curArea].MostFrequent > _history[_curArea].Other ? _curMostFreqSymbol : _curSecondFreqSymbol); } else { return(_fallback.Foresee(image, x, y)); } }
public void PredictionDeTransformXor(Foreseer foreseer) { IntField diff = this.Clone(); foreseer.Initialize(this); int p = 0; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++, p++) { int predicted = foreseer.Foresee(this, x, y); Data[p] = diff.Data[p] ^ predicted; foreseer.Learn(this, x, y, this.Data[p], predicted); } } }
public void Prediction(Foreseer foreseer) { IntField orig = this.Clone(); foreseer.Initialize(orig); int p = 0; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++, p++) { int predicted = foreseer.Foresee(orig, x, y); Data[p] = predicted; foreseer.Learn(orig, x, y, orig.Data[p], predicted); } } }
public override int Foresee(IntField image, int x, int y) { double conf0 = 0, conf1 = 0, conf2 = 0, conf3 = 0; foreach (var size in _sizes) { ulong hash = HashImageRegion(image, x, y, size.Width, size.Height); uint c0, c1, c2, c3; _hashtable.GetCounts(hash, out c0, out c1, out c2, out c3); double total = c0 + c1 + c2 + c3; if (total == 0) { continue; } double wt = Math.Sqrt(size.Width * size.Height); conf0 += c0 / total * wt; conf1 += c1 / total * wt; conf2 += c2 / total * wt; conf3 += c3 / total * wt; } if (conf0 == 0 && conf1 == 0 && conf2 == 0 && conf3 == 0) { return(_fallback.Foresee(image, x, y)); } else if (conf0 >= conf1 && conf0 >= conf2 && conf0 >= conf3) { return(0); } else if (conf1 >= conf2 && conf1 >= conf3) { return(1); } else if (conf2 >= conf3) { return(2); } else { return(3); } }
public void PredictionEnTransformDiff(Foreseer foreseer, int modulus) { IntField orig = this.Clone(); foreseer.Initialize(orig); int p = 0; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++, p++) { int predicted = foreseer.Foresee(orig, x, y); Data[p] = orig.Data[p] - predicted; if (Data[p] < 0) { Data[p] += modulus; } foreseer.Learn(orig, x, y, orig.Data[p], predicted); } } }
public override int Foresee(IntField image, int x, int y) { _curAreas.Clear(); for (int h = _height; h >= 1; h--) { var area = ExtractArea(image, x, y, h); if (area != null) { _curAreas.Add(area); } } foreach (var area in _curAreas) { ColorFrequencies cf; if (_history.TryGetValue(area, out cf)) { return(cf.Predicted()); } } return(_fallback.Foresee(image, x, y)); }