public static DataArray<double> Abs(DataArray<double> data) { if (data == null) { throw new ArgumentNullException("data", "DataArray must not be null."); } var array = new DataArray<double>(data.Count); for (int i = 0; i < data.StartIndex; i++) { array.Add(0.0); } for (int j = data.StartIndex; j < data.Count; j++) { array.Add(Math.Abs(data[j])); } array.StartIndex = data.StartIndex; return array; }
public static DataArray<double> Cumulate(DataArray<double> data) { if (data == null) { throw new ArgumentNullException("data", "DataArray must not be null."); } var array = new DataArray<double>(data.Count); for (int i = 0; i < data.StartIndex; i++) { array.Add(0.0); } if (data.StartIndex < data.Count) { array.Add(data[data.StartIndex]); for (int j = data.StartIndex + 1; j < data.Count; j++) { array.Add(data[j] + array[j - 1]); } } array.StartIndex = data.StartIndex; return array; }
public void ReadFeatureVector(string path) { byte[] bytes = File.ReadAllBytes(path); c.w("Reading input file header\tOK\r\n"); uint [] header = new uint[4]; int header_size = header.Length * sizeof(uint); for (int i = 0; i < header.Length; i++) { header[i] = ConvertToLittleEndean(BitConverter.ToUInt32(bytes, i * 4)); } int n_images = (int)header[1]; int image_width = (int)header[2]; int image_height = (int)header[3]; int image_size = image_width * image_height; c.w($"header.n_images\t\t\t{n_images:N0}\r\n"); c.w($"header.image_width\t\t{image_width} px\r\n"); c.w($"header.image_height\t\t{image_height} px\r\n"); c.w($"header.image_size\t\t{image_size} b\r\n"); for (int i = 0; i < n_images; i++) { var index = header_size + (i * image_size); var image_bytes = new byte[image_size]; Buffer.BlockCopy(bytes, index, image_bytes, 0, image_size); DataArray.Add(new Data() { FeatureVector = image_bytes }); // SaveImage(image_bytes, image_width, image_height, $"D:\\Projects\\Git\\csharp-mnist\\csharp-mnist\\images\\{i}.png"); } c.w($"\r\nSuccessfully read {DataArray.Count:N0} vectors.\r\n\r\n"); }
public static void IncrementMaidScenarioExecuteCount(int eventID, Maid maid) { if (maid == null) { return; } //NDebug.AssertNull(maid); //string guid = maid.status.guid; DataArray <int, byte> dataArray = CreateMaidDataArray(maid); byte b = dataArray.Get(eventID, false); b = 255; //if (b < 255) //{ // b += 1; //} dataArray.Add(eventID, b, true); m_SaveDataScenarioExecuteCountArray.Add(eventID, b, true); }
private static DataArray<double> PerformArithmeticOperation(DataArray<double> data, double value, ArithmeticOperation operation) { if (data == null) { throw new ArgumentNullException("data", "DataArray<double> must not be null."); } var array = new DataArray<double>(data.Count); for (int i = 0; i < data.StartIndex; i++) { array.Add(0.0); } switch (operation) { case ArithmeticOperation.Negation: for (int j = data.StartIndex; j < data.Count; j++) { array.Add(-data[j]); } break; case ArithmeticOperation.Addition: for (int k = data.StartIndex; k < data.Count; k++) { array.Add(data[k] + value); } break; case ArithmeticOperation.Subtraction: for (int m = data.StartIndex; m < data.Count; m++) { array.Add(data[m] - value); } break; case ArithmeticOperation.Multiplication: for (int n = data.StartIndex; n < data.Count; n++) { array.Add(data[n] * value); } break; case ArithmeticOperation.Division: for (int num6 = data.StartIndex; num6 < data.Count; num6++) { array.Add(data[num6] / value); } break; case ArithmeticOperation.Modulus: for (int num7 = data.StartIndex; num7 < data.Count; num7++) { array.Add(data[num7] % value); } break; case ArithmeticOperation.Power: for (int num8 = data.StartIndex; num8 < data.Count; num8++) { array.Add(Math.Pow(data[num8], value)); } break; } array.StartIndex = data.StartIndex; return array; }
private static DataArray<double> PerformLogicalOperation(DataArray<double> data1, DataArray<double> data2, LogicalOperation operation) { if (data1 == null) { throw new ArgumentNullException("data1", "DataArray<double> must not be null."); } if (data2 == null) { throw new ArgumentNullException("data2", "DataArray<double> must not be null."); } if (data1.Count != data2.Count) { throw new ArgumentException("Array sizes do not match.", "data1"); } var array = new DataArray<double>(data1.Count); DataArray<double> array2 = data2; if (data1.StartIndex > data2.StartIndex) { array2 = data1; } for (int i = 0; i < array2.StartIndex; i++) { array.Add(0.0); } switch (operation) { case LogicalOperation.And: for (int j = array2.StartIndex; j < array2.Count; j++) { array.Add(Convert.ToDouble((data1[j] != 0.0) && (data2[j] != 0.0))); } break; case LogicalOperation.Or: for (int k = array2.StartIndex; k < array2.Count; k++) { array.Add(Convert.ToDouble((data1[k] != 0.0) || (data2[k] != 0.0))); } break; case LogicalOperation.Xor: for (int m = array2.StartIndex; m < array2.Count; m++) { array.Add(Convert.ToDouble((data1[m] != 0.0) ^ (data2[m] != 0.0))); } break; } array.StartIndex = array2.StartIndex; return array; }
private static DataArray<double> PerformArithmeticOperation(DataArray<double> data1, DataArray<double> data2, ArithmeticOperation operation) { if (data1 == null) { throw new ArgumentNullException("data1", "DataArray<double> must not be null."); } if (data2 == null) { throw new ArgumentNullException("data2", "DataArray<double> must not be null."); } if (data1.Count != data2.Count) { throw new ArgumentException("Array sizes do not match.", "data1"); } var array = new DataArray<double>(data1.Count); DataArray<double> array2 = data2; if (data1.StartIndex > data2.StartIndex) { array2 = data1; } for (int i = 0; i < array2.StartIndex; i++) { array.Add(0.0); } switch (operation) { case ArithmeticOperation.Addition: for (int j = array2.StartIndex; j < array2.Count; j++) { array.Add(data1[j] + data2[j]); } break; case ArithmeticOperation.Subtraction: for (int k = array2.StartIndex; k < array2.Count; k++) { array.Add(data1[k] - data2[k]); } break; case ArithmeticOperation.Multiplication: for (int m = array2.StartIndex; m < array2.Count; m++) { array.Add(data1[m] * data2[m]); } break; case ArithmeticOperation.Division: for (int n = array2.StartIndex; n < array2.Count; n++) { array.Add(data1[n] / data2[n]); } break; case ArithmeticOperation.Modulus: for (int num6 = array2.StartIndex; num6 < array2.Count; num6++) { array.Add(data1[num6] % data2[num6]); } break; case ArithmeticOperation.Power: for (int num7 = array2.StartIndex; num7 < array2.Count; num7++) { array.Add(Math.Pow(data1[num7], data2[num7])); } break; } array.StartIndex = array2.StartIndex; return array; }
public static DataArray<double> Lowest(DataArray<double> data, int periods) { if (data == null) { throw new ArgumentNullException("data", "DataArray<double> must not be null."); } if (periods <= 0) { throw new ArgumentOutOfRangeException("periods", "Periods must not be negative or zero."); } DataArray<double> array = new DataArray<double>(data.Count); int num = (((data.StartIndex + periods) - 1) < data.Count) ? ((data.StartIndex + periods) - 1) : data.Count; for (int i = 0; i < num; i++) { array.Add(0.0); } if (num < data.Count) { double maxValue = 0.0; int num4 = num - periods; for (int j = num; j < data.Count; j++) { if (num4 <= (j - periods)) { maxValue = double.MaxValue; for (int k = (j - periods) + 1; k <= j; k++) { if (data[k] < maxValue) { maxValue = data[k]; num4 = k; } } } else if (data[j] < maxValue) { maxValue = data[j]; num4 = j; } array.Add(maxValue); } } array.StartIndex = num; return array; }
public static DataArray<double> Minimum(DataArray<double> data, double value) { if (data == null) { throw new ArgumentNullException("data", "DataArray must not be null."); } var array = new DataArray<double>(data.Count); for (int i = 0; i < data.StartIndex; i++) { array.Add(0.0); } for (int j = data.StartIndex; j < data.Count; j++) { array.Add((data[j] < value) ? data[j] : value); } array.StartIndex = data.StartIndex; return array; }
public static DataArray<double> Variance(StockSeriesData data, int periods) { if (data == null) { throw new ArgumentNullException("data", "DataArray<double> must not be null."); } if (periods <= 0) { throw new ArgumentOutOfRangeException("periods", "Periods must not be negative or zero."); } var array = new DataArray<double>(data.Count); int num = (((data.StartIndex + periods) - 1) < data.Count) ? ((data.StartIndex + periods) - 1) : data.Count; for (int i = 0; i < num; i++) { array.Add(0.0); } if (num < data.Count) { double num3 = 0.0; double num4 = 0.0; for (int j = data.StartIndex; j < (data.StartIndex + periods); j++) { num3 += (double)data[j].close; num4 += (double)(data[j].close * data[j].close); } array.Add((num4 / (periods)) - ((num3 / (periods)) * (num3 / (periods)))); for (int k = num + 1; k < data.Count; k++) { num3 = (num3 - (double)data[k - periods].close) + (double)data[k].close; num4 = (num4 - (double)(data[k - periods].close * data[k - periods].close)) + (double)(data[k].close * data[k].close); array.Add((num4 / (periods)) - ((num3 / (periods)) * (num3 / (periods)))); } } array.StartIndex = num; return array; }
private static DataArray<double> PerformRelationalOperation(DataArray<double> data1, DataArray<double> data2, RelationalOperation operation) { if (data1 == null) { throw new ArgumentNullException("data1", "DataArray<double> must not be null."); } if (data2 == null) { throw new ArgumentNullException("data2", "DataArray<double> must not be null."); } if (data1.Count != data2.Count) { throw new ArgumentException("Array sizes do not match.", "data1"); } var array = new DataArray<double>(data1.Count); DataArray<double> array2 = data2; if (data1.StartIndex > data2.StartIndex) { array2 = data1; } for (int i = 0; i < array2.StartIndex; i++) { array.Add(0.0); } switch (operation) { case RelationalOperation.Equal: for (int j = array2.StartIndex; j < array2.Count; j++) { array.Add(Convert.ToDouble(data1[j] == data2[j])); } break; case RelationalOperation.NotEqual: for (int k = array2.StartIndex; k < array2.Count; k++) { array.Add(Convert.ToDouble(data1[k] != data2[k])); } break; case RelationalOperation.Greater: for (int m = array2.StartIndex; m < array2.Count; m++) { array.Add(Convert.ToDouble(data1[m] > data2[m])); } break; case RelationalOperation.GreaterEqual: for (int n = array2.StartIndex; n < array2.Count; n++) { array.Add(Convert.ToDouble(data1[n] >= data2[n])); } break; case RelationalOperation.Less: for (int num6 = array2.StartIndex; num6 < array2.Count; num6++) { array.Add(Convert.ToDouble(data1[num6] < data2[num6])); } break; case RelationalOperation.LessEqual: for (int num7 = array2.StartIndex; num7 < array2.Count; num7++) { array.Add(Convert.ToDouble(data1[num7] <= data2[num7])); } break; } array.StartIndex = array2.StartIndex; return array; }
public static DataArray<double> ExponentialMovingAverage(StockSeriesData data, int periods) { if (data == null) { throw new ArgumentNullException("data", "DataArray<double> must not be null."); } if (periods <= 0) { throw new ArgumentOutOfRangeException("periods", "Periods must not be negative or zero."); } var array = new DataArray<double>(data.Count); int num = (((data.StartIndex + periods) - 1) < data.Count) ? ((data.StartIndex + periods) - 1) : data.Count; for (int i = 0; i < num; i++) { array.Add(0.0); } if (num < data.Count) { double num3 = 0.0; double num4 = 2.0 / (1 + periods); double num5 = 1.0 - num4; for (int j = data.StartIndex; j < (data.StartIndex + periods); j++) { num3 += (double)data[j].close; } array.Add(num3 / periods); for (int k = num + 1; k < data.Count; k++) { array.Add((num4 * (double)data[k].close) + (num5 * array[k - 1])); } } array.StartIndex = num; return array; }
private static DataArray<double> PerformLogicalOperation(DataArray<double> data, double value, LogicalOperation operation) { if (data == null) { throw new ArgumentNullException("data", "DataArray<double> must not be null."); } var array = new DataArray<double>(data.Count); for (int i = 0; i < data.StartIndex; i++) { array.Add(0.0); } switch (operation) { case LogicalOperation.Not: for (int j = data.StartIndex; j < data.Count; j++) { array.Add(Convert.ToDouble(data[j] == 0.0)); } break; case LogicalOperation.And: for (int k = data.StartIndex; k < data.Count; k++) { array.Add(Convert.ToDouble((data[k] != 0.0) && (value != 0.0))); } break; case LogicalOperation.Or: for (int m = data.StartIndex; m < data.Count; m++) { array.Add(Convert.ToDouble((data[m] != 0.0) || (value != 0.0))); } break; case LogicalOperation.Xor: for (int n = data.StartIndex; n < data.Count; n++) { array.Add(Convert.ToDouble((data[n] != 0.0) ^ (value != 0.0))); } break; } array.StartIndex = data.StartIndex; return array; }
/// <summary> /// Adds the specified bar. /// </summary> /// <param name="bar">The bar.</param> public void Add(Bar bar) { BarSeries.Add(bar); }
public static DataArray<double> Reference(DataArray<double> data, int index) { if (data == null) { throw new ArgumentNullException("data", "DataArray<double> must not be null."); } DataArray<double> array = new DataArray<double>(data.Count); if (index <= 0) { index *= -1; int num = ((data.StartIndex + index) < data.Count) ? (data.StartIndex + index) : data.Count; for (int m = 0; m < num; m++) { array.Add(0.0); } for (int n = num; n < data.Count; n++) { array.Add(data[n - index]); } array.StartIndex = num; return array; } int num4 = ((data.StartIndex - index) >= 0) ? (data.StartIndex - index) : 0; int num5 = (((data.Count - 1) - index) >= 0) ? ((data.Count - 1) - index) : -1; for (int i = 0; i < num4; i++) { array.Add(0.0); } for (int j = num4; j <= num5; j++) { array.Add(data[j + index]); } for (int k = num5 + 1; k < data.Count; k++) { array.Add(0.0); } array.StartIndex = num4; return array; }
private void AddData() { DataArray.Add(new Data { A = _random.NextDouble() * 100, B = _random.NextDouble() * 200 }); }
public static DataArray<double> WeightedMovingAverage(StockSeriesData data, int periods) { if (data == null) { throw new ArgumentNullException("data", "DataArray<double> must not be null."); } if (periods <= 0) { throw new ArgumentOutOfRangeException("periods", "Periods must not be negative or zero."); } DataArray<double> array = new DataArray<double>(data.Count); int num = (((data.StartIndex + periods) - 1) < data.Count) ? ((data.StartIndex + periods) - 1) : data.Count; for (int i = 0; i < num; i++) { array.Add(0.0); } if (num < data.Count) { double num3 = 0.0; double num4 = 0.0; double num5 = (periods * (periods + 1)) / 2; for (int j = data.StartIndex; j < (data.StartIndex + periods); j++) { num4 += ((j - data.StartIndex) + 1) * (double)data[j].close; num3 += (double)data[j].close; } array.Add(num4 / num5); for (int k = num + 1; k < data.Count; k++) { num4 = (num4 - num3) + (periods * (double)data[k].close); num3 = (num3 - (double)data[k - periods].close) + (double)data[k].close; array.Add(num4 / num5); } } array.StartIndex = num; return array; }
public static DataArray<double> Maximum(StockSeriesData data, double value) { if (data == null) { throw new ArgumentNullException("data", "DataArray must not be null."); } var array = new DataArray<double>(data.Count); for (int i = 0; i < data.StartIndex; i++) { array.Add(0.0); } for (int j = data.StartIndex; j < data.Count; j++) { array.Add(((double)data[j].close > value) ? (double)data[j].close : value); } array.StartIndex = data.StartIndex; return array; }
public static DataArray<double> Minimum(DataArray<double> data1, DataArray<double> data2) { if (data1 == null) { throw new ArgumentNullException("data1", "DataArray must not be null."); } if (data2 == null) { throw new ArgumentNullException("data2", "DataArray must not be null."); } if (data1.Count != data2.Count) { throw new ArgumentException("Array sizes do not match.", "data1"); } var array = new DataArray<double>(data1.Count); DataArray<double> array2 = data2; if (data1.StartIndex > data2.StartIndex) { array2 = data1; } for (int i = 0; i < array2.StartIndex; i++) { array.Add(0.0); } for (int j = array2.StartIndex; j < array2.Count; j++) { array.Add((data1[j] < data2[j]) ? data1[j] : data2[j]); } array.StartIndex = array2.StartIndex; return array; }
private static DataArray<double> PerformRelationalOperation(DataArray<double> data, double value, RelationalOperation operation) { if (data == null) { throw new ArgumentNullException("data", "DataArray<double> must not be null."); } var array = new DataArray<double>(data.Count); for (int i = 0; i < data.StartIndex; i++) { array.Add(0.0); } switch (operation) { case RelationalOperation.Equal: for (int j = data.StartIndex; j < data.Count; j++) { array.Add(Convert.ToDouble(data[j] == value)); } break; case RelationalOperation.NotEqual: for (int k = data.StartIndex; k < data.Count; k++) { array.Add(Convert.ToDouble(data[k] != value)); } break; case RelationalOperation.Greater: for (int m = data.StartIndex; m < data.Count; m++) { array.Add(Convert.ToDouble(data[m] > value)); } break; case RelationalOperation.GreaterEqual: for (int n = data.StartIndex; n < data.Count; n++) { array.Add(Convert.ToDouble(data[n] >= value)); } break; case RelationalOperation.Less: for (int num6 = data.StartIndex; num6 < data.Count; num6++) { array.Add(Convert.ToDouble(data[num6] < value)); } break; case RelationalOperation.LessEqual: for (int num7 = data.StartIndex; num7 < data.Count; num7++) { array.Add(Convert.ToDouble(data[num7] <= value)); } break; } array.StartIndex = data.StartIndex; return array; }
public void Add(double top, double bottom) { _top.Add(top); _bottom.Add(bottom); }