コード例 #1
0
        }// createPlot
        private PlotModel createIndivsPlotModel(Anacompo pAna, int iFactorX, int iFactorY)
        {
            PlotModel model = null;
            var data = pAna.RecodedInds;
            if (data == null)
            {
                return null;
            }
            bool bLabel = this.HasLabels;
            bool bImage = this.HasImages;
            bool bPoints = this.HasPoints;
            if ((!bLabel) && (!bImage) && (!bPoints))
            {
                return null;
            }
            int nr = data.GetLength(0);
            int nv = data.GetLength(1);
            if ((nv <= iFactorX) || (nv <= iFactorX) || (nr < 1))
            {
                return null;
            }
            var inds = this.Individus.ToArray();
            nr = (inds.Length < nr) ? inds.Length : nr;
            if (nr < 1)
            {
                return null;
            }
            double[] xx = new double[nr];
            double[] yy = new double[nr];
            for (int i = 0; i < nr; ++i)
            {
                xx[i] = data[i, iFactorX];
                yy[i] = data[i, iFactorY];
            }// i
            Dictionary<String, ScatterSeries> oSeries = new Dictionary<string, ScatterSeries>();
            Dictionary<int, String> dict = this.CategDictionary;
            model = new PlotModel("Individus", String.Format("{0} / {1}", this.YAxe, this.XAxe));
            model.LegendPlacement = LegendPlacement.Outside;
            model.Axes.Add(new LinearAxis(AxisPosition.Bottom, xx.Min(), xx.Max(), this.XAxe) { PositionAtZeroCrossing = true });
            model.Axes.Add(new LinearAxis(AxisPosition.Left, yy.Min(), yy.Max(), this.YAxe) { PositionAtZeroCrossing = true });
            ScatterSeries oTrash = null;
            double xwidth = 3.0 * (xx.Max() - xx.Min()) / nr;
            for (int i = 0; i < nr; ++i)
            {
                var ind = inds[i];
                int index = ind.IndivIndex;
                double x = data[i, iFactorX];
                double y = data[i, iFactorY];

                if (dict.ContainsKey(index))
                {
                    String scateg = dict[index];
                    if (!oSeries.ContainsKey(scateg))
                    {
                        oSeries[scateg] = new ScatterSeries() { MarkerType = MarkerType.Circle };
                    }
                    var color = oSeries[scateg].MarkerFill;
                    if (bImage && (this.ImagesDisctionary != null) && this.ImagesDisctionary.ContainsKey(index))
                    {
                        model.Annotations.Add(new ImageAnnotation { 
                            ImageSource = this.ImagesDisctionary[index],
                            X= new PlotLength(x,PlotLengthUnit.Data),
                            Y= new PlotLength(y,PlotLengthUnit.Data),
                            HorizontalAlignment=HorizontalAlignment.Center,
                            VerticalAlignment=VerticalAlignment.Middle,
                            Width = new PlotLength(xwidth,PlotLengthUnit.Data)
                        });
                    }
                    if (bLabel)
                    {
                        String name = ind.Name;
                        if (!String.IsNullOrEmpty(name))
                        {
                            model.Annotations.Add(new TextAnnotation
                            {
                                Position = new DataPoint(x, y),
                                Text = name,
                                TextColor = color,
                                FontWeight = FontWeights.Bold,Tag = ind
                            });
                        }
                    }
                    if (bPoints)
                    {
                        oSeries[scateg].Points.Add(new ScatterPoint(x, y) { Tag = ind });
                    }
                }
                else
                {
                    if (oTrash == null)
                    {
                        oTrash = new ScatterSeries();
                    }
                    if (bImage && (this.ImagesDisctionary != null) && this.ImagesDisctionary.ContainsKey(index))
                    {
                        model.Annotations.Add(new ImageAnnotation
                        {
                            ImageSource = this.ImagesDisctionary[index],
                            X = new PlotLength(x, PlotLengthUnit.Data),
                            Y = new PlotLength(y, PlotLengthUnit.Data),
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment = VerticalAlignment.Middle,
                            Width = new PlotLength(xwidth, PlotLengthUnit.Data)
                        });
                    }
                    if (bLabel)
                    {
                        String name = ind.IdString;
                        if (!String.IsNullOrEmpty(name))
                        {
                            model.Annotations.Add(new TextAnnotation { Position = new DataPoint(x, y), Text = name, 
                                FontWeight = FontWeights.Bold , Tag=ind});
                        }
                    }
                    if (bPoints)
                    {
                        oTrash.Points.Add(new ScatterPoint(x, y) { Tag = ind });
                    }
                }
            }// inds
            foreach (var sx in oSeries.Values)
            {
                model.Series.Add(sx);
            }
            if (oTrash != null)
            {
                model.Series.Add(oTrash);
            }
            return model;
        }//createIndivsPlotModel
