0

値のリストがあり、double または DateTime の可能性があります。

15、36、-7、12、8

このデータは時系列であるため、順序が重要です。また、リストには 3 ~ 6 個の値しかないため、大規模なデータ セットについて話しているわけではありません。

比率など、これらに関する統計を作成したいとします。

15/36、36/-7、-7/12、12/8 == .417、-5.14、-.583、1.5

そして比率の比率

.417/-5.14、-5.14/-.583、-.583/1.5

.. 等々。

過去の各値に対する各値の統計も生成する必要があります。

12/8、-7/8、36/8、15/8

12/-7、12/36、12/15

...

また、前の値の平均に対する各値の比率も必要です。

平均(12,-7) / 8 , 平均(12,-7,36) / 8

data が DateTime の場合、TimeSpan が使用されます。勾配、平均勾配、比率の傾向、勾配の傾向なども必要です。

基本的に、できるだけ多くの関連データを取得しようとしています。時系列であるため、関連するデータは、それぞれの左側の値と、最初と最後の値の統計に制限されます。

デザインパターン、数式、または時系列分析の概念を探しているかどうかはわかりません。

私の現在の設計は、段階的に行うことです。各ペアの比率のクラス、次に比率の比率のクラス...など。より抽象的なものを探しています。

私の問題に対するより抽象的な解決策を書くことを可能にする設計パターン、数式、または時系列の概念はありますか?

ありがとうスタックオーバーフロー!

4

1 に答える 1

2

時系列の数値リストを抽象化することから始める必要があると思います。計算の各セットは、リストを異なる方法でトラバースする必要があるようです。

interface IMyList<T>
{
    void SetList(IList<T> series);

    bool IsDone();
    T GetOperand1();
    T GetOperand2();
    T Calculate(T op1, T op2);
    void SetResult(T result);
    void Next();

    Dictionary<int, IList<T>> GetResults();
}

各クラスに各 IMyList を実装すると、リストをトラバースする方法を正確にクラスに組み込むことができます。最初の例を実装しました。また、再帰を使用していないことにも注意してください。トラバーサルと計算のタイプごとに、次のようなクラスを作成できます。

public class Ratio : IMyList<double>
{
    private Dictionary<int, IList<double>> _results;
    private int _currentSeries;
    private int _seriesResults;
    private int _op1Index;
    private int _op2Index;
    private bool _bDone;

    public Ratio()
    {
        _op1Index = 0;
        _op2Index = 1;
        _currentSeries = 0;
        _seriesResults = 1;
    }

    public void SetList(IList<double> series)
    {
        // the zero entry is the first result set
        _results = new Dictionary<int, IList<double>>();
        _results.Add(_currentSeries, series);
        _results.Add(_seriesResults, new List<double>());
    }

    public bool IsDone()
    {
        return _bDone;
    }

    public double GetOperand1()
    {
        return _results[_currentSeries][_op1Index];
    }

    public double GetOperand2()
    {
        return _results[_currentSeries][_op2Index];
    }

    public double Calculate(double op1, double op2)
    {
        return op1 / op2;
    }

    public void SetResult(double result)
    {
        _results[_seriesResults].Add(result);
    }

    public void Next()
    {
        _op1Index++;
        _op2Index++;

        if (_op2Index >= _results[_currentSeries].Count())
        {
            if (_results[_seriesResults].Count == 1)
            {
                _bDone = true;
            }
            else
            {
                _currentSeries++;
                _seriesResults++;
                _results.Add(_seriesResults, new List<double>());
                _op1Index = 0;
                _op2Index = 1;
            }
        }
    }

    public Dictionary<int, IList<double>> GetResults()
    {
        return _results;
    }
}

これを実行するには、コードは次のようになります。

        List<double> firstList = new List<double>() { 15, 36, -7, 12, 8 };

        // the following section could be refactored further by putting the classes
        // in a list of IMyList and then looping through it
        var rat = new Ratio();
        rat.SetList(firstList);
        while (!rat.IsDone())
        {
            double op1 = rat.GetOperand1();
            double op2 = rat.GetOperand2();
            rat.SetResult(rat.Calculate(op1, op2);
            rat.Next();
        }
        var results = rat.GetResults();
于 2012-03-15T18:15:17.963 に答える