public DisplayItemsArray ComputeCorrelationsDisplay(IEnumerable<VariableDesc> oVars)
 {
     var col = ComputeCorrelations(oVars);
     if (col == null)
     {
         return null;
     }
     DisplayItemsArray oRet = new DisplayItemsArray();
     DisplayItems hh = new DisplayItems();
     hh.Add(new DisplayItem("V1", true));
     hh.Add(new DisplayItem("V2", true));
     hh.Add(new DisplayItem("N", true));
     hh.Add(new DisplayItem("Prob.", true));
     hh.Add(new DisplayItem("Corr.", true));
     hh.Add(new DisplayItem("Min", true));
     hh.Add(new DisplayItem("Max", true));
     oRet.Add(hh);
     foreach (var c in col)
     {
         DisplayItems line = new DisplayItems();
         line.Add(new DisplayItem(c.FirstName));
         line.Add(new DisplayItem(c.SecondName));
         line.Add(new DisplayItem(c.Count));
         line.Add(new DisplayItem(c.Probability));
         line.Add(new DisplayItem(c.Value));
         line.Add(new DisplayItem(c.Minimum));
         line.Add(new DisplayItem(c.Maximum));
         oRet.Add(line);
     }// c
     return oRet;
 }
Пример #2
0
 }//RefreshArrangements 
 public Tuple<int[], DisplayItemsArray, PlotModel> CreateArrangeData(int nbIterations, CancellationToken cancellationToken)
 {
     var pDataModel = this;
     var inds = pDataModel.Individus;
     var vars = pDataModel.CurrentVariables.ToArray();
     int nv = vars.Length;
     int[] pRows = null;
     DisplayItemsArray oDisp = null;
     PlotModel model = null;
     try
     {
         var t1 = ArrangeSet.ArrangeIndex(pDataModel, nbIterations, cancellationToken);
         if (cancellationToken.IsCancellationRequested)
         {
             return new Tuple<int[], DisplayItemsArray, PlotModel>(pRows, oDisp, model);
         }
         pRows = t1.Item1;
         int[] pCols = t1.Item2;
         if ((pRows == null) || (pCols == null))
         {
             return new Tuple<int[], DisplayItemsArray, PlotModel>(pRows, oDisp, model);
         }
         if (pCols.Length < nv)
         {
             return new Tuple<int[], DisplayItemsArray, PlotModel>(pRows, oDisp, model);
         }
         double somme = 0.0;
         List<double> xdelta = new List<double>();
         List<double> xcum = new List<double>();
         oDisp = new DisplayItemsArray();
         DisplayItems header = new DisplayItems();
         header.Add(new DisplayItem("Pos.", true));
         header.Add(new DisplayItem("Index", true));
         header.Add(new DisplayItem("ID", true));
         header.Add(new DisplayItem("Nom", true));
         header.Add(new DisplayItem("Photo", true));
         for (int i = 0; i < nv; ++i)
         {
             int ii = pCols[i];
             if (ii >= nv)
             {
                 return new Tuple<int[], DisplayItemsArray, PlotModel>(pRows, oDisp, model);
             }
             String name = (vars[ii]).Name;
             header.Add(new DisplayItem(name, true));
         }// i
         oDisp.Add(header);
         IndivData firstIndiv = null;
         int nr = pRows.Length;
         for (int i = 0; i < nr; ++i)
         {
             int index = pRows[i];
             var q = from x in inds where x.IndivIndex == index select x;
             if (q.Count() > 0)
             {
                 var ind = q.First();
                 DisplayItems line = new DisplayItems();
                 line.Tag = ind;
                 line.Add(new DisplayItem(i + 1));
                 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());
                 }
                 double[] dd = ind.DoubleData;
                 if ((dd != null) && (dd.Length >= nv))
                 {
                     for (int j = 0; j < nv; ++j)
                     {
                         int ii = pCols[j];
                         double xx = dd[ii];
                         line.Add(new DisplayItem(xx));
                     }// i
                 }// dd
                 oDisp.Add(line);
                 if (firstIndiv == null)
                 {
                     firstIndiv = ind;
                 }
                 else
                 {
                     double dx = ind.ComputeDistance(firstIndiv);
                     somme += dx;
                     xdelta.Add(dx);
                     xcum.Add(somme);
                     firstIndiv = ind;
                 }
             }// ok
         }// i
         if (somme > 0.0)
         {
             double[] ddx = xdelta.ToArray();
             double[] ddc = xcum.ToArray();
             int nx = ddx.Length;
             for (int i = 0; i < nx; ++i)
             {
                 ddx[i] = ddx[i] / somme;
                 ddc[i] = ddc[i] / somme;
             }// i
             double vmin = ddx.Min();
             double vmax = ddx.Max();
             if (vmin < vmax)
             {
                 double delta = vmax - vmin;
                 for (int i = 0; i < nx; ++i)
                 {
                     ddx[i] = (ddx[i] - vmin) / delta;
                 }// i
                 model = new PlotModel("Arrangements");
                 model.Axes.Add(new LinearAxis() { Title = "Position", Minimum = 0.0, Maximum = (double)(nx + 1), Position = AxisPosition.Bottom, FontWeight = FontWeights.Bold });
                 model.Axes.Add(new LinearAxis() { Title = "Distances", Minimum = ddx.Min(), Maximum = ddx.Max(), Position = AxisPosition.Left, FontWeight = FontWeights.Bold });
                 model.Axes.Add(new LinearAxis() { Title = "Position", Minimum = 0.0, Maximum = (double)(nx + 1), Position = AxisPosition.Top, FontWeight = FontWeights.Bold });
                 model.Axes.Add(new LinearAxis() { Title = "Cummul", Minimum = ddc.Min(), Maximum = ddc.Max(), Position = AxisPosition.Right, FontWeight = FontWeights.Bold });
                 var sx = new LineSeries { Title = "Distances", Smooth = true, FontWeight = FontWeights.Bold };
                 var sy = new LineSeries { Title = "Cummul", Smooth = true, FontWeight = FontWeights.Bold };
                 for (int i = 0; i < nx; ++i)
                 {
                     sx.Points.Add(new DataPoint((double)(i + 1), ddx[i]));
                     sy.Points.Add(new DataPoint((double)(i + 1), ddc[i]));
                 }// i
                 model.Series.Add(sx);
                 model.Series.Add(sy);
             }// graph
         }// someme
     }// try
     catch (Exception /* ex */)
     {
     }
     return new Tuple<int[], DisplayItemsArray, PlotModel>(pRows, oDisp, model);
 }//CreateArrangeDataAsync 
 public DisplayItemsArray CreateVariablesInfoDisplay(IEnumerable<VariableInfo> oVars)
 {
     DisplayItemsArray oRet = new DisplayItemsArray();
     try
     {
         DisplayItems hh = new DisplayItems();
         hh.Add(new DisplayItem("Num", true));
         hh.Add(new DisplayItem("Variable", true));
         hh.Add(new DisplayItem("N", true));
         hh.Add(new DisplayItem("Min", true));
         hh.Add(new DisplayItem("Max", true));
         hh.Add(new DisplayItem("Median", true));
         hh.Add(new DisplayItem("Mean", true));
         hh.Add(new DisplayItem("Dev.", true));
         hh.Add(new DisplayItem("Skew.", true));
         hh.Add(new DisplayItem("Kurt.", true));
         hh.Add(new DisplayItem("Q05", true));
         hh.Add(new DisplayItem("Q10", true));
         hh.Add(new DisplayItem("Q25", true));
         hh.Add(new DisplayItem("Q75", true));
         hh.Add(new DisplayItem("Q90", true));
         hh.Add(new DisplayItem("Q95", true));
         oRet.Add(hh);
         int icur = 1;
         foreach (var v in oVars)
         {
             DisplayItems line = new DisplayItems();
             line.Add(new DisplayItem(icur++));
             line.Add(new DisplayItem(v.VariableName));
             line.Add(new DisplayItem(v.TotalValuesCount));
             line.Add(new DisplayItem(v.MinValue));
             line.Add(new DisplayItem(v.MaxValue));
             line.Add(new DisplayItem(v.Median));
             line.Add(new DisplayItem(v.MeanValue));
             line.Add(new DisplayItem(v.Deviation));
             line.Add(new DisplayItem(v.Skewness));
             line.Add(new DisplayItem(v.Flatness));
             line.Add(new DisplayItem(v.Quantile05));
             line.Add(new DisplayItem(v.Quantile10));
             line.Add(new DisplayItem(v.Quantile25));
             line.Add(new DisplayItem(v.Quantile75));
             line.Add(new DisplayItem(v.Quantile90));
             line.Add(new DisplayItem(v.Quantile95));
             oRet.Add(line);
         }// v
     }
     catch (Exception /*ex*/)
     {
         oRet = null;
     }
     return oRet;
 }
 private Task performExport(DisplayItemsArray oAr, String filename)
 {
     return Task.Run(() => {
         using (var fs = new FileStream(filename, FileMode.OpenOrCreate))
         {
             String sVal = oAr.ToString();
             StreamWriter writer = new StreamWriter(fs);
             writer.Write(sVal);
         }// fs
     });
 }
 }// 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
 }// RefreshPhotos
 public void refreshIndivs()
 {
     if (m_busy)
     {
         return;
     }
     m_busy = true;
     this.refreshVariables();
     var oRet = new List<IndivData>();
     var col = m_main.AllIndividus;
     DisplayItemsArray oDisp = new DisplayItemsArray();
     foreach (var ind in col)
     {
         int index = ind.IndivIndex;
         var vv = new IndivData(ind);
         oRet.Add(vv);
         DisplayItems dd = new DisplayItems();
         dd.Tag = vv;
         dd.Add(new DisplayItem(vv.IndivIndex));
         String sz = vv.IdString;
         dd.Add(new DisplayItem(sz));
         dd.Add(new DisplayItem(vv.Name));
         if ((vv.PhotoData != null) && (vv.PhotoData.Length > 1))
         {
             dd.Add(new DisplayItem(vv.PhotoData));
         }
         else
         {
             dd.Add(new DisplayItem());
         }
         oDisp.Add(dd);
     }// ind
     if (oRet.Count > 1)
     {
         oRet.Sort();
     }
     this.Individus = new IndivDatas(oRet);
     this.DisplayIndivs = oDisp;
     this.IsModified = false;
     m_busy = false;
     NotifyPropertyChanged("WorkDone");
 }// refreshIndivs
 }// CommitChanges
 #endregion // Methods
 #region Helpers
 private Tuple<int, DisplayItemsArray> refreshPhotosAsync(IStoreDataManager pMan)
 {
     DisplayItemsArray oRet = null;
     int nRet = 0;
     String s = this.SearchString;
     var xx = pMan.SearchPhotosCount(s);
     if ((xx != null) && (xx.Item2 == null))
     {
         nRet = xx.Item1;
     }
     var yy = pMan.SearchPhotos(s, this.Skip, this.Taken);
     if ((yy != null) && (yy.Item2 == null))
     {
         var col = yy.Item1;
         oRet = new DisplayItemsArray();
         foreach (var v in col)
         {
             DisplayItems vv = new DisplayItems();
             vv.Tag = v;
             vv.Add(new DisplayItem(v.DataBytes));
             vv.Add(new DisplayItem(v.Name));
             oRet.Add(vv);
         }// v
     }
     return new Tuple<int, DisplayItemsArray>(nRet, oRet);
 }// refreshPhotosAsync