private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     m_model = getModel();
     if (m_model != null)
     {
         m_model.PropertyChanged += m_model_PropertyChanged;
     }
     myUpdateUI();
 }
Пример #2
0
 public CategClusterSet(OrdModelView model)
 {
     m_model = model;
     if (model != null)
     {
         m_indivs = (IndivDatas)model.Individus.Clone();
         if ((m_indivs != null) && (m_indivs.Count > 0))
         {
             var p = m_indivs.First();
             m_nvars = p.IntData.Length;
         }
     }
 }
 public MatriceModelView(OrdModelView pMain)
     : base(pMain.ServiceLocator, pMain.PageLocator, pMain.NavigationService)
 {
     m_main = pMain;
     m_main.PropertyChanged += m_main_PropertyChanged;
 }
Пример #4
0
 public static Task<Tuple<int[], int[]>> ArrangeIndexAsync(OrdModelView model, int nbIterations, CancellationToken cancellationToken)
 {
     return Task.Run<Tuple<int[], int[]>>(() =>
     {
         return ArrangeIndex(model, nbIterations, cancellationToken);
     }, cancellationToken);
 }
Пример #5
0
 public static Tuple<int[], int[]> ArrangeIndex(OrdModelView model, int nbIterations, CancellationToken cancellationToken)
 {
     int[] pRows = null;
         int[] pCols = null;
         var inds = model.Individus;
         List<IndivData> oList = transpose(inds);
         int nx = (nbIterations > 5) ? 5 : nbIterations;
         pCols = ArrangeIndex(oList, nx, cancellationToken);
         pRows = ArrangeIndex(inds, nbIterations, cancellationToken);
         return new Tuple<int[], int[]>(pRows, pCols);
 }
Пример #6
0
 public static Task<ArrangeResult> ArrangeAsync(OrdModelView model, int nbIterations,
     CancellationToken cancellationToken, IProgress<Tuple<int, ArrangeResult>> progress)
 {
     return Task.Run<ArrangeResult>(() =>
     {
         ArrangeResult pRet = null;
         try
         {
             Object syncObject = new Object();
             var inds = model.Individus;
             for (int i = 0; i < nbIterations; ++i)
             {
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return null;
                 }
                 ArrangeResult pp = null;
                 int f = (int)(((double)i / (double)nbIterations) * 100.0 + 0.5);
                 ArrangeResult pCur = Arrange(inds, cancellationToken);
                 if (pCur == null)
                 {
                     return null;
                 }
                 if (pCur.IsValid)
                 {
                     lock (syncObject)
                     {
                         if (pRet == null)
                         {
                             pRet = pCur;
                             if (progress != null)
                             {
                                 pp = (ArrangeResult)pCur.Clone();
                             }
                         }
                         else
                         {
                             if (pCur.Criteria < pRet.Criteria)
                             {
                                 pRet = pCur;
                                 if (progress != null)
                                 {
                                     pp = (ArrangeResult)pCur.Clone();
                                 }
                             }
                         }
                     }// lock
                 }// valid
                 if (progress != null)
                 {
                     progress.Report(new Tuple<int, ArrangeResult>(f, pp));
                 }
             }// i
         }
         catch (Exception /*ex */)
         {
             pRet = null;
         }
         return pRet;
     });
 }
 }// myChangeModelData
 private void myChangeOrdViewModel()
 {
     m_ordmodelview = this.OrdModelView;
     if (m_ordmodelview != null)
     {
         m_ordmodelview.PropertyChanged +=m_ordmodelview_PropertyChanged;
     }
     myChangeModelData();
 }
 public MatriceUserControl()
 {
     m_busy = true;
     m_ordmodelview = null;
     m_indivs = null;
     m_colcells = null;
     m_rowcells = null;
     m_refclasses = null;
     m_cts = null;
     m_varcells = null;
     m_indivcells = null;
     m_datacells = null;
     m_defaultitem = null;
     InitializeComponent();
     m_busy = false;
 }