コード例 #2
0
 }// RefreshVariablesValues
 private EigenData computeData(Anacompo p)
 {
     String prefix = this.FactorPrefix;
     EigenData oRet = new EigenData();
     var vals = p.EigenValues;
     int nv = vals.Length;
     double sum = vals.Sum();
     if (sum <= 0.0)
     {
         return null;
     }
     DisplayItemsArray vv = new DisplayItemsArray();
     DisplayItems header = new DisplayItems();
     header.Add(new DisplayItem("Num", true));
     header.Add(new DisplayItem("Facteur", true));
     header.Add(new DisplayItem("Valeur", true));
     header.Add(new DisplayItem("Taux", true));
     header.Add(new DisplayItem("Cummul", true));
     vv.Add(header);
     double s = 0.0;
     for (int i = 0; i < nv; ++i)
     {
         DisplayItems line = new DisplayItems();
         line.Add(new DisplayItem((int)(i + 1)));
         String sname = String.Format("{0}{1}", prefix, i + 1);
         line.Add(new DisplayItem(sname));
         double x = vals[i];
         line.Add(new DisplayItem(x));
         line.Add(new DisplayItem(x / sum));
         s += x;
         line.Add(new DisplayItem(s / sum));
         vv.Add(line);
     }// i
     oRet.EigenValues = vv;
     //
     DisplayItemsArray vecs = new DisplayItemsArray();
     DisplayItems hh = new DisplayItems();
     hh.Add(new DisplayItem("Variable", true));
     var vx = p.EigenVectors;
     nv = vx.GetLength(1);
     int nr = vx.GetLength(0);
     var xnames = this.CurrentVariables.ToArray();
     for (int i = 0; i < nv; ++i)
     {
         String sname = String.Format("{0}{1}", prefix, i + 1);
         hh.Add(new DisplayItem(sname, true));
     }// i
     vecs.Add(hh);
     for (int i = 0; i < nr; ++i)
     {
         DisplayItems line = new DisplayItems();
         String name = xnames[i].Name;
         line.Add(new DisplayItem(name));
         for (int j = 0; j < nv; ++j)
         {
             double x = vx[i, j];
             line.Add(new DisplayItem(x));
         }// j
         vecs.Add(line);
     }// i
     oRet.EigenVectors = vecs;
     //
     DisplayItemsArray vecsv = new DisplayItemsArray();
     DisplayItems hhv = new DisplayItems();
     hhv.Add(new DisplayItem("Variable", true));
     var vxv = p.RecodedVars;
     nv = vxv.GetLength(1);
     nr = vxv.GetLength(0);
     for (int i = 0; i < nv; ++i)
     {
         String sname = String.Format("{0}{1}", prefix, i + 1);
         hhv.Add(new DisplayItem(sname, true));
     }// i
     vecsv.Add(hhv);
     for (int i = 0; i < nr; ++i)
     {
         DisplayItems line = new DisplayItems();
         String name = xnames[i].Name;
         line.Add(new DisplayItem(name));
         for (int j = 0; j < nv; ++j)
         {
             double x = vxv[i, j];
             line.Add(new DisplayItem(x));
         }// j
         vecsv.Add(line);
     }// i
     oRet.EigenVariables = vecsv;
     //
     DisplayItemsArray vecsx = new DisplayItemsArray();
     DisplayItems hhx = new DisplayItems();
     hhx.Add(new DisplayItem("Num", true));
     hhx.Add(new DisplayItem("Index", true));
     hhx.Add(new DisplayItem("Nom", true));
     hhx.Add(new DisplayItem("Photo", true));
     var vxx = p.RecodedInds;
     nv = vxx.GetLength(1);
     nr = vxx.GetLength(0);
     for (int i = 0; i < nv; ++i)
     {
         String sname = String.Format("{0}{1}", prefix, i + 1);
         hhx.Add(new DisplayItem(sname, true));
     }// i
     vecsx.Add(hhx);
     var inds = this.Individus.ToArray();
     for (int i = 0; i < nr; ++i)
     {
         DisplayItems line = new DisplayItems();
         line.Add(new DisplayItem(i+1));
         var ind = inds[i];
         line.Add(new DisplayItem(ind.IndivIndex));
         line.Add(new DisplayItem(ind.IdString));
         line.Add(new DisplayItem(ind.Name));
         if ((ind.PhotoData != null) && (ind.PhotoData.Length > 1))
         {
             line.Add(new DisplayItem(ind.PhotoData));
         }
         else
         {
             line.Add(new DisplayItem());
         }
         for (int j = 0; j < nv; ++j)
         {
             double x = vxx[i, j];
             line.Add(new DisplayItem(x));
         }// j
         vecsx.Add(line);
     }// i
     oRet.EigenIndivs = vecsx;
     return oRet;
 }// computeData
