Esempio n. 1
0
        public void SetData2(int cid, int sid)
        {
            chart2.Series.Clear();
            chart2.ChartAreas.Clear();

            // ChartにSeriesを追加します
            string legend1 = "X";
            string legend2 = "Y";
            string legend3 = "Z";

            chart2.Series.Add(legend1);
            chart2.Series.Add(legend2);
            chart2.Series.Add(legend3);


            chart2.Series[legend1].ChartType = SeriesChartType.Line; // 折れ線グラフ
            chart2.Series[legend2].ChartType = SeriesChartType.Line; // 折れ線グラフ
            chart2.Series[legend3].ChartType = SeriesChartType.Line; // 折れ線グラフ

            chart2.ChartAreas.Add(new ChartArea("Area2"));
            chart2.ChartAreas["Area2"].AxisX.Title = "time";
            chart2.ChartAreas["Area2"].AxisY.Title = "degree";

            //クラスタ型から拾ってくる
            //Centroid のグラフ出力 sid == 0
            if (sid == 0)
            {
                Cluster c = kmeans.clusters[cid];
                for (int i = 0; i < c.centroid.DBAacc.Length; i++)
                {
                    chart2.Series[legend1].Points.AddY(c.centroid.DBAacc[i].x); //X
                    chart2.Series[legend2].Points.AddY(c.centroid.DBAacc[i].y); //Y
                    chart2.Series[legend3].Points.AddY(c.centroid.DBAacc[i].z); //Z
                }
                laShoot2.Text    = "Centroid";
                laShootNum2.Text = "";
            }
            //各クラスタに属する射の入力データのグラフ出力 Centroidに距離が近い順(Sort済み)
            else
            {
                //クラスタ番号cidのクラスタ
                Cluster c = kmeans.clusters[cid];
                //クラスタ番号cidのメンバー 
                Shoot    s   = c.members[sid - 1];
                DBAShoot dba = c.centroid;
                laShoot2.Text    = "Shoot";
                laShootNum2.Text = s.shootnumber.ToString();

                for (int i = 0; i < s.acc.Length - 1; i++)
                {
                    chart2.Series[legend1].Points.AddXY(s.time[i], s.acc[i].x); //X
                    chart2.Series[legend2].Points.AddXY(s.time[i], s.acc[i].y); //Y
                    chart2.Series[legend3].Points.AddXY(s.time[i], s.acc[i].z); //Z
                }
                trackBar2.Minimum = (int)s.time[0] * ViewShootingVideo.fps;
                trackBar2.Maximum = (int)s.time[s.acc.Length - 1] * ViewShootingVideo.fps;
                System.Diagnostics.Debug.WriteLine("video2 t0=" + s.time[0] + " tn=" + s.time[s.acc.Length - 1]);
            }
        }
Esempio n. 2
0
 public Cluster(Cluster c)
 {
     members     = new Shoots();
     prevMembers = new Shoots();
     centroid    = new DBAShoot();
     foreach (Shoot s in c.members)
     {
         members.Add(s);
     }
     centroid.DBAacc = new Vec3[c.centroid.DBAacc.Length];
     for (int i = 0; i < c.centroid.DBAacc.Length; ++i)
     {
         centroid.DBAacc[i] = c.centroid.DBAacc[i].Clone();
     }
 }
Esempio n. 3
0
        //Shoots で直接渡してしまう

        //DBA(平均の波形)をとる
        public static DBAShoot CalcAverage(Shoots shoots, int numberOfUpdates)
        {
            //仮の平均を決める
            //最初の平均は1番目の時系列データe
            //仮の平均 DBAcentroid[n][lengthOfCentroid][axis]
            //時系列データ seq[t][axis]
            //centroidを何回計算するか: numberOfUpdates

            //後のKmeans呼び出しのため、ここで格納
            Cluster cluster = new Cluster();


            //最初のcentroidはshootnumber1番目の時系列データを代入
            //  時系列データの長さが十分にあるとき
            DBAShoot dba = new DBAShoot();

            dba.DBAacc  = (Vec3[])shoots[0].acc.Clone();
            dba.DBAtime = (double[])shoots[0].time.Clone();


            List <Vec3>[] assocTab = Enumerable.Range(0, dba.DBAacc.Length).Select(i => new List <Vec3>()).ToArray();
            //時間格納用
            List <double>[] assocTabTime = Enumerable.Range(0, dba.DBAacc.Length).Select(i => new List <double>()).ToArray();



            for (int nu = 0; nu < numberOfUpdates; nu++)
            {
                string output = "centroidNum,DataNum,assocTab[i]x,y,z,assocTabTime[i],\r\n";

                //仮の平均と時系列データとの距離を求める
                foreach (Shoot s in shoots)
                {
                    string file = "assoctab_" + nu + "_" + s.shootnumber + ".csv";

                    CostPath table = DpMatching(dba.DBAacc, s.acc);
                    int      i     = table.cost.Length - 1;    //時系列データにおけるcentroidの数(固定)
                    int      j     = table.cost[0].Length - 1; //比較する時系列データの数(固定)(X,Y,Zともに共通)
                    while (i > 0 && j > 0)
                    {
                        //時系列データを対応付け
                        //assocTab[xyz][i] = 関連付けた仮の平均に対する時系列データ

                        assocTab[i].Add(s.acc[j]);
                        assocTabTime[i].Add(s.time[j]);

                        output += i + ", " + j + "," + s.acc[j].x + ", " + s.acc[j].y + ", " + s.acc[j].z + ", " + s.time[j] + "\r\n";

                        if (table.path[i][j] == 0)
                        {
                            //斜め
                            i--; j--;
                        }
                        else if (table.path[i][j] == 1)
                        {
                            //たて
                            j--;
                        }
                        else if (table.path[i][j] == 2)
                        {
                            //よこ
                            i--;
                        }
                    }
                    File.WriteAllText(file, output);
                }
            }


            int n = 0;

            foreach (List <Vec3> assoc in assocTab)
            {
                Vec3 asum = new Vec3();
                // + / はCluster.csでoperaterとして定義済み
                foreach (Vec3 a in assoc)
                {
                    asum += a;
                }
                if (assoc.Count > 0)
                {
                    asum /= assoc.Count;
                    //DBAの値 nはカウントのみ
                    dba.DBAacc[n] = asum;

                    //個別データとDBAcentroidとのコストの差を表示したい
                    //[対応するcentroidの数][何番目のデータ]:単位時間あたりのコストの増減
                    //dba.DBAtime[n] = assocTabTime[assoc.Count][n];
                    //DBAの時刻は該当するデータの時間の平均
                }
                else if (n > 0)
                {
                    //比較 長さが不均等なときは直前の値を適用
                    dba.DBAacc[n] = dba.DBAacc[n - 1];
                }
                n++;
            }

            int m = 0;

            foreach (List <double> assoc in assocTabTime)
            {
                //DBAtime* 平均の時間を入れたい場合は以下
                //double tsum = 0;
                //foreach (double t in assoc)
                //{
                //    tsum = tsum + t;
                //}
                if (assoc.Count > 0)
                {
                    //DBAの時刻は該当するデータの時間の平均にしたい場合
                    //tsum = tsum / assoc.Count;
                    //dba.DBAtime[m] = tsum;

                    //下記 インデックスエラーを避けるため
                    //if (m < assoc.Count)
                    //{
                    dba.DBAtime[m] = m;
                    //}
                }
                //else if (m > 0)
                //{
                //    //比較 長さが不均等なときは直前の値を適用
                //    dba.DBAtime[m] = assoc[m - 1];
                //}

                m++;
            }
            return(dba);
        }
