Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/01/19 13:03:13 (5 years ago)
Author:
msemenki
Message:

#2988: Add Model Symbol Frequency Analyzer and Model's Clusters Frequency Analyzer. Fix Bag's with Keys. Fix changing during mutation for Variables Types in SubModels .

Location:
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMAlgorithm.cs

    r16722 r16734  
    3737  [Item("EvolvmentModelsOfModels Algorithm ", "EMM implementation")]
    3838  [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 125)]
    39   [StorableType("D02C50E5-8325-496F-8DEA-C23651756846")]
     39  [StorableType("AD23B21F-089A-4C6C-AD2E-1B01E7939CF5")]
    4040  public class EMMAlgorithm : EvolvmentModelsOfModelsAlgorithmBase {
    4141    public EMMMapTreeModel Map { get; private set; }
     
    5757      InfixExpressionParser parser = new InfixExpressionParser();
    5858      var trees = File.ReadAllLines(InputFileParameter.Value.Value).Select(parser.Parse);
    59       Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value);
    60       ClusterNumbersParameter.Value.Value = Map.K;
    61       if (previousExecutionState != ExecutionState.Paused) {
    62         InitializeAlgorithm(cancellationToken);
    63       }
    64       globalScope.Variables.Add(new Variable("TreeModelMap", Map));
    65       EMMEvolutionaryAlgorithmRun(cancellationToken);
     59      // this.Problem.SymbolicExpressionTreeGrammar;
     60      /*   Problem.ProblemData.Dataset.ColumnNames.Take(2).ToList();
     61         trees.First().Root.Grammar.ContainsSymbol((IVariable)a).
     62           = this.Problem.SymbolicExpressionTreeGrammar;*/
     63      int flag = 1;
     64      switch (flag) {
     65        case 0: // for case when we want only create map, and do  not want made somting also.
     66          Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value);
     67          ClusterNumbersParameter.Value.Value = Map.K;
     68          File.WriteAllLines("Map.txt", Map.MapToString());
     69          File.WriteAllLines("MapToSee.txt", Map.MapToSee());
     70          globalScope = new Scope("Global Scope");
     71          executionContext = new ExecutionContext(null, this, globalScope);
     72          break;
     73        case 1: // for case when we want read existed map and work with it;
     74          Map = new EMMMapTreeModel(RandomParameter.Value, trees);
     75          ClusterNumbersParameter.Value.Value = Map.K;
     76          if (previousExecutionState != ExecutionState.Paused) {
     77            InitializeAlgorithm(cancellationToken);
     78          }
     79          globalScope.Variables.Add(new Variable("TreeModelMap", Map));
     80          EMMEvolutionaryAlgorithmRun(cancellationToken);
     81          break;
     82
     83        default: //for case of usial from zero step starting
     84          Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value);
     85          ClusterNumbersParameter.Value.Value = Map.K;
     86          if (previousExecutionState != ExecutionState.Paused) {
     87            InitializeAlgorithm(cancellationToken);
     88          }
     89          globalScope.Variables.Add(new Variable("TreeModelMap", Map));
     90          EMMEvolutionaryAlgorithmRun(cancellationToken);
     91          break;
     92      }
     93
    6694    }
    6795    private void EMMEvolutionaryAlgorithmRun(CancellationToken cancellationToken) {
     
    201229        foreach (var node in tree.IterateNodesPostfix().OfType<TreeModelTreeNode>()) {
    202230          node.Tree = Map.NewModelForInizializtion(random, out int cluster, out int treeNumber);
    203           node.Tree.Root.ShakeLocalParameters(random, 0.5);
     231          node.SetLocalParameters(random, 0.5);
    204232          node.ClusterNumer = cluster;
    205233          node.TreeNumber = treeNumber;
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMBaseAlgorithm.cs

    r16722 r16734  
    4040namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels {
    4141  [Item("MOEADAlgorithmBase", "Base class for all MOEA/D algorithm variants.")]
    42   [StorableType("DD721D8A-A4DE-44C1-8D83-7888E8433B5F")]
     42  [StorableType("A56A396B-965A-4ADE-8A2B-AE3A45F9C239")]
    4343  public abstract class EvolvmentModelsOfModelsAlgorithmBase : FixedDataAnalysisAlgorithm<ISymbolicDataAnalysisSingleObjectiveProblem> {
    4444    #region data members
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMapBase.cs

    r16722 r16734  
    2525
    2626namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels {
    27   [StorableType("8A5818D6-2B74-4148-AFBC-D36CE6256406")]
     27  [StorableType("83CF9650-98FF-454B-9072-82EA4D39C752")]
    2828  public abstract class EMMMapBase<T> : Item where T : class {
    2929    public List<T> ModelSet { get; set; }
     
    3434
    3535    protected abstract void CalculateDistances();
    36     public abstract void CreateMap(IRandom random, int k);
     36    protected abstract void CreateMap(IRandom random, int k);
    3737    public abstract T NewModelForInizializtion(IRandom random, out int cluster, out int treeNumber);
    3838
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMapTreeModel.cs

    r16722 r16734  
    2626using HeuristicLab.Problems.DataAnalysis.Symbolic;
    2727using System.Collections.Generic;
     28using System.IO;
    2829using System.Linq;
    2930
    3031namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels {
    31   [StorableType("A9AE93F0-E589-44D0-AD34-0E3AA358D669")]
    3232  [Item("TreeModelMap", "A map of models of models of models")]
     33  [StorableType("E4AB04B9-FD5D-47EE-949D-243660754F3A")]
    3334  public class EMMMapTreeModel : EMMMapBase<ISymbolicExpressionTree> {
    3435    #region conctructors
     
    6263      CreateMap(random, k);
    6364    }
     65    public EMMMapTreeModel(IRandom random, IEnumerable<ISymbolicExpressionTree> trees) : this(1) {
     66      ModelSet = trees.ToList();
     67      string input = File.ReadAllText("Map.txt");
     68
     69      int i = 0;
     70      foreach (var row in input.Split('\n')) {
     71        Map.Add(new List<int>());
     72        foreach (var col in row.Trim().Split(' ')) {
     73          Map[i].Add(int.Parse(col.Trim()));
     74        }
     75        i++;
     76      }
     77      K = Map.Count;
     78      MapPreparation();
     79    }
    6480    public override IDeepCloneable Clone(Cloner cloner) {
    6581      return new EMMMapTreeModel(this, cloner);
     
    7591      }
    7692    }
    77     override public void CreateMap(IRandom random, int k) {
     93    override protected void CreateMap(IRandom random, int k) {
    7894      K = k;
    7995      //Clusterization
     
    96112      }
    97113    }
     114    protected void MapPreparation() {
     115      for (int i = 0; i < Map.Count; i++) {
     116        for (int j = 0; j < Map[i].Count; j++) {
     117          ClusterNumber.Add(0);
     118        }
     119      }
     120      for (int i = 0; i < Map.Count; i++) {
     121        for (int j = 0; j < Map[i].Count; j++) {
     122          ClusterNumber[Map[i][j]] = i;
     123        }
     124      }
     125    }
    98126    #endregion
    99127    #region Dialog with surroudings
     
    103131      return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone();
    104132    }
     133    public string[] MapToString() {
     134      string[] s;
     135      s = new string[K];
     136      for (int i = 0; i < K; i++) {
     137        s[i] = "";
     138        for (int j = 0; j < Map[i].Count; j++) {
     139          s[i] += Map[i][j].ToString();
     140          s[i] += " ";
     141        }
     142      }
     143      return s;
     144    }
     145    public string[] MapToSee() {
     146      var fmt = new InfixExpressionFormatter();
     147      string[] s;
     148      s = new string[(ModelSet.Count) + 1];
     149      s[0] = "ClusterNumber" + "," + "Modfelnumber" + "," + "Model";
     150      for (int i = 1; i < ((ModelSet.Count) + 1); i++) {
     151        s[i] = ClusterNumber[i - 1].ToString() + "," + (i - 1).ToString() + "," + fmt.Format(ModelSet[i - 1]);
     152      }
     153      return s;
     154    }
    105155
    106156    #endregion
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMutators.cs

    r16722 r16734  
    3232
    3333namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels {
    34   [StorableType("92D37E9F-8726-4524-AF8F-F3787641F7B9")]
    3534  [Item("EMMChangeNodeTypeManipulation", "Selects a random tree node and changes the symbol.")]
     35  [StorableType("990D3946-7F06-48B4-B8DB-F8E308D6304D")]
    3636  public sealed class EMMMutators : SymbolicExpressionTreeManipulator {
    3737    private const int MAX_TRIES = 100;
     
    125125            int p = random.Next(map.Count);
    126126            if (child is TreeModelTreeNode chNode) // in real life never bacame true. It need some cheking
    127               p = chNode.ClusterNumer;
     127            { p = chNode.ClusterNumer; }
    128128            treeNode.TreeNumber = map[p].SampleRandom(random).Value;
    129129            treeNode.Tree = (ISymbolicExpressionTree)modelSet[treeNode.TreeNumber].Clone();
    130             treeNode.Tree.Root.ShakeLocalParameters(random, 0.5);
     130            treeNode.SetLocalParameters(random, 0.5);
    131131          } else
    132132            newNode.ResetLocalParameters(random);
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMSolution.cs

    r16722 r16734  
    2626// Can be deleted potnetinaly
    2727namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels {
     28  [StorableType("AB38211D-5F52-4420-A606-1C3CB58BA27C")]
    2829  public interface IEMMSolution : IItem {
    2930    IItem Individual { get; set; }
     
    3132  }
    3233  [Item("EMMSolution", "Represents a solution inside the EMM population")]
    33   [StorableType("708BDF29-AD3F-4AFC-83AE-551A27FF45A0")]
     34  [StorableType("C0E63430-5000-4592-BBE4-2D3E0EE1AE3F")]
    3435  public class EMMSolution : Item, IEMMSolution {
    3536    [Storable]
     
    6970  }
    7071  [Item("EMMSolution", "Represents a solution inside the EMM population")]
    71   [StorableType("36929CD1-63A5-4270-8C65-2A8177BCA0AE")]
     72  [StorableType("559EA31B-2263-4233-900C-EC62120EE580")]
    7273  public class EMMSolution<T> : EMMSolution where T : class, IItem {
    7374    public new T Individual {
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Plugin.cs

    r16722 r16734  
    2626  /// Plugin class for HeuristicLab.Algorithms.EMMAlgorithm plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.16565")]
     28  [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.16722")]
    2929  [PluginFile("HeuristicLab.Algorithms.EMMAlgorithm-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Analysis", "3.3")]
Note: See TracChangeset for help on using the changeset viewer.