Changeset 17134 for branches/2988_ModelsOfModels2
- Timestamp:
- 07/11/19 16:30:22 (5 years ago)
- Location:
- branches/2988_ModelsOfModels2
- Files:
-
- 8 added
- 5 edited
- 15 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Analyzers/ModelClustersFrequencyAnalyzer.cs
r17133 r17134 37 37 /// Calculates the accumulated frequencies of variable-symbols over all trees in the population. 38 38 /// </summary> 39 [Item("Symbolic DataAnalysisModelClustersFrequencyAnalyzer", "Calculates the accumulated frequencies of Model Clusters over all trees in the population.")]39 [Item("Symbolic Data Analysis Model Clusters Frequency Analyzer", "Calculates the accumulated frequencies of Model Clusters over all trees in the population.")] 40 40 [StorableType("4755115D-1B73-4577-BA2A-A762AE4C3B2F")] 41 41 public sealed class ModelClustersFrequencyAnalyzer : SymbolicDataAnalysisAnalyzer { … … 156 156 for (int i = 0; i < map.ModelSet.Count; i++) { 157 157 string referenceId = "Tree Probability" + i; 158 references[referenceId] = sMap. Probabilities[i];158 references[referenceId] = sMap.SelfConfigurationMechanism.Probabilities[i]; 159 159 } 160 160 } else { -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMAlgorithm/EMMAlgorithm.cs
r17133 r17134 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Problems.DataAnalysis; 27 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 29 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 28 30 using HeuristicLab.Random; 29 31 using HeuristicLab.Selection; … … 34 36 35 37 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 36 [Item("Evolv ment Models Of Models Algorithm (EMM) ", "EMM implementation")]38 [Item("Evolvement Models Of Models Algorithm (EMM) ", "EMM implementation")] 37 39 [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 125)] 38 40 [StorableType("AD23B21F-089A-4C6C-AD2E-1B01E7939CF5")] 39 41 public class EMMAlgorithm : EvolvmentModelsOfModelsAlgorithmBase { 42 #region Constructors 40 43 public EMMAlgorithm() : base() { } 41 44 protected EMMAlgorithm(EMMAlgorithm original, Cloner cloner) : base(original, cloner) { } … … 46 49 [StorableConstructor] 47 50 protected EMMAlgorithm(StorableConstructorFlag _) : base(_) { } 48 51 #endregion 52 #region Algorithm run 49 53 protected override void Run(CancellationToken cancellationToken) { 54 55 Map.DistanceParametr = DistanceType.Value; 56 50 57 if (AlgorithmImplemetationType.Value == "Read") { 51 Map.MapRead( RandomParameter.Value, trees, "Map.txt");58 Map.MapRead(trees); 52 59 } else { 53 60 Map.MapCreationPrepare(trees); 54 Map.CreateMap(RandomParameter.Value, ClusterNumbersParameter.Value.Value); 55 // Map.WriteMapToTxtFile(RandomParameter.Value); хайв этого не любит.. ворчит 56 } 57 ClusterNumbersShowParameter.Value.Value = Map.Map.Count; 58 59 if (AlgorithmImplemetationType.Value == "OnlyMap") { 60 globalScope = new Scope("Global Scope"); 61 executionContext = new ExecutionContext(null, this, globalScope); 62 } else { 63 if (previousExecutionState != ExecutionState.Paused) { 64 InitializeAlgorithm(cancellationToken); 65 } 66 if (!globalScope.Variables.ContainsKey("TreeModelMap")) 67 globalScope.Variables.Add(new Variable("TreeModelMap", Map)); 68 if (!globalScope.Variables.ContainsKey("Map")) 69 globalScope.Variables.Add(new Variable("Map", Map)); 70 EMMAlgorithmRun(cancellationToken); 71 } 61 Map.CreateMap(RandomParameter.Value, Problem); 62 } 63 if (previousExecutionState != ExecutionState.Paused) { 64 InitializeAlgorithm(cancellationToken); 65 } 66 if (!globalScope.Variables.ContainsKey("TreeModelMap")) 67 globalScope.Variables.Add(new Variable("TreeModelMap", Map)); 68 if (!globalScope.Variables.ContainsKey("Map")) 69 globalScope.Variables.Add(new Variable("Map", Map)); 70 EMMAlgorithmRun(cancellationToken); 72 71 } 73 72 private void EMMAlgorithmRun(CancellationToken cancellationToken) { … … 88 87 var rand = RandomParameter.Value; 89 88 var elites = Elites.Value; 90 91 // cancellation token for the inner operations which should not be immediately cancel led89 var fmd = new InfixExpressionFormatter(); 90 // cancellation token for the inner operations which should not be immediately canceled 92 91 var innerToken = new CancellationToken(); 92 // for future 93 //var mutatorTypes = new SymbolicExpressionTreeManipulator[] 94 //{ 95 // new EMMMultyPointsMutator(), 96 // new EMMMultyPointsMutatorNodeTypeSaving (), 97 // new EMMMutators() 98 //}; 99 //var tuu = MutatorParameter.ValidValues; 100 //var select = SelectorParameter.ValidValues; 93 101 94 102 while (EvaluatedSolutions < maximumEvaluatedSolutions && !cancellationToken.IsCancellationRequested) { … … 113 121 114 122 for (int i = 0; i < selector.NumberOfSelectedSubScopesParameter.Value.Value; i += 2) { 115 // crossover116 123 IScope childScope = null; 124 // for future 125 //var obbbb = CrossoverParameter.ValidValues.ToList(); 126 //int nn = 3; 127 //if (rand.NextDouble() < crossoverProbability) { 128 // childScope = new Scope($"{i}+{i + 1}") { Parent = executionContext.Scope }; 129 // childScope.SubScopes.Add(selected.SubScopes[i]); 130 // childScope.SubScopes.Add(selected.SubScopes[i + 1]); 131 // var op1 = executionContext.CreateChildOperation(obbbb[nn], childScope); 132 // ExecuteOperation(executionContext, innerToken, op1); 133 // childScope.SubScopes.Clear(); 134 //} 135 117 136 if (rand.NextDouble() < crossoverProbability) { 118 137 childScope = new Scope($"{i}+{i + 1}") { Parent = executionContext.Scope }; … … 133 152 // evaluation 134 153 if (childScope != null) { 135 var op3 = executionContext.CreateChildOperation(evaluator, childScope); 136 ExecuteOperation(executionContext, innerToken, op3); 137 //if (Problem.ProblemData is IRegressionProblemData problemData) { 138 // SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(Problem.SymbolicExpressionTreeInterpreter, (ISymbolicExpressionTree)childScope.Variables["SymbolicExpressionTree"].Value, problemData, problemData.TestIndices, true, 100 /*max iterration*/, true); 139 //} 140 ++EvaluatedSolutions; 141 Population.Add(new EMMSolution(childScope)); 154 if (!childScope.Variables.ContainsKey("Quality")) 155 childScope.Variables.Add(new Variable("Quality")); 156 EvaluationComplex(executionContext, innerToken, childScope); 142 157 } else {// no crossover or mutation were applied, a child was not produced, do nothing 143 158 Population.Add(new EMMSolution(selected.SubScopes[i])); … … 146 161 break; 147 162 } 148 149 } 150 if (Map is EMMSucsessMap) { 151 var population = new Dictionary<ISymbolicExpressionTree, double>(); 152 foreach (var individ in Population) { 153 var tree = (ISymbolicExpressionTree)(((IScope)individ.Individual).Variables["SymbolicExpressionTree"].Value); 154 population.Add(tree, individ.Qualities.Value); 155 } 156 Map.MapUpDate(population); 157 population.Clear(); 158 } 159 //List<object> A = new List<object>(); 160 //A.Add(new Scope ()); 161 //A.Add(new SymbolicExpressionTree()); 163 } 164 165 UpDateParameters(); 162 166 163 167 globalScope.SubScopes.Replace(Population.Select(x => (IScope)x.Individual)); … … 165 169 var analyze = executionContext.CreateChildOperation(analyzer, globalScope); 166 170 ExecuteOperation(executionContext, innerToken, analyze); 171 167 172 Results.AddOrUpdateResult("Evaluated Solutions", new IntValue(EvaluatedSolutions)); 168 173 } 169 174 } 175 protected virtual void UpDateParameters() { 176 if (Map is EMMSucsessMap) { 177 var population = new Dictionary<ISymbolicExpressionTree, double>(); 178 foreach (var individ in Population) { 179 var tree = (ISymbolicExpressionTree)(((IScope)individ.Individual).Variables["SymbolicExpressionTree"].Value); 180 population.Add(tree, individ.Qualities.Value); 181 } 182 Map.MapUpDate(population); 183 population.Clear(); 184 } 185 } 186 #endregion 187 #region Initialization 170 188 protected void InitializeAlgorithm(CancellationToken cancellationToken) { 171 189 globalScope = new Scope("Global Scope"); … … 181 199 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed(); 182 200 rand.Reset(Seed); 183 201 EvaluatedSolutions = 0; 202 // InitializeParametrs(); for future 184 203 InitializePopulation(executionContext, cancellationToken, rand); 185 EvaluatedSolutions = PopulationSize.Value; 204 186 205 187 206 base.Initialize(cancellationToken); 188 207 } 208 protected virtual void InitializeParametrs() { } 189 209 190 210 private void InitializePopulation(ExecutionContext executionContext, CancellationToken cancellationToken, IRandom random) { 191 211 Population = new List<IEMMSolution>(); 212 var fmd = new InfixExpressionFormatter(); 192 213 var evaluator = Problem.Evaluator; 193 214 var creator = Problem.SolutionCreator; 215 var parser = new InfixExpressionParser(); 216 194 217 var parentScope = executionContext.Scope; //main scope for the next step work 195 218 // first, create all individuals … … 199 222 var name = ((ISymbolicExpressionTreeCreator)creator).SymbolicExpressionTreeParameter.ActualName; 200 223 var tree = (ISymbolicExpressionTree)childScope.Variables[name].Value; 224 201 225 foreach (var node in tree.IterateNodesPostfix().OfType<TreeModelTreeNode>()) { 202 226 Map.NodeManipulationForInizializtion(random, node); … … 207 231 for (int i = 0; i < PopulationSize.Value; ++i) { 208 232 var childScope = parentScope.SubScopes[i]; 209 ExecuteOperation(executionContext, cancellationToken, executionContext.CreateChildOperation(evaluator, childScope)); 210 Population.Add(new EMMSolution(childScope)); // Create solution and push individual inside. push solution to Population 211 } 212 } 213 233 if (!childScope.Variables.ContainsKey("Quality")) 234 childScope.Variables.Add(new Variable("Quality", new DoubleValue(0))); 235 EvaluationComplex(executionContext, cancellationToken, childScope); 236 } 237 } 238 #endregion 239 #region Evaluators 240 private void EvaluationComplex(ExecutionContext executionContext, CancellationToken cancellationToken, IScope childScope) { 241 var evaluator = Problem.Evaluator; 242 if (evaluator is SymbolicRegressionConstantOptimizationEvaluator eval) { 243 var creator = Problem.SolutionCreator; 244 var name = ((ISymbolicExpressionTreeCreator)creator).SymbolicExpressionTreeParameter.ActualName; 245 var tree = (ISymbolicExpressionTree)childScope.Variables[name].Value; 246 var treeWithModelInside = ModelToTreePusher(tree); 247 248 //ExecuteOperation(executionContext, cancellationToken, executionContext.CreateChildOperation(evaluator, treeScope)); 249 var pd = (IRegressionProblemData)Problem.ProblemData; 250 var estimationLimits = ((SymbolicRegressionSingleObjectiveProblem)Problem).EstimationLimits; 251 var interpreter = new SymbolicDataAnalysisExpressionTreeBatchInterpreter(); 252 var quality = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, treeWithModelInside, pd, pd.TrainingIndices, applyLinearScaling: true, maxIterations: 10, updateVariableWeights: true, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper, updateConstantsInTree: true); 253 childScope.Variables["Quality"].Value = new DoubleValue(quality); 254 255 int index = 0; 256 ConstuntValuesInTreeUpdate(tree, ConstantValuesFromTreeToListExtruction(treeWithModelInside), ref index); 257 childScope.Variables[name].Value = tree; 258 EvaluatedSolutions += 10; 259 } else { 260 var op3 = executionContext.CreateChildOperation(evaluator, childScope); 261 ExecuteOperation(executionContext, cancellationToken, op3); 262 EvaluatedSolutions += 1; 263 } 264 Population.Add(new EMMSolution(childScope)); 265 } 266 private ISymbolicExpressionTree ModelToTreePusher(ISymbolicExpressionTree tree) { 267 //All model nodes in tree are exchange to trees that are stored in model nodes. 268 // After this function we have deal with usual tree 269 var clone = (ISymbolicExpressionTree)tree.Clone(); 270 foreach (var node in clone.IterateNodesPostfix().OfType<TreeModelTreeNode>()) { 271 var newChild = node.Tree.Root.GetSubtree(0).GetSubtree(0); 272 Swap(node, newChild); 273 } 274 return clone; 275 } 276 protected static void Swap(ISymbolicExpressionTreeNode oldChild, ISymbolicExpressionTreeNode newChild) { 277 var parent = oldChild.Parent; 278 if (parent == null) 279 return; 280 281 var index = parent.IndexOfSubtree(oldChild); 282 parent.RemoveSubtree(index); 283 parent.InsertSubtree(index, newChild); 284 } 285 private List<double> ConstantValuesFromTreeToListExtruction(ISymbolicExpressionTree tree) { 286 //This function stored in a list all constants and coefficients from the tree 287 var constants = new List<double>(); 288 foreach (var node in tree.IterateNodesPostfix()) { 289 if (node is ConstantTreeNode cNode) { 290 constants.Add(cNode.Value); 291 } 292 if (node is VariableTreeNode vNode) { 293 constants.Add(vNode.Weight); 294 } 295 } 296 return constants; 297 } 298 private void ConstuntValuesInTreeUpdate(ISymbolicExpressionTree tree, List<double> constants, ref int index) { 299 foreach (var node in tree.IterateNodesPostfix()) { 300 if (node is ConstantTreeNode cNode) { 301 cNode.Value = constants[index]; 302 index++; 303 } else if (node is VariableTreeNode vNode) { 304 vNode.Weight = constants[index]; 305 index++; 306 } else if (node is TreeModelTreeNode mNode) { 307 ConstuntValuesInTreeUpdate(mNode.Tree, constants, ref index); 308 } 309 310 } 311 } 312 #endregion 313 #region Local Search 214 314 // next function was not tested in real work 215 315 private void LocalDecent(ISymbolicDataAnalysisSingleObjectiveProblem problem, CancellationToken cancellationToken, IScope childScope) { … … 257 357 } 258 358 } 359 #endregion 259 360 } 260 361 -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMAlgorithm/EMMBaseAlgorithm.cs
r17133 r17134 41 41 42 42 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 43 [Item(" MOEADAlgorithmBase", "Base class for all MOEA/Dalgorithm variants.")]43 [Item("EMMAlgorithmBase", "Base class for all EMM algorithm variants.")] 44 44 [StorableType("A56A396B-965A-4ADE-8A2B-AE3A45F9C239")] 45 45 public abstract class EvolvmentModelsOfModelsAlgorithmBase : FixedDataAnalysisAlgorithm<ISymbolicDataAnalysisSingleObjectiveProblem> { … … 78 78 private const string AnalyzerParameterName = "Analyzer"; 79 79 private const string InputFileParameterName = "InputFile"; 80 private const string ClusterNumbersParameterName = "ClusterNumbers";81 private const string ClusterNumbersShowParameterName = "ClusterNumbersShow";82 80 private const string AlgorithmImplementationTypeParameterName = "AlgorithmImplementationType"; 81 private const string DistanceTypeParameterName = "DistanceType"; 83 82 private const string MapParameterName = "Map"; 84 private const string NegbourTypeParameterName = "NegbourType";85 private const string NegbourNumberParameterName = "NegbourNumber";86 83 public IValueParameter<MultiAnalyzer> AnalyzerParameter { 87 84 get { return (ValueParameter<MultiAnalyzer>)Parameters[AnalyzerParameterName]; } … … 90 87 get { return (IFixedValueParameter<IntValue>)Parameters[SeedParameterName]; } 91 88 } 92 public IValueParameter<IntValue> ClusterNumbersParameter {93 get { return (IValueParameter<IntValue>)Parameters[ClusterNumbersParameterName]; }94 }95 public IValueParameter<IntValue> ClusterNumbersShowParameter {96 get { return (IValueParameter<IntValue>)Parameters[ClusterNumbersShowParameterName]; }97 }98 89 public IConstrainedValueParameter<StringValue> AlgorithmImplementationTypeParameter { 99 90 get { return (IConstrainedValueParameter<StringValue>)Parameters[AlgorithmImplementationTypeParameterName]; } 100 91 } 92 public IConstrainedValueParameter<StringValue> DistanceTypeParameter { 93 get { return (IConstrainedValueParameter<StringValue>)Parameters[DistanceTypeParameterName]; } 94 } 101 95 public IConstrainedValueParameter<EMMMapBase<ISymbolicExpressionTree>> MapParameter { 102 96 get { return (IConstrainedValueParameter<EMMMapBase<ISymbolicExpressionTree>>)Parameters[MapParameterName]; } 103 97 } 104 public IFixedValueParameter<StringValue> NegbourTypeParameter { 105 get { return (IFixedValueParameter<StringValue>)Parameters[NegbourTypeParameterName]; } 106 } 107 public IFixedValueParameter<IntValue> NegbourNumberParameter { 108 get { return (IFixedValueParameter<IntValue>)Parameters[NegbourNumberParameterName]; } 109 } 98 110 99 public IFixedValueParameter<StringValue> InputFileParameter { 111 100 get { return (IFixedValueParameter<StringValue>)Parameters[InputFileParameterName]; } … … 151 140 set { SeedParameter.Value.Value = value; } 152 141 } 153 public IntValue ClusterNumbers {154 get { return ClusterNumbersParameter.Value; }155 set { ClusterNumbersParameter.Value = value; }156 }157 public IntValue ClusterNumbersShow {158 get { return ClusterNumbersShowParameter.Value; }159 set { ClusterNumbersShowParameter.Value = value; }160 }161 142 public StringValue AlgorithmImplemetationType { 162 143 get { return AlgorithmImplementationTypeParameter.Value; } 163 144 set { AlgorithmImplementationTypeParameter.Value.Value = value.Value; } 164 145 } 146 public StringValue DistanceType { 147 get { return DistanceTypeParameter.Value; } 148 set { DistanceTypeParameter.Value.Value = value.Value; } 149 } 165 150 public EMMMapBase<ISymbolicExpressionTree> Map { 166 151 get { return MapParameter.Value; } 167 152 set { MapParameter.Value = value; } 168 153 } 169 public StringValue NegbourType {170 get { return NegbourTypeParameter.Value; }171 set { NegbourTypeParameter.Value.Value = value.Value; }172 }173 public IntValue NegbourNumber {174 get { return NegbourNumberParameter.Value; }175 set { NegbourNumberParameter.Value.Value = value.Value; }176 }177 154 public StringValue InputFile { 178 155 get { return InputFileParameter.Value; } … … 229 206 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 230 207 Parameters.Add(new FixedValueParameter<StringValue>(InputFileParameterName, "The file with set of models that will be.", new StringValue("input.txt"))); 231 Parameters.Add(new ConstrainedValueParameter<StringValue>(AlgorithmImplementationTypeParameterName, "The Type of possible algorith, implemetation, choose one: OnlyMap, Full, Read.")); 232 Parameters.Add(new ConstrainedValueParameter<EMMMapBase<ISymbolicExpressionTree>>(MapParameterName, "The type of map crearion algorithm. Use one from: IslandMap, NetworkMap.")); 233 Parameters.Add(new FixedValueParameter<IntValue>(NegbourNumberParameterName, "The parametr for FullMap type of map crearion algorithm. Use one from: 10, 20.", new IntValue(10))); 234 Parameters.Add(new FixedValueParameter<StringValue>(NegbourTypeParameterName, "The parametr for FullMap type of map crearion algorithm. Use one from: Percent, Number.", new StringValue("Number"))); 208 Parameters.Add(new ConstrainedValueParameter<StringValue>(AlgorithmImplementationTypeParameterName, "The Type of possible algorithm, implementation, choose one: OnlyMap, Full, Read.")); 209 Parameters.Add(new ConstrainedValueParameter<StringValue>(DistanceTypeParameterName, "The Type of possible distance calculator for case of only distance calculation.")); 210 Parameters.Add(new ConstrainedValueParameter<EMMMapBase<ISymbolicExpressionTree>>(MapParameterName, "The type of map creation algorithm. Use one from: IslandMap, NetworkMap.")); 235 211 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 236 212 Parameters.Add(new ValueParameter<IntValue>(PopulationSizeParameterName, "The size of the population of Solutions.", new IntValue(100))); 237 Parameters.Add(new ConstrainedValueParameter<ISelector>(SelectorParameterName, "The operator used to sel lect parents."));213 Parameters.Add(new ConstrainedValueParameter<ISelector>(SelectorParameterName, "The operator used to select parents.")); 238 214 Parameters.Add(new ValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that the crossover operator is applied.", new PercentValue(0.9))); 239 215 Parameters.Add(new ValueParameter<IntValue>(GroupSizeParameterName, "The GoupSize that the Selector operator is applied.", new IntValue(3))); … … 244 220 Parameters.Add(new ValueParameter<IntValue>(MaximumEvaluatedSolutionsParameterName, "The maximum number of evaluated Solutions (approximately).", new IntValue(100_000))); 245 221 Parameters.Add(new ValueParameter<IRandom>(RandomParameterName, new MersenneTwister())); 246 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite Solutions which are kept in each generation.", new IntValue(1))); 247 Parameters.Add(new ValueParameter<IntValue>(ClusterNumbersParameterName, "The number of clusters for model Map.", new IntValue(10))); 248 Parameters.Add(new ValueParameter<IntValue>(ClusterNumbersShowParameterName, "The number of clusters for model Map.", new IntValue(10))); 222 Parameters.Add(new ValueParameter<IntValue>("Elites", "The number of elite Solutions which are kept in each generation.", new IntValue(1))); 249 223 foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) 250 224 SelectorParameter.ValidValues.Add(selector); … … 274 248 if (Problem != null) { 275 249 Problem.SymbolicExpressionTreeInterpreter = new SymbolicDataAnalysisExpressionTreeBatchInterpreter(); 276 //Problem.SymbolicExpressionTreeGrammar = new EMMGrammar();277 250 } 278 251 } 279 252 protected void MapParameterUpdate() { 280 int neghboorNumber = 10;281 282 switch (NegbourType.Value) {283 case "Percent": neghboorNumber = Convert.ToInt32((Convert.ToDouble(ClusterNumbersParameter.Value.Value)) * (Convert.ToDouble(NegbourNumber.Value)) / 100.0); break;284 case "Number": neghboorNumber = NegbourNumber.Value; break;285 default: neghboorNumber = NegbourNumber.Value; break;286 }287 253 var mapTypes = new EMMMapBase<ISymbolicExpressionTree>[] 288 254 { 289 255 new EMMIslandMap(), 290 new EMMNetworkMap( neghboorNumber),256 new EMMNetworkMap(), 291 257 new EMMDisatanceMap(), 292 258 new EMMRankMap(), … … 301 267 new StringValue("Full"), 302 268 new StringValue("Read"), 303 new StringValue ("OnlyMap")304 269 }; 305 270 foreach (var t in algorithmType) { 306 271 AlgorithmImplementationTypeParameter.ValidValues.Add(t); 307 272 } 273 var distanceType = new StringValue[] 274 { 275 new StringValue("MSE"), 276 new StringValue("PearsonsRSquared"), 277 new StringValue ("Covariance"), 278 new StringValue ("MaxAbsoluteError"), 279 new StringValue ("MeanAbsoluteError"), 280 new StringValue ("Symbolic") 281 }; 282 foreach (var t in distanceType) { 283 DistanceTypeParameter.ValidValues.Add(t); 284 } 308 285 } 309 286 … … 320 297 } 321 298 322 //if (original.offspringPopulation != null) {323 // offspringPopulation = original.offspringPopulation.Select(cloner.Clone).ToList();324 //}325 326 //if (original.jointPopulation != null) {327 // jointPopulation = original.jointPopulation.Select(x => cloner.Clone(x)).ToList();328 //}329 330 299 if (original.executionContext != null) { 331 300 executionContext = cloner.Clone(original.executionContext); … … 335 304 globalScope = cloner.Clone(original.globalScope); 336 305 } 337 338 // hack 339 trees = original.trees.Select(x => cloner.Clone(x)).ToArray(); 306 // hack 307 if (original.trees != null) { 308 trees = original.trees.Select(x => cloner.Clone(x)).ToArray(); 309 } 340 310 } 341 311 -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMAlgorithm/EMMSolution.cs
r17133 r17134 24 24 using HeuristicLab.Core; 25 25 using DoubleValue = HeuristicLab.Data.DoubleValue; 26 // Can be deleted pot netinaly26 // Can be deleted potentially 27 27 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 28 28 [StorableType("AB38211D-5F52-4420-A606-1C3CB58BA27C")] -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMOperators/EMMMultyPointsMutator.cs
r17133 r17134 71 71 72 72 List<ISymbol> allowedSymbols = new List<ISymbol>(); 73 var probability = (1 / mutationProbability.Value) / (symbolicExpressionTree.Length); // probability for e dch node to mutate73 var probability = (1 / mutationProbability.Value) / (symbolicExpressionTree.Length); // probability for each node to mutate 74 74 var allAllowedSymbols = symbolicExpressionTree.Root.Grammar.AllowedSymbols.Where(s => 75 75 !(s is Defun) && … … 81 81 symbolicExpressionTree.Root.ForEachNodePostfix(node => {//for each node in tree - try to mutate 82 82 83 if (SymbolTypeCheck(node.Symbol, allAllowedSymbols)) { // we do not want to to ch StartSymbol83 if (SymbolTypeCheck(node.Symbol, allAllowedSymbols)) { // we do not want to touch StartSymbol 84 84 if (random.NextDouble() < probability) { // ok. this node decide to mutate 85 85 … … 87 87 if ((symbol.MaximumArity == node.Symbol.MaximumArity) && (symbol.MinimumArity == node.Symbol.MinimumArity)) { allowedSymbols.Add(symbol); } 88 88 } 89 if (node.Symbol.MaximumArity == 0) { // for terminal nodes add ad itional the same type of nodes89 if (node.Symbol.MaximumArity == 0) { // for terminal nodes add additional the same type of nodes 90 90 allowedSymbols.Add(node.Symbol); 91 91 } 92 92 int pTemp = random.Next(map.Count); 93 if (node is TreeModelTreeNode treeNode) { pTemp = treeNode.TreeNumber; } //reme ber the cluster number93 if (node is TreeModelTreeNode treeNode) { pTemp = treeNode.TreeNumber; } //remember the cluster number 94 94 var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList(); // set up probabilities 95 95 96 96 #pragma warning disable CS0618 // Type or member is obsolete 97 var newSymbol = allowedSymbols.SelectRandom(weights, random); // create new node from the cho osen symbol type. Ror terminal nodes it means that we have only one possible varint.97 var newSymbol = allowedSymbols.SelectRandom(weights, random); // create new node from the chosen symbol type. For terminal nodes it means that we have only one possible variant. 98 98 #pragma warning restore CS0618 // Type or member is obsolete 99 99 node = newSymbol.CreateTreeNode(); 100 100 101 if (node is TreeModelTreeNode treeNode2) { // make rig thmutation for tree model101 if (node is TreeModelTreeNode treeNode2) { // make right mutation for tree model 102 102 treeNode2.TreeNumber = pTemp; 103 103 MapParameter.ActualValue.NodeForMutationChange(random, treeNode2); 104 } else if (node.HasLocalParameters) { // make local paramet rs set up for other node types104 } else if (node.HasLocalParameters) { // make local parameters set up for other node types 105 105 node.ResetLocalParameters(random); 106 106 } -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMOperators/EMMMultyPointsMutatorNodeTypeSaving.cs
r17133 r17134 74 74 75 75 List<ISymbol> allowedSymbols = new List<ISymbol>(); 76 var probability = (1 / mutationProbability.Value) / (symbolicExpressionTree.Length); // probability for e dch node to mutate76 var probability = (1 / mutationProbability.Value) / (symbolicExpressionTree.Length); // probability for each node to mutate 77 77 var allAllowedSymbols = symbolicExpressionTree.Root.Grammar.AllowedSymbols.Where(s => 78 78 !(s is Defun) && … … 84 84 symbolicExpressionTree.Root.ForEachNodePostfix(node => {//for each node in tree - try to mutate 85 85 86 if (SymbolTypeCheck(node.Symbol, allAllowedSymbols)) { // we do not want to to ch StartSymbol86 if (SymbolTypeCheck(node.Symbol, allAllowedSymbols)) { // we do not want to touch StartSymbol 87 87 if (random.NextDouble() < probability) { // ok. this node decide to mutate 88 88 if (node.Symbol.MaximumArity > 0) { … … 94 94 } 95 95 int pTemp = random.Next(modelSet.Count); 96 if (node is TreeModelTreeNode treeNode) { pTemp = treeNode.TreeNumber; } //reme ber the cluster number96 if (node is TreeModelTreeNode treeNode) { pTemp = treeNode.TreeNumber; } //remember the cluster number 97 97 var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList(); // set up probabilities 98 98 99 99 #pragma warning disable CS0618 // Type or member is obsolete 100 var newSymbol = allowedSymbols.SelectRandom(weights, random); // create new node from the cho osen symbol type. Ror terminal nodes it means that we have only one possible varint.100 var newSymbol = allowedSymbols.SelectRandom(weights, random); // create new node from the chosen symbol type. For terminal nodes it means that we have only one possible variant. 101 101 #pragma warning restore CS0618 // Type or member is obsolete 102 102 node = newSymbol.CreateTreeNode(); 103 103 104 if (node is TreeModelTreeNode treeNode2) { // make rig thmutation for tree model104 if (node is TreeModelTreeNode treeNode2) { // make right mutation for tree model 105 105 treeNode2.TreeNumber = pTemp; 106 106 MapParameter.ActualValue.NodeForMutationChange(random, treeNode2); 107 } else if (node.HasLocalParameters) { // make local paramet rs set up for other node types107 } else if (node.HasLocalParameters) { // make local parameters set up for other node types 108 108 node.ResetLocalParameters(random); 109 109 } -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/HelpFunctions.cs
r17002 r17134 20 20 #endregion 21 21 using HeuristicLab.Core; 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 23 using HeuristicLab.Problems.DataAnalysis.Symbolic; 24 using HeuristicLab.Random; 22 25 using System.Collections.Generic; 23 26 using System.Linq; … … 85 88 return maxElementNumber; 86 89 } 87 public static double CheckSocialKatre(double socialKarteValue, double value, double stepValue) {88 if (value > (socialKarteValue + stepValue))89 return stepValue;90 else if (value > socialKarteValue)91 return (value - socialKarteValue);92 else return 0;93 }94 public static void ProbabilitiesUpDate(List<List<double>> sucsessStatistics, List<double> probabilities) {95 90 96 var averageQuality = new List<double>(); 97 foreach (var variant in sucsessStatistics) { 98 if (variant[0] > 0.005) { 99 averageQuality.Add(variant[1] / variant[0]); 100 } else { averageQuality.Add(0); } 91 public static void SetLocalParametersForTree(IRandom random, double shakingFactor, ISymbolicExpressionTree tree) { 92 foreach (var node in tree.IterateNodesPrefix().Where(x => x.HasLocalParameters)) { 93 if (node is VariableTreeNode variableTreeNode) { 94 var symbol = variableTreeNode.Symbol; 95 variableTreeNode.Weight = NormalDistributedRandom.NextDouble(random, symbol.WeightManipulatorMu, symbol.WeightManipulatorSigma); 96 } else { 97 node.ResetLocalParameters(random); 98 } 101 99 } 102 int bestModelNumber = ChooseMaxElementIndex(averageQuality);103 double socialKarte = 1.0 / (probabilities.Count * 20.0); // parameters of method104 double stepValue = socialKarte / 5.0;105 double totalChangeValue = 0, changeValue = 0;106 for (int i = 0; i < probabilities.Count; i++) {107 changeValue = CheckSocialKatre(socialKarte, probabilities[i], stepValue);108 totalChangeValue += changeValue;109 probabilities[i] -= changeValue;110 }111 probabilities[bestModelNumber] += totalChangeValue;112 100 } 113 101 } -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/HeuristicLab.Algorithms.EvolvmentModelsOfModels.csproj
r17002 r17134 117 117 </ItemGroup> 118 118 <ItemGroup> 119 <Compile Include="EMMDisatanceMap.cs" /> 120 <Compile Include="EMMMultyPointsMutator.cs" /> 121 <Compile Include="EMMAlgorithm.cs" /> 122 <Compile Include="EMMClustering.cs" /> 123 <Compile Include="EMMBaseMap.cs" /> 124 <Compile Include="EMMIslandMap.cs" /> 125 <Compile Include="EMMMultyPointsMutatorNodeTypeSaving.cs" /> 126 <Compile Include="EMMMutators.cs" /> 127 <Compile Include="EMMSolution.cs" /> 128 <Compile Include="EMMBaseAlgorithm.cs" /> 129 <Compile Include="EMMNetworkMap.cs" /> 130 <Compile Include="EMMSucsessMap.cs" /> 131 <Compile Include="EMMZeroMap.cs" /> 119 <Compile Include="FileComuncations.cs" /> 120 <Compile Include="Maps\EMMDistanceMap.cs" /> 121 <Compile Include="EMMOperators\EMMMultyPointsMutator.cs" /> 122 <Compile Include="EMMAlgorithm\EMMAlgorithm.cs" /> 123 <Compile Include="KMeansClusterizationAlgorithm.cs" /> 124 <Compile Include="Maps\EMMBaseMap.cs" /> 125 <Compile Include="Maps\EMMIslandMap.cs" /> 126 <Compile Include="EMMOperators\EMMMultyPointsMutatorNodeTypeSaving.cs" /> 127 <Compile Include="EMMOperators\EMMMutators.cs" /> 128 <Compile Include="EMMAlgorithm\EMMSolution.cs" /> 129 <Compile Include="EMMAlgorithm\EMMBaseAlgorithm.cs" /> 130 <Compile Include="Maps\EMMNetworkMap.cs" /> 131 <Compile Include="Maps\EMMSucsessMap.cs" /> 132 <Compile Include="Maps\EMMZeroMap.cs" /> 132 133 <Compile Include="HelpFunctions.cs" /> 133 <Compile Include="ModelClustersFrequencyAnalyzer.cs" /> 134 <Compile Include="Analyzers\ModelClustersFrequencyAnalyzer.cs" /> 135 <Compile Include="ModelSetPreporation.cs" /> 134 136 <Compile Include="Plugin.cs" /> 135 137 <Compile Include="Properties\AssemblyInfo.cs" /> 136 <Compile Include="EMMRankMap.cs" /> 138 <Compile Include="Maps\EMMRankMap.cs" /> 139 <Compile Include="SelfConfiguration.cs" /> 137 140 </ItemGroup> 138 141 <ItemGroup> -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/KMeansClusterizationAlgorithm.cs
r17133 r17134 21 21 22 22 using HeuristicLab.Core; 23 using System; 23 24 using System.Collections.Generic; 24 25 25 26 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 26 public class EMModelsClusterizationAlgorithm {27 public class KMeansClusterizationAlgorithm { 27 28 public int K { get; private set; } 28 public EMModelsClusterizationAlgorithm() {29 public KMeansClusterizationAlgorithm() { 29 30 } 30 public EMModelsClusterizationAlgorithm(int k) {31 public KMeansClusterizationAlgorithm(int k) { 31 32 K = k; 32 33 } 33 public EMModelsClusterizationAlgorithm(EMModelsClusterizationAlgorithm old) {34 public KMeansClusterizationAlgorithm(KMeansClusterizationAlgorithm old) { 34 35 this.K = old.K; 35 36 } … … 52 53 } 53 54 bool flag = true; 54 55 while (flag ) {55 int count = 0; 56 while (flag&&(count<1000)) { 56 57 clusters.Clear(); 57 58 for (int i = 0; i < k; i++) { … … 61 62 for (int i = 0; i < mapSize; i++) { 62 63 numberCluster[i] = LookCloseCentroid(centroids, distances, i, k); 63 clusters[numberCluster[i]].Add( numberCluster[i]);64 clusters[numberCluster[i]].Add(i); 64 65 } 65 66 k = NullSizeClusterDelete(centroids, clusters, mapSize, numberCluster, k); … … 74 75 averageClusterDistance.Clear(); 75 76 } 77 count++; 76 78 } 77 79 return k; … … 110 112 } 111 113 clusters.Remove(clusters[i - iter]); 112 centroids.Remove( i - iter);114 centroids.Remove(centroids[i - iter]); 113 115 iter++; 114 116 } … … 117 119 return k; 118 120 } 119 p rivatestatic void AverageClusterDistanceCalculation(List<double> averageClusterDistance, double[,] distances, List<int> numberCluster, int MapSize, int currentClusterNumber) {121 public static void AverageClusterDistanceCalculation(List<double> averageClusterDistance, double[,] distances, List<int> numberCluster, int MapSize, int currentClusterNumber) { 120 122 int m = 0; 121 123 for (int i = 0; i < MapSize; i++) { … … 124 126 for (int j = 0; j < MapSize; j++) { 125 127 if (numberCluster[j] == currentClusterNumber) 126 averageClusterDistance[m] += distances[i, j];128 averageClusterDistance[m] += Math.Abs(distances[i, j]); 127 129 } 128 130 m++; -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps/EMMBaseMap.cs
r17133 r17134 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 27 using HeuristicLab.Random;28 27 using System.Collections.Generic; 29 28 using System.IO; … … 32 31 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 33 32 [StorableType("83CF9650-98FF-454B-9072-82EA4D39C752")] 34 public abstract class EMMMapBase<T> : Item where T : class {33 public abstract class EMMMapBase<T> : ParameterizedNamedItem where T : class { 35 34 #region data members 36 35 [Storable] 37 public List<T> ModelSet { get; set; }36 public List<T> ModelSet { get; protected set; } 38 37 [Storable] 39 38 public List<List<int>> Map { get; set; } 39 public string DistanceParametr { get; set; } 40 40 #endregion 41 41 #region constructors … … 44 44 public EMMMapBase() { 45 45 Map = new List<List<int>>(); 46 DistanceParametr = "Symbolic"; 46 47 } 47 public EMMMapBase(EMMMapBase<T> original, Cloner cloner) {48 public EMMMapBase(EMMMapBase<T> original, Cloner cloner) : base(original, cloner) { 48 49 if (original.ModelSet != null) { 49 50 if (original.ModelSet is List<ISymbolicExpressionTree> originalSet && ModelSet is List<ISymbolicExpressionTree> set) … … 54 55 Map = original.Map.Select(x => x.ToList()).ToList(); 55 56 } 57 DistanceParametr = original.DistanceParametr; 56 58 } 57 59 #endregion 58 60 #region map creation functions 59 protected double[,] CalculateDistances() { 60 double[,] distances; 61 if (ModelSet is List<ISymbolicExpressionTree> set) { 62 distances = SymbolicExpressionTreeHash.ComputeSimilarityMatrix(set, simplify: false, strict: true); 63 } else { /// for future work 64 distances = new double[ModelSet.Count, ModelSet.Count]; 65 for (int i = 0; i < ModelSet.Count - 1; i++) { 66 for (int j = 0; j <= i; j++) { 67 distances[i, j] = 0; 68 } 69 } 70 } 71 for (int i = 0; i < ModelSet.Count - 1; i++) { 72 for (int j = i + 1; j < ModelSet.Count; j++) { 73 distances[j, i] = distances[i, j] = 1 - distances[i, j]; 74 } 75 } 76 return distances; 77 } 78 public abstract void CreateMap(IRandom random, int k); 61 62 public abstract void CreateMap(IRandom random); 79 63 public void MapCreationPrepare(IEnumerable<T> trees) { 80 64 ModelSet = trees.ToList(); 65 } 66 public virtual void CreateMap(IRandom random, ISymbolicDataAnalysisSingleObjectiveProblem problem) { 67 if (Map != null) { 68 Map.Clear(); 69 } 70 CreateMap(random); 71 } 72 public virtual void CreateMap(IRandom random, double[,] totalDistance) { 73 if (Map != null) { 74 Map.Clear(); 75 } 76 CreateMap(random); 81 77 } 82 78 … … 95 91 #endregion 96 92 #region map and files 97 public v oid MapRead(IRandom random, IEnumerable<T> trees, string fileName = "Map.txt") {93 public virtual void MapRead(IEnumerable<T> trees) { 98 94 ModelSet = trees.ToList(); 99 MapFromFileRead(fileName);100 if (this is EMMIslandMap island) { island.ClusterNumbersCalculate(); }101 if (this is EMMNetworkMap one) { one.NeghboorNumber = Map[0].Count; }102 95 } 103 96 public void WriteMapToTxtFile(IRandom random) { 104 string s = random. ToString();105 string fileName = "Map ";97 string s = random.NextDouble().ToString(); 98 string fileName = "MapToAnalize"; 106 99 fileName += s; 100 fileName += DistanceParametr; 107 101 fileName += ".txt"; 108 102 File.WriteAllLines(fileName, MapToString()); 109 103 string fileName2 = "MapToSee"; 110 104 fileName2 += s; 105 fileName2 += DistanceParametr; 111 106 fileName2 += ".txt"; 112 107 File.WriteAllLines(fileName2, MapToSee()); 108 string fileName3 = "Map"; 109 fileName3 += DistanceParametr; 110 fileName3 += ".txt"; 111 File.WriteAllLines(fileName3, MapToStoreInFile()); 113 112 } 114 public string[] MapToString() { // Function that preapre Map to printing in .txt File: create a set of strings for future reading by computer 113 public string[] MapToString() { // Function that prepare Map to printing in .txt File: create a set of strings for future analyzing 114 string[] s; 115 s = new string[Map.Count]; 116 for (int i = 0; i < Map.Count; i++) { 117 s[i] = i.ToString() + ": "; 118 for (int j = 0; j < Map[i].Count; j++) { 119 s[i] += Map[i][j].ToString(); 120 s[i] += " "; 121 } 122 if (this is EMMIslandMap island) { 123 s[i] += " Average distance:" + island.AverageDistance[i].ToString(); 124 } 125 } 126 return s; 127 } 128 public virtual string[] MapToStoreInFile() { // Function that prepare Map to printing in .txt File: create a set of strings for future reading by computer 115 129 string[] s; 116 130 s = new string[Map.Count]; … … 119 133 for (int j = 0; j < Map[i].Count; j++) { 120 134 s[i] += Map[i][j].ToString(); 121 s[i] += " ";135 if (j != (Map[i].Count - 1)) { s[i] += " "; } 122 136 } 123 137 } … … 140 154 } 141 155 return s; 142 }143 public void MapFromFileRead(string fileName) {144 string input = File.ReadAllText(fileName);145 int i = 0;146 foreach (var row in input.Split('\n')) {147 Map.Add(new List<int>());148 foreach (var col in row.Trim().Split(' ')) {149 Map[i].Add(int.Parse(col.Trim()));150 }151 i++;152 }153 156 } 154 157 #endregion … … 173 176 treeNode.Tree = new SymbolicExpressionTree(NewModelForMutation(random, out treeNumber, treeNumber2).Root); 174 177 treeNode.TreeNumber = treeNumber; 175 SetLocalParametersForTree(random, 0.5, treeNode.Tree); 176 } 177 public void SetLocalParametersForTree(IRandom random, double shakingFactor, ISymbolicExpressionTree tree) { 178 foreach (var node in tree.IterateNodesPrefix().Where(x => x.HasLocalParameters)) { 179 if (node is VariableTreeNode variableTreeNode) { 180 var symbol = variableTreeNode.Symbol; 181 variableTreeNode.Weight = NormalDistributedRandom.NextDouble(random, symbol.WeightManipulatorMu, symbol.WeightManipulatorSigma); 182 } else { 183 node.ResetLocalParameters(random); 184 } 185 } 178 HelpFunctions.SetLocalParametersForTree(random, 0.5, treeNode.Tree); 186 179 } 187 180 public virtual void MapUpDate(Dictionary<ISymbolicExpressionTree, double> population) { } -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps/EMMDistanceMap.cs
r17133 r17134 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 26 27 using System; 27 28 using System.Collections.Generic; 29 using System.Linq; 28 30 29 31 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { … … 33 35 [Storable] 34 36 public List<List<double>> Probabilities { get; set; } 35 #region con ctructors37 #region constructors 36 38 [StorableConstructor] 37 39 protected EMMDisatanceMap(StorableConstructorFlag _) : base(_) { } … … 39 41 return new EMMDisatanceMap(this, cloner); 40 42 } 41 public EMMDisatanceMap() : base() { ModelSet = new List<ISymbolicExpressionTree>(); } 42 public EMMDisatanceMap(EMMDisatanceMap original, Cloner cloner) : base(original, cloner) { } 43 public EMMDisatanceMap() : base() { 44 ModelSet = new List<ISymbolicExpressionTree>(); 45 Probabilities = new List<List<double>>(); 46 } 47 public EMMDisatanceMap(EMMDisatanceMap original, Cloner cloner) : base(original, cloner) { 48 if (original.Probabilities != null) { 49 Probabilities = original.Probabilities.Select(x => x.ToList()).ToList(); 50 } 51 } 43 52 #endregion 44 #region MapCreation 45 override public void CreateMap(IRandom random, int k) { 46 47 Probabilities = new List<List<double>>(); 53 #region Map Creation 54 override public void CreateMap(IRandom random) { 48 55 MapSizeCheck(ModelSet.Count); 49 ApplyDistanceMapCreationAlgorithm(random, CalculateDistances(), Map, Probabilities);56 ApplyDistanceMapCreationAlgorithm(random, ModelSetPreparation.CalculateDistances(ModelSet), Map, Probabilities); 50 57 } 51 public static void ApplyDistanceMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, List<List<double>> probabilities) { 58 override public string[] MapToStoreInFile() { // Function that prepare Map to printing in .txt File: create a set of strings for future reading by computer 59 string[] s; 60 s = new string[Map.Count]; 61 for (int i = 0; i < Map.Count; i++) { 62 s[i] = ""; 63 for (int j = 0; j < (Map.Count - 1); j++) { 64 s[i] += Probabilities[i][j].ToString(); 65 if (j != (Map.Count - 2)) { s[i] += " "; } 66 } 67 } 68 return s; 69 } 70 override public void MapRead(IEnumerable<ISymbolicExpressionTree> trees) { 71 base.MapRead(trees); 72 MapFullment(trees.Count()); 73 string fileName = ("Map" + DistanceParametr + ".txt"); 74 Probabilities = FileComuncations.DoubleMatrixFromFileRead(fileName); 75 } 76 override public void CreateMap(IRandom random, ISymbolicDataAnalysisSingleObjectiveProblem problem) { 77 MapSizeCheck(ModelSet.Count); 78 if (Map != null) { 79 Map.Clear(); 80 } 81 ApplyDistanceMapCreationAlgorithm(random, ModelSetPreparation.DistanceMatrixCalculation(ModelSet, DistanceParametr, problem), Map, Probabilities); 82 } 83 protected void ApplyDistanceMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, List<List<double>> probabilities) { 52 84 int mapSize = distances.GetLength(0); 53 85 for (int t = 0; t < mapSize; t++) { … … 65 97 } 66 98 } 99 protected void MapFullment(int mapSize) { 100 if (Map != null) { 101 Map.Clear(); 102 } 103 for (int t = 0; t < mapSize; t++) { 104 for (int i = 0; i < mapSize; i++) { 105 if (i == t) 106 continue; 107 Map[t].Add(i); 108 } 109 } 110 } 67 111 #endregion 68 #region Map ApplayFunctions112 #region Map Apply Functions 69 113 public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { 70 114 treeNumber = HelpFunctions.OneElementFromListProportionalSelection(random, Probabilities[parentTreeNumber]); -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps/EMMIslandMap.cs
r17133 r17134 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 25 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 26 29 using HeuristicLab.Random; 27 30 using System.Collections.Generic; … … 32 35 [StorableType("E4AB04B9-FD5D-47EE-949D-243660754F3A")] 33 36 public class EMMIslandMap : EMMMapBase<ISymbolicExpressionTree> { 37 34 38 [Storable] 35 39 public List<int> ClusterNumber { get; set; } // May be only Island Map really need it 36 #region conctructors 40 public double[] AverageDistance { get; private set; } 41 private const string ClusterNumbersParameterName = "ClusterNumbers"; 42 private const string ClusterNumbersShowParameterName = "ClusterNumbersShow"; 43 public IValueParameter<IntValue> ClusterNumbersParameter { 44 get { return (IValueParameter<IntValue>)Parameters[ClusterNumbersParameterName]; } 45 } 46 public IValueParameter<IntValue> ClusterNumbersShowParameter { 47 get { return (IValueParameter<IntValue>)Parameters[ClusterNumbersShowParameterName]; } 48 } 49 public IntValue ClusterNumbers { 50 get { return ClusterNumbersParameter.Value; } 51 set { ClusterNumbersParameter.Value = value; } 52 } 53 public IntValue ClusterNumbersShow { 54 get { return ClusterNumbersShowParameter.Value; } 55 set { ClusterNumbersShowParameter.Value = value; } 56 } 57 #region constructors 37 58 [StorableConstructor] 38 59 protected EMMIslandMap(StorableConstructorFlag _) : base(_) { } 39 60 public EMMIslandMap() { 61 Parameters.Add(new ValueParameter<IntValue>(ClusterNumbersParameterName, "The number of clusters for model Map.", new IntValue(10))); 62 Parameters.Add(new ValueParameter<IntValue>(ClusterNumbersShowParameterName, "The number of clusters for model Map.", new IntValue(10))); 40 63 ModelSet = new List<ISymbolicExpressionTree>(); 41 64 ClusterNumber = new List<int>(); … … 50 73 } 51 74 #endregion 52 #region MapApplayFunctions 53 override public void CreateMap(IRandom random, int k) { 54 55 k = EMModelsClusterizationAlgorithm.ApplyClusteringAlgorithm(random, CalculateDistances(), ClusterNumber, k); 56 MapSizeCheck(k); 75 #region Map Apply Functions 76 override public void CreateMap(IRandom random) { 77 var totalDistance = ModelSetPreparation.CalculateDistances(ModelSet); //structure distances 78 CreateMap(random, totalDistance); 79 } 80 override public void CreateMap(IRandom random, ISymbolicDataAnalysisSingleObjectiveProblem problem) { 81 CreateMap(random, ModelSetPreparation.TotalDistanceMatrixCalculation(random, problem, ModelSet, DistanceParametr)); 82 } 83 override public void CreateMap(IRandom random, double[,] totalDistance) { 84 if (Map != null) { 85 Map.Clear(); 86 } 87 ClusterNumbersShow.Value = KMeansClusterizationAlgorithm.ApplyClusteringAlgorithm(random, totalDistance, ClusterNumber, ClusterNumbers.Value); 88 MapSizeCheck(ClusterNumbersShow.Value); 57 89 for (int i = 0; i < ModelSet.Count; i++) { 58 90 Map[ClusterNumber[i]].Add(i); 59 91 } 92 AverageDistanceInClusterCalculation(totalDistance, ClusterNumbersShow.Value); 93 } 94 override public void MapRead(IEnumerable<ISymbolicExpressionTree> trees) { 95 base.MapRead(trees); 96 string fileName = ("Map" + DistanceParametr + ".txt"); 97 Map = FileComuncations.IntMatrixFromFileRead(fileName); 98 ClusterNumbers.Value = Map.Count; 99 ClusterNumbersShow.Value = ClusterNumbers.Value; 100 ClusterNumbersCalculate(); 101 AverageDistanceInClusterCalculation(ModelSetPreparation.CalculateDistances(ModelSet), Map.Count); 60 102 } 61 103 override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { 62 104 return NewModelForInizializtion(random, out treeNumber); 63 105 } 64 106 private void AverageDistanceInClusterCalculation(double[,] distances, int k) { 107 AverageDistance = new double[k]; 108 var temp = new List<double>(); 109 for (int i = 0; i < k; i++) { 110 KMeansClusterizationAlgorithm.AverageClusterDistanceCalculation(temp, distances, ClusterNumber, ClusterNumber.Count, i); 111 var number = HelpFunctions.ChooseMinElementIndex(temp); 112 AverageDistance[i] = temp[number] / Map[i].Count; 113 temp.Clear(); 114 } 115 } 65 116 public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { 66 117 if (parentTreeNumber == -10) { … … 71 122 return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); 72 123 } 73 public void ClusterNumbersCalculate() { // May be it should be transported to Child Clase (IslandMap)124 public void ClusterNumbersCalculate() { 74 125 for (int i = 0; i < Map.Count; i++) { 75 126 for (int j = 0; j < Map[i].Count; j++) { -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps/EMMNetworkMap.cs
r17133 r17134 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 25 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 26 29 using HeuristicLab.Random; 30 using System; 27 31 using System.Collections.Generic; 28 32 … … 31 35 [StorableType("C200ECC2-6D33-4468-A538-580B07D75B3C")] 32 36 public class EMMNetworkMap : EMMMapBase<ISymbolicExpressionTree> { 33 public int NeghboorNumber { get; set; } 34 #region conctructors 37 private const string NegbourTypeParameterName = "NegbourType"; 38 private const string NegbourNumberParameterName = "NegbourNumber"; 39 public IFixedValueParameter<StringValue> NegbourTypeParameter { 40 get { return (IFixedValueParameter<StringValue>)Parameters[NegbourTypeParameterName]; } 41 } 42 public IValueParameter<IntValue> NegbourNumberParameter { 43 get { return (IValueParameter<IntValue>)Parameters[NegbourNumberParameterName]; } 44 } 45 public StringValue NegbourType { 46 get { return NegbourTypeParameter.Value; } 47 set { NegbourTypeParameter.Value.Value = value.Value; } 48 } 49 public IntValue NegbourNumber { 50 get { return NegbourNumberParameter.Value; } 51 set { NegbourNumberParameter.Value.Value = value.Value; } 52 } 53 #region constructors 35 54 [StorableConstructor] 36 55 protected EMMNetworkMap(StorableConstructorFlag _) : base(_) { } 37 public EMMNetworkMap() : this(1) { } 56 38 57 public override IDeepCloneable Clone(Cloner cloner) { 39 58 return new EMMNetworkMap(this, cloner); 40 59 } 41 public EMMNetworkMap(int neghboorNumber = 10) : base() { 42 NeghboorNumber = neghboorNumber; 60 public EMMNetworkMap() : base() { 61 Parameters.Add(new ValueParameter<IntValue>(NegbourNumberParameterName, "The parameter for FullMap type of map creation algorithm. Use one from: 10, 20.", new IntValue(10))); 62 Parameters.Add(new FixedValueParameter<StringValue>(NegbourTypeParameterName, "The parameter for FullMap type of map creation algorithm. Use one from: Percent, Number.", new StringValue("Number"))); 63 MapParameterUpdate(); 64 ModelSet = new List<ISymbolicExpressionTree>(); 43 65 } 44 public EMMNetworkMap(EMMNetworkMap original, Cloner cloner) : base(original, cloner) { Neg hboorNumber = original.NeghboorNumber; }66 public EMMNetworkMap(EMMNetworkMap original, Cloner cloner) : base(original, cloner) { NegbourNumber = original.NegbourNumber; } 45 67 #endregion 46 #region MapTransformation 47 override public void CreateMap(IRandom random, int k) { 48 ApplyNetworkMapCreationAlgorithm(random, CalculateDistances(), Map, NeghboorNumber); 68 #region Map Transformation 69 override public void CreateMap(IRandom random) { 70 MapParameterUpdate(); 71 if (Map != null) { 72 Map.Clear(); 73 } 74 ApplyNetworkMapCreationAlgorithm(random, ModelSetPreparation.CalculateDistances(ModelSet), Map, NegbourNumber.Value); 75 } 76 override public void CreateMap(IRandom random, ISymbolicDataAnalysisSingleObjectiveProblem problem) { 77 MapParameterUpdate(); 78 if (Map != null) { 79 Map.Clear(); 80 } 81 ApplyNetworkMapCreationAlgorithm(random, ModelSetPreparation.DistanceMatrixCalculation(ModelSet, DistanceParametr, problem), Map, NegbourNumber.Value); 82 } 83 override public void MapRead(IEnumerable<ISymbolicExpressionTree> trees) { 84 base.MapRead(trees); 85 string fileName = ("Map" + DistanceParametr + ".txt"); 86 Map = FileComuncations.IntMatrixFromFileRead(fileName); 87 NegbourNumber.Value = Map[0].Count; 49 88 } 50 89 public static void ApplyNetworkMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, int neghboorNumber = 10) { … … 63 102 } 64 103 } 104 protected void MapParameterUpdate() { 105 switch (NegbourType.Value) { 106 case "Percent": NegbourNumber.Value = Convert.ToInt32((Convert.ToDouble(ModelSet.Count)) * (Convert.ToDouble(NegbourNumber.Value)) / 100.0); break; 107 case "Number": NegbourNumber.Value = NegbourNumber.Value; break; 108 default: NegbourNumber.Value = NegbourNumber.Value; break; 109 } 110 } 65 111 #endregion 66 #region Dialog with surrou dings112 #region Dialog with surroundings 67 113 public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { 68 114 treeNumber = Map[parentTreeNumber].SampleRandom(random); -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps/EMMRankMap.cs
r17133 r17134 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 26 27 using System; 27 28 using System.Collections.Generic; 29 using System.Linq; 28 30 29 31 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 30 32 [Item("RankMap", "A map of models of models of models")] 31 33 [StorableType("1D4DD90E-553A-46DB-B0CD-6A899AA0B6D0")] 32 public class EMMRankMap : EMMMapBase<ISymbolicExpressionTree> { 34 public class EMMRankMap : EMMMapBase<ISymbolicExpressionTree> { // it do not work absolutely 33 35 [Storable] 34 36 public List<List<double>> Probabilities { get; set; } 35 #region con ctructors37 #region constructors 36 38 [StorableConstructor] 37 39 protected EMMRankMap(StorableConstructorFlag _) : base(_) { } … … 39 41 return new EMMRankMap(this, cloner); 40 42 } 41 public EMMRankMap() : base() { ModelSet = new List<ISymbolicExpressionTree>(); } 42 public EMMRankMap(EMMRankMap original, Cloner cloner) : base(original, cloner) { } 43 public EMMRankMap() : base() { 44 ModelSet = new List<ISymbolicExpressionTree>(); 45 Probabilities = new List<List<double>>(); 46 } 47 public EMMRankMap(EMMRankMap original, Cloner cloner) : base(original, cloner) { 48 if (original.Probabilities != null) { 49 Probabilities = original.Probabilities.Select(x => x.ToList()).ToList(); 50 } 51 } 43 52 #endregion 44 53 #region MapCreation 45 override public void CreateMap(IRandom random, int k) { 46 47 Probabilities = new List<List<double>>(); 54 override public void CreateMap(IRandom random) { 48 55 MapSizeCheck(ModelSet.Count); 49 ApplyRankMapCreationAlgorithm( random, CalculateDistances(), Map, Probabilities);56 ApplyRankMapCreationAlgorithm(ModelSetPreparation.CalculateDistances(ModelSet), Map, Probabilities); 50 57 } 51 public static void ApplyRankMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, List<List<double>> probabilities) { 58 override public void CreateMap(IRandom random, ISymbolicDataAnalysisSingleObjectiveProblem problem) { 59 MapSizeCheck(ModelSet.Count); 60 ApplyRankMapCreationAlgorithm(ModelSetPreparation.DistanceMatrixCalculation(ModelSet, DistanceParametr, problem), Map, Probabilities); 61 } 62 override public void MapRead(IEnumerable<ISymbolicExpressionTree> trees) { 63 base.MapRead(trees); 64 MapFullment(trees.Count()); 65 string fileName = ("Map" + DistanceParametr + ".txt"); 66 Probabilities = FileComuncations.DoubleMatrixFromFileRead(fileName); 67 } 68 protected void MapFullment(int mapSize) { 69 if (Map != null) { 70 Map.Clear(); 71 } 72 for (int t = 0; t < mapSize; t++) { 73 for (int i = 0; i < mapSize; i++) { 74 if (i == t) 75 continue; 76 Map[t].Add(i); 77 } 78 } 79 } 80 override public string[] MapToStoreInFile() { // Function that prepare Map to printing in .txt File: create a set of strings for future reading by computer 81 string[] s; 82 s = new string[Map.Count]; 83 for (int i = 0; i < Map.Count; i++) { 84 s[i] = ""; 85 for (int j = 0; j < (Map.Count - 1); j++) { 86 s[i] += Probabilities[i][j].ToString(); 87 if (j != (Map.Count - 2)) { s[i] += " "; } 88 } 89 } 90 return s; 91 } 92 public static void ApplyRankMapCreationAlgorithm(double[,] distances, List<List<int>> map, List<List<double>> probabilities) { 52 93 int mapSize = distances.GetLength(0); 53 94 double tempSum = 0; … … 64 105 currentList[i].Add(distances[i, t]); 65 106 } 66 currentList.Sort((a, b) => a[1].CompareTo(b[1])); /// загадкой является то нафига оно мне вообще понадобилось in DistanceMap.. но это работающая сортировка.107 currentList.Sort((a, b) => a[1].CompareTo(b[1])); ///workable sorting 67 108 for (int i = 0; i < currentList.Count; i++) { 68 109 currentList[i].Add(currentList.Count - i); … … 79 120 } 80 121 #endregion 81 #region Map ApplayFunctions122 #region Map Apply Functions 82 123 public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { 83 124 treeNumber = Map[parentTreeNumber][HelpFunctions.OneElementFromListProportionalSelection(random, Probabilities[parentTreeNumber])]; -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps/EMMSucsessMap.cs
r17133 r17134 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 using HeuristicLab.Problems.DataAnalysis.Symbolic;26 25 using System.Collections.Generic; 27 using System.Linq;28 26 29 27 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { … … 32 30 public class EMMSucsessMap : EMMMapBase<ISymbolicExpressionTree> { 33 31 [Storable] 34 public List<double> Probabilities { get; private set; } 35 [Storable] 36 public List<List<double>> SucsessStatistics { get; private set; } 37 #region conctructors 32 public SelfConfiguration SelfConfigurationMechanism { get; private set; } 33 #region constructors 38 34 [StorableConstructor] 39 35 protected EMMSucsessMap(StorableConstructorFlag _) : base(_) { } … … 43 39 public EMMSucsessMap() : base() { 44 40 ModelSet = new List<ISymbolicExpressionTree>(); 45 S ucsessStatistics = new List<List<double>>();41 SelfConfigurationMechanism = new SelfConfiguration(); 46 42 } 47 43 public EMMSucsessMap(EMMSucsessMap original, Cloner cloner) : base(original, cloner) { 48 S ucsessStatistics = original.SucsessStatistics.Select(x => x.ToList()).ToList();44 SelfConfigurationMechanism = new SelfConfiguration(original.SelfConfigurationMechanism, cloner); 49 45 } 50 46 #endregion 51 #region Map Creation52 override public void CreateMap(IRandom random , int k) {53 54 Probabilities = new List<double>();55 Map.Clear();47 #region Map Creation 48 override public void CreateMap(IRandom random) { 49 if (Map != null) { 50 Map.Clear(); 51 } 56 52 Map.Add(new List<int>()); 57 53 MapSizeCheck(ModelSet.Count); 58 ApplySucsessMapCreationAlgorithm(random, CalculateDistances(), Map, Probabilities, SucsessStatistics);54 ApplySucsessMapCreationAlgorithm(random, ModelSet.Count); 59 55 } 60 public static void ApplySucsessMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, List<double> probabilities, List<List<double>> sucsessStatistics) { 61 int mapSize = distances.GetLength(0); 56 override public void MapRead(IEnumerable<ISymbolicExpressionTree> trees) { 57 base.MapRead(trees); 58 string fileName = ("Map" + DistanceParametr + ".txt"); 59 SelfConfigurationMechanism.ReadFromFile(ModelSet.Count, fileName); 60 } 61 override public string[] MapToStoreInFile() { // Function that prepare Map to printing in .txt File: create a set of strings for future reading by computer 62 string[] s; 63 s = new string[1]; 64 for (int i = 0; i < Map.Count; i++) { 65 s[0] = ""; 66 s[0] += SelfConfigurationMechanism.Probabilities[i].ToString(); 67 } 68 return s; 69 } 70 private void ApplySucsessMapCreationAlgorithm(IRandom random, int mapSize) { 62 71 for (int t = 0; t < mapSize; t++) { 63 map[t].Add(t); 64 probabilities.Add(1.0 / ((double)(mapSize))); // uniform distribution as start point 72 Map[t].Add(t); 65 73 } 74 SelfConfigurationMechanism.Initialization(mapSize); 66 75 } 67 76 public override void MapUpDate(Dictionary<ISymbolicExpressionTree, double> population) { 68 SucsessStatisticCollection(population); 69 HelpFunctions.ProbabilitiesUpDate(SucsessStatistics, Probabilities); 70 } 71 private void SucsessStatisticCollection(Dictionary<ISymbolicExpressionTree, double> population) { 72 if (SucsessStatistics.Count != 0) 73 SucsessStatistics.Clear(); 74 for (int t = 0; t < Probabilities.Count; t++) { 75 SucsessStatistics.Add(new List<double>()); 76 SucsessStatistics[t].Add(0); 77 SucsessStatistics[t].Add(0); 78 } 79 foreach (var solution in population) { 80 TreeCheck(solution.Key, solution.Value); 81 } 82 } 83 private void TreeCheck(ISymbolicExpressionTree tree, double treeQuality) { 84 foreach (var treeNode in tree.IterateNodesPrefix().OfType<TreeModelTreeNode>()) { 85 SucsessStatistics[treeNode.TreeNumber][0] += 1; 86 SucsessStatistics[treeNode.TreeNumber][1] += treeQuality; 87 } 77 SelfConfigurationMechanism.UpDate(population); 88 78 } 89 79 #endregion 90 #region Map ApplayFunctions80 #region Map Apply Functions 91 81 public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { 92 treeNumber = Map[ HelpFunctions.OneElementFromListProportionalSelection(random, Probabilities)][0];82 treeNumber = Map[SelfConfigurationMechanism.Aplay(random)][0]; 93 83 return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); 94 84 } -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps/EMMZeroMap.cs
r17133 r17134 30 30 [StorableType("FF199AE7-DF0A-4E2A-99BC-BECD647E18F0")] 31 31 public class EMMZeroMap : EMMMapBase<ISymbolicExpressionTree> { 32 #region con ctructors32 #region constructors 33 33 [StorableConstructor] 34 34 protected EMMZeroMap(StorableConstructorFlag _) : base(_) { } … … 41 41 public EMMZeroMap(EMMZeroMap original, Cloner cloner) : base(original, cloner) { } 42 42 #endregion 43 #region Map ApplayFunctions44 override public void CreateMap(IRandom random , int k) { }43 #region Map Apply Functions 44 override public void CreateMap(IRandom random) { } 45 45 override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { 46 46 return NewModelForInizializtion(random, out treeNumber); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs
r16722 r17134 20 20 #endregion 21 21 22 using HEAL.Attic; 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 22 26 using System; 23 27 using System.Globalization; 24 28 using System.Linq; 25 29 using System.Text; 26 using HeuristicLab.Common;27 using HeuristicLab.Core;28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;29 using HEAL.Attic;30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 58 58 /// <param name="formatString">The format string for numeric parameters (e.g. \"G4\" to limit to 4 digits, default is \"G\")</param> 59 59 /// <returns>Infix expression</returns> 60 public string Format(ISymbolicExpressionTree symbolicExpressionTree, NumberFormatInfo numberFormat, string formatString ="G") {60 public string Format(ISymbolicExpressionTree symbolicExpressionTree, NumberFormatInfo numberFormat, string formatString = "G") { 61 61 // skip root and start symbols 62 62 StringBuilder strBuilder = new StringBuilder(); … … 182 182 else 183 183 strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat)).Append(")"); // (-1 184 } else if (node.Symbol is TreeModel) { 185 var modelNode = node as TreeModelTreeNode; 186 strBuilder.Append(modelNode.TreeToString()); 184 187 } 185 188 } -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/BatchOperations.cs
r16722 r17134 101 101 public static void CubeRoot(double[] a, double[] b) { 102 102 for (int i = 0; i < BATCHSIZE; ++i) 103 a[i] = Math.Pow(b[i], 1d / 3d);103 a[i] = b[i] < 0 ? -Math.Pow(-b[i], 1d / 3d) : Math.Pow(b[i], 1d / 3d); 104 104 } 105 105 -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ModelTreeNode.cs
r17002 r17134 94 94 return s; 95 95 } 96 public string TreeToString() { 97 var fmt = new InfixExpressionFormatter(); 98 string s = fmt.Format(Tree); 99 return s; 100 } 96 101 } 97 102 }
Note: See TracChangeset
for help on using the changeset viewer.