Esempio n. 4
0
 public double distFromCentroid; //クラスタの中心からの距離 クラスタークラスタ間用
 public Cluster()
 {
     members     = new Shoots();
     prevMembers = new Shoots();
     centroid    = new DBAShoot();
 }
        public void SetData(int cid, int sid)
        {
            chart1.Series.Clear();
            chart1.ChartAreas.Clear();

            // ChartにSeriesを追加します
            string legend1 = "X";
            string legend2 = "Y";
            string legend3 = "Z";
            string legend4 = "cost";

            chart1.Series.Add(legend1);
            chart1.Series.Add(legend2);
            chart1.Series.Add(legend3);
            chart1.Series.Add(legend4);

            chart1.Series[legend1].ChartType = SeriesChartType.Line; // 折れ線グラフ
            chart1.Series[legend2].ChartType = SeriesChartType.Line; // 折れ線グラフ
            chart1.Series[legend3].ChartType = SeriesChartType.Line; // 折れ線グラフ
            chart1.Series[legend4].ChartType = SeriesChartType.Line; // 折れ線グラフ

            chart1.ChartAreas.Add(new ChartArea("Area1"));
            chart1.ChartAreas["Area1"].AxisX.Title = "time";
            chart1.ChartAreas["Area1"].AxisY.Title = "degree";

            //クラスタ型から拾ってくる
            //Centroid のグラフ出力 sid == 0
            if (sid == 0)
            {
                Cluster c = kmeans.clusters[cid];
                for (int i = 0; i < c.centroid.DBAacc.Length; i++)
                {
                    chart1.Series[legend1].Points.AddY(c.centroid.DBAacc[i].x); //X
                    chart1.Series[legend2].Points.AddY(c.centroid.DBAacc[i].y); //Y
                    chart1.Series[legend3].Points.AddY(c.centroid.DBAacc[i].z); //Z
                }
                laShoot.Text    = "Centroid";
                laShootNum.Text = "";
                distNum.Text    = " ";
            }
            //各クラスタに属する射の入力データのグラフ出力 Centroidに距離が近い順(Sort済み)
            else
            {
                //クラスタ番号cidのクラスタ
                Cluster c = kmeans.clusters[cid];
                //クラスタ番号cidのメンバー 
                Shoot    s   = c.members[sid - 1];
                DBAShoot dba = c.centroid;
                laShoot.Text    = "Shoot";
                laShootNum.Text = s.shootnumber.ToString();
                distNum.Text    = DBA.CalcCost(s.acc, dba.DBAacc).dist.ToString();
                //double dt = 0.1;
                //double[] dtCost = new double[s.acc.Length];
                for (int i = 0; i < s.acc.Length - 1; i++)
                {
                    chart1.Series[legend1].Points.AddXY(s.time[i], s.acc[i].x); //X
                    chart1.Series[legend2].Points.AddXY(s.time[i], s.acc[i].y); //Y
                    chart1.Series[legend3].Points.AddXY(s.time[i], s.acc[i].z); //Z
                }

                //costのグラフも表示
                for (int i = 0; i < s.cost.Length; i++)
                {
                    ////chart1.Series[legend4].Points.AddY(s.path[i]); //cost
                    //dtCost[i] = (s.cost[i] - s.cost[i - 1]) / dt;
                    //dtCost[i] = s.cost[i];
                    //costの軸は2軸目(右側のY軸目盛り)で表示
                    double[] DBAcost = DBA.CalcCost(s.acc, dba.DBAacc).cost;

                    chart1.Series[legend4].YAxisType = AxisType.Secondary;
                    //chart1.Series[legend4].Points.AddXY(dba.DBAtime[i], s.cost[i]); //cost
                    chart1.Series[legend4].Points.AddXY(s.time[i], DBAcost[i]); //cost
                }
            }
        }