Changeset 1873 for trunk/sources/HeuristicLab.CEDMA.Server/3.3
- Timestamp:
- 05/20/09 17:38:19 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.CEDMA.Server/3.3
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs
r1869 r1873 61 61 DataSet dataSet = new DataSet(store, dataSetEntity); 62 62 63 int targetVariable = SelectTargetVariable(dataSet , dataSet.Problem.AllowedTargetVariables.ToArray());64 IAlgorithm selectedAlgorithm = SelectAlgorithm(dataSet , targetVariable, dataSet.Problem.LearningTask);63 int targetVariable = SelectTargetVariable(dataSetEntity, dataSet.Problem.AllowedTargetVariables.ToArray()); 64 IAlgorithm selectedAlgorithm = SelectAlgorithm(dataSetEntity, targetVariable, dataSet.Problem.LearningTask); 65 65 string targetVariableName = dataSet.Problem.GetVariableName(targetVariable); 66 66 … … 75 75 76 76 public abstract Entity SelectDataSet(Entity[] datasets); 77 public abstract int SelectTargetVariable( DataSetdataSet, int[] targetVariables);78 public abstract IAlgorithm SelectAlgorithm( DataSetdataSet, int targetVariable, LearningTask learningTask);77 public abstract int SelectTargetVariable(Entity dataSet, int[] targetVariables); 78 public abstract IAlgorithm SelectAlgorithm(Entity dataSet, int targetVariable, LearningTask learningTask); 79 79 80 80 private Execution CreateExecution(Problem problem, int targetVariable, IAlgorithm algorithm) { -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/Executer.cs
r1529 r1873 129 129 private void StoreResults(Execution finishedExecution, ProcessingEngine finishedEngine) { 130 130 Entity model = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid()); 131 store.Add(new Statement(model, Ontology.PredicateInstanceOf, Ontology.TypeGeneticProgrammingFunctionTree));132 131 store.Add(new Statement(finishedExecution.DataSetEntity, Ontology.PredicateHasModel, model)); 133 132 StoreModelAttribute(model, Ontology.TargetVariable, finishedExecution.TargetVariable); -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/HeuristicLab.CEDMA.Server-3.3.csproj
r1857 r1873 95 95 <Compile Include="Execution.cs" /> 96 96 <Compile Include="Executer.cs" /> 97 <Compile Include="RandomDispatcher.cs" />98 97 <Compile Include="Server.cs" /> 99 98 <Compile Include="ServerApplication.cs" /> … … 106 105 <DependentUpon>ServerForm.cs</DependentUpon> 107 106 </Compile> 107 <Compile Include="SimpleDispatcher.cs" /> 108 108 </ItemGroup> 109 109 <ItemGroup> -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/ServerForm.cs
r1529 r1873 63 63 64 64 private void connectButton_Click(object sender, EventArgs e) { 65 dispatcher = new RandomDispatcher(store);65 dispatcher = new SimpleDispatcher(store); 66 66 executer = new Executer(dispatcher, store, gridAddress.Text); 67 67 executer.Start(); -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/SimpleDispatcher.cs
r1857 r1873 38 38 39 39 namespace HeuristicLab.CEDMA.Server { 40 public class RandomDispatcher : DispatcherBase {40 public class SimpleDispatcher : DispatcherBase { 41 41 private Random random; 42 public RandomDispatcher(IStore store) 42 private IStore store; 43 private Dictionary<Entity, Dictionary<int, List<string>>> finishedAndDispatchedRuns; 44 45 public SimpleDispatcher(IStore store) 43 46 : base(store) { 47 this.store = store; 44 48 random = new Random(); 49 finishedAndDispatchedRuns = new Dictionary<Entity, Dictionary<int, List<string>>>(); 50 PopulateFinishedRuns(); 45 51 } 46 52 47 public override IAlgorithm SelectAlgorithm( DataSet dataSet, int targetVariable, LearningTask learningTask) {53 public override IAlgorithm SelectAlgorithm(Entity dataSetEntity, int targetVariable, LearningTask learningTask) { 48 54 DiscoveryService ds = new DiscoveryService(); 49 55 IAlgorithm[] algos = ds.GetInstances<IAlgorithm>(); 56 IAlgorithm selectedAlgorithm = null; 50 57 switch (learningTask) { 51 58 case LearningTask.Regression: { 52 59 var regressionAlgos = algos.Where(a => (a as IClassificationAlgorithm) == null && (a as ITimeSeriesAlgorithm) == null); 53 if (regressionAlgos.Count() == 0) return null;54 return regressionAlgos.ElementAt(random.Next(regressionAlgos.Count()));60 selectedAlgorithm = ChooseDeterministic(dataSetEntity, targetVariable, regressionAlgos) ?? ChooseStochastic(regressionAlgos); 61 break; 55 62 } 56 63 case LearningTask.Classification: { 57 64 var classificationAlgos = algos.Where(a => (a as IClassificationAlgorithm) != null); 58 if (classificationAlgos.Count() == 0) return null;59 return classificationAlgos.ElementAt(random.Next(classificationAlgos.Count()));65 selectedAlgorithm = ChooseDeterministic(dataSetEntity, targetVariable, classificationAlgos) ?? ChooseStochastic(classificationAlgos); 66 break; 60 67 } 61 68 case LearningTask.TimeSeries: { 62 69 var timeSeriesAlgos = algos.Where(a => (a as ITimeSeriesAlgorithm) != null); 63 if (timeSeriesAlgos.Count() == 0) return null;64 return timeSeriesAlgos.ElementAt(random.Next(timeSeriesAlgos.Count()));70 selectedAlgorithm = ChooseDeterministic(dataSetEntity, targetVariable, timeSeriesAlgos) ?? ChooseStochastic(timeSeriesAlgos); 71 break; 65 72 } 66 73 } 67 return null; 74 if (selectedAlgorithm != null) { 75 AddDispatchedRun(dataSetEntity, targetVariable, selectedAlgorithm.Name); 76 } 77 return selectedAlgorithm; 78 } 79 80 private IAlgorithm ChooseDeterministic(Entity dataSetEntity, int targetVariable, IEnumerable<IAlgorithm> algos) { 81 var deterministicAlgos = algos 82 .Where(a => (a as IStochasticAlgorithm) == null) 83 .Where(a => AlgorithmFinishedOrDispatched(dataSetEntity, targetVariable, a.Name) == false); 84 85 if (deterministicAlgos.Count() == 0) return null; 86 return deterministicAlgos.ElementAt(random.Next(deterministicAlgos.Count())); 87 } 88 89 private IAlgorithm ChooseStochastic(IEnumerable<IAlgorithm> regressionAlgos) { 90 var stochasticAlgos = regressionAlgos.Where(a => (a as IStochasticAlgorithm) != null); 91 if (stochasticAlgos.Count() == 0) return null; 92 return stochasticAlgos.ElementAt(random.Next(stochasticAlgos.Count())); 68 93 } 69 94 … … 72 97 } 73 98 74 public override int SelectTargetVariable( DataSetdataSet, int[] targetVariables) {99 public override int SelectTargetVariable(Entity dataSet, int[] targetVariables) { 75 100 return targetVariables[random.Next(targetVariables.Length)]; 101 } 102 103 private void PopulateFinishedRuns() { 104 var result = store 105 .Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> ." + Environment.NewLine + 106 "?DataSet <" + Ontology.PredicateHasModel + "> ?Model ." + Environment.NewLine + 107 "?Model <" + Ontology.TargetVariable + "> ?TargetVariable ." + Environment.NewLine + 108 "?Model <" + Ontology.AlgorithmName + "> ?AlgoName .", 109 0, 1000) 110 .Select(x => new Resource[] { (Entity)x.Get("DataSet"), (Literal)x.Get("TargetVariable"), (Literal)x.Get("AlgoName") }); 111 112 foreach (Resource[] row in result) { 113 Entity dataset = (Entity)row[0]; 114 int targetVariable = (int)((Literal)row[1]).Value; 115 string algoName = (string)((Literal)row[2]).Value; 116 if (!AlgorithmFinishedOrDispatched(dataset, targetVariable, algoName)) 117 AddDispatchedRun(dataset, targetVariable, algoName); 118 } 119 } 120 121 private void AddDispatchedRun(Entity dataSetEntity, int targetVariable, string algoName) { 122 if (!finishedAndDispatchedRuns.ContainsKey(dataSetEntity)) { 123 finishedAndDispatchedRuns[dataSetEntity] = new Dictionary<int, List<string>>(); 124 } 125 if (!finishedAndDispatchedRuns[dataSetEntity].ContainsKey(targetVariable)) { 126 finishedAndDispatchedRuns[dataSetEntity][targetVariable] = new List<string>(); 127 } 128 finishedAndDispatchedRuns[dataSetEntity][targetVariable].Add(algoName); 129 } 130 131 private bool AlgorithmFinishedOrDispatched(Entity dataSetEntity, int targetVariable, string algoName) { 132 return 133 finishedAndDispatchedRuns.ContainsKey(dataSetEntity) && 134 finishedAndDispatchedRuns[dataSetEntity].ContainsKey(targetVariable) && 135 finishedAndDispatchedRuns[dataSetEntity][targetVariable].Contains(algoName); 76 136 } 77 137 }
Note: See TracChangeset
for help on using the changeset viewer.