Пример #9
0
 public static CategClusterSet ProcessAsync(OrdModelView model, int nClusters, CancellationToken cancellationToken)
 {
     if ((model == null) || (nClusters < 2))
     {
         return null;
     }
     if (cancellationToken.IsCancellationRequested)
     {
         return null;
     }
     var rd = new Random();
     CategClusterSet oRet = new CategClusterSet(model);
     Cluster[] cc = new Cluster[nClusters];
     IndivData[] inds = oRet.Indivs.ToArray();
     int nMax = inds.Length;
     if (nMax < nClusters)
     {
         return null;
     }
     HashSet<int> oCur = new HashSet<int>();
     for (int i = 0; i < nClusters; ++i)
     {
         int nx = rd.Next(0, nMax);
         while (nx >= nMax)
         {
             nx = rd.Next(nMax);
         }
         IndivData indiv = inds[nx];
         int index = indiv.IndivIndex;
         while (oCur.Contains(index))
         {
             nx = rd.Next(0, nMax);
             while (nx >= nMax)
             {
                 nx = rd.Next(0, nMax);
             }
             indiv = inds[nx];
             index = indiv.IndivIndex;
         }
         oCur.Add(index);
         var xc = new Cluster(indiv, ClassificationType.Utility);
         xc.Name = String.Format("CU{0}", i + 1);
         xc.Index = i;
         cc[i] = xc;
     }// i
     oRet.Clusters = cc.ToList();
     double xx = oRet.compute_global_crit(cancellationToken);
     oRet.GlobalCrit = xx;
     if (cancellationToken.IsCancellationRequested)
     {
         return null;
     }
     foreach (var ind in inds)
     {
         if (cancellationToken.IsCancellationRequested)
         {
             return null;
         }
         if (!oCur.Contains(ind.IndivIndex))
         {
             if (!oRet.processOne(ind, cancellationToken))
             {
                 return null;
             }
         }
     }// inds
     return oRet;
 }
Пример #10
0
 public static Task<CategClusterSet> KMeansAsync(OrdModelView model, int nClusters, int nbIterations, CancellationToken cancellationToken,
     IProgress<Tuple<int, CategClusterSet>> progress)
 {
     return Task.Run<CategClusterSet>(() =>
     {
         CategClusterSet oBest = new CategClusterSet(model);
         oBest.initializeCiusters(nClusters);
         for (int i = 0; i < nbIterations; ++i)
         {
             CategClusterSet pp = new CategClusterSet();
             pp.m_model = oBest.m_model;
             pp.m_nvars = oBest.m_nvars;
             pp.m_indivs = oBest.m_indivs;
             List<Cluster> oList = new List<Cluster>();
             foreach (var c in oBest.Clusters)
             {
                 Cluster cc = new Cluster();
                 cc.Index = c.Index;
                 cc.Name = c.Name;
                 cc.Center = (double[])c.Center.Clone();
                 oList.Add(cc);
             }// c
             pp.Clusters = oList;
             int f = (int)(((double)i / (double)nbIterations) * 100.0 + 0.5);
             if (cancellationToken.IsCancellationRequested)
             {
                 break;
             }
             pp.kmeansstep(cancellationToken);
             if (cancellationToken.IsCancellationRequested)
             {
                 break;
             }
             if (oBest.Equals(pp))
             {
                 break;
             }
             oBest = pp;
             if (progress != null)
             {
                 progress.Report(new Tuple<int, CategClusterSet>(f, pp));
             }
         }// i
         return oBest;
     }, cancellationToken);
 }
Пример #11
0
 public static Task<CategClusterSet> ClusterizeAsync(OrdModelView model, int nClusters, int nbIterations,
     CancellationToken cancellationToken, IProgress<Tuple<int, CategClusterSet>> progress)
 {
     return Task.Run<CategClusterSet>(() =>
     {
         CategClusterSet oBest = null;
         double bestcrit = 0.0;
         for (int i = 0; i < nbIterations; ++i)
         {
             CategClusterSet pp = null;
             int f = (int)(((double)i / (double)nbIterations) * 100.0 + 0.5);
             if (cancellationToken.IsCancellationRequested)
             {
                 break;
             }
             var p = ProcessAsync(model, nClusters, cancellationToken);
             if (p == null)
             {
                 break;
             }
             if (oBest == null)
             {
                 oBest = p;
                 bestcrit = p.CurrentCrit;
                 if (progress != null)
                 {
                     pp = (CategClusterSet)oBest.Clone();
                     pp.UpdateCenters();
                 }
             }
             else if (p.CurrentCrit > bestcrit)
             {
                 oBest = p;
                 bestcrit = p.CurrentCrit;
                 if (progress != null)
                 {
                     pp = (CategClusterSet)oBest.Clone();
                     pp.UpdateCenters();
                 }
             }
             if (progress != null)
             {
                 progress.Report(new Tuple<int, CategClusterSet>(f, pp));
             }
         }// i
         if (oBest != null)
         {
             oBest.UpdateCenters();
         }
         return oBest;
     }, cancellationToken);
 }