- Timestamp:
- 02/25/20 17:18:00 (4 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface
- Files:
-
- 2 added
- 14 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs
r17444 r17451 27 27 IAlgorithm algorithm = value as IAlgorithm; 28 28 foreach (var res in algorithm.Results) { 29 item.AddChildren(new Result Item() {29 item.AddChildren(new ResultJsonItem() { 30 30 Name = res.Name, 31 31 Description = res.Description -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/RegressionProblemDataConverter.cs
r17433 r17451 1 1 using System; 2 using System.Collections; 2 3 using System.Collections.Generic; 3 4 using System.Linq; … … 7 8 using HeuristicLab.Core; 8 9 using HeuristicLab.Data; 10 using Newtonsoft.Json.Linq; 9 11 10 12 namespace HeuristicLab.JsonInterface { … … 15 17 16 18 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 17 // TODO: inject data 18 throw new NotImplementedException(); 19 //Dictionary<string, IList<double>> dict = null; 20 var dictTmp = new Dictionary<string, IList>(); 21 /*if (data.Children[0].Value is JObject jObj) { 22 dict = jObj.ToObject<Dictionary<string, IList<double>>>(); 23 foreach (var x in dict) { 24 dictTmp.Add(x.Key, (IList)x.Value); 25 } 26 } else if(data.Children[0].Value is Dictionary<string, IList<double>> d) { 27 dict = d; 28 } else { 29 dictTmp = (Dictionary<string, IList>)data.Children[0].Value; 30 } 31 */ 32 DoubleNamedMatrixJsonItem matrix = data.Children[0] as DoubleNamedMatrixJsonItem; 33 if(matrix != null) { 34 int c = 0; 35 foreach(var col in matrix.RowNames) { 36 dictTmp.Add(col, new List<double>(matrix.Value[c])); 37 ++c; 38 } 39 } 40 41 dynamic val = (dynamic)item; 42 object dataset = (object)val.Dataset; 43 var dataInfo = dataset.GetType().GetField("variableValues", flags); 44 dataInfo.SetValue(dataset, dictTmp); 45 val.TargetVariable = (string)data.Children[3].Value; 46 val.TrainingPartition.Start = ((IntRangeJsonItem)data.Children[2]).Value.First(); 47 val.TrainingPartition.End = ((IntRangeJsonItem)data.Children[2]).Value.Last(); 48 val.TestPartition.Start = ((IntRangeJsonItem)data.Children[1]).Value.First(); 49 val.TestPartition.End = ((IntRangeJsonItem)data.Children[1]).Value.Last(); 19 50 } 20 51 … … 28 59 object dataset = (object)val.Dataset; 29 60 dynamic targetVariable = val.TargetVariable; 30 FieldInfo dataInfo = dataset.GetType().GetField("storableData", flags); 31 // TODO: aufteilen in trainings und test daten abschnitte 32 item.AddChildren(new JsonItem() { 33 Name = "Dataset", 34 Value = dataInfo.GetValue(dataset) 61 62 FieldInfo dataInfo = dataset.GetType().GetField("variableValues", flags); 63 64 if(dataInfo.GetValue(dataset) is Dictionary<string, IList> dict) { 65 int cols = dict.Count; 66 int rows = 0; 67 IList<string> rowNames = new List<string>(); 68 double[][] mat = new double[cols][]; 69 int c = 0; 70 foreach(var x in dict) { 71 rows = Math.Max(rows, x.Value.Count); 72 rowNames.Add(x.Key); 73 mat[c] = new double[rows]; 74 int r = 0; 75 foreach(var rowValue in x.Value) { 76 mat[c][r] = (double)rowValue; 77 ++r; 78 } 79 ++c; 80 } 81 item.AddChildren(new DoubleNamedMatrixJsonItem() { 82 Name = "Dataset", 83 Value = mat, 84 RowNames = rowNames 85 }); 86 } 87 88 var trainingPartition = ((IntRange)val.TrainingPartition); 89 var testPartition = ((IntRange)val.TestPartition); 90 91 item.AddChildren(new IntRangeJsonItem() { 92 Name = "TestPartition", 93 Value = new int[] { testPartition.Start, testPartition.End }, 94 Range = new int[] { 0, Math.Max(testPartition.End, trainingPartition.End) } 95 }); 96 97 98 item.AddChildren(new IntRangeJsonItem() { 99 Name = "TrainingPartition", 100 Value = new int[] { trainingPartition.Start, trainingPartition.End }, 101 Range = new int[] { 0, Math.Max(testPartition.End, trainingPartition.End)} 35 102 }); 36 103 … … 42 109 }); 43 110 44 45 item.AddChildren(new JsonItem() {111 /* 112 item.AddChildren(new StringArrayJsonItem() { 46 113 Name = "AllowedInputVariables", 47 Value = ( object)val.AllowedInputVariables,114 Value = (string[])val.AllowedInputVariables, 48 115 Range = variables.Select(x => x.Value) 49 }); 116 });*/ 50 117 return item; 51 118 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ResultParameterConverter.cs
r17446 r17451 15 15 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 16 16 IResultParameter res = value as IResultParameter; 17 return new Result Item() {17 return new ResultJsonItem() { 18 18 Name = res.ActualName, 19 19 ActualName = res.ActualName, -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs
r17433 r17451 27 27 item = tmp; 28 28 } else { 29 item.Range = new object[] { GetMinValue(param.DataType), GetMaxValue(param.DataType) }; 29 var min = GetMinValue(param.DataType); 30 var max = GetMaxValue(param.DataType); 31 if (min != null && max != null) 32 item.Range = new object[] { min, max }; 33 else 34 item.Range = null; 30 35 } 31 36 item.Name = param.Name; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueRangeConverter.cs
r17433 r17451 17 17 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 18 18 IntRange range = item as IntRange; 19 Int ArrayJsonItem cdata = data as IntArrayJsonItem;19 IntRangeJsonItem cdata = data as IntRangeJsonItem; 20 20 range.Start = cdata.Value[0]; 21 21 range.End = cdata.Value[1]; … … 39 39 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 40 40 DoubleRange range = item as DoubleRange; 41 Double ArrayJsonItem cdata = data as DoubleArrayJsonItem;41 DoubleRangeJsonItem cdata = data as DoubleRangeJsonItem; 42 42 range.Start = cdata.Value[0]; 43 43 range.End = cdata.Value[1]; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeArrayConverter.cs
r17433 r17451 40 40 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 41 41 DoubleArray arr = item as DoubleArray; 42 double[] d = CastValue<double[]>(data); 42 DoubleArrayJsonItem doubleItem = data as DoubleArrayJsonItem; 43 //double[] d = CastValue<double[]>(data); 43 44 bool resizeTmp = arr.Resizable; 44 45 arr.Resizable = true; 45 arr.Length = d.Length; 46 for (int i = 0; i < d.Length; ++i) 47 arr[i] = d[i]; 46 //arr.Length = d.Length; 47 arr.Length = doubleItem.Value.Length; 48 for (int i = 0; i < doubleItem.Value.Length; ++i) 49 arr[i] = doubleItem.Value[i]; 48 50 arr.Resizable = resizeTmp; 49 51 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeMatrixConverter.cs
r17433 r17451 33 33 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 34 34 DoubleMatrix mat = item as DoubleMatrix; 35 Double MatrixJsonItem d = data as DoubleMatrixJsonItem;35 DoubleNamedMatrixJsonItem d = data as DoubleNamedMatrixJsonItem; 36 36 CopyMatrixData(mat, d.Value); 37 37 } 38 38 39 39 public override IJsonItem Extract(IItem value, IJsonItemConverter root) => 40 new Double MatrixJsonItem() {40 new DoubleNamedMatrixJsonItem() { 41 41 Name = "[OverridableParamName]", 42 42 Description = value.ItemDescription, 43 43 Value = Transform((DoubleMatrix)value), 44 Range = new double[] { double.MinValue, double.MaxValue } 44 Range = new double[] { double.MinValue, double.MaxValue }, 45 RowNames = ((DoubleMatrix)value).RowNames, 46 ColumnNames = ((DoubleMatrix)value).ColumnNames 45 47 }; 46 48 } … … 90 92 #region Helper 91 93 protected void CopyMatrixData(MatrixType matrix, T[][] data) { 92 var rows = data.Length;93 var cols = data.Length > 0 ? data[0].Length : 0;94 var cols = data.Length; 95 var rows = data.Length > 0 ? data[0].Length : 0; 94 96 95 97 var rowInfo = matrix.GetType().GetProperty("Rows"); … … 100 102 for (int x = 0; x < rows; ++x) { 101 103 for (int y = 0; y < cols; ++y) { 102 matrix[x, y] = data[ x][y];104 matrix[x, y] = data[y][x]; 103 105 } 104 106 } … … 106 108 107 109 protected T[][] Transform(MatrixType matrix) { 108 T[][] m = new T[matrix. Rows][];109 for (int r = 0; r < matrix.Rows; ++r) {110 m[ r] = new T[matrix.Columns];111 for (int c = 0; c < matrix.Columns; ++c) {112 m[ r][c] = matrix[r, c];110 T[][] m = new T[matrix.Columns][]; 111 for (int column = 0; column < matrix.Columns; ++column) { 112 m[column] = new T[matrix.Rows]; 113 for (int row = 0; row < matrix.Rows; ++row) { 114 m[column][row] = matrix[row, column]; 113 115 } 114 116 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r17446 r17451 71 71 <Compile Include="Interfaces\IJsonItemValidator.cs" /> 72 72 <Compile Include="Interfaces\IMatrixJsonItem.cs" /> 73 <Compile Include="Interfaces\INamedMatrixJsonItem.cs" /> 73 74 <Compile Include="Models\ArrayJsonItemBase.cs" /> 74 75 <Compile Include="Models\BoolJsonItems.cs" /> … … 79 80 <Compile Include="Models\JsonItem.cs" /> 80 81 <Compile Include="Models\MatrixJsonItemBase.cs" /> 81 <Compile Include="Models\ResultItem.cs" /> 82 <Compile Include="Models\NamedMatrixJsonItemBase.cs" /> 83 <Compile Include="Models\ResultJsonItem.cs" /> 82 84 <Compile Include="Models\StringJsonItem.cs" /> 83 85 <Compile Include="Models\UnsupportedJsonItem.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Interfaces/IJsonItem.cs
r17446 r17451 9 9 namespace HeuristicLab.JsonInterface { 10 10 public interface IJsonItem { 11 bool Active { get; set; } 11 12 string Name { get; set; } 12 13 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs
r17439 r17451 41 41 // filter result items 42 42 foreach (var item in jsonItems) { 43 if (item is Result Item)43 if (item is ResultJsonItem) 44 44 resultItems.Add(Serialize(item)); 45 45 else … … 60 60 // serializes ParameterizedItems and saves them in list "JsonItems". 61 61 private void PopulateJsonItems(IJsonItem item, IList<IJsonItem> jsonItems) { 62 IEnumerable<IJsonItem> tmpParameter= item.Children;62 IEnumerable<IJsonItem> children = item.Children; 63 63 64 if (item. Value != null || item.Range != null || item is ResultItem || item.ActualName != null) {64 if (item.Active && (item.Value != null || item.Range != null || item is ResultJsonItem || item.ActualName != null)) { 65 65 jsonItems.Add(item); 66 66 } 67 67 68 if ( tmpParameter!= null) {69 foreach (var p in tmpParameter) {68 if (children != null) { 69 foreach (var p in children) { 70 70 PopulateJsonItems(p, jsonItems); 71 71 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/DoubleJsonItems.cs
r17446 r17451 23 23 } 24 24 } 25 26 public class DoubleNamedMatrixJsonItem : NamedMatrixJsonItemBase<double> { 27 protected override bool IsInRange() { 28 for (int c = 0; c < Value.Length; ++c) { 29 for (int r = 0; r < Value[c].Length; ++r) { 30 if (Value[c][r] < Range.First() && Range.Last() < Value[c][r]) 31 return false; 32 } 33 } 34 return true; 35 } 36 } 25 37 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/IntJsonItems.cs
r17446 r17451 6 6 7 7 namespace HeuristicLab.JsonInterface { 8 public class IntJsonItem : JsonItem<int> { } 8 public class IntJsonItem : JsonItem<int> { 9 /*I 10 public int MinValue { get; set; } 11 public int MaxValue { get; set; } 12 */ 13 } 9 14 public class IntArrayJsonItem : ArrayJsonItemBase<int> { } 10 15 public class IntRangeJsonItem : ArrayJsonItemBase<int> { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/JsonItem.cs
r17446 r17451 66 66 public virtual IEnumerable<object> Range { get; set; } 67 67 68 // TODO eigene items für LookUp? 68 69 public virtual string ActualName { get; set; } 70 71 // TODO jsonIgnore dataType? 69 72 70 73 [JsonIgnore] … … 73 76 [JsonIgnore] 74 77 public virtual IJsonItem Parent { get; set; } 78 79 [JsonIgnore] 80 public virtual bool Active { get; set; } 75 81 76 82 #region Constructors … … 81 87 } 82 88 #endregion 83 84 #region Public Static Methods 85 public static void Merge(JsonItem target, JsonItem from) { 86 target.Name = from.Name ?? target.Name; 87 target.Range = from.Range ?? target.Range; 88 target.Value = from.Value ?? target.Value; 89 target.ActualName = from.ActualName ?? target.ActualName; 90 if(target.Children != null) { 91 if (from.Children != null) 92 ((List<IJsonItem>)from.Children).AddRange(target.Children); 93 } else { 94 target.Children = from.Children; 95 } 96 } 97 #endregion 98 89 99 90 #region Public Methods 100 91 public void AddChildren(params IJsonItem[] childs) => … … 124 115 125 116 #region Helper 117 /* 118 * TODO protected abstract bool Validate(); 119 */ 120 126 121 protected virtual bool IsInRange() { 127 122 bool b1 = true, b2 = true; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/ResultJsonItem.cs
r17450 r17451 6 6 7 7 namespace HeuristicLab.JsonInterface { 8 public class Result Item : JsonItem {8 public class ResultJsonItem : JsonItem { 9 9 10 10 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/StringJsonItem.cs
r17446 r17451 7 7 namespace HeuristicLab.JsonInterface { 8 8 public class StringJsonItem : JsonItem<string> { } 9 public class StringArrayJsonItem : JsonItem<string[], string> { } 9 10 }
Note: See TracChangeset
for help on using the changeset viewer.