private double[] ConvertToValidInputType(object inputData) { if (inputData.GetType() == PredictionType) { return((double[])inputData); } // if not exact same type, try parsing as double if (!AI.Utils.Types.IsList(inputData)) { throw new ArgumentException("Type cannot be converted"); } var inputList = (IList)inputData; var outputList = new double[inputList.Count]; for (int i = 0; i < inputList.Count; i++) { double parsed; if (!double.TryParse(inputList[i].ToString(), out parsed)) { throw new Exception( "Input data type is not valid and conversion failed." + Environment.NewLine + "Supplied : " + inputData.GetType().ToString() + Environment.NewLine + "Expected : " + PredictionType.ToString()); } else { outputList[i] = parsed; } } return(outputList); }
private void ConfigurePredicitonType(PredictionType type) { switch (type) { case PredictionType.EnglandWales2017: pollingDataPath = Path.Combine(Environment.CurrentDirectory, "Data", "yougov2017.csv"); containsScotland = false; break; case PredictionType.Scotland2017: pollingDataPath = Path.Combine(Environment.CurrentDirectory, "Data", "yougov2017Scot.csv"); containsScotland = true; break; case PredictionType.EnglandWales2019: pollingDataPath = Path.Combine(Environment.CurrentDirectory, "Data", "yougov2019.csv"); containsScotland = false; break; case PredictionType.Scotland2019: pollingDataPath = Path.Combine(Environment.CurrentDirectory, "Data", "yougov2019Scot.csv"); containsScotland = true; break; default: throw new Exception($"Unhandled prediction type {type.ToString()}"); } }
private double ConvertToValidInputType(object inputData) { if (inputData.GetType() == PredictionType) { return((double)inputData); } // if not exact same type, try parsing as double var parsed = new double(); if (!double.TryParse(inputData.ToString(), out parsed)) { throw new Exception( "Input data type is not valid and conversion failed." + Environment.NewLine + "Supplied : " + inputData.GetType().ToString() + Environment.NewLine + "Expected : " + PredictionType.ToString()); } else { return(parsed); } }
public void Validate() { if (this.GetEncoderModeIndex() < 0) { throw new Exception("unsupported encoder mode"); } this.SetDefaultValuesForMode(); if (Padding < 0) { throw new Exception("unsupported padding value " + Padding.ToString()); } if (BlockSize != 0 && (BlockSize < 256 || BlockSize >= FlakeConstants.MAX_BLOCKSIZE)) { throw new Exception("unsupported block size " + BlockSize.ToString()); } if (MinLPCOrder > MaxLPCOrder || MaxLPCOrder > lpc.MAX_LPC_ORDER) { throw new Exception("invalid MaxLPCOrder " + MaxLPCOrder.ToString()); } if (MinFixedOrder < 0 || MinFixedOrder > 4) { throw new Exception("invalid MinFixedOrder " + MinFixedOrder.ToString()); } if (MaxFixedOrder < 0 || MaxFixedOrder > 4) { throw new Exception("invalid MaxFixedOrder " + MaxFixedOrder.ToString()); } if (MinPartitionOrder < 0) { throw new Exception("invalid MinPartitionOrder " + MinPartitionOrder.ToString()); } if (MinPartitionOrder > MaxPartitionOrder || MaxPartitionOrder > 8) { throw new Exception("invalid MaxPartitionOrder " + MaxPartitionOrder.ToString()); } if (PredictionType == PredictionType.None) { throw new Exception("invalid PredictionType " + PredictionType.ToString()); } if (PredictionType != PredictionType.Fixed) { if (WindowMethod == WindowMethod.Invalid) { throw new InvalidOperationException("invalid WindowMethod " + WindowMethod.ToString()); } if (WindowFunctions == WindowFunction.None) { throw new InvalidOperationException("invalid WindowFunctions " + WindowFunctions.ToString()); } if (EstimationDepth > 32 || EstimationDepth < 1) { throw new InvalidOperationException("invalid EstimationDepth " + EstimationDepth.ToString()); } if (MinPrecisionSearch < 0 || MinPrecisionSearch >= lpc.MAX_LPC_PRECISIONS) { throw new Exception("unsupported MinPrecisionSearch value"); } if (MaxPrecisionSearch < 0 || MaxPrecisionSearch >= lpc.MAX_LPC_PRECISIONS) { throw new Exception("unsupported MaxPrecisionSearch value"); } if (MaxPrecisionSearch < MinPrecisionSearch) { throw new Exception("unsupported MaxPrecisionSearch value"); } } if (!AllowNonSubset && !IsSubset()) { throw new Exception("the encoding parameters specified do not conform to the FLAC Subset"); } }