- Timestamp:
- 08/10/09 15:50:02 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs
r2270 r2271 69 69 public void Persist(HeuristicLab.Modeling.IAlgorithm algorithm) { 70 70 GetOrCreateProblem(algorithm.Dataset); 71 Persist(algorithm.Model, algorithm.Name, algorithm.Description); 72 } 73 74 public void Persist(HeuristicLab.Modeling.IModel model, string algorithmName, string algorithmDescription) { 71 75 Dictionary<string, Variable> variables = GetAllVariables(); 72 Algorithm algo = GetOrCreateAlgorithm(algorithm .Name, algorithm.Description);73 Variable target = variables[ algorithm.Model.TargetVariable];74 Model m odel;75 76 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 77 m odel= new Model(target, algo);78 m odel.TrainingSamplesStart = algorithm.Model.TrainingSamplesStart;79 m odel.TrainingSamplesEnd = algorithm.Model.TrainingSamplesEnd;80 m odel.ValidationSamplesStart = algorithm.Model.ValidationSamplesStart;81 m odel.ValidationSamplesEnd = algorithm.Model.ValidationSamplesEnd;82 m odel.TestSamplesStart = algorithm.Model.TestSamplesStart;83 m odel.TestSamplesEnd = algorithm.Model.TestSamplesEnd;84 85 ctx.Models.InsertOnSubmit(m odel);86 87 ctx.SubmitChanges(); 88 } 89 90 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 91 ctx.ModelData.InsertOnSubmit(new ModelData(m odel, PersistenceManager.SaveToGZip(algorithm.Model.Data)));92 } 93 94 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 95 foreach (string inputVariable in algorithm.Model.InputVariables) {96 ctx.InputVariables.InsertOnSubmit(new InputVariable(m odel, variables[inputVariable]));76 Algorithm algo = GetOrCreateAlgorithm(algorithmName, algorithmDescription); 77 Variable target = variables[model.TargetVariable]; 78 Model m; 79 80 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 81 m = new Model(target, algo); 82 m.TrainingSamplesStart = model.TrainingSamplesStart; 83 m.TrainingSamplesEnd = model.TrainingSamplesEnd; 84 m.ValidationSamplesStart = model.ValidationSamplesStart; 85 m.ValidationSamplesEnd = model.ValidationSamplesEnd; 86 m.TestSamplesStart = model.TestSamplesStart; 87 m.TestSamplesEnd = model.TestSamplesEnd; 88 89 ctx.Models.InsertOnSubmit(m); 90 91 ctx.SubmitChanges(); 92 } 93 94 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 95 ctx.ModelData.InsertOnSubmit(new ModelData(m, PersistenceManager.SaveToGZip(model.Data))); 96 } 97 98 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 99 foreach (string inputVariable in model.InputVariables) { 100 ctx.InputVariables.InsertOnSubmit(new InputVariable(m, variables[inputVariable])); 97 101 } 98 102 ctx.SubmitChanges(); … … 101 105 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 102 106 //get all double properties to save as modelResult 103 IEnumerable<PropertyInfo> modelResultInfos = algorithm.Model.GetType().GetProperties().Where(107 IEnumerable<PropertyInfo> modelResultInfos = model.GetType().GetProperties().Where( 104 108 info => info.PropertyType == typeof(double)); 105 109 foreach (PropertyInfo modelResultInfo in modelResultInfos) { 106 110 Result result = GetOrCreateResult(modelResultInfo.Name); 107 double value = (double)modelResultInfo.GetValue( algorithm.Model, null);108 ctx.ModelResults.InsertOnSubmit(new ModelResult(m odel, result, value));109 } 110 ctx.SubmitChanges(); 111 } 112 113 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 114 IEnumerable<MethodInfo> inputVariableResultInfos = algorithm.Model.GetType().GetMethods().Where(111 double value = (double)modelResultInfo.GetValue(model, null); 112 ctx.ModelResults.InsertOnSubmit(new ModelResult(m, result, value)); 113 } 114 ctx.SubmitChanges(); 115 } 116 117 using (ModelingDataContext ctx = new ModelingDataContext(connection)) { 118 IEnumerable<MethodInfo> inputVariableResultInfos = model.GetType().GetMethods().Where( 115 119 info => info.GetParameters().Count() == 1 && 116 120 info.GetParameters()[0].ParameterType == typeof(string) && … … 121 125 Result result = GetOrCreateResult(inputVariableResultInfo.Name.Substring(3)); 122 126 foreach (InputVariable variable in ctx.InputVariables.Where(iv => iv.Model == model)) { 123 double value = (double)inputVariableResultInfo.Invoke( algorithm.Model, new object[] { variable.Variable.Name });127 double value = (double)inputVariableResultInfo.Invoke(model, new object[] { variable.Variable.Name }); 124 128 ctx.InputVariableResults.InsertOnSubmit(new InputVariableResult(variable, result, value)); 125 129 } … … 127 131 ctx.SubmitChanges(); 128 132 } 129 130 133 } 131 134
Note: See TracChangeset
for help on using the changeset viewer.