Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16760 for branches


Ignore:
Timestamp:
04/04/19 14:33:12 (6 years ago)
Author:
msemenki
Message:

#2988: ADD:

  1. new type of mutation that respect node type and do not change trigonometric node to "add" node;
  2. variation of previous mutation type that do not change type of terminal node;
  3. some interface adjusting for comfort work with algorithm;
  4. second variant of map, that is not "island" map but provide "net" map.
Location:
branches/2988_ModelsOfModels2
Files:
3 added
10 edited

Legend:

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

    r16734 r16760  
    2828using HeuristicLab.Random;
    2929using HeuristicLab.Selection;
     30using System;
    3031using System.Collections.Generic;
    3132using System.IO;
     
    6162         trees.First().Root.Grammar.ContainsSymbol((IVariable)a).
    6263           = 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);
     64      int neghboorNumber = 10;
     65      switch (MapCreationType.Value) { // Configure Map type and it's parameters: IslandMap, FullMap and Percent, Number
     66        case "IslandMap": break;
     67        case "FullMap":
     68          ClusterNumbersParameter.Value.Value = trees.Count();
     69          switch (NegbourType.Value) {
     70            case "Percent": neghboorNumber = Convert.ToInt32((Convert.ToDouble(ClusterNumbersParameter.Value.Value)) * (Convert.ToDouble(NegbourNumber.Value)) / 100.0); break;
     71            case "Number": neghboorNumber = NegbourNumber.Value; break;
     72            default: neghboorNumber = NegbourNumber.Value; break;
     73          }
     74          break;
     75        default: MapCreationType.Value = "IslandMap"; break;
     76      }
     77      switch (AlgorithmImplemetationType.Value) { //Configure type of algorithm application
     78        case "OnlyMapCreation": // for case when we want only create map, and do  not want made somting also. OnlyMapCreation, CrateMapAndGo, ReadMapAndGo
     79          Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value, neghboorNumber);
    6780          ClusterNumbersParameter.Value.Value = Map.K;
    6881          File.WriteAllLines("Map.txt", Map.MapToString());
     
    7184          executionContext = new ExecutionContext(null, this, globalScope);
    7285          break;
    73         case 1: // for case when we want read existed map and work with it;
     86        case "ReadMapAndGo": // for case when we want read existed map and work with it;
    7487          Map = new EMMMapTreeModel(RandomParameter.Value, trees);
    7588          ClusterNumbersParameter.Value.Value = Map.K;
     
    7891          }
    7992          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);
     93          EMMAlgorithmRun(cancellationToken);
     94          break;
     95        case "CreateMapAndGo":
     96          Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value, neghboorNumber);
    8597          ClusterNumbersParameter.Value.Value = Map.K;
    8698          if (previousExecutionState != ExecutionState.Paused) {
     
    88100          }
    89101          globalScope.Variables.Add(new Variable("TreeModelMap", Map));
    90           EMMEvolutionaryAlgorithmRun(cancellationToken);
    91           break;
    92       }
    93 
    94     }
    95     private void EMMEvolutionaryAlgorithmRun(CancellationToken cancellationToken) {
     102          File.WriteAllLines("Map.txt", Map.MapToString());
     103          File.WriteAllLines("MapToSee.txt", Map.MapToSee());
     104          EMMAlgorithmRun(cancellationToken);
     105          break;
     106        default: //for case of usial from zero step starting
     107          AlgorithmImplemetationType.Value = "CreateMapAndGo";
     108          Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value, neghboorNumber);
     109          ClusterNumbersParameter.Value.Value = Map.K;
     110          File.WriteAllLines("Map.txt", Map.MapToString());
     111          File.WriteAllLines("MapToSee.txt", Map.MapToSee());
     112          if (previousExecutionState != ExecutionState.Paused) {
     113            InitializeAlgorithm(cancellationToken);
     114          }
     115          globalScope.Variables.Add(new Variable("TreeModelMap", Map));
     116          EMMAlgorithmRun(cancellationToken);
     117          break;
     118      }
     119
     120    }
     121    private void EMMAlgorithmRun(CancellationToken cancellationToken) {
    96122      var bestSelector = new BestSelector();
    97123      bestSelector.CopySelected = new BoolValue(false);
     
    116142      var innerToken = new CancellationToken();
    117143
    118       while (evaluatedSolutions < maximumEvaluatedSolutions && !cancellationToken.IsCancellationRequested) {
     144      while (EvaluatedSolutions < maximumEvaluatedSolutions && !cancellationToken.IsCancellationRequested) {
    119145
    120146        var op4 = executionContext.CreateChildOperation(bestSelector, executionContext.Scope); // select elites
     
    125151        var selected = executionContext.Scope.SubScopes.Single(x => x.Name == "Selected");
    126152        executionContext.Scope.SubScopes.AddRange(selected.SubScopes);
    127         population.Clear();
    128         population.AddRange(selected.SubScopes.Select(x => new EMMSolution(x)));
     153        Population.Clear();
     154        Population.AddRange(selected.SubScopes.Select(x => new EMMSolution(x)));
    129155        executionContext.Scope.SubScopes.Remove(remaining);
    130156        executionContext.Scope.SubScopes.Remove(selected);
    131157
    132         var op = executionContext.CreateChildOperation(selector, executionContext.Scope);// select the rest of the population
     158        var op = executionContext.CreateChildOperation(selector, executionContext.Scope);// select the rest of the Population
    133159        ExecuteOperation(executionContext, innerToken, op);
    134160
     
    163189            // set child qualities
    164190            childSolution.Qualities = qualities;
    165             ++evaluatedSolutions;
    166             population.Add(new EMMSolution(childScope));
     191            ++EvaluatedSolutions;
     192            Population.Add(new EMMSolution(childScope));
    167193          } else {// no crossover or mutation were applied, a child was not produced, do nothing
    168             population.Add(new EMMSolution(selected.SubScopes[i]));
    169           }
    170 
    171           if (evaluatedSolutions >= maximumEvaluatedSolutions) {
     194            Population.Add(new EMMSolution(selected.SubScopes[i]));
     195          }
     196
     197          if (EvaluatedSolutions >= maximumEvaluatedSolutions) {
    172198            break;
    173199          }
    174200
    175201        }
    176         globalScope.SubScopes.Replace(population.Select(x => (IScope)x.Individual));
     202        globalScope.SubScopes.Replace(Population.Select(x => (IScope)x.Individual));
    177203        // run analyzer
    178204        var analyze = executionContext.CreateChildOperation(analyzer, globalScope);
    179205        ExecuteOperation(executionContext, innerToken, analyze);
    180         Results.AddOrUpdateResult("Evaluated Solutions", new IntValue(evaluatedSolutions));
     206        Results.AddOrUpdateResult("Evaluated Solutions", new IntValue(EvaluatedSolutions));
    181207      }
    182208    }
     
    211237      globalScope.Variables.Add(new Core.Variable("ClusterNumber", clusterNumber));
    212238
    213       evaluatedSolutions = populationSize;
     239      EvaluatedSolutions = populationSize;
    214240      base.Initialize(cancellationToken);
    215241    }
     
    218244      var evaluator = Problem.Evaluator;
    219245      var populationSize = PopulationSize.Value;
    220       population = new List<IEMMSolution>(populationSize);
     246      Population = new List<IEMMSolution>(populationSize);
    221247
    222248      var parentScope = executionContext.Scope; //main scope for the next step work
     
    245271
    246272        solution.Qualities = qualities;
    247         population.Add(solution);  // push solution to population
     273        Population.Add(solution);  // push solution to Population
    248274      }
    249275    }
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMBaseAlgorithm.cs

    r16734 r16760  
    4444    #region data members
    4545    [Storable]
    46     protected IList<IEMMSolution> solutions;
    47     [Storable]
    48     protected List<IEMMSolution> population;
    49     [Storable]
    50     protected List<IEMMSolution> offspringPopulation;
    51     [Storable]
    52     protected List<IEMMSolution> jointPopulation;
    53     [Storable]
    54     protected int evaluatedSolutions;
     46    protected IList<IEMMSolution> Solutions;
     47    [Storable]
     48    protected List<IEMMSolution> Population;
     49    [Storable]
     50    protected int EvaluatedSolutions;
    5551    [Storable]
    5652    protected ExecutionContext executionContext;
     
    7672    private const string InputFileParameterName = "InputFile";
    7773    private const string ClusterNumbersParameterName = "ClusterNumbers";
    78 
     74    private const string AlgorithmImplementationTypeParameterName = "AlgorithmImplemetationType";
     75    private const string MapCreationTypeParameterName = "MapCreationType";
     76    private const string NegbourTypeParameterName = "NegbourType";
     77    private const string NegbourNumberParameterName = "NegbourNumber";
    7978    public IValueParameter<MultiAnalyzer> AnalyzerParameter {
    8079      get { return (ValueParameter<MultiAnalyzer>)Parameters[AnalyzerParameterName]; }
     
    8584    public IValueParameter<IntValue> ClusterNumbersParameter {
    8685      get { return (IValueParameter<IntValue>)Parameters[ClusterNumbersParameterName]; }
     86    }
     87    public IFixedValueParameter<StringValue> AlgorithmImplementationTypeParameter {
     88      get { return (IFixedValueParameter<StringValue>)Parameters[AlgorithmImplementationTypeParameterName]; }
     89    }
     90    public IFixedValueParameter<StringValue> MapCreationTypeParameter {
     91      get { return (IFixedValueParameter<StringValue>)Parameters[MapCreationTypeParameterName]; }
     92    }
     93    public IFixedValueParameter<StringValue> NegbourTypeParameter {
     94      get { return (IFixedValueParameter<StringValue>)Parameters[NegbourTypeParameterName]; }
     95    }
     96    public IFixedValueParameter<IntValue> NegbourNumberParameter {
     97      get { return (IFixedValueParameter<IntValue>)Parameters[NegbourNumberParameterName]; }
    8798    }
    8899    public IFixedValueParameter<StringValue> InputFileParameter {
     
    133144      set { ClusterNumbersParameter.Value = value; }
    134145    }
     146    public StringValue AlgorithmImplemetationType {
     147      get { return AlgorithmImplementationTypeParameter.Value; }
     148      set { AlgorithmImplementationTypeParameter.Value.Value = value.Value; }
     149    }
     150    public StringValue MapCreationType {
     151      get { return MapCreationTypeParameter.Value; }
     152      set { MapCreationTypeParameter.Value.Value = value.Value; }
     153    }
     154    public StringValue NegbourType {
     155      get { return NegbourTypeParameter.Value; }
     156      set { NegbourTypeParameter.Value.Value = value.Value; }
     157    }
     158    public IntValue NegbourNumber {
     159      get { return NegbourNumberParameter.Value; }
     160      set { NegbourNumberParameter.Value.Value = value.Value; }
     161    }
    135162    public StringValue InputFile {
    136163      get { return InputFileParameter.Value; }
     
    186213
    187214      Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    188       Parameters.Add(new FixedValueParameter<StringValue>(InputFileParameterName, "The file with set of models that will be .", new StringValue("input.txt")));
     215      Parameters.Add(new FixedValueParameter<StringValue>(InputFileParameterName, "The file with set of models that will be.", new StringValue("input.txt")));
     216      Parameters.Add(new FixedValueParameter<StringValue>(AlgorithmImplementationTypeParameterName, "The Type of possible algorith, implemetation, choose one: OnlyMapCreation, CreateMapAndGo, ReadMapAndGo.", new StringValue("CreateMapAndGo")));
     217      Parameters.Add(new FixedValueParameter<StringValue>(MapCreationTypeParameterName, "The type of map crearion algorithm. Use one from: IslandMap, FullMap.", new StringValue("IslandMap")));
     218      Parameters.Add(new FixedValueParameter<IntValue>(NegbourNumberParameterName, "The parametr for FullMap type of map crearion algorithm. Use one from: 10, 20.", new IntValue(10)));
     219      Parameters.Add(new FixedValueParameter<StringValue>(NegbourTypeParameterName, "The parametr for FullMap type of map crearion algorithm. Use one from: Percent, Number.", new StringValue("Number")));
    189220      Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    190       Parameters.Add(new ValueParameter<IntValue>(PopulationSizeParameterName, "The size of the population of solutions.", new IntValue(100)));
     221      Parameters.Add(new ValueParameter<IntValue>(PopulationSizeParameterName, "The size of the population of Solutions.", new IntValue(100)));
    191222      Parameters.Add(new ConstrainedValueParameter<ISelector>(SelectorParameterName, "The operator used to sellect parents."));
    192223      Parameters.Add(new ValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that the crossover operator is applied.", new PercentValue(0.9)));
    193224      Parameters.Add(new ValueParameter<IntValue>(GroupSizeParameterName, "The GoupSize that the Selector operator is applied.", new IntValue(3)));
    194       Parameters.Add(new ConstrainedValueParameter<ICrossover>(CrossoverParameterName, "The operator used to cross solutions."));
     225      Parameters.Add(new ConstrainedValueParameter<ICrossover>(CrossoverParameterName, "The operator used to cross Solutions."));
    195226      Parameters.Add(new ValueParameter<PercentValue>(MutationProbabilityParameterName, "The probability that the mutation operator is applied on a solution.", new PercentValue(0.25)));
    196       Parameters.Add(new ConstrainedValueParameter<IManipulator>(MutatorParameterName, "The operator used to mutate solutions."));
     227      Parameters.Add(new ConstrainedValueParameter<IManipulator>(MutatorParameterName, "The operator used to mutate Solutions."));
    197228      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    198       Parameters.Add(new ValueParameter<IntValue>(MaximumEvaluatedSolutionsParameterName, "The maximum number of evaluated solutions (approximately).", new IntValue(100_000)));
     229      Parameters.Add(new ValueParameter<IntValue>(MaximumEvaluatedSolutionsParameterName, "The maximum number of evaluated Solutions (approximately).", new IntValue(100_000)));
    199230      Parameters.Add(new ValueParameter<IRandom>(RandomParameterName, new MersenneTwister()));
    200       Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
     231      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite Solutions which are kept in each generation.", new IntValue(1)));
    201232      Parameters.Add(new ValueParameter<IntValue>(ClusterNumbersParameterName, "The number of clusters for model Map.", new IntValue(100)));
    202233      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
     
    218249
    219250    protected EvolvmentModelsOfModelsAlgorithmBase(EvolvmentModelsOfModelsAlgorithmBase original, Cloner cloner) : base(original, cloner) {
    220       evaluatedSolutions = original.evaluatedSolutions;
     251      EvaluatedSolutions = original.EvaluatedSolutions;
    221252      previousExecutionState = original.previousExecutionState;
    222253
    223       if (original.solutions != null) {
    224         solutions = original.solutions.Select(cloner.Clone).ToArray();
    225       }
    226 
    227       if (original.population != null) {
    228         population = original.population.Select(cloner.Clone).ToList();
    229       }
    230 
    231       if (original.offspringPopulation != null) {
    232         offspringPopulation = original.offspringPopulation.Select(cloner.Clone).ToList();
    233       }
    234 
    235       if (original.jointPopulation != null) {
    236         jointPopulation = original.jointPopulation.Select(x => cloner.Clone(x)).ToList();
    237       }
     254      if (original.Solutions != null) {
     255        Solutions = original.Solutions.Select(cloner.Clone).ToArray();
     256      }
     257
     258      if (original.Population != null) {
     259        Population = original.Population.Select(cloner.Clone).ToList();
     260      }
     261
     262      //if (original.offspringPopulation != null) {
     263      //  offspringPopulation = original.offspringPopulation.Select(cloner.Clone).ToList();
     264      //}
     265
     266      //if (original.jointPopulation != null) {
     267      //  jointPopulation = original.jointPopulation.Select(x => cloner.Clone(x)).ToList();
     268      //}
    238269
    239270      if (original.executionContext != null) {
     
    264295
    265296    public IList<IEMMSolution> GetResult(IRandom random) {
    266       return population;
     297      return Population;
    267298    }
    268299
     
    384415
    385416    protected override void OnStopped() {
    386       if (solutions != null) {
    387         solutions.Clear();
    388       }
    389       if (population != null) {
    390         population.Clear();
    391       }
    392       if (offspringPopulation != null) {
    393         offspringPopulation.Clear();
    394       }
    395       if (jointPopulation != null) {
    396         jointPopulation.Clear();
    397       }
     417      if (Solutions != null) {
     418        Solutions.Clear();
     419      }
     420      if (Population != null) {
     421        Population.Clear();
     422      }
     423      //if (offspringPopulation != null) {
     424      //  offspringPopulation.Clear();
     425      //}
     426      //if (jointPopulation != null) {
     427      //  jointPopulation.Clear();
     428      //}
    398429      executionContext.Scope.SubScopes.Clear();
    399430      base.OnStopped();
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMClustering.cs

    r16722 r16760  
    3636    }
    3737    public int Apply(IRandom random, double[,] distances, List<int> numberCluster) {
     38
     39      K = ApplyClusteringAlgorithm(random, distances, numberCluster, K);
     40      return K;
     41    }
     42    public static void ApplyFullConectedMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, int k, int neghboorNumber = 10) {
     43      int mapSize = distances.GetLength(0);
     44      List<double> currentList = new List<double>();
     45      for (int i = 0; i < mapSize; i++) {
     46        map.Add(new List<int>());
     47        for (int j = 0; j < mapSize; j++) {
     48          currentList.Add(distances[i, j]);
     49        }
     50        map[i].Add(ChooseMinElement(currentList));
     51        while (map[i].Count < neghboorNumber) {
     52          map[i].Add(ChooseMinElement(currentList, i, map[i]));
     53        }
     54        currentList.Clear();
     55      }
     56    }
     57    private static bool CheckNumberIsInList(int number, List<int> priviousNumber) {
     58      foreach (var pNum in priviousNumber) {
     59        if (number == pNum)
     60          return true;
     61      }
     62      return false;
     63    }
     64    public static int ApplyClusteringAlgorithm(IRandom random, double[,] distances, List<int> numberCluster, int k) {
    3865      int mapSize = distances.GetLength(0);
    3966      List<int> centroids = new List<int>(); // capacity is equal K
    4067      List<double> averageClusterDistance = new List<double>();
    4168      List<List<int>> clusters = new List<List<int>>(); // capacity is equal K
    42       CentroidsRandomSetUp(random, centroids, mapSize);
     69      CentroidsRandomSetUp(random, centroids, mapSize, k);
    4370      if (numberCluster.Count == 0) {
    4471        for (int i = 0; i < mapSize; i++) {
     
    5077      while (flag) {
    5178        clusters.Clear();
    52         for (int i = 0; i < K; i++) {
     79        for (int i = 0; i < k; i++) {
    5380          clusters.Add(new List<int>());
    5481
    5582        }
    5683        for (int i = 0; i < mapSize; i++) {
    57           numberCluster[i] = LookCloseCentroid(centroids, mapSize, distances, i);
     84          numberCluster[i] = LookCloseCentroid(centroids, mapSize, distances, i, k);
    5885          clusters[numberCluster[i]].Add(numberCluster[i]);
    5986        }
    60         NullSizeClusterDelete(centroids, clusters, mapSize, numberCluster);
     87        k = NullSizeClusterDelete(centroids, clusters, mapSize, numberCluster, k);
    6188        flag = false;
    62         for (int i = 0; i < K; i++) {
     89        for (int i = 0; i < k; i++) {
    6390          AverageClusterDistanceCalculation(averageClusterDistance, distances, numberCluster, mapSize, i);
    6491          var newCentroid = clusters[i][ChooseMinElement(averageClusterDistance)];
     
    7097        }
    7198      }
    72       return K;
     99      return k;
    73100    }
    74     private void CentroidsRandomSetUp(IRandom random, List<int> centroids, int size) {
    75       for (int i = 0; i < K; i++) {
     101    private static void CentroidsRandomSetUp(IRandom random, List<int> centroids, int size, int k) {
     102      for (int i = 0; i < k; i++) {
    76103        centroids.Add(random.Next(size));
    77104      }
    78105    }
    79     private int LookCloseCentroid(List<int> centroids, int MapSize, double[,] distances, int currentNumber) {
     106    private static int LookCloseCentroid(List<int> centroids, int MapSize, double[,] distances, int currentNumber, int k) {
    80107      double minDistanse = distances[currentNumber, centroids[0]];
    81108      int clusterNum = 0;
    82       for (int i = 1; i < K; i++) {
     109      for (int i = 1; i < k; i++) {
    83110        if (minDistanse > distances[currentNumber, centroids[i]]) {
    84111          minDistanse = distances[currentNumber, centroids[i]];
     
    88115      return clusterNum;
    89116    }
    90     private void NullSizeClusterDelete(List<int> centroids, List<List<int>> clusters, int mapSize, List<int> numberCluster) {
     117    private static int NullSizeClusterDelete(List<int> centroids, List<List<int>> clusters, int mapSize, List<int> numberCluster, int k) {
    91118      int iter = 0;
    92       for (int i = 0; i < K; i++) {
     119      for (int i = 0; i < k; i++) {
    93120        if (clusters[i - iter].Count == 0) {
    94121          for (int j = 0; j < mapSize; j++) {
     
    97124          }
    98125
    99           for (int j = 0; j < K - iter; j++) {
     126          for (int j = 0; j < k - iter; j++) {
    100127            if (j != i - iter) {
    101128              for (int m = 0; m < clusters[j].Count; m++)
     
    109136        }
    110137      }
    111       K -= iter;
     138      k -= iter;
     139      return k;
    112140    }
    113     private void AverageClusterDistanceCalculation(List<double> averageClusterDistance, double[,] distances, List<int> numberCluster, int MapSize, int currentClusterNumber) {
     141    private static void AverageClusterDistanceCalculation(List<double> averageClusterDistance, double[,] distances, List<int> numberCluster, int MapSize, int currentClusterNumber) {
    114142      int m = 0;
    115143      for (int i = 0; i < MapSize; i++) {
     
    124152      }
    125153    }
    126     private int ChooseMinElement(List<double> averageClusterDistance) {
     154    private static int ChooseMinElement(List<double> averageClusterDistance) {
    127155      double minValue = averageClusterDistance[0];
    128156      int minElementNumber = 0;
     
    135163      return minElementNumber;
    136164    }
     165    private static int ChooseMinElement(List<double> distances, int currentElement, List<int> previousNumbers) {
     166      double minValue = 100;
     167      int minElementNumber = 0;
     168      int temp = 0, i = 0;
     169      while (temp == 0) {
     170        if ((currentElement != i) && (!CheckNumberIsInList(i, previousNumbers))) {
     171          minValue = distances[i];
     172          minElementNumber = i;
     173          temp = i;
     174        }
     175        i++;
     176      }
     177      for (i = 0; i < distances.Count(); i++) {
     178        if ((distances[i] < minValue) && (currentElement != i) && (!CheckNumberIsInList(i, previousNumbers))) {
     179          minValue = distances[i];
     180          minElementNumber = i;
     181        }
     182      }
     183      return minElementNumber;
     184    }
    137185  }
    138186}
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMapBase.cs

    r16734 r16760  
    3434
    3535    protected abstract void CalculateDistances();
    36     protected abstract void CreateMap(IRandom random, int k);
     36    protected abstract void CreateIslandMap(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

    r16734 r16760  
    5858      K = original.K;
    5959    }
    60     public EMMMapTreeModel(IRandom random, IEnumerable<ISymbolicExpressionTree> trees, int k) : this(k) {
     60    public EMMMapTreeModel(IRandom random, IEnumerable<ISymbolicExpressionTree> trees, int k, int neghboorNumber) : this(k) {
    6161      ModelSet = trees.ToList();
    6262      CalculateDistances();
    63       CreateMap(random, k);
     63      if (k < ModelSet.Count)
     64        CreateIslandMap(random, k);
     65      else if (k == ModelSet.Count) {
     66        CreateFullConnectedMap(random, k, neghboorNumber);
     67      } else {
     68        k -= ModelSet.Count;
     69        CreateIslandMap(random, k);
     70      }
    6471    }
    6572    public EMMMapTreeModel(IRandom random, IEnumerable<ISymbolicExpressionTree> trees) : this(1) {
     
    9198      }
    9299    }
    93     override protected void CreateMap(IRandom random, int k) {
     100    protected void CreateFullConnectedMap(IRandom random, int k, int neghboorNumber) {
     101      EMModelsClusterizationAlgorithm.ApplyFullConectedMapCreationAlgorithm(random, Distances, Map, k, neghboorNumber);
    94102      K = k;
     103      for (int i = 0; i < Map.Count; i++) {
     104        ClusterNumber.Add(i);
     105      }
     106    }
     107    override protected void CreateIslandMap(IRandom random, int k) {
    95108      //Clusterization
    96       EMModelsClusterizationAlgorithm clusteringAlgorithm = new EMModelsClusterizationAlgorithm(K);
    97       K = clusteringAlgorithm.Apply(random, Distances, ClusterNumber);
     109      K = EMModelsClusterizationAlgorithm.ApplyClusteringAlgorithm(random, Distances, ClusterNumber, k);
    98110      // Cheking a Map size
    99111      if (Map != null) Map.Clear();
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMutators.cs

    r16734 r16760  
    7171
    7272    protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
    73       //EMMMapTreeModel map= (EMMMapTreeModel)ExecutionContext.Scope.Variables["TreeModelMap"].Value;
    7473      EMMMutatorsPart(random, symbolicExpressionTree, ModelSet, ClusterNumber, Map);
    7574    }
     
    121120
    122121        var newNode = newSymbol.CreateTreeNode();
    123         if (newNode.HasLocalParameters)
    124           if (newNode is TreeModelTreeNode treeNode) {
    125             int p = random.Next(map.Count);
    126             if (child is TreeModelTreeNode chNode) // in real life never bacame true. It need some cheking
    127             { p = chNode.ClusterNumer; }
    128             treeNode.TreeNumber = map[p].SampleRandom(random).Value;
    129             treeNode.Tree = (ISymbolicExpressionTree)modelSet[treeNode.TreeNumber].Clone();
    130             treeNode.SetLocalParameters(random, 0.5);
    131           } else
    132             newNode.ResetLocalParameters(random);
     122
     123        if (newNode is TreeModelTreeNode treeNode) {
     124          int p = random.Next(map.Count);
     125          if (child is TreeModelTreeNode chNode) { p = chNode.ClusterNumer; }
     126          treeNode.TreeNumber = map[p].SampleRandom(random).Value;
     127          treeNode.Tree = (ISymbolicExpressionTree)modelSet[treeNode.TreeNumber].Clone();
     128          treeNode.ClusterNumer = p;
     129          treeNode.SetLocalParameters(random, 0.5);
     130        } else if (newNode.HasLocalParameters)
     131          newNode.ResetLocalParameters(random);
    133132        foreach (var subtree in child.Subtrees)
    134133          newNode.AddSubtree(subtree);
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/HeuristicLab.Algorithms.EvolvmentModelsOfModels.csproj

    r16722 r16760  
    109109  </ItemGroup>
    110110  <ItemGroup>
     111    <Compile Include="EMMMultyPointsMutator.cs" />
    111112    <Compile Include="EMMAlgorithm.cs" />
    112113    <Compile Include="EMMClustering.cs" />
    113114    <Compile Include="EMMMapBase.cs" />
    114115    <Compile Include="EMMMapTreeModel.cs" />
     116    <Compile Include="EMMMultyPointsMutatorNodeTypeSaving.cs" />
    115117    <Compile Include="EMMMutators.cs" />
    116118    <Compile Include="EMMSolution.cs" />
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Plugin.cs

    r16734 r16760  
    2626  /// Plugin class for HeuristicLab.Algorithms.EMMAlgorithm plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.16722")]
     28  [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.16734")]
    2929  [PluginFile("HeuristicLab.Algorithms.EMMAlgorithm-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Analysis", "3.3")]
  • branches/2988_ModelsOfModels2/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj

    r16722 r16760  
    182182    <Compile Include="ArchitectureManipulators\SubroutineDuplicater.cs" />
    183183    <Compile Include="ArchitectureManipulators\SymbolicExpressionTreeArchitectureManipulator.cs" />
    184     <Compile Include="Grammars\EMMTreeModelGrammar.cs" />
    185184    <Compile Include="Grammars\GrammarUtils.cs" />
    186185    <Compile Include="SymbolicExpressionTreeProblem.cs" />
  • branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r16734 r16760  
    235235    </Compile>
    236236    <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" />
     237    <Compile Include="Analyzers\TerminalNodesFrequencyAnalyzer.cs" />
    237238    <Compile Include="Converters\LinearModelToTreeConverter.cs" />
    238239    <Compile Include="Converters\TreeSimplifier.cs" />
Note: See TracChangeset for help on using the changeset viewer.