public static byte[] Encode(int[] data, PredictorType predictorType = PredictorType.NULL) { var packedValue = PackUnpack(data, predictorType, false); var encodedValues = EncodeValues(packedValue); return(encodedValues); }
public static Int32[] GetArrayI32(Stream stream, PredictorType predictorType = PredictorType.NULL) { var decodedSymbols = DecodeBytes(stream); var unpackedValues = PackUnpack(decodedSymbols, predictorType); return(unpackedValues); }
public static Int32[] PackUnpack(Int32[] residuals, PredictorType predictorType, bool unpack = true) { if (predictorType == PredictorType.NULL) { return(residuals); } var unpackedResiduals = new Int32[residuals.Length]; for (int i = 0, c = residuals.Length; i < c; ++i) // The first four values are not handeled { if (i < 4) { unpackedResiduals[i] = residuals[i]; } else { var iPredicted = PredictValue(unpack ? unpackedResiduals : residuals, i, predictorType); unpackedResiduals[i] = (predictorType == PredictorType.Xor1 || predictorType == PredictorType.Xor2 ? residuals[i] ^ iPredicted : residuals[i] + ((unpack ? 1 : -1) * iPredicted)); } } return(unpackedResiduals); }
private static Int32 PredictValue(Int32[] unpackedValues, int index, PredictorType predictorType) { var v1 = unpackedValues[index - 1]; var v2 = unpackedValues[index - 2]; var v4 = unpackedValues[index - 4]; switch (predictorType) { default: case PredictorType.Lag1: case PredictorType.Xor1: return(v1); case PredictorType.Lag2: case PredictorType.Xor2: return(v2); case PredictorType.Stride1: return(v1 + (v1 - v2)); case PredictorType.Stride2: return(v2 + (v2 - v4)); case PredictorType.StripIndex: return(v2 - v4 < 8 && v2 - v4 > -8 ? v2 + (v2 - v4) : v2 + 2); case PredictorType.Ramp: return(index); } }
// Predict values public static Int32 PredictValue(List<Int32> rvVals, Int32 iIndex, PredictorType ePredType) { int iPredicted, v1 = rvVals[iIndex - 1], v2 = rvVals[iIndex - 2], v3 = rvVals[iIndex - 3], v4 = rvVals[iIndex - 4]; switch ( ePredType ) { default: iPredicted = v1; break; case PredictorType.PredLag2: case PredictorType.PredXor2: iPredicted = v2; break; case PredictorType.PredStride1: iPredicted = v1 + ( v1 - v2 ); break; case PredictorType.PredStride2: iPredicted = v2 + ( v2 - v4 ); break; case PredictorType.PredStripIndex: if ( v2 - v4 < 8 && v2 - v4 > -8 ) iPredicted = v2 + ( v2 - v4 ); else iPredicted = v2 + 2; break; case PredictorType.PredRamp: iPredicted = iIndex; break; } return iPredicted; }
public override int GetHashCode() { int hash = 13; hash = (hash * 7) + ExportNonTryptic.GetHashCode(); hash = (hash * 7) + ExportPartiallyTryptic.GetHashCode(); hash = (hash * 7) + ExportTryptic.GetHashCode(); hash = (hash * 7) + MaxDelCN.GetHashCode(); hash = (hash * 7) + MaxLogEValForXTandemAlignment.GetHashCode(); hash = (hash * 7) + MaxLogEValForXTandemExport.GetHashCode(); hash = (hash * 7) + MaxModificationsForAlignment.GetHashCode(); hash = (hash * 7) + MaxModsForAlignment.GetHashCode(); hash = (hash * 7) + MaxRankForExport.GetHashCode(); hash = (hash * 7) + MinDelCNForExport.GetHashCode(); hash = (hash * 7) + MinObservationsForExport.GetHashCode(); hash = (hash * 7) + MinXCorrForAlignment.GetHashCode(); hash = (hash * 7) + MinXCorrForExportNonTrytpic.GetHashCode(); hash = (hash * 7) + MinXCorrForExportPartiallyTrytpic.GetHashCode(); hash = (hash * 7) + MinXCorrForExportTrytpic.GetHashCode(); if (PredictionAlgorithm != null) { hash = (hash * 7) + PredictionAlgorithm.GetHashCode(); } hash = (hash * 7) + PredictorType.GetHashCode(); hash = (hash * 7) + Regression.GetHashCode(); hash = (hash * 7) + RegressionOrder.GetHashCode(); hash = (hash * 7) + TargetFilterType.GetHashCode(); hash = (hash * 7) + UseDelCN.GetHashCode(); return(hash); }
// tagMethods can be null public void TIFFPredictorInit(TiffTagMethods tagMethods) { // Merge codec-specific tag information and override parent get/set field methods. m_tif.MergeFieldInfo(m_predictFieldInfo, m_predictFieldInfo.Length); m_childTagMethods = tagMethods; m_parentTagMethods = m_tif.m_tagmethods; m_tif.m_tagmethods = m_tagMethods; m_predictor = Predictor.NONE; // default value m_predictorType = PredictorType.ptNone; // no predictor method }
public static IHiddenMarkovModelPredictor GetPredictor(PredictorType type) { switch (type) { case PredictorType.HmmLikelihood: return(new LikelihoodBasedPredictor()); case PredictorType.HmmViterbi: return(new ViterbiBasedPredictor()); case PredictorType.Genetic: return(new GeneticBasedPredictor()); } throw new ApplicationException("Not implemented"); }
public IPredictionResult Predict(PredictorType predictorType, double[][] observations, double[] weights) { var model = (HiddenMarkovModelMultivariateGaussianDistribution)HiddenMarkovModelFactory.GetModel(new ModelCreationParameters <IMultivariateDistribution> { Pi = _pi, TransitionProbabilityMatrix = _transitionProbabilityMatrix, Emissions = _emission }); //new HiddenMarkovModelState<IMultivariateDistribution>(_pi, _transitionProbabilityMatrix, _emission); model.Normalized = Normalized; var request = new PredictionRequest(); request.TrainingSet = observations; request.NumberOfDays = 1; request.Tolerance = PREDICTION_LIKELIHOOD_TOLERANCE; var predictor = HiddenMarkovModelPredictorFactory.GetPredictor(predictorType); return(predictor.Predict(model, request)); }
public IPredictionResult Predict(PredictorType predictorType, double[][] observations, int numberOfIterations, double likelihoodTolerance) { var model = (HiddenMarkovModelWeightedMixtureDistribution)HiddenMarkovModelFactory.GetModel <HiddenMarkovModelWeightedMixtureDistribution, Mixture <IMultivariateDistribution> >(new ModelCreationParameters <Mixture <IMultivariateDistribution> > { Pi = _pi, TransitionProbabilityMatrix = _transitionProbabilityMatrix, Emissions = _emission }); //HiddenMarkovModelStateFactory.GetState(new ModelCreationParameters<Mixture<IMultivariateDistribution>> { Pi = _pi, TransitionProbabilityMatrix = _transitionProbabilityMatrix, Emissions = _emission }); model.Normalized = Normalized; var request = new PredictionRequest(); request.TrainingSet = observations; request.NumberOfDays = 1; request.Tolerance = PREDICTION_LIKELIHOOD_TOLERANCE; request.TrainingLikelihoodTolerance = likelihoodTolerance; request.NumberOfTrainingIterations = numberOfIterations; var predictor = HiddenMarkovModelPredictorFactory.GetPredictor(predictorType); return(predictor.Predict(model, request)); }
public PredictorTypeInfo(Type predictorType, string displayName) { this.predictorType = predictorType; this.displayName = displayName; try { predictorProperties = (List <PredictorPropertyBase>)PredictorType.InvokeMember("Properties", BindingFlags.GetField | BindingFlags.Static | BindingFlags.Public, null, null, null); } catch { ErrorNotifier.showError("Class \"" + predictorType.FullName + "\" is not implemented correctly."); } try { toolTipInfo = (string)PredictorType.InvokeMember("ToolTipInfo", BindingFlags.GetField | BindingFlags.Static | BindingFlags.Public, null, null, null); } catch { toolTipInfo = displayName + " Branch Predictor"; } }
private bool PredictorSetupEncode() { if (!predictor_setupencode() || !PredictorSetup()) { return(false); } m_passThruEncode = true; if (m_predictor == Predictor.HORIZONTAL) { switch (m_tif.m_dir.td_bitspersample) { case 8: m_predictorType = PredictorType.ptHorDiff8; break; case 16: m_predictorType = PredictorType.ptHorDiff16; break; case 32: m_predictorType = PredictorType.ptHorDiff32; break; } // Override default encoding method with one that does the predictor stuff. m_passThruEncode = false; } else if (m_predictor == Predictor.FLOATINGPOINT) { m_predictorType = PredictorType.ptFpDiff; // Override default encoding method with one that does the predictor stuff. m_passThruEncode = false; } return(true); }
private bool PredictorSetupEncode() { if (!predictor_setupencode() || !PredictorSetup()) return false; m_passThruEncode = true; if (m_predictor == PredictionScheme.Horizontal) { switch (m_tif.m_dir.td_bitspersample) { case 8: m_predictorType = PredictorType.ptHorDiff8; break; case 16: m_predictorType = PredictorType.ptHorDiff16; break; case 32: m_predictorType = PredictorType.ptHorDiff32; break; } // Override default encoding method with one that does the predictor stuff. m_passThruEncode = false; } else if (m_predictor == PredictionScheme.FloatingPoint) { m_predictorType = PredictorType.ptFpDiff; // Override default encoding method with one that does the predictor stuff. m_passThruEncode = false; } return true; }
private bool PredictorSetupDecode() { if (!predictor_setupdecode() || !PredictorSetup()) return false; m_passThruDecode = true; if (m_predictor == PredictionScheme.Horizontal) { switch (m_tif.m_dir.td_bitspersample) { case 8: m_predictorType = PredictorType.ptHorAcc8; break; case 16: m_predictorType = PredictorType.ptHorAcc16; break; case 32: m_predictorType = PredictorType.ptHorAcc32; break; } // Override default decoding method with one that does the predictor stuff. m_passThruDecode = false; // If the data is horizontally differenced 16-bit data that requires byte-swapping, // then it must be byte swapped before the accumulation step. We do this with a // special-purpose method and override the normal post decoding logic that the // library setup when the directory was read. if ((m_tif.m_flags & TiffFlags.Swab) == TiffFlags.Swab) { if (m_predictorType == PredictorType.ptHorAcc16) { m_predictorType = PredictorType.ptSwabHorAcc16; m_tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmNone; } else if (m_predictorType == PredictorType.ptHorAcc32) { m_predictorType = PredictorType.ptSwabHorAcc32; m_tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmNone; } } } else if (m_predictor == PredictionScheme.FloatingPoint) { m_predictorType = PredictorType.ptFpAcc; // Override default decoding method with one that does the predictor stuff. m_passThruDecode = false; // The data should not be swapped outside of the floating point predictor, the // accumulation method should return bytes in the native order. if ((m_tif.m_flags & TiffFlags.Swab) == TiffFlags.Swab) m_tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmNone; // Allocate buffer to keep the decoded bytes before rearranging in the right order } return true; }
// tagMethods can be null public void TIFFPredictorInit(TiffTagMethods tagMethods) { // Merge codec-specific tag information and override parent get/set field methods. m_tif.MergeFieldInfo(m_predictFieldInfo, m_predictFieldInfo.Length); m_childTagMethods = tagMethods; m_parentTagMethods = m_tif.m_tagmethods; m_tif.m_tagmethods = m_tagMethods; m_predictor = PredictionScheme.None; // default value m_predictorType = PredictorType.ptNone; // no predictor method }
private bool PredictorSetupDecode() { if (!predictor_setupdecode() || !PredictorSetup()) { return(false); } m_passThruDecode = true; if (m_predictor == Predictor.HORIZONTAL) { switch (m_tif.m_dir.td_bitspersample) { case 8: m_predictorType = PredictorType.ptHorAcc8; break; case 16: m_predictorType = PredictorType.ptHorAcc16; break; case 32: m_predictorType = PredictorType.ptHorAcc32; break; } // Override default decoding method with one that does the predictor stuff. m_passThruDecode = false; // If the data is horizontally differenced 16-bit data that requires byte-swapping, // then it must be byte swapped before the accumulation step. We do this with a // special-purpose method and override the normal post decoding logic that the // library setup when the directory was read. if ((m_tif.m_flags & TiffFlags.SWAB) == TiffFlags.SWAB) { if (m_predictorType == PredictorType.ptHorAcc16) { m_predictorType = PredictorType.ptSwabHorAcc16; m_tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmNone; } else if (m_predictorType == PredictorType.ptHorAcc32) { m_predictorType = PredictorType.ptSwabHorAcc32; m_tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmNone; } } } else if (m_predictor == Predictor.FLOATINGPOINT) { m_predictorType = PredictorType.ptFpAcc; // Override default decoding method with one that does the predictor stuff. m_passThruDecode = false; // The data should not be swapped outside of the floating point predictor, the // accumulation method should return bytes in the native order. if ((m_tif.m_flags & TiffFlags.SWAB) == TiffFlags.SWAB) { m_tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmNone; } // Allocate buffer to keep the decoded bytes before rearranging in the right order } return(true); }
private bool PredictorSetupEncode() { if (!predictor_setupencode() || !PredictorSetup()) return false; m_passThruEncode = true; if (m_predictor == Predictor.HORIZONTAL) { switch (m_tif.m_dir.td_bitspersample) { case 8: m_predictorType = PredictorType.ptHorDiff8; break; case 16: m_predictorType = PredictorType.ptHorDiff16; break; case 32: m_predictorType = PredictorType.ptHorDiff32; break; } // Override default encoding method with one that does the predictor stuff. m_passThruEncode = false; } else if (m_predictor == Predictor.FLOATINGPOINT) { m_predictorType = PredictorType.ptFpDiff; // Override default encoding method with one that does the predictor stuff. m_passThruEncode = false; } return true; }
public static bool UnpackResiduals(List<double> rvResidual, out List<double> rvVals, PredictorType ePredType) { if( ePredType == PredictorType.PredXor1 || ePredType == PredictorType.PredXor2 ) { rvVals = null; return false; } if( ePredType == PredictorType.PredNULL ) { rvVals = rvResidual; return true; } rvVals = new List<double>(rvResidual.Count); for( Int32 i = 0; i < rvResidual.Count; i++ ) { if( i < 4 ) { // The first four values are just primers rvVals[i] = rvResidual[i]; } else { // Get a predicted value var iPredicted = PredictValue(rvVals, i, ePredType); // Decode the value as the residual plus predicted rvVals[i] = rvResidual[i] + iPredicted; } } return true; }
// Returns the original values from the predicted residual values. public static bool UnpackResiduals(List<Int32> rvResidual, out List<Int32> rvVals, PredictorType ePredType) { rvVals = new List<int>(rvResidual.Count); for( int i = 0; i < rvResidual.Count; i++ ) { if( i < 4 ) { // The first four values are just primers rvVals[i] = rvResidual[i]; } else { // Get a predicted value int iPredicted = PredictValue(rvVals, i, ePredType); if( ePredType == PredictorType.PredXor1 || ePredType == PredictorType.PredXor2 ) { // Decode the residual as the current value XOR predicted rvVals[i] = rvResidual[i] ^ iPredicted; } else { // Decode the residual as the current value plus predicted rvVals[i] = rvResidual[i] + iPredicted; } } } return true; }