public void CanGenerateGenoType() { var randomGenerator = new UniformRandomGenerator(); var possibleFunctions = new List <IGenoTypeNode> { new SquareRoot(), new Multiplication(), new Plus(), new Minus() }; var possibleTerminals = new List <IGenoTypeNode> { new FeatureTerminal("a"), new FeatureTerminal("b"), new FeatureTerminal("c"), new FeatureTerminal("d") }; var eaGeneExpressionParameters = new EaGeneExpressionParameters(4, possibleFunctions, possibleTerminals); var parameterTerminalFactory = new ParameterTerminalFactory(eaGeneExpressionParameters, randomGenerator); var genoTypeFactory = new GenoTypeFactory(eaGeneExpressionParameters, randomGenerator, parameterTerminalFactory); var genoType = genoTypeFactory.GetGenoType(); Assert.NotNull(genoType); }
public void todo(IDataSet dataSet) { var randomGenerator = new UniformRandomGenerator(); var possibleFunctions = new List <IGenoTypeNode> { new Multiplication(), new Plus(), new Minus() }; var possibleTerminals = new List <IGenoTypeNode>(); foreach (var mappedColumn in dataSet.MappedColumns) { possibleTerminals.Add(new FeatureTerminal(mappedColumn.Key)); } var eaGeneExpressionParameters = new EaGeneExpressionParameters(10, possibleFunctions, possibleTerminals); var parameterTerminalFactory = new ParameterTerminalFactory(eaGeneExpressionParameters, randomGenerator); var genoTypeFactory = new GenoTypeFactory(eaGeneExpressionParameters, randomGenerator, parameterTerminalFactory); var genoType = genoTypeFactory.GetGenoType(); var phenoTypeTree = new PhenoTypeTree(genoType.GenoTypeNodes); var stringExpresssion = phenoTypeTree.ToString(); // TODO make mapped columns more sophisticated var mappedColumnsUsedInExpression = new Dictionary <string, int>(); foreach (var mappedColumn in dataSet.MappedColumns) { if (stringExpresssion.Contains(mappedColumn.Key)) { mappedColumnsUsedInExpression.Add(mappedColumn.Key, mappedColumn.Value); } } var expression = new Expression(stringExpresssion); var numberOfRows = dataSet.MappedData.GetLength(0); var sum = 0.0; for (var row = 0; row < numberOfRows; row++) { foreach (var usedMappedColumn in mappedColumnsUsedInExpression) { expression.Parameters[usedMappedColumn.Key.Replace("]", "").Replace("[", "")] = dataSet.MappedData[row, usedMappedColumn.Value]; } if (!expression.HasErrors()) { var test = (double)expression.Evaluate(); sum = sum + test; } } }
public void CanTranslateTest3() { var randomGenerator = new UniformRandomGenerator(); var possibleFunctions = new List <IGenoTypeNode> { new SquareRoot(), new Multiplication(), new Division(), new Plus(), new Minus(), new Minimum(), new Maximum(), new Not(), new Exp(), new Sinus(), new Cosinus() }; var possibleTerminals = new List <IGenoTypeNode> { new FeatureTerminal("a"), new FeatureTerminal("b"), new FeatureTerminal("c"), new FeatureTerminal("d") }; var eaGeneExpressionParameters = new EaGeneExpressionParameters(20, possibleFunctions, possibleTerminals); var parameterTerminalFactory = new ParameterTerminalFactory(eaGeneExpressionParameters, randomGenerator); var genoTypeFactory = new GenoTypeFactory(eaGeneExpressionParameters, randomGenerator, parameterTerminalFactory); eaGeneExpressionParameters.ParameterTypeInteger = true; eaGeneExpressionParameters.ConstantProbability = 0; var genoType = genoTypeFactory.GetGenoType(); var phenoTypeTree = new GeneExpression.PhenoTypeTree(genoType.GenoTypeNodes); var expresssion = phenoTypeTree.ToString(); }