Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/22/10 10:34:37 (14 years ago)
Author:
gkronber
Message:

Implemented set-memory and read-memory operation for GP-based data-analysis. #1290

Location:
branches/GP-MemoryOperations/HeuristicLab.Problems.DataAnalysis
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/GP-MemoryOperations/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj

    r4562 r4897  
    149149    <Compile Include="Symbolic\Symbols\Constant.cs" />
    150150    <Compile Include="Symbolic\Symbols\ConstantTreeNode.cs" />
     151    <Compile Include="Symbolic\Symbols\ReadMem.cs" />
     152    <Compile Include="Symbolic\Symbols\ReadMemTreeNode.cs" />
     153    <Compile Include="Symbolic\Symbols\SetMem.cs" />
     154    <Compile Include="Symbolic\Symbols\SetMemTreeNode.cs" />
    151155    <Compile Include="Symbolic\Symbols\LaggedVariable.cs" />
    152156    <Compile Include="Symbolic\Symbols\LaggedVariableTreeNode.cs" />
  • branches/GP-MemoryOperations/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/FullFunctionalExpressionGrammar.cs

    r4722 r4897  
    6060      var or = new Or();
    6161      var not = new Not();
     62      var setMem = new SetMem();
     63      var readMem = new ReadMem();
    6264      var constant = new Constant();
    6365      constant.MinValue = -20;
     
    6769      laggedVariable.InitialFrequency = 0.0;
    6870
    69       var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, constant, variableSymbol, laggedVariable };
    70       var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not };
     71      var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, setMem, readMem, constant, variableSymbol, laggedVariable };
     72      var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not, setMem};
    7173      var binaryFunctionSymbols = new List<Symbol>() { gt, lt };
    7274      var functionSymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or };
    73       var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };
     75      var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable, readMem };
    7476
    7577      foreach (var symb in allSymbols)
  • branches/GP-MemoryOperations/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs

    r4722 r4897  
    5757      public const byte NOT = 15;
    5858
    59 
    6059      public const byte Average = 16;
    6160
     
    6665      public const byte Constant = 20;
    6766      public const byte Arg = 21;
     67
     68      public const byte Set = 22;
     69      public const byte Read = 23;
    6870    }
    6971
     
    9092      { typeof(Constant), OpCodes.Constant },
    9193      { typeof(Argument), OpCodes.Arg },
     94      { typeof(SetMem), OpCodes.Set },
     95      { typeof(ReadMem), OpCodes.Read },
    9296    };
    9397    private const int ARGUMENT_STACK_SIZE = 1024;
     98    private const int MAX_MEMORY_SIZE = 128;
    9499
    95100    private Dataset dataset;
     
    99104    private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];
    100105    private int argStackPointer;
     106    private double[] memory = new double[MAX_MEMORY_SIZE];
    101107
    102108    public override bool CanChangeName {
     
    124130      compiler.AddInstructionPostProcessingHook(PostProcessInstruction);
    125131      code = compiler.Compile(tree, MapSymbolToOpCode);
     132      Array.Clear(memory, 0, MAX_MEMORY_SIZE);
    126133      foreach (var row in rows) {
    127134        this.row = row;
     
    139146        var variableTreeNode = instr.dynamicNode as LaggedVariableTreeNode;
    140147        instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName);
     148      } else if (instr.opCode == OpCodes.Set) {
     149        var setMemTreeNode = instr.dynamicNode as SetMemTreeNode;
     150        instr.iArg0 = (ushort)setMemTreeNode.Address;
     151      } else if (instr.opCode == OpCodes.Read) {
     152        var readMemTreeNode = instr.dynamicNode as ReadMemTreeNode;
     153        instr.iArg0 = (ushort)readMemTreeNode.Address;
    141154      }
    142155      return instr;
     
    290303            return constTreeNode.Value;
    291304          }
     305        case OpCodes.Set: {
     306            double d = Evaluate();
     307            memory[currentInstr.iArg0] = d;
     308            return d;
     309          }
     310        case OpCodes.Read: {
     311            return memory[currentInstr.iArg0];
     312          }
    292313        default: throw new NotSupportedException();
    293314      }
Note: See TracChangeset for help on using the changeset viewer.