Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2137 for trunk/sources


Ignore:
Timestamp:
07/06/09 19:52:06 (15 years ago)
Author:
gkronber
Message:

Improved loading speed of CEDMA results by:

  • Limit number of models to the best 10% for each target variable
  • Cache sqlite rdf store to memory on first query

#286 (Variable-usage diagrams for the CEDMA frontend)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Charting/3.3/BubbleChart.cs

    r2135 r2137  
    201201          double x = xs[Math.Min(i, xs.Count() - 1)];
    202202          double y = ys[Math.Min(i, ys.Count() - 1)];
    203           string actualXValue = actualXValues[Math.Min(i, actualXValues.Count() - 1)].ToString();
    204           string actualYValue = actualYValues[Math.Min(i, actualYValues.Count() - 1)].ToString();
    205203          if (double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN;
    206204          if (double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN;
    207205          if (!double.IsNaN(x) && !double.IsNaN(y)) {
     206            string actualXValue = actualXValues[Math.Min(i, actualXValues.Count() - 1)].ToString();
     207            string actualYValue = actualYValues[Math.Min(i, actualYValues.Count() - 1)].ToString();
    208208            UpdateViewSize(x, y, size);
    209209            int alpha = CalculateAlpha(size);
  • trunk/sources/HeuristicLab.CEDMA.Core/3.3/Results.cs

    r2131 r2137  
    9090    }
    9191
     92    long nStatements;
     93    DateTime start, stop;
    9294    private IEnumerable<ResultsEntry> SelectRows() {
     95      start = DateTime.Now;
     96      nStatements = 0;
    9397      int page = 0;
    9498      int resultsReturned = 0;
    95       bool newEntry = false;
    96       if (store == null) yield break;
    9799      entries = new List<ResultsEntry>();
     100      if (store == null) return entries;
    98101      do {
    99         var allBindings = store.Query(
     102        var allModels = store.Query(
    100103          "?Model <" + Ontology.InstanceOf + "> <" + Ontology.TypeModel + "> ." +
    101           "?Model ?Attribute ?Value .",
    102           page, PAGE_SIZE);
    103         var allModelBindings = allBindings.GroupBy(x => (Entity)x.Get("Model"));
    104         resultsReturned = allBindings.Count;
    105 
    106         foreach (var modelBindings in allModelBindings) {
    107           ResultsEntry entry = entries.FirstOrDefault(x => x.Uri == modelBindings.Key.Uri);
    108           newEntry = false;
    109           if (entry == null) {
    110             entry = new ResultsEntry();
    111             entry.Uri = modelBindings.Key.Uri;
     104          "?Model <" + Ontology.TargetVariable + "> ?TargetVariable ." +
     105          "?Model <" + Ontology.TestMeanSquaredError + "> ?TestMSE .",
     106          0, 3000)
     107          .Select(modelBinding => new {
     108            Model = ((Entity)modelBinding.Get("Model")).Uri,
     109            TestMSE = (double)((Literal)modelBinding.Get("TestMSE")).Value,
     110            TargetVariable = (string)((Literal)modelBinding.Get("TargetVariable")).Value
     111          })
     112          .Distinct()
     113          .GroupBy(m => m.TargetVariable)
     114          .Select(grouping => grouping.OrderBy(m => m.TestMSE));
     115        foreach (var targetVariableBindings in allModels) {
     116          resultsReturned = targetVariableBindings.Count();
     117          nStatements += resultsReturned;
     118          int nModels = Math.Max(10, resultsReturned * 10 / 100);
     119          foreach (var modelBindings in targetVariableBindings.Take(nModels)) {
     120            ResultsEntry entry = new ResultsEntry();
     121            entry.Uri = modelBindings.Model;
    112122            entries.Add(entry);
    113             newEntry = true;
    114             entry.Set("VariableImpacts", SelectVariableImpacts(entry.Uri));
     123            SetModelAttributes(entry, modelBindings.Model);
     124            entry.Set("VariableImpacts", SelectVariableImpacts(modelBindings.Model));
    115125          }
    116           foreach (var binding in modelBindings) {
    117             if (binding.Get("Value") is Literal) {
    118               string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");
    119               if (entry.Get(name) == null) {
    120                 object value = ((Literal)binding.Get("Value")).Value;
    121                 entry.Set(name, value);
    122               }
    123             }
    124           }
    125           if (newEntry) yield return entry;
    126126        }
    127127        page++;
    128128      } while (resultsReturned == PAGE_SIZE);
    129 
     129      stop = DateTime.Now;
    130130      FireChanged();
    131131      cached = true;
     132      return entries;
     133    }
     134
     135    private void SetModelAttributes(ResultsEntry entry, string modelUri) {
     136      var modelBindings = store.Query(
     137        "<" + modelUri + "> ?Attribute ?Value .",
     138        0, PAGE_SIZE);
     139      nStatements += modelBindings.Count();
     140      foreach (var binding in modelBindings) {
     141        if (binding.Get("Value") is Literal) {
     142          string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");
     143          if (entry.Get(name) == null) {
     144            object value = ((Literal)binding.Get("Value")).Value;
     145            entry.Set(name, value);
     146          }
     147        }
     148      }
    132149    }
    133150
    134151    private IEnumerable<ResultsEntry> SelectVariableImpacts(string modelUri) {
    135       var allBindings = store.Query(
     152      var inputVariableNameBindings = store.Query(
    136153          "<" + modelUri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." +
    137           "?InputVariable <" + Ontology.Name + "> ?InputName ." +
    138           "?InputVariable <" + Ontology.QualityImpact + "> ?QualityImpact ." +
    139           "?InputVariable <" + Ontology.EvaluationImpact + "> ?EvaluationImpact .",
     154          "?InputVariable <" + Ontology.Name + "> ?InputName .",
    140155          0, PAGE_SIZE);
    141       var allInputVariableBindings = allBindings.GroupBy(x => (Entity)x.Get("InputVariable"));
    142       List<ResultsEntry> variableImpacts = new List<ResultsEntry>();
    143 
    144       foreach (var inputVariableBinding in allInputVariableBindings) {
    145         ResultsEntry entry = new ResultsEntry();
    146         VariableBindings binding = inputVariableBinding.First();
    147         double evaluationImpact = (double)((Literal)binding.Get("EvaluationImpact")).Value;
    148         double qualityImpact = (double)((Literal)binding.Get("QualityImpact")).Value;
    149         if (binding.Get("InputName") != null) entry.Set("InputVariableName", ((Literal)binding.Get("InputName")).Value);
    150         if (binding.Get("QualityImpact") != null) entry.Set("QualityImpact", qualityImpact);
    151         if (binding.Get("EvaluationImpact") != null) entry.Set("EvaluationImpact", evaluationImpact);
    152         if (!IsAlmost(evaluationImpact, 0.0) && !IsAlmost(qualityImpact, 1.0)) {
    153           variableImpacts.Add(entry);
    154         }
    155       }
    156       return variableImpacts;
     156
     157      var qualityImpactBindings = store.Query(
     158          "<" + modelUri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." +
     159          "?InputVariable <" + Ontology.QualityImpact + "> ?QualityImpact .",
     160          0, PAGE_SIZE);
     161
     162      var evaluationImpactBindings = store.Query(
     163           "<" + modelUri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." +
     164           "?InputVariable <" + Ontology.EvaluationImpact + "> ?EvaluationImpact .",
     165           0, PAGE_SIZE);
     166      Dictionary<object, ResultsEntry> inputVariableAttributes = new Dictionary<object, ResultsEntry>();
     167      nStatements += inputVariableNameBindings.Count();
     168      nStatements += qualityImpactBindings.Count();
     169      nStatements += evaluationImpactBindings.Count();
     170
     171      foreach (var inputVariableNameBinding in inputVariableNameBindings) {
     172        object inputVariable = inputVariableNameBinding.Get("InputVariable");
     173        object name = ((Literal)inputVariableNameBinding.Get("InputName")).Value;
     174        if (!inputVariableAttributes.ContainsKey(inputVariable)) {
     175          inputVariableAttributes[inputVariable] = new ResultsEntry();
     176          inputVariableAttributes[inputVariable].Set("InputVariableName", name);
     177        }
     178      }
     179
     180      foreach (var qualityImpactBinding in qualityImpactBindings) {
     181        double qualityImpact = (double)((Literal)qualityImpactBinding.Get("QualityImpact")).Value;
     182        object inputVariable = qualityImpactBinding.Get("InputVariable");
     183        if (!IsAlmost(qualityImpact, 1.0)) {
     184          if (inputVariableAttributes[inputVariable].Get("QualityImpact") == null)
     185            inputVariableAttributes[inputVariable].Set("QualityImpact", qualityImpact);
     186        } else inputVariableAttributes.Remove(inputVariable);
     187      }
     188
     189      foreach (var evaluationImpactBinding in evaluationImpactBindings) {
     190        double evaluationImpact = (double)((Literal)evaluationImpactBinding.Get("EvaluationImpact")).Value;
     191        object inputVariable = evaluationImpactBinding.Get("InputVariable");
     192        if (!IsAlmost(evaluationImpact, 0.0)) {
     193          if (inputVariableAttributes.ContainsKey(inputVariable) && inputVariableAttributes[inputVariable].Get("EvaluationImpact") == null)
     194            inputVariableAttributes[inputVariable].Set("EvaluationImpact", evaluationImpact);
     195        } else inputVariableAttributes.Remove(inputVariable);
     196      }
     197
     198      return inputVariableAttributes.Values;
    157199    }
    158200
    159201    private bool IsAlmost(double x, double y) {
    160       return (y + 1.0E-7 > x) && (y - 1.0E-7 < x);
     202      return Math.Abs(x - y) < 1.0E-12;
    161203    }
    162204
  • trunk/sources/HeuristicLab.CEDMA.DB/3.3/Store.cs

    r2053 r2137  
    7575        SemWeb.N3Reader n3Reader = new SemWeb.N3Reader(new StringReader(query));
    7676        SemWeb.Query.GraphMatch matcher = new SemWeb.Query.GraphMatch(n3Reader);
    77         matcher.Run(store, resultSink);
     77        if (memStore == null) {
     78          CacheStore();
     79        }
     80        matcher.Run(memStore, resultSink);
    7881        return resultSink.Bindings.Skip(page * pageSize).Take(pageSize).ToList();
    7982      }
    8083    }
    8184
     85    SemWeb.Store memStore;
     86    private void CacheStore() {
     87      memStore = new SemWeb.MemoryStore();
     88      memStore.Import(store);
     89    }
     90
    8291    public ICollection<VariableBindings> Query(ICollection<Statement> query, int page, int pageSize) {
    8392      lock (bigLock) {
    8493        MyQueryResultSink resultSink = new MyQueryResultSink();
    85         Translate(query).Run(store, resultSink);
     94        if (memStore == null) {
     95          CacheStore();
     96        }
     97        Translate(query).Run(memStore, resultSink);
    8698        return resultSink.Bindings.Skip(page * pageSize).Take(pageSize).ToList();
    8799      }
Note: See TracChangeset for help on using the changeset viewer.