Changeset 1922 for trunk/sources/HeuristicLab.CEDMA.Server
- Timestamp:
- 05/27/09 18:26:10 (15 years ago)
- 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 44 44 } 45 45 46 public ExecutionGetNextJob() {46 public IAlgorithm GetNextJob() { 47 47 // find and select a dataset 48 48 var dataSetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("DataSet"); … … 67 67 68 68 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; 74 72 } 75 73 … … 78 76 public abstract IAlgorithm SelectAlgorithm(Entity dataSet, int targetVariable, LearningTask learningTask); 79 77 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 87 78 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; 90 81 algo.ProblemInjector.GetVariable("TrainingSamplesStart").GetValue<IntData>().Data = problem.TrainingSamplesStart; 91 82 algo.ProblemInjector.GetVariable("TrainingSamplesEnd").GetValue<IntData>().Data = problem.TrainingSamplesEnd; -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/ExecuterBase.cs
r1898 r1922 38 38 using HeuristicLab.Core; 39 39 using System.Threading; 40 using HeuristicLab.Modeling; 40 41 41 42 namespace HeuristicLab.CEDMA.Server { … … 68 69 protected abstract void StartJobs(); 69 70 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); 100 94 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)))); 108 97 } 109 98 -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs
r1898 r1922 38 38 using HeuristicLab.Core; 39 39 using System.Threading; 40 using HeuristicLab.Modeling; 40 41 41 42 namespace HeuristicLab.CEDMA.Server { 42 43 public class GridExecuter : ExecuterBase { 43 44 private JobManager jobManager; 44 private Dictionary<WaitHandle, Execution> activeExecutions;45 private Dictionary<WaitHandle, IAlgorithm> activeAlgorithms; 45 46 46 47 private TimeSpan StartJobInterval { … … 66 67 Thread.Sleep(StartJobInterval); 67 68 // 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); 72 73 wh.Add(opWh); 73 74 activeOperations.Add(opWh, op); 74 lock (active Executions) {75 active Executions.Add(opWh, execution);75 lock (activeAlgorithms) { 76 activeAlgorithms.Add(opWh, algorithm); 76 77 } 77 78 } … … 84 85 AtomicOperation finishedOp = activeOperations[readyHandle]; 85 86 wh.Remove(readyHandle); 86 Execution finishedExecution= null;87 lock (active Executions) {88 finished Execution = activeExecutions[readyHandle];89 active Executions.Remove(readyHandle);87 IAlgorithm finishedAlgorithm = null; 88 lock (activeAlgorithms) { 89 finishedAlgorithm = activeAlgorithms[readyHandle]; 90 activeAlgorithms.Remove(readyHandle); 90 91 } 91 92 activeOperations.Remove(readyHandle); … … 99 100 } 100 101 if (finishedEngine != null) { 101 StoreResults(finished Execution, finishedEngine);102 StoreResults(finishedAlgorithm); 102 103 } 103 104 } … … 110 111 111 112 public override string[] GetJobs() { 112 lock (active Executions) {113 string[] retVal = new string[active Executions.Count];113 lock (activeAlgorithms) { 114 string[] retVal = new string[activeAlgorithms.Count]; 114 115 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; 117 118 } 118 119 return retVal; -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/HeuristicLab.CEDMA.Server-3.3.csproj
r1898 r1922 99 99 <Compile Include="GridExecuter.cs" /> 100 100 <Compile Include="IDispatcher.cs" /> 101 <Compile Include="Execution.cs" />102 101 <Compile Include="Server.cs" /> 103 102 <Compile Include="ServerApplication.cs" /> -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/HiveExecuter.cs
r1898 r1922 39 39 using System.Threading; 40 40 using HeuristicLab.Hive.Engine; 41 using HeuristicLab.Modeling; 41 42 42 43 namespace HeuristicLab.CEDMA.Server { 43 44 public class HiveExecuter : ExecuterBase { 44 private Dictionary<WaitHandle, Execution> activeExecutions;45 private Dictionary<WaitHandle, IAlgorithm> activeAlgorithms; 45 46 private Dictionary<WaitHandle, HiveEngine> activeEngines; 46 47 private string hiveUrl; … … 57 58 : base(dispatcher, store) { 58 59 this.hiveUrl = hiveUrl; 59 active Executions = new Dictionary<WaitHandle, Execution>();60 activeAlgorithms = new Dictionary<WaitHandle, IAlgorithm>(); 60 61 activeEngines = new Dictionary<WaitHandle, HiveEngine>(); 61 62 } … … 68 69 while (wh.Count < MaxActiveJobs) { 69 70 Thread.Sleep(StartJobInterval); 70 // get an executionfrom the dispatcher and execute in grid via job-manager71 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) { 73 74 HiveEngine engine = new HiveEngine(); 74 75 engine.HiveServerUrl = hiveUrl; 75 IOperator initialOp = execution.Engine.OperatorGraph.InitialOperator;76 IOperator initialOp = algorithm.Engine.OperatorGraph.InitialOperator; 76 77 engine.OperatorGraph.AddOperator(initialOp); 77 78 engine.OperatorGraph.InitialOperator = initialOp; 78 RegisterFinishedCallback(engine, execution, wh);79 RegisterFinishedCallback(engine, algorithm, wh); 79 80 engine.Reset(); 80 81 engine.Execute(); … … 90 91 activeEngines.Remove(readyHandle); 91 92 92 Execution finishedExecution = activeExecutions[readyHandle];93 lock (active Executions) {94 active Executions.Remove(readyHandle);93 IAlgorithm finishedAlgorithm = activeAlgorithms[readyHandle]; 94 lock (activeAlgorithms) { 95 activeAlgorithms.Remove(readyHandle); 95 96 } 96 StoreResults(finished Execution, finishedEngine);97 StoreResults(finishedAlgorithm); 97 98 readyHandle.Close(); 98 99 } … … 104 105 } 105 106 106 private void RegisterFinishedCallback(HiveEngine engine, Execution execution, List<WaitHandle> wh) {107 private void RegisterFinishedCallback(HiveEngine engine, IAlgorithm algorithm, List<WaitHandle> wh) { 107 108 ManualResetEvent waithandle = new ManualResetEvent(false); 108 109 wh.Add(waithandle); 109 110 engine.Finished += (sender, args) => waithandle.Set(); 110 lock (active Executions) {111 active Executions.Add(waithandle, execution);111 lock (activeAlgorithms) { 112 activeAlgorithms.Add(waithandle, algorithm); 112 113 } 113 114 activeEngines.Add(waithandle, engine); … … 115 116 116 117 public override string[] GetJobs() { 117 lock (active Executions) {118 string[] retVal = new string[active Executions.Count];118 lock (activeAlgorithms) { 119 string[] retVal = new string[activeAlgorithms.Count]; 119 120 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; 122 123 } 123 124 return retVal; -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/IDispatcher.cs
r1529 r1922 35 35 using HeuristicLab.Data; 36 36 using HeuristicLab.Core; 37 using HeuristicLab.Modeling; 37 38 38 39 namespace HeuristicLab.CEDMA.Server { 39 40 public interface IDispatcher { 40 ExecutionGetNextJob();41 IAlgorithm GetNextJob(); 41 42 } 42 43 }
Note: See TracChangeset
for help on using the changeset viewer.