Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/27/09 18:26:10 (15 years ago)
Author:
gkronber
Message:

#650 (IAlgorithm and derived interfaces should provide properties to retrieve results):

  • Implemented properties to retrieve model quality
  • Changed CEDMA executor to retrieve results via properties
  • Removed obsolete class Execution in CEDMA (replaced by the interface IAlgorithm)
Location:
trunk/sources/HeuristicLab.CEDMA.Server/3.3
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs

    r1873 r1922  
    4444    }
    4545
    46     public Execution GetNextJob() {
     46    public IAlgorithm GetNextJob() {
    4747      // find and select a dataset
    4848      var dataSetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("DataSet");
     
    6767
    6868      if (selectedAlgorithm != null) {
    69         Execution exec = CreateExecution(dataSet.Problem, targetVariable, selectedAlgorithm);
    70         exec.DataSetEntity = dataSetEntity;
    71         exec.TargetVariable = targetVariableName;
    72         return exec;
    73       } else return null;
     69        SetProblemParameters(selectedAlgorithm, dataSet.Problem, targetVariable);
     70      }
     71      return selectedAlgorithm;
    7472    }
    7573
     
    7876    public abstract IAlgorithm SelectAlgorithm(Entity dataSet, int targetVariable, LearningTask learningTask);
    7977
    80     private Execution CreateExecution(Problem problem, int targetVariable, IAlgorithm algorithm) {
    81       SetProblemParameters(algorithm, problem, targetVariable);
    82       Execution exec = new Execution(algorithm.Engine);
    83       exec.Description = algorithm.Name;
    84       return exec;
    85     }
    86 
    8778    private void SetProblemParameters(IAlgorithm algo, Problem problem, int targetVariable) {
    88       algo.ProblemInjector.GetVariable("Dataset").Value = problem.DataSet;
    89       algo.ProblemInjector.GetVariable("TargetVariable").GetValue<IntData>().Data = targetVariable;
     79      algo.Dataset = problem.DataSet;
     80      algo.TargetVariable = targetVariable;
    9081      algo.ProblemInjector.GetVariable("TrainingSamplesStart").GetValue<IntData>().Data = problem.TrainingSamplesStart;
    9182      algo.ProblemInjector.GetVariable("TrainingSamplesEnd").GetValue<IntData>().Data = problem.TrainingSamplesEnd;
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/ExecuterBase.cs

    r1898 r1922  
    3838using HeuristicLab.Core;
    3939using System.Threading;
     40using HeuristicLab.Modeling;
    4041
    4142namespace HeuristicLab.CEDMA.Server {
     
    6869    protected abstract void StartJobs();
    6970
    70     protected void StoreResults(Execution finishedExecution, IEngine finishedEngine) {
    71       Entity model = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
    72       store.Add(new Statement(finishedExecution.DataSetEntity, Ontology.PredicateHasModel, model));
    73       StoreModelAttribute(model, Ontology.TargetVariable, finishedExecution.TargetVariable);
    74       StoreModelAttribute(model, Ontology.AlgorithmName, finishedExecution.Description);
    75       Scope bestModelScope = finishedEngine.GlobalScope.GetVariableValue<Scope>("BestValidationSolution", false);
    76       StoreModelVariable(model, Ontology.TrainingMeanSquaredError, bestModelScope, "Quality");
    77       StoreModelVariable(model, Ontology.ValidationMeanSquaredError, bestModelScope, "ValidationQuality");
    78       StoreModelVariable(model, Ontology.TestMeanSquaredError, bestModelScope, "TestQuality");
    79       StoreModelVariable(model, Ontology.TrainingMeanAbsolutePercentageError, bestModelScope, "TrainingMAPE");
    80       StoreModelVariable(model, Ontology.ValidationMeanAbsolutePercentageError, bestModelScope, "ValidationMAPE");
    81       StoreModelVariable(model, Ontology.TestMeanAbsolutePercentageError, bestModelScope, "TestMAPE");
    82       StoreModelVariable(model, Ontology.TrainingMeanAbsolutePercentageOfRangeError, bestModelScope, "TrainingMAPRE");
    83       StoreModelVariable(model, Ontology.ValidationMeanAbsolutePercentageOfRangeError, bestModelScope, "ValidationMAPRE");
    84       StoreModelVariable(model, Ontology.TestMeanAbsolutePercentageOfRangeError, bestModelScope, "TestMAPRE");
    85       StoreModelVariable(model, Ontology.TrainingCoefficientOfDetermination, bestModelScope, "TrainingR2");
    86       StoreModelVariable(model, Ontology.ValidationCoefficientOfDetermination, bestModelScope, "ValidationR2");
    87       StoreModelVariable(model, Ontology.TestCoefficientOfDetermination, bestModelScope, "TestR2");
    88       StoreModelVariable(model, Ontology.TrainingCoefficientOfDetermination, bestModelScope, "TrainingVAF");
    89       StoreModelVariable(model, Ontology.ValidationCoefficientOfDetermination, bestModelScope, "ValidationVAF");
    90       StoreModelVariable(model, Ontology.TestCoefficientOfDetermination, bestModelScope, "TestVAF");
    91       StoreModelVariable(model, Ontology.TrainingTheilsInequalityCoefficient, bestModelScope, "TrainingTheilInequalityCoefficient");
    92       StoreModelVariable(model, Ontology.ValidationTheilsInequalityCoefficient, bestModelScope, "ValidationTheilInequalityCoefficient");
    93       StoreModelVariable(model, Ontology.TestTheilsInequalityCoefficient, bestModelScope, "TestTheilInequalityCoefficient");
    94       StoreModelVariable(model, Ontology.TrainingAccuracy, bestModelScope, "TrainingAccuracy");
    95       StoreModelVariable(model, Ontology.ValidationAccuracy, bestModelScope, "ValidationAccuracy");
    96       StoreModelVariable(model, Ontology.TestAccuracy, bestModelScope, "TestAccuracy");
    97       StoreModelVariable(model, Ontology.TreeSize, bestModelScope, "TreeSize");
    98       StoreModelVariable(model, Ontology.TreeHeight, bestModelScope, "TreeHeight");
    99       StoreModelVariable(model, Ontology.EvaluatedSolutions, bestModelScope, "EvaluatedSolutions");
     71    protected void StoreResults(IAlgorithm finishedAlgorithm) {
     72      Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
     73      // TODO (gkronber 27052009)
     74      // store.Add(new Statement(finishedAlgorithm.DataSetEntity, Ontology.PredicateHasModel, modelEntity));
     75      StoreModelAttribute(modelEntity, Ontology.TargetVariable, finishedAlgorithm.Model.TargetVariable);
     76      StoreModelAttribute(modelEntity, Ontology.AlgorithmName, finishedAlgorithm.Description);
     77     
     78      IModel model = finishedAlgorithm.Model;
     79      StoreModelAttribute(modelEntity, Ontology.TrainingMeanSquaredError, model.TrainingMeanSquaredError);
     80      StoreModelAttribute(modelEntity, Ontology.ValidationMeanSquaredError, model.ValidationMeanSquaredError);
     81      StoreModelAttribute(modelEntity, Ontology.TestMeanSquaredError, model.TestMeanSquaredError);
     82      StoreModelAttribute(modelEntity, Ontology.TrainingCoefficientOfDetermination, model.TrainingCoefficientOfDetermination);
     83      StoreModelAttribute(modelEntity, Ontology.ValidationCoefficientOfDetermination, model.ValidationCoefficientOfDetermination);
     84      StoreModelAttribute(modelEntity, Ontology.TestCoefficientOfDetermination, model.TestCoefficientOfDetermination);
     85      StoreModelAttribute(modelEntity, Ontology.TrainingVarianceAccountedFor, model.TrainingVarianceAccountedFor);
     86      StoreModelAttribute(modelEntity, Ontology.ValidationVarianceAccountedFor, model.ValidationVarianceAccountedFor);
     87      StoreModelAttribute(modelEntity, Ontology.TestVarianceAccountedFor, model.TestVarianceAccountedFor);
     88      StoreModelAttribute(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, model.TrainingMeanAbsolutePercentageError);
     89      StoreModelAttribute(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, model.ValidationMeanAbsolutePercentageError);
     90      StoreModelAttribute(modelEntity, Ontology.TestMeanAbsolutePercentageError, model.TestMeanAbsolutePercentageError);
     91      StoreModelAttribute(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, model.TrainingMeanAbsolutePercentageOfRangeError);
     92      StoreModelAttribute(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, model.ValidationMeanAbsolutePercentageOfRangeError);
     93      StoreModelAttribute(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, model.TestMeanAbsolutePercentageOfRangeError);
    10094
    101       byte[] serializedModel = PersistenceManager.SaveToGZip(bestModelScope.GetVariableValue("FunctionTree", false));
    102       store.Add(new Statement(model, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
    103     }
    104 
    105     private void StoreModelVariable(Entity model, Entity entity, Scope scope, string variableName) {
    106       if (scope.GetVariable(variableName) != null)
    107         StoreModelAttribute(model, entity, scope.GetVariableValue<ObjectData>(variableName, false).Data);
     95      byte[] serializedModel = PersistenceManager.SaveToGZip(model.Data);
     96      store.Add(new Statement(modelEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
    10897    }
    10998
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs

    r1898 r1922  
    3838using HeuristicLab.Core;
    3939using System.Threading;
     40using HeuristicLab.Modeling;
    4041
    4142namespace HeuristicLab.CEDMA.Server {
    4243  public class GridExecuter : ExecuterBase {
    4344    private JobManager jobManager;
    44     private Dictionary<WaitHandle, Execution> activeExecutions;
     45    private Dictionary<WaitHandle, IAlgorithm> activeAlgorithms;
    4546
    4647    private TimeSpan StartJobInterval {
     
    6667            Thread.Sleep(StartJobInterval);
    6768            // get an execution from the dispatcher and execute in grid via job-manager
    68             Execution execution = Dispatcher.GetNextJob();
    69             if (execution != null) {
    70               AtomicOperation op = new AtomicOperation(execution.Engine.OperatorGraph.InitialOperator, execution.Engine.GlobalScope);
    71               WaitHandle opWh = jobManager.BeginExecuteOperation(execution.Engine.GlobalScope, op);
     69            IAlgorithm algorithm = Dispatcher.GetNextJob();
     70            if (algorithm != null) {
     71              AtomicOperation op = new AtomicOperation(algorithm.Engine.OperatorGraph.InitialOperator, algorithm.Engine.GlobalScope);
     72              WaitHandle opWh = jobManager.BeginExecuteOperation(algorithm.Engine.GlobalScope, op);
    7273              wh.Add(opWh);
    7374              activeOperations.Add(opWh, op);
    74               lock (activeExecutions) {
    75                 activeExecutions.Add(opWh, execution);
     75              lock (activeAlgorithms) {
     76                activeAlgorithms.Add(opWh, algorithm);
    7677              }
    7778            }
     
    8485            AtomicOperation finishedOp = activeOperations[readyHandle];
    8586            wh.Remove(readyHandle);
    86             Execution finishedExecution = null;
    87             lock (activeExecutions) {
    88               finishedExecution = activeExecutions[readyHandle];
    89               activeExecutions.Remove(readyHandle);
     87            IAlgorithm finishedAlgorithm = null;
     88            lock (activeAlgorithms) {
     89              finishedAlgorithm = activeAlgorithms[readyHandle];
     90              activeAlgorithms.Remove(readyHandle);
    9091            }
    9192            activeOperations.Remove(readyHandle);
     
    99100            }
    100101            if (finishedEngine != null) {
    101               StoreResults(finishedExecution, finishedEngine);
     102              StoreResults(finishedAlgorithm);
    102103            }
    103104          }
     
    110111
    111112    public override string[] GetJobs() {
    112       lock (activeExecutions) {
    113         string[] retVal = new string[activeExecutions.Count];
     113      lock (activeAlgorithms) {
     114        string[] retVal = new string[activeAlgorithms.Count];
    114115        int i = 0;
    115         foreach (Execution e in activeExecutions.Values) {
    116           retVal[i++] = "Target-Variable: " + e.TargetVariable + " " + e.Description;
     116        foreach (IAlgorithm a in activeAlgorithms.Values) {
     117          retVal[i++] = "Target-Variable: " + a.TargetVariable + " " + a.Description;
    117118        }
    118119        return retVal;
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/HeuristicLab.CEDMA.Server-3.3.csproj

    r1898 r1922  
    9999    <Compile Include="GridExecuter.cs" />
    100100    <Compile Include="IDispatcher.cs" />
    101     <Compile Include="Execution.cs" />
    102101    <Compile Include="Server.cs" />
    103102    <Compile Include="ServerApplication.cs" />
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/HiveExecuter.cs

    r1898 r1922  
    3939using System.Threading;
    4040using HeuristicLab.Hive.Engine;
     41using HeuristicLab.Modeling;
    4142
    4243namespace HeuristicLab.CEDMA.Server {
    4344  public class HiveExecuter : ExecuterBase {
    44     private Dictionary<WaitHandle, Execution> activeExecutions;
     45    private Dictionary<WaitHandle, IAlgorithm> activeAlgorithms;
    4546    private Dictionary<WaitHandle, HiveEngine> activeEngines;
    4647    private string hiveUrl;
     
    5758      : base(dispatcher, store) {
    5859      this.hiveUrl = hiveUrl;
    59       activeExecutions = new Dictionary<WaitHandle, Execution>();
     60      activeAlgorithms = new Dictionary<WaitHandle, IAlgorithm>();
    6061      activeEngines = new Dictionary<WaitHandle, HiveEngine>();
    6162    }
     
    6869          while (wh.Count < MaxActiveJobs) {
    6970            Thread.Sleep(StartJobInterval);
    70             // get an execution from the dispatcher and execute in grid via job-manager
    71             Execution execution = Dispatcher.GetNextJob();
    72             if (execution != null) {
     71            // get an algo from the dispatcher and execute in grid via job-manager
     72            IAlgorithm algorithm = Dispatcher.GetNextJob();
     73            if (algorithm != null) {
    7374              HiveEngine engine = new HiveEngine();
    7475              engine.HiveServerUrl = hiveUrl;
    75               IOperator initialOp = execution.Engine.OperatorGraph.InitialOperator;
     76              IOperator initialOp = algorithm.Engine.OperatorGraph.InitialOperator;
    7677              engine.OperatorGraph.AddOperator(initialOp);
    7778              engine.OperatorGraph.InitialOperator = initialOp;
    78               RegisterFinishedCallback(engine, execution, wh);
     79              RegisterFinishedCallback(engine, algorithm, wh);
    7980              engine.Reset();
    8081              engine.Execute();
     
    9091            activeEngines.Remove(readyHandle);
    9192
    92             Execution finishedExecution = activeExecutions[readyHandle];
    93             lock (activeExecutions) {
    94               activeExecutions.Remove(readyHandle);
     93            IAlgorithm finishedAlgorithm = activeAlgorithms[readyHandle];
     94            lock (activeAlgorithms) {
     95              activeAlgorithms.Remove(readyHandle);
    9596            }
    96             StoreResults(finishedExecution, finishedEngine);
     97            StoreResults(finishedAlgorithm);
    9798            readyHandle.Close();
    9899          }
     
    104105    }
    105106
    106     private void RegisterFinishedCallback(HiveEngine engine, Execution execution, List<WaitHandle> wh) {
     107    private void RegisterFinishedCallback(HiveEngine engine, IAlgorithm algorithm, List<WaitHandle> wh) {
    107108      ManualResetEvent waithandle = new ManualResetEvent(false);
    108109      wh.Add(waithandle);
    109110      engine.Finished += (sender, args) => waithandle.Set();
    110       lock (activeExecutions) {
    111         activeExecutions.Add(waithandle, execution);
     111      lock (activeAlgorithms) {
     112        activeAlgorithms.Add(waithandle, algorithm);
    112113      }
    113114      activeEngines.Add(waithandle, engine);
     
    115116
    116117    public override string[] GetJobs() {
    117       lock (activeExecutions) {
    118         string[] retVal = new string[activeExecutions.Count];
     118      lock (activeAlgorithms) {
     119        string[] retVal = new string[activeAlgorithms.Count];
    119120        int i = 0;
    120         foreach (Execution e in activeExecutions.Values) {
    121           retVal[i++] = "Target-Variable: " + e.TargetVariable + " " + e.Description;
     121        foreach (IAlgorithm a in activeAlgorithms.Values) {
     122          retVal[i++] = "Target-Variable: " + a.TargetVariable + " " + a.Description;
    122123        }
    123124        return retVal;
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/IDispatcher.cs

    r1529 r1922  
    3535using HeuristicLab.Data;
    3636using HeuristicLab.Core;
     37using HeuristicLab.Modeling;
    3738
    3839namespace HeuristicLab.CEDMA.Server {
    3940  public interface IDispatcher {
    40     Execution GetNextJob();
     41    IAlgorithm GetNextJob();
    4142  }
    4243}
Note: See TracChangeset for help on using the changeset viewer.