コード例 #3
0
 }// RefreshVariablesValues
 private Tuple<IndivDatas, Anacompo,EigenData> refreshData()
 {
     IndivDatas dx = this.Individus;
     Anacompo cp = null;
     EigenData eigen = null;
     try
     {
         var oAr = this.Individus.ToArray();
         int nr = oAr.Length;
         if (nr < 2)
         {
             return new Tuple<IndivDatas, Anacompo, EigenData>(dx, cp, eigen);
         }
         int nv = oAr[0].DoubleData.Length;
         if (nv < 2)
         {
             return new Tuple<IndivDatas, Anacompo, EigenData>(dx, cp, eigen);
         }
         double[,] alldata = new double[nr, nv];
         List<int> zinds = new List<int>();
         for (int i = 0; i < nr; ++i)
         {
             var ind = oAr[i];
             zinds.Add(ind.IndivIndex);
             double[] dd = ind.DoubleData;
             for (int j = 0; j < nv; ++j)
             {
                 alldata[i, j] = dd[j];
             }// j
         }// i
         Exception err = null;
         cp = new Anacompo();
         if (!cp.ComputeEigen(alldata, out err))
         {
             cp = null;
         }
         if (cp != null)
         {
             eigen = computeData(cp);
         }
         cp.Indexes = zinds.ToArray();
     }
     catch (Exception /*ex */)
     {
         dx = null;
         cp = null;
     }
     return new Tuple<IndivDatas, Anacompo,EigenData>(dx, cp,eigen);
 }// RefreshVariablesValues
コード例 #4
0
 }// reateVariablesPlotModel
 private PlotModel createEigenValuesPlotModel(Anacompo pAna)
 {
     PlotModel model = null;
     var data = pAna.EigenValues;
     if (data == null)
     {
         return null;
     }
     if (data.Length < 1)
     {
         return null;
     }
     int n = data.Length;
     double[] dd = new double[n];
     for (int i = 0; i < n; ++i)
     {
         double x = data[i];
         if (x < 0.0)
         {
             x = 0;
         }
         dd[i] = x;
     }// i
     double somme = dd.Sum();
     if (somme <= 0.0)
     {
         return null;
     }
     model = new PlotModel("Valeurs propres");
     var ps = new PieSeries();
     for (int i = 0; i < n; ++i)
     {
         double x = (dd[i] / somme) * 100.0 + 0.5;
         if (x > 100.0)
         {
             x = 100.0;
         }
         ps.Slices.Add(new PieSlice(String.Format("FACT{0}", i + 1), x) { IsExploded = true });
     }
     ps.InnerDiameter = 0;
     ps.ExplodedDistance = 0.0;
     ps.Stroke = OxyColors.White;
     ps.StrokeThickness = 2.0;
     ps.InsideLabelPosition = 0.8;
     ps.AngleSpan = 360;
     ps.StartAngle = 0;
     ps.FontWeight = FontWeights.Bold;
     model.Series.Add(ps);
     return model;
 }//createEigenValuesPlotMode
コード例 #5
0
 }//createCombinedPlotModel
 private PlotModel createVariablesPlotModel(Anacompo pAna, int iFactorX, int iFactorY)
 {
     PlotModel model = null;
     var data = pAna.RecodedVars;
     if (data == null)
     {
         return null;
     }
     int nr = data.GetLength(0);
     int nv = data.GetLength(1);
     if ((nv < iFactorX) || (nv < iFactorY) || (nr < 1))
     {
         return null;
     }
     model = new PlotModel("Variables", String.Format("{0} / {1}", this.YAxe, this.XAxe));
     double[] yy = new double[nr];
     double[] xx = new double[nr];
     String[] names = new String[nr];
     var col = this.CurrentVariables.ToArray();
     for (int i = 0; i < nr; ++i)
     {
         yy[i] = data[i, iFactorY];
         xx[i] = data[i, iFactorX];
         names[i] = (i < col.Length) ? col[i].Name : "";
     }// i
     model.Axes.Add(new LinearAxis(AxisPosition.Bottom, -1.0, 1.0, this.XAxe) { PositionAtZeroCrossing = true });
     model.Axes.Add(new LinearAxis(AxisPosition.Left, -1.0, 1.0, this.YAxe) { PositionAtZeroCrossing = true });
     for (int i = 0; i < nr; ++i)
     {
         double x = xx[i];
         double y = yy[i];
         String sname = names[i];
         model.Annotations.Add(new ArrowAnnotation { StartPoint = new DataPoint(0, 0), EndPoint = new DataPoint(x, y) });
         model.Annotations.Add(new TextAnnotation { Position = new DataPoint(x, y), Text = sname });
     }// i
     return model;
 }// reateVariablesPlotModel
