protected PredictionOfCurrencyDataTable GetData(string backupFileName, DateTime from, DateTime to) { var result = new PredictionOfCurrencyDataTable(Names); var serializer = new Serializer(); if (!serializer.Exists(backupFileName)) { for (var i = from; i < to; i = i.Add(DataParameter.Step)) { var vector = GetRawData(i, DataParameter.Step); if (vector.Length == Collectors.Count) { result.Add(new PredictionOfCurrencyData { Date = i, Vector = vector }); } } result = DataValueTypeConverter[DataType](result); result = DataProcessingMethodsConverter[DataProcessingMethods](result); serializer.Serialize(result, backupFileName); } else { result = serializer.Deserialize <PredictionOfCurrencyDataTable>(backupFileName); } return(result); }
protected void InitMaxsAndMins(PredictionOfCurrencyDataTable table) { Maxs = new PredictionOfCurrencyDataTable(Names); Maxs.Add(new PredictionOfCurrencyData { Vector = GetMaxs(table, GetBackupName()) }); Mins = new PredictionOfCurrencyDataTable(Names); Mins.Add(new PredictionOfCurrencyData { Vector = GetMins(table, GetBackupName()) }); }
protected void InitExpectedValuesAndDispersions(PredictionOfCurrencyDataTable table) { ExpectedValues = new PredictionOfCurrencyDataTable(Names); ExpectedValues.Add(new PredictionOfCurrencyData { Vector = GetExpectedValues(table, GetBackupName()) }); Dispersions = new PredictionOfCurrencyDataTable(Names); Dispersions.Add(new PredictionOfCurrencyData { Vector = GetDispersions(table, GetBackupName(), ExpectedValues[0].Vector) }); }
protected PredictionOfCurrencyDataTable Convert(PredictionOfCurrencyDataTable table, Func <Vector, Vector> formula) { var result = new PredictionOfCurrencyDataTable(Names); for (var i = 0; i < table.Data.Count; i++) { result.Add(new PredictionOfCurrencyData { Date = table[i].Date, Vector = formula(table[i].Vector) }); } return(result); }
protected Vector GetMins(PredictionOfCurrencyDataTable table, string backupName) { var serializer = new Serializer(); var backupFileName = $"BackupMins{ backupName }.json"; var result = new Vector(Collectors.Count); if (backupName == null || !serializer.Exists(backupFileName)) { for (var i = 0; i < result.Length; i++) { result[i] = table[Collectors[i].GetType().Name].Min(); } serializer.Serialize(result, backupFileName); } else { result = serializer.Deserialize <Vector>(backupFileName); } return(result); }
protected Vector GetDispersions(PredictionOfCurrencyDataTable table, string backupName, Vector expectedValues = null) { if (expectedValues == null) { expectedValues = GetExpectedValues(table, backupName); } var serializer = new Serializer(); var backupFileName = $"BackupDispersions{ backupName }.json"; var result = new Vector(Collectors.Count); if (backupName == null || !serializer.Exists(backupFileName)) { for (var i = 0; i < result.Length; i++) { result[i] = table[Collectors[i].GetType().Name].Aggregate(0.0, (x, y) => x + Math.Pow(y - expectedValues[i], 2)); } serializer.Serialize(result, backupFileName); } else { result = serializer.Deserialize <Vector>(backupFileName); } return(result); }
protected PredictionOfCurrencyDataTable ConvertInRelativePercentage(PredictionOfCurrencyDataTable table) => ConvertRelative(table, (current, previouse) => (current - previouse) / previouse);
protected PredictionOfCurrencyDataTable NormalizeAndScale(PredictionOfCurrencyDataTable table) => Scale(Normalize(table));
protected PredictionOfCurrencyDataTable Scale(PredictionOfCurrencyDataTable table) { InitMaxsAndMins(table); return(Convert(table, x => Scaling(x, Maxs[0].Vector, Mins[0].Vector))); }
protected PredictionOfCurrencyDataTable Normalize(PredictionOfCurrencyDataTable table) { InitExpectedValuesAndDispersions(table); return(Convert(table, x => Normalize(x, ExpectedValues[0].Vector, Dispersions[0].Vector))); }