Changeset 1130


Ignore:
Timestamp:
01/14/09 20:48:04 (12 years ago)
Author:
gkronber
Message:
  • re-enabled security for all WCF services;
  • debugged rdf queries
  • added tracing for WCF services
  • implemented simple version of quality based dispatching
  • extended ontology to include a number of predefined model-attributes (quality, size, evaluated solutions etc.)

ticket: #419 (Refactor CEDMA plugins)

Location:
branches/CEDMA-Refactoring-Ticket419
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Console.cs

    r1129 r1130  
    7979      binding.ReaderQuotas.MaxStringContentLength = 1000000000; // also 100M chars
    8080      binding.ReaderQuotas.MaxArrayLength = 1000000000; // also 100M elements;
    81       binding.Security.Mode = SecurityMode.None;
    8281      factory = new ChannelFactory<IStore>(binding);
    8382      store = factory.CreateChannel(new EndpointAddress(serverUri));
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSet.cs

    r1129 r1130  
    4949        // lazy loading of problem from DB
    5050        if (problem == null) {
    51           var serializedDataVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("SerializedData");
     51          //var serializedDataVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("SerializedData");
     52          //var persistedData = Store.Query(
     53          //  new Statement[] { new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, serializedDataVar)});
    5254          var persistedData = Store.Query(
    53             new Statement[] { new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, serializedDataVar)});
     55            "<" + Ontology.CedmaNameSpace + Guid + "> <" + Ontology.PredicateSerializedData.Uri + "> ?SerializedData .");
    5456          if (persistedData.Count() == 1) {
    5557            Literal persistedLiteral = (Literal)persistedData.First().Get("SerializedData");
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/Ontology.cs

    r988 r1130  
    3333    }
    3434
    35     #region model attributes
    36     public static Entity PredicateModelAttribute {
    37       get { return new Entity(CedmaNameSpace + "ModelAttribute"); }
    38     }
    39     public static Entity PredicateModelAttributeName {
    40       get { return new Entity(CedmaNameSpace + "ModelAttributeName"); }
    41     }
    42     public static Entity PredicateModelAttributeValue {
    43       get { return new Entity(CedmaNameSpace + "ModelAttributeValue"); }
    44     }
    45     public static Entity PredicateModelAttributeType {
    46       get { return new Entity(CedmaNameSpace + "ModelAttributeType"); }
    47     }
     35    #region model attribute types
    4836    /// <summary>
    4937    /// Attribute value is ordinal, values can be sorted.
     
    118106    #endregion
    119107
     108    #region default attributes
     109    public static Entity TargetVariable {
     110      get { return new Entity(CedmaNameSpace + "TargetVariable"); }
     111    }
     112    public static Entity TrainingMeanSquaredError {
     113      get { return new Entity(CedmaNameSpace + "TrainingMeanSquaredError"); }
     114    }
     115    public static Entity ValidationMeanSquaredError {
     116      get { return new Entity(CedmaNameSpace + "ValidationMeanSquaredError"); }
     117    }
     118    public static Entity TrainingMeanAbsolutePercentageError {
     119      get { return new Entity(CedmaNameSpace + "TrainingMeanAbsolutePercentageError"); }
     120    }
     121    public static Entity ValidationMeanAbsolutePercentageError {
     122      get { return new Entity(CedmaNameSpace + "ValidationMeanAbsolutePercentageError"); }
     123    }
     124    public static Entity TreeSize {
     125      get { return new Entity(CedmaNameSpace + "TreeSize"); }
     126    }
     127    public static Entity TreeHeight {
     128      get { return new Entity(CedmaNameSpace + "TreeHeight"); }
     129    }
     130    public static Entity EvaluatedSolutions {
     131      get { return new Entity(CedmaNameSpace + "EvaluatedSolutions"); }
     132    }
     133    #endregion
     134
     135    public static ICollection<Statement> InitialStatements {
     136      get {
     137        return new List<Statement> {
     138          new Statement(TargetVariable, PredicateInstanceOf, TypeCategoricalAttribute),
     139          new Statement(TrainingMeanSquaredError, PredicateInstanceOf, TypeOrdinalAttribute),
     140          new Statement(TrainingMeanSquaredError, PredicateInstanceOf, TypeQualityAttribute),
     141          new Statement(ValidationMeanSquaredError, PredicateInstanceOf, TypeOrdinalAttribute),
     142          new Statement(ValidationMeanSquaredError, PredicateInstanceOf, TypeQualityAttribute),
     143          new Statement(TrainingMeanAbsolutePercentageError, PredicateInstanceOf, TypeOrdinalAttribute),
     144          new Statement(TrainingMeanAbsolutePercentageError, PredicateInstanceOf, TypeQualityAttribute),
     145          new Statement(ValidationMeanAbsolutePercentageError, PredicateInstanceOf, TypeOrdinalAttribute),
     146          new Statement(ValidationMeanAbsolutePercentageError, PredicateInstanceOf, TypeQualityAttribute),
     147          new Statement(TreeSize, PredicateInstanceOf, TypeOrdinalAttribute),
     148          new Statement(TreeSize, PredicateInstanceOf, TypeComplexityAttribute),
     149          new Statement(TreeHeight, PredicateInstanceOf, TypeOrdinalAttribute),
     150          new Statement(TreeHeight, PredicateInstanceOf, TypeComplexityAttribute),
     151          new Statement(EvaluatedSolutions, PredicateInstanceOf, TypeOrdinalAttribute)
     152        };
     153      }
     154    }
     155
     156
    120157    /// <summary>
    121158    /// Wildcard entity for filtering.
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/Store.cs

    r1129 r1130  
    4545        this.connectionString = connectionString;
    4646        store = SemWeb.Store.Create(connectionString);
     47        InitStore();
     48      }
     49    }
     50
     51    private void InitStore() {
     52      foreach (Statement s in Ontology.InitialStatements) {
     53        Add(s);
    4754      }
    4855    }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs

    r1129 r1130  
    5151
    5252    private void FillDispatchQueue() {
    53       //Dictionary<Entity, Dictionary<int, int>> numberOfModelsOfTargetVariableOfDataSet = new Dictionary<Entity, Dictionary<int, int>>();
    54       //var datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
    55       //foreach (Statement datasetStatement in datasetStatements) {
    56       //  numberOfModelsOfTargetVariableOfDataSet.Add(datasetStatement.Subject, new Dictionary<int, int>());
    57       //  var modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity));
    58       //  foreach (Statement modelStatement in modelStatements) {
    59       //    var modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
    60       //    foreach (Statement modelAttrStatement in modelAttributeStatements) {
    61       //      var targetVariableStatements = store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
    62       //         .Where(t => (string)((Literal)t.Property).Value == "TargetVariable")
    63       //         .SelectMany(t => store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity)))
    64       //         .GroupBy(t => (int)((Literal)t.Property).Value);
    65       //      foreach (var targetVariable in targetVariableStatements) {
    66       //        if (numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject].ContainsKey(targetVariable.Key)) {
    67       //          numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject][targetVariable.Key] = targetVariable.Count();
    68       //        } else {
    69       //          numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject].Add(targetVariable.Key, targetVariable.Count());
    70       //        }
    71       //      }
    72       //    }
    73       //  }
    74       //}
    75       //foreach (KeyValuePair<Entity, Dictionary<int, int>> dataSetEntry in numberOfModelsOfTargetVariableOfDataSet) {
    76       //  DataSet dataSet = new DataSet(store, dataSetEntry.Key);
    77       //  foreach (int targetVariable in dataSet.Problem.AllowedTargetVariables)
    78       //    if (!dataSetEntry.Value.ContainsKey(targetVariable) || dataSetEntry.Value[targetVariable] < 10) {
    79       //      IEngine engine = CreateEngine(dataSet.Problem, targetVariable);
    80       //      if (engine != null) {
    81       //        QueueJob(new Execution(dataSetEntry.Key, engine, targetVariable));
    82       //      }
    83       //    }
    84       //}
     53      // find and select a dataset
     54      var dataSetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("DataSet");
     55      var dataSetQuery = new Statement[] {
     56        new Statement(dataSetVar, Ontology.PredicateInstanceOf, Ontology.TypeDataSet)
     57      };
     58
     59      var dataSetBindings = store.Query("?DataSet <"+Ontology.PredicateInstanceOf.Uri+"> <"+Ontology.TypeDataSet.Uri+"> .");
     60
     61      // no datasets => do nothing
     62      if (dataSetBindings.Count() == 0) return;
     63
     64      // assume last dataset is the most interesting one
     65      // find and select all results for this dataset
     66      var dataSetEntity = (Entity)dataSetBindings.Last().Get("DataSet");
     67      var targetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("TargetVariable");
     68      var modelVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("Model");
     69      var modelMAPE = new HeuristicLab.CEDMA.DB.Interfaces.Variable("ModelMAPE");
     70
     71      //var query = new Statement[] {
     72      //  new Statement(dataSetEntity, Ontology.PredicateHasModel, modelVar),
     73      //  new Statement(modelVar, Ontology.TargetVariable, targetVar),
     74      //  new Statement(modelVar, Ontology.ValidationMeanAbsolutePercentageError, modelMAPE)
     75      //};
     76
     77      var query = "<" + dataSetEntity.Uri + "> <" + Ontology.PredicateHasModel.Uri + "> ?Model ." + Environment.NewLine +
     78        "?Model <" + Ontology.TargetVariable.Uri + "> ?TargetVariable ." + Environment.NewLine +
     79        "?Model <" + Ontology.ValidationMeanAbsolutePercentageError.Uri + "> ?ModelMAPE .";
     80
     81
     82
     83      var bindings = store.Query(query);
     84      DataSet dataSet = new DataSet(store, dataSetEntity);
     85      double[] utilization = new double[dataSet.Problem.AllowedTargetVariables.Count];
     86      int i = 0;
     87      int totalN = bindings.Count();
     88      foreach (int targetVariable in dataSet.Problem.AllowedTargetVariables) {
     89        var targetVarBindings = bindings.Where(x => (int)((Literal)x.Get("TargetVariable")).Value == targetVariable);
     90        if (targetVarBindings.Count() == 0) {
     91          utilization[i++] = double.PositiveInfinity;
     92        } else {
     93          double averageMape = targetVarBindings.Average(x => (double)((Literal)x.Get("ModelMAPE")).Value);
     94          double n = targetVarBindings.Count();
     95          utilization[i++] = -averageMape + Math.Sqrt(Math.Log(totalN) / n) * 0.1;
     96        }
     97      }
     98      int[] idx = Enumerable.Range(0, utilization.Length).ToArray();
     99      Array.Sort(utilization, idx);
     100      int nConfigurations = utilization.Length;
     101      for (int j = nConfigurations - 1; j > nConfigurations * 0.8; j--) {
     102        int targetVariable = dataSet.Problem.AllowedTargetVariables[j];
     103        IEngine engine = CreateEngine(dataSet.Problem, targetVariable);
     104        if (engine != null) {
     105          QueueJob(new Execution(dataSetEntity, engine, targetVariable));
     106        }
     107      }
    85108    }
    86109
     
    90113
    91114    public Execution GetNextJob() {
    92       if (dispatchQueue.Count == 0) FillDispatchQueue();
     115      if (dispatchQueue.Count == 0) {
     116        FillDispatchQueue();
     117      }
    93118      if (dispatchQueue.Count > 0) {
    94119        Execution next = dispatchQueue[0];
     
    120145      StandardGP sgp = new StandardGP();
    121146      sgp.SetSeedRandomly = true;
    122       sgp.MaxGenerations = 100;
    123       sgp.PopulationSize = 1000;
     147      sgp.MaxGenerations = 300;
     148      sgp.PopulationSize = 10000;
    124149      sgp.Elites = 1;
    125150      sgp.ProblemInjector = probInjector;
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs

    r1116 r1130  
    103103
    104104    private void StoreResults(Execution finishedExecution, ProcessingEngine finishedEngine) {
    105       Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
    106       store.Add(new Statement(modelEntity, Ontology.PredicateInstanceOf, Ontology.TypeGeneticProgrammingFunctionTree));
    107       store.Add(new Statement(finishedExecution.DataSetEntity, Ontology.PredicateHasModel, modelEntity));
    108       StoreModelAttribute(modelEntity, "TargetVariable", finishedExecution.TargetVariable);
     105      Entity model = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
     106      store.Add(new Statement(model, Ontology.PredicateInstanceOf, Ontology.TypeGeneticProgrammingFunctionTree));
     107      store.Add(new Statement(finishedExecution.DataSetEntity, Ontology.PredicateHasModel, model));
     108      StoreModelAttribute(model, Ontology.TargetVariable, finishedExecution.TargetVariable);
    109109      Scope bestModelScope = finishedEngine.GlobalScope.GetVariableValue<Scope>("BestValidationSolution", false);
    110       StoreModelAttribute(modelEntity, "TrainingMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("Quality", false).Data);
    111       StoreModelAttribute(modelEntity, "ValidationMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data);
    112       StoreModelAttribute(modelEntity, "TrainingMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("TrainingMAPE", false).Data);
    113       StoreModelAttribute(modelEntity, "ValidationMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data);
    114       StoreModelAttribute(modelEntity, "TreeSize", bestModelScope.GetVariableValue<IntData>("TreeSize", false).Data);
    115       StoreModelAttribute(modelEntity, "TreeHeight", bestModelScope.GetVariableValue<IntData>("TreeHeight", false).Data);
    116       StoreModelAttribute(modelEntity, "EvaluatedSolutions", bestModelScope.GetVariableValue<IntData>("EvaluatedSolutions", false).Data);
     110      StoreModelAttribute(model, Ontology.TrainingMeanSquaredError, bestModelScope.GetVariableValue<DoubleData>("Quality", false).Data);
     111      StoreModelAttribute(model, Ontology.ValidationMeanSquaredError, bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data);
     112      StoreModelAttribute(model, Ontology.TrainingMeanAbsolutePercentageError, bestModelScope.GetVariableValue<DoubleData>("TrainingMAPE", false).Data);
     113      StoreModelAttribute(model, Ontology.ValidationMeanAbsolutePercentageError, bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data);
     114      StoreModelAttribute(model, Ontology.TreeSize, bestModelScope.GetVariableValue<IntData>("TreeSize", false).Data);
     115      StoreModelAttribute(model, Ontology.TreeHeight, bestModelScope.GetVariableValue<IntData>("TreeHeight", false).Data);
     116      StoreModelAttribute(model, Ontology.EvaluatedSolutions, bestModelScope.GetVariableValue<IntData>("EvaluatedSolutions", false).Data);
    117117       
    118118      byte[] serializedModel = PersistenceManager.SaveToGZip(bestModelScope.GetVariableValue("FunctionTree", false));
    119       store.Add(new Statement(modelEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
     119      store.Add(new Statement(model, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
     120   }
    120121
    121     }
    122 
    123     private void StoreModelAttribute(Entity model, string name, object value) {
    124       Entity attr = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
    125       store.Add(new Statement(model, Ontology.PredicateModelAttribute, attr));
    126       store.Add(new Statement(attr, Ontology.PredicateModelAttributeName, new Literal(name)));
    127       store.Add(new Statement(attr, Ontology.PredicateModelAttributeValue, new Literal(value)));
    128       store.Add(new Statement(attr, Ontology.PredicateModelAttributeType, Ontology.TypeOrdinalAttribute));
     122    private void StoreModelAttribute(Entity model, Entity predicate, object value) {
     123      store.Add(new Statement(model, predicate, new Literal(value)));
    129124    }
    130125  }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs

    r1129 r1130  
    7575        binding.ReaderQuotas.MaxStringContentLength = 1000000000; // also 100M chars
    7676        binding.ReaderQuotas.MaxArrayLength = 1000000000; // also 100M elements;
    77         binding.Security.Mode = SecurityMode.None;
    78 
    7977        host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
    8078        host.Open();
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.Grid/GridClient.cs

    r766 r1130  
    101101      binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
    102102      binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
    103       binding.Security.Mode = SecurityMode.None;
    104103      factory = new ChannelFactory<IEngineStore>(binding);
    105104      engineStore = factory.CreateChannel(new EndpointAddress(uri));
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.Grid/JobManager.cs

    r1113 r1130  
    9999        binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
    100100        binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
    101         binding.Security.Mode = SecurityMode.None;
    102101
    103102        factory = new ChannelFactory<IGridServer>(binding);
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.Grid/ServerForm.cs

    r1113 r1130  
    7373        binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
    7474        binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
    75         binding.Security.Mode = SecurityMode.None;
    76        
    77 
    7875        externalHost.AddServiceEndpoint(typeof(IGridServer), binding, externalAddressTextBox.Text);
    7976        externalHost.Open();
Note: See TracChangeset for help on using the changeset viewer.