コード例 #6
0
        }//createIndivsPlotModel
        private PlotModel createCombinedPlotModel(Anacompo pAna, int iFactorX, int iFactorY)
        {
            PlotModel model = null;
            var data = pAna.RecodedInds;
            if (data == null)
            {
                return null;
            }
            int nr = data.GetLength(0);
            int nv = data.GetLength(1);
            if ((nv <= iFactorX) || (nv <= iFactorX) || (nr < 1))
            {
                return null;
            }
            var inds = this.Individus.ToArray();
            nr = (inds.Length < nr) ? inds.Length : nr;
            if (nr < 1)
            {
                return null;
            }
            double[] xx = new double[nr];
            double[] yy = new double[nr];
            for (int i = 0; i < nr; ++i)
            {
                xx[i] = data[i, iFactorX];
                yy[i] = data[i, iFactorY];
            }// i
            Dictionary<String, ScatterSeries> oSeries = new Dictionary<string, ScatterSeries>();
            Dictionary<int, String> dict = this.CategDictionary;
            model = new PlotModel("Individus", String.Format("{0} / {1}", this.YAxe, this.XAxe));
            model.LegendPlacement = LegendPlacement.Outside;
            model.Axes.Add(new LinearAxis(AxisPosition.Bottom, xx.Min(), xx.Max(), this.XAxe) { PositionAtZeroCrossing = true });
            model.Axes.Add(new LinearAxis(AxisPosition.Left, yy.Min(), yy.Max(), this.YAxe) { PositionAtZeroCrossing = true });
            var vardata = pAna.RecodedVars;
            var names = this.CurrentVariables.ToArray();
            for (int i = 0; i < nv; ++i)
            {
                double x = vardata[i, iFactorX];
                double y = vardata[i, iFactorY];
                String sname = names[i].Name;
                model.Annotations.Add(new ArrowAnnotation { StartPoint = new DataPoint(0, 0), EndPoint = new DataPoint(x, y), LineStyle=LineStyle.DashDotDot });
                model.Annotations.Add(new TextAnnotation { Position = new DataPoint(x, y), Text = sname, HorizontalAlignment=HorizontalAlignment.Center,
                VerticalAlignment=VerticalAlignment.Middle});
            }// i
            bool bLabel = this.HasLabels;
            ScatterSeries oTrash = null;
            for (int i = 0; i < nr; ++i)
            {
                var ind = inds[i];
                int index = ind.IndivIndex;
                double x = data[i, iFactorX];
                double y = data[i, iFactorY];

                if (dict.ContainsKey(index))
                {
                    String scateg = dict[index];
                    if (!oSeries.ContainsKey(scateg))
                    {
                        oSeries[scateg] = new ScatterSeries() { MarkerType = MarkerType.Circle };
                    }
                    var color = oSeries[scateg].MarkerFill;
                    if (bLabel)
                    {
                        String name = ind.Name;
                        if (!String.IsNullOrEmpty(name))
                        {
                            model.Annotations.Add(new TextAnnotation
                            {
                                Position = new DataPoint(x, y),
                                Text = name,
                                TextColor = color,
                                FontWeight = FontWeights.Bold,
                                Tag = ind,HorizontalAlignment=HorizontalAlignment.Center,VerticalAlignment=VerticalAlignment.Middle
                            });
                        }
                    }
                    else
                    {
                        oSeries[scateg].Points.Add(new ScatterPoint(x, y) { Tag = ind });
                    }
                }
                else
                {
                    if (oTrash == null)
                    {
                        oTrash = new ScatterSeries();
                    }
                    if (bLabel)
                    {
                        String name = ind.IdString;
                        if (!String.IsNullOrEmpty(name))
                        {
                            model.Annotations.Add(new TextAnnotation
                            {
                                Position = new DataPoint(x, y),
                                Text = name,
                                FontWeight = FontWeights.Bold,
                                Tag = ind,HorizontalAlignment=HorizontalAlignment.Center,VerticalAlignment=VerticalAlignment.Middle
                            });
                        }
                    }
                    else
                    {
                        oTrash.Points.Add(new ScatterPoint(x, y) { Tag = ind });
                    }
                }
            }// inds
            foreach (var sx in oSeries.Values)
            {
                model.Series.Add(sx);
            }
            if (oTrash != null)
            {
                model.Series.Add(oTrash);
            }
            return model;
        }//createCombinedPlotModel