- Timestamp:
- 09/08/16 11:41:45 (8 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 8 added
- 3 deleted
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r14251 r14277 32 32 using HeuristicLab.Problems.DataAnalysis.Symbolic; 33 33 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 34 using HeuristicLab.Random; 34 35 35 36 namespace HeuristicLab.Algorithms.DataAnalysis { … … 44 45 private const string ModelStructureParameterName = "Model structure"; 45 46 private const string IterationsParameterName = "Iterations"; 47 private const string RestartsParameterName = "Restarts"; 48 private const string SetSeedRandomlyParameterName = "SetSeedRandomly"; 49 private const string SeedParameterName = "Seed"; 46 50 47 51 public IFixedValueParameter<StringValue> ModelStructureParameter { … … 50 54 public IFixedValueParameter<IntValue> IterationsParameter { 51 55 get { return (IFixedValueParameter<IntValue>)Parameters[IterationsParameterName]; } 56 } 57 58 public IFixedValueParameter<BoolValue> SetSeedRandomlyParameter { 59 get { return (IFixedValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; } 60 } 61 62 public IFixedValueParameter<IntValue> SeedParameter { 63 get { return (IFixedValueParameter<IntValue>)Parameters[SeedParameterName]; } 64 } 65 66 public IFixedValueParameter<IntValue> RestartsParameter { 67 get { return (IFixedValueParameter<IntValue>)Parameters[RestartsParameterName]; } 52 68 } 53 69 … … 62 78 } 63 79 80 public int Restarts { 81 get { return RestartsParameter.Value.Value; } 82 set { RestartsParameter.Value.Value = value; } 83 } 84 85 public int Seed { 86 get { return SeedParameter.Value.Value; } 87 set { SeedParameter.Value.Value = value; } 88 } 89 90 public bool SetSeedRandomly { 91 get { return SetSeedRandomlyParameter.Value.Value; } 92 set { SetSeedRandomlyParameter.Value.Value = value; } 93 } 64 94 65 95 [StorableConstructor] … … 73 103 Parameters.Add(new FixedValueParameter<StringValue>(ModelStructureParameterName, "The function for which the parameters must be fit (only numeric constants are tuned).", new StringValue("1.0 * x*x + 0.0"))); 74 104 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "The maximum number of iterations for constants optimization.", new IntValue(200))); 75 } 105 Parameters.Add(new FixedValueParameter<IntValue>(RestartsParameterName, "The number of independent random restarts", new IntValue(10))); 106 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The PRNG seed value.", new IntValue())); 107 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "Switch to determine if the random number seed should be initialized randomly.", new BoolValue(true))); 108 } 109 76 110 [StorableHook(HookType.AfterDeserialization)] 77 private void AfterDeserialization() { } 111 private void AfterDeserialization() { 112 // BackwardsCompatibility3.3 113 #region Backwards compatible code, remove with 3.4 114 if (!Parameters.ContainsKey(RestartsParameterName)) 115 Parameters.Add(new FixedValueParameter<IntValue>(RestartsParameterName, "The number of independent random restarts", new IntValue(1))); 116 if (!Parameters.ContainsKey(SeedParameterName)) 117 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The PRNG seed value.", new IntValue())); 118 if (!Parameters.ContainsKey(SetSeedRandomlyParameterName)) 119 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "Switch to determine if the random number seed should be initialized randomly.", new BoolValue(true))); 120 #endregion 121 } 78 122 79 123 public override IDeepCloneable Clone(Cloner cloner) { … … 83 127 #region nonlinear regression 84 128 protected override void Run() { 85 var solution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations); 86 Results.Add(new Result(RegressionSolutionResultName, "The nonlinear regression solution.", solution)); 87 Results.Add(new Result("Root mean square error (train)", "The root of the mean of squared errors of the regression solution on the training set.", new DoubleValue(solution.TrainingRootMeanSquaredError))); 88 Results.Add(new Result("Root mean square error (test)", "The root of the mean of squared errors of the regression solution on the test set.", new DoubleValue(solution.TestRootMeanSquaredError))); 89 } 90 91 public static ISymbolicRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData, string modelStructure, int maxIterations) { 129 if (SetSeedRandomly) Seed = (new System.Random()).Next(); 130 var rand = new MersenneTwister((uint)Seed); 131 IRegressionSolution bestSolution = null; 132 for (int r = 0; r < Restarts; r++) { 133 var solution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand); 134 if (bestSolution == null || solution.TrainingRootMeanSquaredError < bestSolution.TrainingRootMeanSquaredError) { 135 bestSolution = solution; 136 } 137 } 138 139 Results.Add(new Result(RegressionSolutionResultName, "The nonlinear regression solution.", bestSolution)); 140 Results.Add(new Result("Root mean square error (train)", "The root of the mean of squared errors of the regression solution on the training set.", new DoubleValue(bestSolution.TrainingRootMeanSquaredError))); 141 Results.Add(new Result("Root mean square error (test)", "The root of the mean of squared errors of the regression solution on the test set.", new DoubleValue(bestSolution.TestRootMeanSquaredError))); 142 143 } 144 145 /// <summary> 146 /// Fits a model to the data by optimizing the numeric constants. 147 /// Model is specified as infix expression containing variable names and numbers. 148 /// The starting point for the numeric constants is initialized randomly if a random number generator is specified (~N(0,1)). Otherwise the user specified constants are 149 /// used as a starting point. 150 /// </summary> 151 /// <param name="problemData">Training and test data</param> 152 /// <param name="modelStructure">The function as infix expression</param> 153 /// <param name="maxIterations">Number of constant optimization iterations (using Levenberg-Marquardt algorithm)</param> 154 /// <param name="random">Optional random number generator for random initialization of numeric constants.</param> 155 /// <returns></returns> 156 public static ISymbolicRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData, string modelStructure, int maxIterations, IRandom random = null) { 92 157 var parser = new InfixExpressionParser(); 93 158 var tree = parser.Parse(modelStructure); … … 117 182 if (!SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)) throw new ArgumentException("The optimizer does not support the specified model structure."); 118 183 184 // initialize constants randomly 185 if (random != null) { 186 foreach (var node in tree.IterateNodesPrefix().OfType<ConstantTreeNode>()) { 187 node.Value = NormalDistributedRandom.NextDouble(random, 0, 1); 188 } 189 } 119 190 var interpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); 191 120 192 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, 121 193 applyLinearScaling: false, maxIterations: maxIterations, 122 194 updateVariableWeights: false, updateConstantsInTree: true); 123 124 195 125 196 var scaledModel = new SymbolicRegressionModel(problemData.TargetVariable, tree, (ISymbolicDataAnalysisExpressionTreeInterpreter)interpreter.Clone()); -
branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4
- Property svn:ignore
-
old new 1 1 ComparisonFilterView.resx 2 2 FilterView.resx 3 *.user
-
- Property svn:ignore
-
branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4/HistogramView.Designer.cs
r14185 r14277 49 49 this.label1 = new System.Windows.Forms.Label(); 50 50 this.classifierComboBox = new System.Windows.Forms.ComboBox(); 51 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 52 this.splitContainer.Panel1.SuspendLayout(); 53 this.splitContainer.SuspendLayout(); 51 54 this.optionsBox.SuspendLayout(); 52 55 this.SuspendLayout(); 53 56 // 57 // splitContainer 58 // 59 // 60 // splitContainer.Panel1 61 // 62 this.splitContainer.Panel1.Controls.Add(this.optionsBox); 63 // 54 64 // optionsBox 55 65 // 56 this.optionsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 66 this.optionsBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 67 | System.Windows.Forms.AnchorStyles.Right))); 57 68 this.optionsBox.Controls.Add(this.displayDetailsCheckBox); 58 69 this.optionsBox.Controls.Add(this.label1); 59 70 this.optionsBox.Controls.Add(this.classifierComboBox); 60 this.optionsBox.Location = new System.Drawing.Point(5, 324); 61 this.optionsBox.Margin = new System.Windows.Forms.Padding(4); 71 this.optionsBox.Location = new System.Drawing.Point(4, 262); 62 72 this.optionsBox.Name = "optionsBox"; 63 this.optionsBox.Padding = new System.Windows.Forms.Padding(4); 64 this.optionsBox.Size = new System.Drawing.Size(203, 165); 73 this.optionsBox.Size = new System.Drawing.Size(84, 138); 65 74 this.optionsBox.TabIndex = 7; 66 75 this.optionsBox.TabStop = false; … … 70 79 // 71 80 this.displayDetailsCheckBox.AutoSize = true; 72 this.displayDetailsCheckBox.Location = new System.Drawing.Point(7, 71); 81 this.displayDetailsCheckBox.Location = new System.Drawing.Point(5, 58); 82 this.displayDetailsCheckBox.Margin = new System.Windows.Forms.Padding(2); 73 83 this.displayDetailsCheckBox.Name = "displayDetailsCheckBox"; 74 84 this.displayDetailsCheckBox.RightToLeft = System.Windows.Forms.RightToLeft.Yes; 75 this.displayDetailsCheckBox.Size = new System.Drawing.Size(1 53, 21);85 this.displayDetailsCheckBox.Size = new System.Drawing.Size(119, 17); 76 86 this.displayDetailsCheckBox.TabIndex = 3; 77 87 this.displayDetailsCheckBox.Text = "Display value count"; … … 82 92 // 83 93 this.label1.AutoSize = true; 84 this.label1.Location = new System.Drawing.Point(4, 19); 85 this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 94 this.label1.Location = new System.Drawing.Point(3, 15); 86 95 this.label1.Name = "label1"; 87 this.label1.Size = new System.Drawing.Size( 108, 17);96 this.label1.Size = new System.Drawing.Size(81, 13); 88 97 this.label1.TabIndex = 2; 89 98 this.label1.Text = "Target variable:"; … … 91 100 // classifierComboBox 92 101 // 102 this.classifierComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 103 | System.Windows.Forms.AnchorStyles.Right))); 93 104 this.classifierComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 94 105 this.classifierComboBox.FormattingEnabled = true; 95 this.classifierComboBox.Location = new System.Drawing.Point(7, 40); 96 this.classifierComboBox.Margin = new System.Windows.Forms.Padding(4); 106 this.classifierComboBox.Location = new System.Drawing.Point(5, 32); 97 107 this.classifierComboBox.Name = "classifierComboBox"; 98 this.classifierComboBox.Size = new System.Drawing.Size( 160, 24);108 this.classifierComboBox.Size = new System.Drawing.Size(73, 21); 99 109 this.classifierComboBox.TabIndex = 1; 100 110 this.classifierComboBox.SelectedIndexChanged += new System.EventHandler(this.classifierComboBox_SelectedIndexChanged); … … 102 112 // HistogramView 103 113 // 104 this.AutoScaleDimensions = new System.Drawing.SizeF( 8F, 16F);114 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 105 115 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 106 this.Controls.Add(this.optionsBox); 107 this.Margin = new System.Windows.Forms.Padding(5); 116 this.Margin = new System.Windows.Forms.Padding(4); 108 117 this.Name = "HistogramView"; 109 this.Controls.SetChildIndex(this.optionsBox, 0); 118 this.splitContainer.Panel1.ResumeLayout(false); 119 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 120 this.splitContainer.ResumeLayout(false); 110 121 this.optionsBox.ResumeLayout(false); 111 122 this.optionsBox.PerformLayout(); -
branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4/LineChartView.Designer.cs
r14185 r14277 47 47 this.optionsBox = new System.Windows.Forms.GroupBox(); 48 48 this.allInOneCheckBox = new System.Windows.Forms.CheckBox(); 49 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 50 this.splitContainer.Panel1.SuspendLayout(); 51 this.splitContainer.SuspendLayout(); 49 52 this.optionsBox.SuspendLayout(); 50 53 this.SuspendLayout(); 51 54 // 55 // splitContainer 56 // 57 // 58 // splitContainer.Panel1 59 // 60 this.splitContainer.Panel1.Controls.Add(this.optionsBox); 61 // 52 62 // optionsBox 53 63 // 54 this.optionsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 64 this.optionsBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 65 | System.Windows.Forms.AnchorStyles.Right))); 55 66 this.optionsBox.Controls.Add(this.allInOneCheckBox); 56 67 this.optionsBox.Location = new System.Drawing.Point(4, 262); 57 68 this.optionsBox.Name = "optionsBox"; 58 this.optionsBox.Size = new System.Drawing.Size( 151, 134);69 this.optionsBox.Size = new System.Drawing.Size(84, 138); 59 70 this.optionsBox.TabIndex = 7; 60 71 this.optionsBox.TabStop = false; … … 78 89 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 79 90 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 80 this.Controls.Add(this.optionsBox);81 91 this.Name = "LineChartView"; 82 this.Controls.SetChildIndex(this.optionsBox, 0); 92 this.splitContainer.Panel1.ResumeLayout(false); 93 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 94 this.splitContainer.ResumeLayout(false); 83 95 this.optionsBox.ResumeLayout(false); 84 96 this.optionsBox.PerformLayout(); -
branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingChartView.Designer.cs
r14185 r14277 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.dataTableView = new DataPreprocessing.Views.PreprocessingDataTableView();48 47 this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 48 this.dataTableView = new HeuristicLab.DataPreprocessing.Views.PreprocessingDataTableView(); 49 this.splitContainer = new System.Windows.Forms.SplitContainer(); 49 50 this.checkedItemList = new HeuristicLab.DataPreprocessing.Views.PreprocessingCheckedItemListView(); 50 51 this.tableLayoutPanel.SuspendLayout(); 52 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 53 this.splitContainer.Panel1.SuspendLayout(); 54 this.splitContainer.Panel2.SuspendLayout(); 55 this.splitContainer.SuspendLayout(); 51 56 this.SuspendLayout(); 57 // 58 // tableLayoutPanel 59 // 60 this.tableLayoutPanel.ColumnCount = 1; 61 this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); 62 this.tableLayoutPanel.Controls.Add(this.dataTableView, 0, 0); 63 this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; 64 this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0); 65 this.tableLayoutPanel.Name = "tableLayoutPanel"; 66 this.tableLayoutPanel.RowCount = 1; 67 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); 68 this.tableLayoutPanel.Size = new System.Drawing.Size(559, 403); 69 this.tableLayoutPanel.TabIndex = 6; 70 this.tableLayoutPanel.Layout += new System.Windows.Forms.LayoutEventHandler(this.tableLayoutPanel_Layout); 52 71 // 53 72 // dataTableView 54 73 // 74 this.dataTableView.AutoScroll = true; 55 75 this.dataTableView.Caption = "DataTable View"; 76 this.dataTableView.Classification = null; 56 77 this.dataTableView.Content = null; 57 78 this.dataTableView.Dock = System.Windows.Forms.DockStyle.Fill; 79 this.dataTableView.IsDetailedChartViewEnabled = false; 58 80 this.dataTableView.Location = new System.Drawing.Point(3, 3); 59 81 this.dataTableView.Name = "dataTableView"; 60 82 this.dataTableView.ReadOnly = false; 61 this.dataTableView.Size = new System.Drawing.Size( 486, 390);83 this.dataTableView.Size = new System.Drawing.Size(553, 397); 62 84 this.dataTableView.TabIndex = 0; 63 85 // 64 // tableLayoutPanel86 // splitContainer 65 87 // 66 this. tableLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)67 | System.Windows.Forms.AnchorStyles.Left)68 | System.Windows.Forms.AnchorStyles.Right)));69 this.tableLayoutPanel.AutoScroll = true;70 this.tableLayoutPanel.ColumnCount = 1;71 this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());72 this. tableLayoutPanel.Controls.Add(this.dataTableView, 0, 0);73 this.tableLayoutPanel.Location = new System.Drawing.Point(162, 4);74 this.tableLayoutPanel.Name = "tableLayoutPanel";75 this.tableLayoutPanel.RowCount = 1;76 this. tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());77 this. tableLayoutPanel.Size = new System.Drawing.Size(492, 396);78 this. tableLayoutPanel.TabIndex = 6;79 this. tableLayoutPanel.Layout += new System.Windows.Forms.LayoutEventHandler(this.tableLayoutPanel_Layout);88 this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill; 89 this.splitContainer.Location = new System.Drawing.Point(0, 0); 90 this.splitContainer.Name = "splitContainer"; 91 // 92 // splitContainer.Panel1 93 // 94 this.splitContainer.Panel1.Controls.Add(this.checkedItemList); 95 // 96 // splitContainer.Panel2 97 // 98 this.splitContainer.Panel2.Controls.Add(this.tableLayoutPanel); 99 this.splitContainer.Size = new System.Drawing.Size(654, 403); 100 this.splitContainer.SplitterDistance = 91; 101 this.splitContainer.TabIndex = 7; 80 102 // 81 103 // checkedItemList 82 104 // 83 this.checkedItemList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 84 | System.Windows.Forms.AnchorStyles.Left))); 105 this.checkedItemList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 106 | System.Windows.Forms.AnchorStyles.Left) 107 | System.Windows.Forms.AnchorStyles.Right))); 85 108 this.checkedItemList.Caption = "View"; 86 109 this.checkedItemList.Content = null; … … 88 111 this.checkedItemList.Name = "checkedItemList"; 89 112 this.checkedItemList.ReadOnly = false; 90 this.checkedItemList.Size = new System.Drawing.Size( 152, 252);113 this.checkedItemList.Size = new System.Drawing.Size(84, 252); 91 114 this.checkedItemList.TabIndex = 4; 92 115 // … … 95 118 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 96 119 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 97 this.Controls.Add(this.tableLayoutPanel); 98 this.Controls.Add(this.checkedItemList); 120 this.Controls.Add(this.splitContainer); 99 121 this.Name = "PreprocessingChartView"; 100 122 this.Size = new System.Drawing.Size(654, 403); 101 123 this.tableLayoutPanel.ResumeLayout(false); 124 this.splitContainer.Panel1.ResumeLayout(false); 125 this.splitContainer.Panel2.ResumeLayout(false); 126 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 127 this.splitContainer.ResumeLayout(false); 102 128 this.ResumeLayout(false); 103 129 … … 109 135 private DataPreprocessing.Views.PreprocessingDataTableView dataTableView; 110 136 private System.Windows.Forms.TableLayoutPanel tableLayoutPanel; 137 protected System.Windows.Forms.SplitContainer splitContainer; 111 138 } 112 139 } -
branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingChartView.cs
r14185 r14277 59 59 //Add or remove data row 60 60 private void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) { 61 61 tableLayoutPanel.SuspendLayout(); 62 62 foreach (IndexedItem<StringValue> item in checkedItems.Items) { 63 63 string variableName = item.Value.Value; 64 64 65 // variable is displayed -> remove66 if ( VariableIsDisplayed(variableName)) {67 dataTable .Rows.Remove(variableName);65 // not checked -> remove 66 if (!VariableIsChecked(variableName)) { 67 dataTableView.SetRowEnabled(variableName, false); 68 68 dataTable.SelectedRows.Remove(variableName); 69 69 dataTablePerVariable.Remove(dataTablePerVariable.Find(x => (x.Name == variableName))); 70 //variable isnt't displayed -> add71 70 } else { 72 71 DataRow row = GetDataRow(variableName); 73 72 DataRow selectedRow = GetSelectedDataRow(variableName); 74 dataTable .Rows.Add(row);73 dataTableView.SetRowEnabled(variableName, true); 75 74 76 75 PreprocessingDataTable pdt = new PreprocessingDataTable(variableName); 77 76 pdt.Rows.Add(row); 78 dataTablePerVariable.Add(pdt); 77 // dataTablePerVariable does not contain unchecked variables => reduce insert position by number of uncheckt variables to correct the index 78 int uncheckedUntilVariable = checkedItemList.Content.TakeWhile(x => x.Value != variableName).Count(x => !checkedItemList.Content.ItemChecked(x)); 79 dataTablePerVariable.Insert(item.Index - uncheckedUntilVariable, pdt); 79 80 80 81 //update selection … … 89 90 if (Content != null && !Content.AllInOneMode) 90 91 GenerateChart(); 91 92 } 93 94 private bool VariableIsDisplayed(string name) { 95 96 foreach (var item in dataTable.Rows) { 97 if (item.Name == name) 98 return true; 99 } 100 return false; 92 tableLayoutPanel.ResumeLayout(true); 93 } 94 95 private bool VariableIsChecked(string name) { 96 return Content.VariableItemList.CheckedItems.Any(x => x.Value.Value == name); 101 97 } 102 98 … … 158 154 dataTable.SelectedRows.Clear(); 159 155 foreach (var selectedRow in selectedDataRows) { 160 if (VariableIs Displayed(selectedRow.Name))156 if (VariableIsChecked(selectedRow.Name)) 161 157 dataTable.SelectedRows.Add(selectedRow); 162 158 } -
branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingDataTableView.cs
r14185 r14277 139 139 } 140 140 } else MessageBox.Show("Nothing to configure."); 141 } 142 143 public bool IsRowEnabled(string name) { 144 return chart.Series.FindByName(name) != null && chart.Series[name].Enabled; 145 } 146 public void SetRowEnabled(string name, bool enabled) { 147 if (chart.Series.FindByName(name) != null) 148 chart.Series[name].Enabled = enabled; 141 149 } 142 150 -
branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Datatypes.cs
r14276 r14277 49 49 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] 50 50 internal class igraph_matrix_t { 51 i graph_vector_t data = new igraph_vector_t();51 internal igraph_vector_t data = new igraph_vector_t(); 52 52 internal int nrow; 53 53 internal int ncol; … … 128 128 #endregion 129 129 130 #region Delegates 131 [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] 132 internal delegate bool igraph_bfshandler_t(igraph_t graph, int vid, int pred, int succ, int rank, int dist, IntPtr extra); 133 134 [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] 135 internal delegate bool igraph_dfshandler_t(igraph_t graph, int vid, int dist, IntPtr extra); 136 #endregion 137 130 138 #region Enums 131 139 internal enum igraph_layout_grid_t { -
branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/DllImporter.cs
r14276 r14277 87 87 arpackoptions.nev = 1; 88 88 arpackoptions.ishift = 1; 89 arpackoptions.mxiter = 3000;89 arpackoptions.mxiter = 1000; 90 90 arpackoptions.nb = 1; 91 91 arpackoptions.mode = 1; … … 109 109 internal static int igraph_add_edge(igraph_t graph, int from, int to) { 110 110 return X86 ? igraph_add_edge_x86(graph, from, to) : igraph_add_edge_x64(graph, from, to); 111 } 112 #endregion 113 114 #region igraph visits 115 internal static int igraph_bfs(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, igraph_vector_t order, igraph_vector_t rank, igraph_vector_t father, igraph_vector_t pred, igraph_vector_t succ, igraph_vector_t dist, igraph_bfshandler_t callback, object tag) { 116 return MarshalIfExistsAndCall(tag, ptr => X86 ? igraph_bfs_x86(graph, root, roots, mode, unreachable, restricted, order, rank, father, pred, succ, dist, callback, ptr) : igraph_bfs_x64(graph, root, roots, mode, unreachable, restricted, order, rank, father, pred, succ, dist, callback, ptr)); 117 } 118 internal static int igraph_dfs(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, igraph_vector_t order, igraph_vector_t order_out, igraph_vector_t father, igraph_vector_t dist, igraph_dfshandler_t inWrapper, igraph_dfshandler_t outWrapper, object tag) { 119 return MarshalIfExistsAndCall(tag, ptr => X86 ? igraph_dfs_x86(graph, root, mode, unreachable, order, order_out, father, dist, inWrapper, outWrapper, ptr) : igraph_dfs_x64(graph, root, mode, unreachable, order, order_out, father, dist, inWrapper, outWrapper, ptr)); 111 120 } 112 121 #endregion … … 137 146 [DllImport(X64Dll, EntryPoint = "igraph_pagerank", CallingConvention = CallingConvention.Cdecl)] 138 147 private static extern int igraph_pagerank_x64(igraph_t graph, igraph_pagerank_algo_t algo, [In, Out]igraph_vector_t vector, ref double value, igraph_vs_t vids, bool directed, double damping, igraph_vector_t weights, IntPtr options); 148 [DllImport(X86Dll, EntryPoint = "igraph_bfs", CallingConvention = CallingConvention.Cdecl)] 149 private static extern int igraph_bfs_x86(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t rank, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t pred, [In, Out]igraph_vector_t succ, [In, Out]igraph_vector_t dist, igraph_bfshandler_t callback, IntPtr extra); 150 [DllImport(X64Dll, EntryPoint = "igraph_bfs", CallingConvention = CallingConvention.Cdecl)] 151 private static extern int igraph_bfs_x64(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t rank, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t pred, [In, Out]igraph_vector_t succ, [In, Out]igraph_vector_t dist, igraph_bfshandler_t callback, IntPtr extra); 152 [DllImport(X86Dll, EntryPoint = "igraph_dfs", CallingConvention = CallingConvention.Cdecl)] 153 private static extern int igraph_dfs_x86(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t order_out, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t dist, igraph_dfshandler_t in_callback, igraph_dfshandler_t out_callback, IntPtr extra); 154 [DllImport(X64Dll, EntryPoint = "igraph_dfs", CallingConvention = CallingConvention.Cdecl)] 155 private static extern int igraph_dfs_x64(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t order_out, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t dist, igraph_dfshandler_t in_callback, igraph_dfshandler_t out_callback, IntPtr extra); 139 156 #endregion 140 157 #endregion … … 168 185 return X86 ? igraph_vector_init_x86(vector, length) : igraph_vector_init_x64(vector, length); 169 186 } 187 internal static int igraph_vector_init_copy(igraph_vector_t vector, double[] vec) { 188 return X86 ? igraph_vector_init_copy_x86(vector, vec, vec.Length) : igraph_vector_init_copy_x64(vector, vec, vec.Length); 189 } 170 190 internal static void igraph_vector_destroy(igraph_vector_t vector) { 171 191 if (X86) igraph_vector_destroy_x86(vector); … … 175 195 return X86 ? igraph_vector_copy_x86(to, from) : igraph_vector_copy_x64(to, from); 176 196 } 197 internal static double[] igraph_vector_to_array(igraph_vector_t from) { 198 var len = igraph_vector_size(from); 199 var result = new double[len]; 200 if (X86) igraph_vector_copy_to_x86(from, result); 201 else igraph_vector_copy_to_x64(from, result); 202 return result; 203 } 177 204 178 205 internal static int igraph_vector_size(igraph_vector_t vector) { … … 187 214 if (X86) igraph_vector_set_x86(vector, index, value); 188 215 else igraph_vector_set_x64(vector, index, value); 216 } 217 internal static void igraph_vector_fill(igraph_vector_t vector, double v) { 218 if (X86) igraph_vector_fill_x86(vector, v); 219 else igraph_vector_fill_x64(vector, v); 220 } 221 internal static void igraph_vector_scale(igraph_vector_t vector, double by) { 222 if (X86) igraph_vector_scale_x86(vector, by); 223 else igraph_vector_scale_x64(vector, by); 224 } 225 226 internal static int igraph_vector_reverse(igraph_vector_t vector) { 227 return X86 ? igraph_vector_reverse_x86(vector) : igraph_vector_reverse_x64(vector); 228 } 229 internal static int igraph_vector_shuffle(igraph_vector_t vector) { 230 return X86 ? igraph_vector_shuffle_x86(vector) : igraph_vector_shuffle_x64(vector); 189 231 } 190 232 … … 194 236 [DllImport(X64Dll, EntryPoint = "igraph_vector_init", CallingConvention = CallingConvention.Cdecl)] 195 237 private static extern int igraph_vector_init_x64([In, Out]igraph_vector_t vector, int length); 238 [DllImport(X86Dll, EntryPoint = "igraph_vector_init_copy", CallingConvention = CallingConvention.Cdecl)] 239 private static extern int igraph_vector_init_copy_x86([In, Out]igraph_vector_t vector, double[] vec, int length); 240 [DllImport(X64Dll, EntryPoint = "igraph_vector_init_copy", CallingConvention = CallingConvention.Cdecl)] 241 private static extern int igraph_vector_init_copy_x64([In, Out]igraph_vector_t vector, double[] vec, int length); 196 242 [DllImport(X86Dll, EntryPoint = "igraph_vector_destroy", CallingConvention = CallingConvention.Cdecl)] 197 243 private static extern void igraph_vector_destroy_x86([In, Out]igraph_vector_t vector); … … 214 260 [DllImport(X64Dll, EntryPoint = "igraph_vector_copy", CallingConvention = CallingConvention.Cdecl)] 215 261 private static extern int igraph_vector_copy_x64([In, Out]igraph_vector_t to, igraph_vector_t from); 262 [DllImport(X86Dll, EntryPoint = "igraph_vector_copy_to", CallingConvention = CallingConvention.Cdecl)] 263 private static extern void igraph_vector_copy_to_x86(igraph_vector_t from, [In, Out]double[] to); 264 [DllImport(X64Dll, EntryPoint = "igraph_vector_copy_to", CallingConvention = CallingConvention.Cdecl)] 265 private static extern void igraph_vector_copy_to_x64(igraph_vector_t from, [In, Out]double[] to); 266 [DllImport(X86Dll, EntryPoint = "igraph_vector_fill", CallingConvention = CallingConvention.Cdecl)] 267 private static extern int igraph_vector_fill_x86([In, Out]igraph_vector_t vector, double v); 268 [DllImport(X64Dll, EntryPoint = "igraph_vector_fill", CallingConvention = CallingConvention.Cdecl)] 269 private static extern int igraph_vector_fill_x64([In, Out]igraph_vector_t vector, double v); 270 [DllImport(X86Dll, EntryPoint = "igraph_vector_reverse", CallingConvention = CallingConvention.Cdecl)] 271 private static extern int igraph_vector_reverse_x86([In, Out]igraph_vector_t vector); 272 [DllImport(X64Dll, EntryPoint = "igraph_vector_reverse", CallingConvention = CallingConvention.Cdecl)] 273 private static extern int igraph_vector_reverse_x64([In, Out]igraph_vector_t vector); 274 [DllImport(X86Dll, EntryPoint = "igraph_vector_shuffle", CallingConvention = CallingConvention.Cdecl)] 275 private static extern int igraph_vector_shuffle_x86([In, Out]igraph_vector_t vector); 276 [DllImport(X64Dll, EntryPoint = "igraph_vector_shuffle", CallingConvention = CallingConvention.Cdecl)] 277 private static extern int igraph_vector_shuffle_x64([In, Out]igraph_vector_t vector); 278 [DllImport(X86Dll, EntryPoint = "igraph_vector_scale", CallingConvention = CallingConvention.Cdecl)] 279 private static extern void igraph_vector_scale_x86([In, Out]igraph_vector_t vector, double by); 280 [DllImport(X64Dll, EntryPoint = "igraph_vector_scale", CallingConvention = CallingConvention.Cdecl)] 281 private static extern void igraph_vector_scale_x64([In, Out]igraph_vector_t vector, double by); 216 282 #endregion 217 283 #endregion … … 236 302 if (X86) igraph_matrix_set_x86(matrix, row, col, value); 237 303 else igraph_matrix_set_x64(matrix, row, col, value); 304 } 305 306 internal static void igraph_matrix_fill(igraph_matrix_t matrix, double v) { 307 if (X86) igraph_matrix_fill_x86(matrix, v); 308 else igraph_matrix_fill_x64(matrix, v); 309 } 310 311 internal static int igraph_matrix_transpose(igraph_matrix_t matrix) { 312 return X86 ? igraph_matrix_transpose_x86(matrix) : igraph_matrix_transpose_x64(matrix); 313 } 314 315 internal static void igraph_matrix_scale(igraph_matrix_t matrix, double by) { 316 if (X86) igraph_matrix_scale_x86(matrix, by); 317 else igraph_matrix_scale_x64(matrix, by); 238 318 } 239 319 … … 259 339 [DllImport(X64Dll, EntryPoint = "igraph_matrix_copy", CallingConvention = CallingConvention.Cdecl)] 260 340 private static extern int igraph_matrix_copy_x64([In, Out]igraph_matrix_t to, igraph_matrix_t from); 341 [DllImport(X86Dll, EntryPoint = "igraph_matrix_fill", CallingConvention = CallingConvention.Cdecl)] 342 private static extern void igraph_matrix_fill_x86([In, Out]igraph_matrix_t matrix, double v); 343 [DllImport(X64Dll, EntryPoint = "igraph_matrix_fill", CallingConvention = CallingConvention.Cdecl)] 344 private static extern void igraph_matrix_fill_x64([In, Out]igraph_matrix_t matrix, double v); 345 [DllImport(X86Dll, EntryPoint = "igraph_matrix_transpose", CallingConvention = CallingConvention.Cdecl)] 346 private static extern int igraph_matrix_transpose_x86([In, Out]igraph_matrix_t matrix); 347 [DllImport(X64Dll, EntryPoint = "igraph_matrix_transpose", CallingConvention = CallingConvention.Cdecl)] 348 private static extern int igraph_matrix_transpose_x64([In, Out]igraph_matrix_t matrix); 349 [DllImport(X86Dll, EntryPoint = "igraph_matrix_scale", CallingConvention = CallingConvention.Cdecl)] 350 private static extern int igraph_matrix_scale_x86([In, Out]igraph_matrix_t matrix, double by); 351 [DllImport(X64Dll, EntryPoint = "igraph_matrix_scale", CallingConvention = CallingConvention.Cdecl)] 352 private static extern int igraph_matrix_scale_x64([In, Out]igraph_matrix_t matrix, double by); 261 353 #endregion 262 354 #endregion … … 271 363 internal static int igraph_layout_davidson_harel(igraph_t graph, igraph_matrix_t res, bool use_seed, int maxiter, int fineiter, double cool_fact, double weight_node_dist, double weight_border, double weight_edge_lengths, double weight_edge_crossings, double weight_node_edge_dist) { 272 364 return X86 ? igraph_layout_davidson_harel_x86(graph, res, use_seed, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist) : igraph_layout_davidson_harel_x64(graph, res, use_seed, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist); 365 } 366 internal static int igraph_layout_mds(igraph_t graph, igraph_matrix_t res, igraph_matrix_t dist = null, int dim = 2) { 367 return MarshalIfExistsAndCall(GetDefaultArpackOptions(), ptr => X86 ? igraph_layout_mds_x86(graph, res, dist, dim, ptr) : igraph_layout_mds_x64(graph, res, dist, dim, ptr)); 273 368 } 274 369 … … 286 381 [DllImport(X64Dll, EntryPoint = "igraph_layout_davidson_harel", CallingConvention = CallingConvention.Cdecl)] 287 382 private static extern int igraph_layout_davidson_harel_x64(igraph_t graph, [In, Out]igraph_matrix_t res, bool use_seed, int maxiter, int fineiter, double cool_fact, double weight_node_dist, double weight_border, double weight_edge_lengths, double weight_edge_crossings, double weight_node_edge_dist); 383 [DllImport(X86Dll, EntryPoint = "igraph_layout_mds", CallingConvention = CallingConvention.Cdecl)] 384 private static extern int igraph_layout_mds_x86(igraph_t graph, [In, Out]igraph_matrix_t res, igraph_matrix_t dist, int dim, IntPtr options); 385 [DllImport(X64Dll, EntryPoint = "igraph_layout_mds", CallingConvention = CallingConvention.Cdecl)] 386 private static extern int igraph_layout_mds_x64(igraph_t graph, [In, Out]igraph_matrix_t res, igraph_matrix_t dist, int dim, IntPtr options); 288 387 #endregion 289 388 #endregion … … 309 408 #endregion 310 409 #endregion 410 411 private static int MarshalIfExistsAndCall(object o, Func<IntPtr, int> call) { 412 var ptr = IntPtr.Zero; 413 if (o != null) { 414 try { 415 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(o)); 416 } catch (OutOfMemoryException e) { throw new InvalidOperationException("Not enough memory to perform operation.", e); } 417 Marshal.StructureToPtr(o, ptr, false); 418 } 419 try { 420 return call(ptr); 421 } finally { 422 if (o != null) { 423 Marshal.DestroyStructure(ptr, o.GetType()); 424 Marshal.FreeHGlobal(ptr); 425 } 426 } 427 } 428 429 private static void MarshalIfExistsAndCall(object o, Action<IntPtr> call) { 430 var ptr = IntPtr.Zero; 431 if (o != null) { 432 try { 433 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(o)); 434 } catch (OutOfMemoryException e) { throw new InvalidOperationException("Not enough memory to perform operation.", e); } 435 Marshal.StructureToPtr(o, ptr, false); 436 } 437 try { 438 call(ptr); 439 } finally { 440 if (o != null) { 441 Marshal.DestroyStructure(ptr, o.GetType()); 442 Marshal.FreeHGlobal(ptr); 443 } 444 } 445 } 311 446 } 312 447 } -
branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Graph.cs
r14276 r14277 86 86 } 87 87 public Matrix LayoutWithFruchtermanReingold(int niter, double startTemp, Matrix initialCoords = null) { 88 if (initialCoords != null && (initialCoords.Rows != graph.n|| initialCoords.Columns != 2))88 if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2)) 89 89 throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords"); 90 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix( graph.n, 2);90 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2); 91 91 DllImporter.igraph_layout_fruchterman_reingold(graph, coords.NativeInstance, initialCoords != null, niter, startTemp, igraph_layout_grid_t.IGRAPH_LAYOUT_AUTOGRID, null, null, null, null, null); 92 92 return coords; … … 97 97 } 98 98 public Matrix LayoutWithKamadaKawai(int maxiter, double epsilon, double kkconst, Matrix initialCoords = null) { 99 if (initialCoords != null && (initialCoords.Rows != graph.n|| initialCoords.Columns != 2))99 if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2)) 100 100 throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords"); 101 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix( graph.n, 2);101 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2); 102 102 DllImporter.igraph_layout_kamada_kawai(graph, coords.NativeInstance, initialCoords != null, maxiter, epsilon, kkconst, null, null, null, null, null); 103 103 return coords; … … 109 109 } 110 110 public Matrix LayoutWithDavidsonHarel(int maxiter, int fineiter, double cool_fact, double weight_node_dist, double weight_border, double weight_edge_lengths, double weight_edge_crossings, double weight_node_edge_dist, Matrix initialCoords = null) { 111 if (initialCoords != null && (initialCoords.Rows != graph.n|| initialCoords.Columns != 2))111 if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2)) 112 112 throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords"); 113 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix( graph.n, 2);113 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2); 114 114 DllImporter.igraph_layout_davidson_harel(graph, coords.NativeInstance, initialCoords != null, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist); 115 115 return coords; 116 116 } 117 118 /// <summary> 119 /// Use multi-dimensional scaling to layout vertices. 120 /// A distance matrix can be used to specify the distances between the vertices. 121 /// Otherwise the distances will be calculated by shortest-path-length. 122 /// </summary> 123 /// <remarks> 124 /// For disconnected graphs, dimension must be 2. 125 /// </remarks> 126 /// <param name="dist">The distance matrix to layout the vertices.</param> 127 /// <param name="dim">How many dimensions should be used.</param> 128 /// <returns>The coordinates matrix of the aligned vertices.</returns> 129 public Matrix LayoutWithMds(Matrix dist = null, int dim = 2) { 130 var coords = new Matrix(Vertices, dim); 131 DllImporter.igraph_layout_mds(graph, coords.NativeInstance, dist != null ? dist.NativeInstance : null, dim); 132 return coords; 133 } 134 135 public void BreadthFirstWalk(BreadthFirstHandler handler, int root, DirectedWalkMode mode, bool includeUnreachableFromRoot = false, object tag = null) { 136 igraph_bfshandler_t wrapper = (t, vid, pred, succ, rank, dist, extra) => handler != null && handler(this, vid, pred, succ, rank, dist, tag); 137 DllImporter.igraph_bfs(graph, root, null, (igraph_neimode_t)mode, includeUnreachableFromRoot, null, null, null, null, null, null, null, wrapper, tag); 138 } 139 140 public void DepthFirstWalk(DepthFirstHandler inHandler, DepthFirstHandler outHandler, int root, DirectedWalkMode mode, bool includeUnreachableFromRoot = false, object tag = null) { 141 igraph_dfshandler_t inWrapper = (t, vid, dist, extra) => inHandler != null && inHandler(this, vid, dist, tag); 142 igraph_dfshandler_t outWrapper = (t, vid, dist, extra) => outHandler != null && outHandler(this, vid, dist, tag); 143 DllImporter.igraph_dfs(graph, root, (igraph_neimode_t)mode, includeUnreachableFromRoot, null, null, null, null, inWrapper, outWrapper, tag); 144 } 117 145 } 118 146 } -
branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Matrix.cs
r14276 r14277 39 39 DllImporter.igraph_matrix_copy(matrix, other.NativeInstance); 40 40 } 41 public Matrix(double[,] mat) { 42 if (mat == null) throw new ArgumentNullException("mat"); 43 matrix = new igraph_matrix_t(); 44 var nrows = mat.GetLength(0); 45 var ncols = mat.GetLength(1); 46 DllImporter.igraph_matrix_init(matrix, nrows, ncols); 47 var colwise = new double[ncols * nrows]; 48 for (var j = 0; j < ncols; j++) 49 for (var i = 0; i < nrows; i++) 50 colwise[j * nrows + i] = mat[i, j]; 51 DllImporter.igraph_vector_init_copy(matrix.data, colwise); 52 } 41 53 ~Matrix() { 42 54 DllImporter.igraph_matrix_destroy(matrix); … … 48 60 matrix = null; 49 61 GC.SuppressFinalize(this); 62 } 63 64 public void Fill(double v) { 65 DllImporter.igraph_matrix_fill(matrix, v); 66 } 67 68 public void Transpose() { 69 DllImporter.igraph_matrix_transpose(matrix); 70 } 71 72 public void Scale(double by) { 73 DllImporter.igraph_matrix_scale(matrix, by); 50 74 } 51 75 -
branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Vector.cs
r14276 r14277 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 24 26 namespace HeuristicLab.IGraph.Wrappers { … … 39 41 DllImporter.igraph_vector_init(vector, length); 40 42 } 41 43 public Vector(IEnumerable<double> data) { 44 if (data == null) throw new ArgumentNullException("data"); 45 var vec = data.ToArray(); 46 vector = new igraph_vector_t(); 47 DllImporter.igraph_vector_init_copy(vector, vec); 48 } 42 49 public Vector(Vector other) { 43 50 if (other == null) throw new ArgumentNullException("other"); … … 45 52 DllImporter.igraph_vector_copy(vector, other.NativeInstance); 46 53 } 47 48 54 ~Vector() { 49 55 DllImporter.igraph_vector_destroy(vector); … … 55 61 vector = null; 56 62 GC.SuppressFinalize(this); 63 } 64 65 public void Fill(double v) { 66 DllImporter.igraph_vector_fill(vector, v); 67 } 68 69 public void Reverse() { 70 DllImporter.igraph_vector_reverse(vector); 71 } 72 73 public void Shuffle() { 74 DllImporter.igraph_vector_shuffle(vector); 75 } 76 77 public void Scale(double by) { 78 DllImporter.igraph_vector_scale(vector, by); 57 79 } 58 80 … … 69 91 70 92 public double[] ToArray() { 71 var result = new double[Length]; 72 for (var i = 0; i < result.Length; i++) { 73 result[i] = DllImporter.igraph_vector_e(vector, i); 74 } 75 return result; 93 return DllImporter.igraph_vector_to_array(vector); 76 94 } 77 95 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.BinPacking.Views/3.3/HeuristicLab.Problems.BinPacking.Views-3.3.csproj
r14178 r14277 168 168 </ItemGroup> 169 169 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 170 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 171 Other similar extension points exist, see Microsoft.Common.targets. 172 <Target Name="BeforeBuild"> 173 </Target> 174 <Target Name="AfterBuild"> 175 </Target> 176 --> 170 177 <PropertyGroup> 171 178 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) … … 183 190 </PreBuildEvent> 184 191 </PropertyGroup> 185 <PropertyGroup>186 <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)187 set ProjectDir=$(ProjectDir)188 set SolutionDir=$(SolutionDir)189 set Outdir=$(Outdir)190 191 call PreBuildEvent.cmd192 </PreBuildEvent>193 </PropertyGroup>194 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.195 Other similar extension points exist, see Microsoft.Common.targets.196 <Target Name="BeforeBuild">197 </Target>198 <Target Name="AfterBuild">199 </Target>200 -->201 192 </Project> -
branches/symbreg-factors-2650/HeuristicLab.Problems.BinPacking/3.3/HeuristicLab.Problems.BinPacking-3.3.csproj
r14178 r14277 217 217 </ItemGroup> 218 218 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 219 <PropertyGroup>220 <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)221 set ProjectDir=$(ProjectDir)222 set SolutionDir=$(SolutionDir)223 set Outdir=$(Outdir)224 225 call PreBuildEvent.cmd226 </PreBuildEvent>227 </PropertyGroup>228 219 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 229 220 Other similar extension points exist, see Microsoft.Common.targets. … … 233 224 </Target> 234 225 --> 226 <PropertyGroup> 227 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 228 set ProjectDir=$(ProjectDir) 229 set SolutionDir=$(SolutionDir) 230 set Outdir=$(Outdir) 231 232 call PreBuildEvent.cmd 233 </PreBuildEvent> 234 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 235 export ProjectDir=$(ProjectDir) 236 export SolutionDir=$(SolutionDir) 237 238 $SolutionDir/PreBuildEvent.sh 239 </PreBuildEvent> 240 </PropertyGroup> 235 241 </Project> -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4.csproj
r14241 r14277 150 150 <Compile Include="SymbolicDiscriminantFunctionClassificationSolutionView.Designer.cs"> 151 151 <DependentUpon>SymbolicDiscriminantFunctionClassificationSolutionView.cs</DependentUpon> 152 </Compile> 153 <Compile Include="SymbolicClassificationModelMathView.cs"> 154 <SubType>UserControl</SubType> 155 </Compile> 156 <Compile Include="SymbolicClassificationModelMathView.designer.cs"> 157 <DependentUpon>SymbolicClassificationModelMathView.cs</DependentUpon> 152 158 </Compile> 153 159 <None Include="HeuristicLab.snk" /> -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views-3.4.csproj
r14125 r14277 121 121 <Compile Include="InteractiveSymbolicRegressionSolutionSimplifierView.Designer.cs"> 122 122 <DependentUpon>InteractiveSymbolicRegressionSolutionSimplifierView.cs</DependentUpon> 123 </Compile> 124 <Compile Include="SymbolicRegressionModelMathView.cs"> 125 <SubType>UserControl</SubType> 126 </Compile> 127 <Compile Include="SymbolicRegressionModelMathView.designer.cs"> 128 <DependentUpon>SymbolicRegressionModelMathView.cs</DependentUpon> 123 129 </Compile> 124 130 <Compile Include="Plugin.cs" /> -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r12817 r14277 121 121 <DependentUpon>InteractiveSymbolicExpressionTreeChart.cs</DependentUpon> 122 122 </Compile> 123 <Compile Include=" MathSymbolicDataAnalysisModelView.cs">124 <SubType>UserControl</SubType> 125 </Compile> 126 <Compile Include=" MathSymbolicDataAnalysisModelView.designer.cs">127 <DependentUpon> MathSymbolicDataAnalysisModelView.cs</DependentUpon>123 <Compile Include="SymbolicDataAnalysisModelMathView.cs"> 124 <SubType>UserControl</SubType> 125 </Compile> 126 <Compile Include="SymbolicDataAnalysisModelMathView.designer.cs"> 127 <DependentUpon>SymbolicDataAnalysisModelMathView.cs</DependentUpon> 128 128 </Compile> 129 129 <Compile Include="Plugin.cs" /> -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
r14259 r14277 37 37 private int targetCount; 38 38 private int currentLag; 39 private string targetVariable; 40 private bool containsTimeSeriesSymbol; 39 41 40 42 [StorableConstructor] … … 59 61 60 62 public string Format(ISymbolicExpressionTree symbolicExpressionTree) { 63 return Format(symbolicExpressionTree, null); 64 } 65 public string Format(ISymbolicExpressionTree symbolicExpressionTree, string targetVariable) { 61 66 try { 62 67 StringBuilder strBuilder = new StringBuilder(); 63 68 constants.Clear(); 64 69 constIndex = 0; 70 this.targetVariable = targetVariable; 71 containsTimeSeriesSymbol = symbolicExpressionTree.IterateNodesBreadth().Any(n => IsTimeSeriesSymbol(n.Symbol)); 65 72 strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root)); 66 73 return strBuilder.ToString(); … … 68 75 return ex.Message + Environment.NewLine + ex.StackTrace; 69 76 } 77 } 78 static bool IsTimeSeriesSymbol(ISymbol s) { 79 return s is TimeLag || s is Integral || s is Derivative || s is LaggedVariable; 70 80 } 71 81 … … 227 237 strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( "); 228 238 } else if (node.Symbol is StartSymbol) { 229 strBuilder.Append("target_" + (targetCount++) + "(t) & = ");239 FormatStartSymbol(strBuilder); 230 240 } else if (node.Symbol is Argument) { 231 241 var argSym = node.Symbol as Argument; … … 337 347 } else if (node.Symbol is StartSymbol) { 338 348 strBuilder.Append(@"\\" + Environment.NewLine); 339 strBuilder.Append("target_" + (targetCount++) + "(t) & = ");349 FormatStartSymbol(strBuilder); 340 350 } else if (node.Symbol is Power) { 341 351 strBuilder.Append(@"\right) ^ { \operatorname{round} \left("); … … 471 481 } 472 482 483 private void FormatStartSymbol(StringBuilder strBuilder) { 484 strBuilder.Append(targetVariable ?? "target_" + (targetCount++)); 485 if (containsTimeSeriesSymbol) 486 strBuilder.Append("(t)"); 487 strBuilder.Append(" & = "); 488 } 489 473 490 private string LagToString(int lag) { 474 491 if (lag < 0) { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionConfusionMatrixView.cs
r14185 r14277 76 76 dataGridView.RowCount = 1; 77 77 dataGridView.ColumnCount = 1; 78 dataGridView.TopLeftHeaderCell.Value = string.Empty; 78 79 } else { 79 80 dataGridView.ColumnCount = Content.ProblemData.Classes + 1; … … 91 92 dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader); 92 93 dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders); 94 95 dataGridView.TopLeftHeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; 96 dataGridView.TopLeftHeaderCell.Value = Content.Model.TargetVariable; 93 97 94 98 FillDataGridView(); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs
r14185 r14277 120 120 IEnumerator<double> classValueEnumerator = Content.ProblemData.ClassValues.OrderBy(x => x).GetEnumerator(); 121 121 while (classNameEnumerator.MoveNext() && classValueEnumerator.MoveNext()) { 122 Series series = new Series( classNameEnumerator.Current);122 Series series = new Series(Content.Model.TargetVariable + ": " + classNameEnumerator.Current); 123 123 series.ChartType = SeriesChartType.FastPoint; 124 124 series.Tag = classValueEnumerator.Current; -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/GradientChart.cs
r14248 r14277 284 284 285 285 if (ShowCursor) 286 chart.Titles[0].Text = FreeVariable + " : " + defaultValue.ToString(" N3", CultureInfo.CurrentCulture);286 chart.Titles[0].Text = FreeVariable + " : " + defaultValue.ToString("G5", CultureInfo.CurrentCulture); 287 287 288 288 ResizeAllSeriesData(); … … 658 658 659 659 if (ShowCursor) { 660 chart.Titles[0].Text = FreeVariable + " : " + x.ToString(" N3", CultureInfo.CurrentCulture);660 chart.Titles[0].Text = FreeVariable + " : " + x.ToString("G5", CultureInfo.CurrentCulture); 661 661 chart.Update(); 662 662 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/ConfidenceRegressionSolutionLineChartView.cs
r14185 r14277 28 28 using HeuristicLab.Problems.DataAnalysis; 29 29 using HeuristicLab.Problems.DataAnalysis.Views; 30 using HeuristicLab.Visualization.ChartControlsExtensions; 30 31 31 32 namespace HeuristicLab.Algorithms.DataAnalysis.Views { … … 109 110 // target 110 111 this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME); 111 this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable;112 this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME; 112 113 this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine; 113 114 this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(), … … 126 127 var s3Color = chart.Series[3].Color; 127 128 this.chart.PaletteCustomColors = new Color[] { s1Color, s2Color, s3Color, s0Color }; 129 130 // set the y-axis 131 var axisY = this.chart.ChartAreas[0].AxisY; 132 axisY.Title = Content.ProblemData.TargetVariable; 133 double min = double.MaxValue, max = double.MinValue; 134 foreach (var point in chart.Series.SelectMany(x => x.Points)) { 135 if (!point.YValues.Any() || double.IsInfinity(point.YValues[0]) || double.IsNaN(point.YValues[0])) 136 continue; 137 var y = point.YValues[0]; 138 if (y < min) 139 min = y; 140 if (y > max) 141 max = y; 142 } 143 144 double axisMin, axisMax, axisInterval; 145 ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval); 146 axisY.Minimum = axisMin; 147 axisY.Maximum = axisMax; 148 axisY.Interval = axisInterval; 128 149 129 150 UpdateCursorInterval(); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r14185 r14277 154 154 } 155 155 156 chart.ChartAreas[0].AxisX.Title = residualComboBox.SelectedItem.ToString();156 chart.ChartAreas[0].AxisX.Title = string.Format("{0} ({1})", residualComboBox.SelectedItem, Content.ProblemData.TargetVariable); 157 157 } 158 158 -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs
r14185 r14277 64 64 65 65 this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME); 66 this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable;66 this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME; 67 67 this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine; 68 68 this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(), … … 97 97 this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]); 98 98 99 // set the y-axis bounds99 // set the y-axis 100 100 var axisY = this.chart.ChartAreas[0].AxisY; 101 axisY.Title = Content.ProblemData.TargetVariable; 101 102 double min = double.MaxValue, max = double.MinValue; 102 103 foreach (var point in chart.Series.SelectMany(x => x.Points)) { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs
r14185 r14277 96 96 97 97 ChartArea chartArea = chart.ChartAreas[0]; 98 chartArea.AxisX.Title = string.Format("Residuals ({0})", Content.ProblemData.TargetVariable); 98 99 chartArea.AxisX.Minimum = -roundedMax - intervalWidth; 99 100 chartArea.AxisX.Maximum = roundedMax + intervalWidth; -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs
r14185 r14277 172 172 double axisMin, axisMax, axisInterval; 173 173 ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval); 174 this.chart.ChartAreas[0].AxisX.Title = "Estimated " + targetVariableName; 174 175 this.chart.ChartAreas[0].AxisX.Maximum = axisMax; 175 176 this.chart.ChartAreas[0].AxisX.Minimum = axisMin; 176 177 this.chart.ChartAreas[0].AxisX.Interval = axisInterval; 178 this.chart.ChartAreas[0].AxisY.Title = targetVariableName; 177 179 this.chart.ChartAreas[0].AxisY.Maximum = axisMax; 178 180 this.chart.ChartAreas[0].AxisY.Minimum = axisMin; -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionTargetResponseGradientView.cs
r14248 r14277 24 24 using System.Collections.Generic; 25 25 using System.Drawing; 26 using System.Globalization; 26 27 using System.Linq; 27 28 using System.Threading.Tasks; … … 38 39 private readonly Dictionary<string, DensityChart> densityCharts; 39 40 private readonly Dictionary<string, Panel> groupingPanels; 41 private ModifiableDataset sharedFixedVariables; 40 42 41 43 private const int Points = 200; … … 122 124 }); 123 125 124 var sharedFixedVariables = new ModifiableDataset(doubleVariables.Concat(factorVariables), doubleVariableValues.Concat(factorVariableValues)); 126 if (sharedFixedVariables != null) 127 sharedFixedVariables.ItemChanged += SharedFixedVariables_ItemChanged; 128 129 sharedFixedVariables = new ModifiableDataset(doubleVariables.Concat(factorVariables), doubleVariableValues.Concat(factorVariableValues)); 125 130 126 131 … … 218 223 variableListView.ItemChecked += variableListView_ItemChecked; 219 224 225 sharedFixedVariables.ItemChanged += SharedFixedVariables_ItemChanged; 226 220 227 RecalculateAndRelayoutCharts(); 221 228 } 229 230 private void SharedFixedVariables_ItemChanged(object sender, EventArgs<int, int> e) { 231 double yValue = Content.Model.GetEstimatedValues(sharedFixedVariables, new[] { 0 }).Single(); 232 string title = Content.ProblemData.TargetVariable + ": " + yValue.ToString("G5", CultureInfo.CurrentCulture); 233 foreach (var chart in gradientCharts.Values) { 234 if (!string.IsNullOrEmpty(chart.YAxisTitle)) { // only show title for first column in grid 235 chart.YAxisTitle = title; 236 } 237 } 238 } 239 222 240 223 241 private void OnGradientChartPostPaint(object o, EventArgs e) { … … 349 367 tl.Controls.Clear(); 350 368 int row = 0, column = 0; 369 double yValue = Content.Model.GetEstimatedValues(sharedFixedVariables, new[] { 0 }).Single(); 370 string title = Content.ProblemData.TargetVariable + ": " + yValue.ToString("G5", CultureInfo.CurrentCulture); 371 351 372 foreach (var v in VisibleVariables) { 352 373 var chartsPanel = groupingPanels[v]; … … 354 375 355 376 var chart = gradientCharts[v]; 356 chart.YAxisTitle = column == 0 ? Content.ProblemData.TargetVariable : string.Empty;377 chart.YAxisTitle = column == 0 ? title : string.Empty; 357 378 column++; 358 379 -
branches/symbreg-factors-2650/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VariableNetworks/VariableNetwork.cs
r14185 r14277 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Globalization; 24 25 using System.Linq; 25 26 using HeuristicLab.Common; … … 60 61 .Select(i => string.Format("X{0:000}", i)) 61 62 .ToArray(); 63 64 variableRelevances = new Dictionary<string, IEnumerable<KeyValuePair<string, double>>>(); 62 65 } 63 66 … … 83 86 protected override int TestPartitionEnd { get { return nTrainingSamples + nTestSamples; } } 84 87 88 private Dictionary<string, IEnumerable<KeyValuePair<string, double>>> variableRelevances; 89 public IEnumerable<KeyValuePair<string, double>> GetVariableRelevance(string targetVar) { 90 return variableRelevances[targetVar]; 91 } 85 92 86 93 protected override List<List<double>> GenerateValues() { … … 94 101 List<string> description = new List<string>(); // store information how the variable is actually produced 95 102 List<string[]> inputVarNames = new List<string[]>(); // store information to produce graphviz file 103 List<double[]> relevances = new List<double[]>(); // stores variable relevance information (same order as given in inputVarNames) 96 104 97 105 var nrand = new NormalDistributedRandom(random, 0, 1); 98 106 for (int c = 0; c < numLvl0; c++) { 99 var datai = Enumerable.Range(0, TestPartitionEnd).Select(_ => nrand.NextDouble()).ToList();100 107 inputVarNames.Add(new string[] { }); 101 description.Add("~ N(0, 1)"); 102 lvl0.Add(datai); 108 relevances.Add(new double[] { }); 109 description.Add(" ~ N(0, 1)"); 110 lvl0.Add(Enumerable.Range(0, TestPartitionEnd).Select(_ => nrand.NextDouble()).ToList()); 103 111 } 104 112 105 113 // lvl1 contains variables which are functions of vars in lvl0 (+ noise) 106 List<List<double>> lvl1 = new List<List<double>>();107 114 int numLvl1 = (int)Math.Ceiling(numberOfFeatures * 0.33); 108 for (int c = 0; c < numLvl1; c++) { 109 string[] selectedVarNames; 110 var x = GenerateRandomFunction(random, lvl0, out selectedVarNames); 111 var sigma = x.StandardDeviation(); 112 var noisePrng = new NormalDistributedRandom(random, 0, sigma * Math.Sqrt(noiseRatio / (1.0 - noiseRatio))); 113 lvl1.Add(x.Select(t => t + noisePrng.NextDouble()).ToList()); 114 115 inputVarNames.Add(selectedVarNames); 116 var desc = string.Format("f({0})", string.Join(",", selectedVarNames)); 117 description.Add(string.Format(" ~ N({0}, {1:N3})", desc, noisePrng.Sigma)); 118 } 115 List<List<double>> lvl1 = CreateVariables(lvl0, numLvl1, inputVarNames, description, relevances); 119 116 120 117 // lvl2 contains variables which are functions of vars in lvl0 and lvl1 (+ noise) 121 List<List<double>> lvl2 = new List<List<double>>();122 118 int numLvl2 = (int)Math.Ceiling(numberOfFeatures * 0.2); 123 for (int c = 0; c < numLvl2; c++) { 124 string[] selectedVarNames; 125 var x = GenerateRandomFunction(random, lvl0.Concat(lvl1).ToList(), out selectedVarNames); 126 var sigma = x.StandardDeviation(); 127 var noisePrng = new NormalDistributedRandom(random, 0, sigma * Math.Sqrt(noiseRatio / (1.0 - noiseRatio))); 128 lvl2.Add(x.Select(t => t + noisePrng.NextDouble()).ToList()); 129 130 inputVarNames.Add(selectedVarNames); 131 var desc = string.Format("f({0})", string.Join(",", selectedVarNames)); 132 description.Add(string.Format(" ~ N({0}, {1:N3})", desc, noisePrng.Sigma)); 133 } 119 List<List<double>> lvl2 = CreateVariables(lvl0.Concat(lvl1).ToList(), numLvl2, inputVarNames, description, relevances); 134 120 135 121 // lvl3 contains variables which are functions of vars in lvl0, lvl1 and lvl2 (+ noise) 136 List<List<double>> lvl3 = new List<List<double>>();137 122 int numLvl3 = numberOfFeatures - numLvl0 - numLvl1 - numLvl2; 138 for (int c = 0; c < numLvl3; c++) { 139 string[] selectedVarNames; 140 var x = GenerateRandomFunction(random, lvl0.Concat(lvl1).Concat(lvl2).ToList(), out selectedVarNames); 141 var sigma = x.StandardDeviation(); 142 var noisePrng = new NormalDistributedRandom(random, 0, sigma * Math.Sqrt(noiseRatio / (1.0 - noiseRatio))); 143 lvl3.Add(x.Select(t => t + noisePrng.NextDouble()).ToList()); 144 145 inputVarNames.Add(selectedVarNames); 146 var desc = string.Format("f({0})", string.Join(",", selectedVarNames)); 147 description.Add(string.Format(" ~ N({0}, {1:N3})", desc, noisePrng.Sigma)); 148 } 149 150 networkDefinition = string.Join(Environment.NewLine, variableNames.Zip(description, (n, d) => n + d)); 123 List<List<double>> lvl3 = CreateVariables(lvl0.Concat(lvl1).Concat(lvl2).ToList(), numLvl3, inputVarNames, description, relevances); 124 125 this.variableRelevances.Clear(); 126 for (int i = 0; i < variableNames.Length; i++) { 127 var targetVarName = variableNames[i]; 128 var targetRelevantInputs = 129 inputVarNames[i].Zip(relevances[i], (inputVar, rel) => new KeyValuePair<string, double>(inputVar, rel)) 130 .ToArray(); 131 variableRelevances.Add(targetVarName, targetRelevantInputs); 132 } 133 134 networkDefinition = string.Join(Environment.NewLine, variableNames.Zip(description, (n, d) => n + d).OrderBy(x => x)); 151 135 // for graphviz 152 136 networkDefinition += Environment.NewLine + "digraph G {"; 153 foreach (var t in variableNames.Zip(inputVarNames, Tuple.Create).OrderBy(t => t.Item1)) { 154 var name = t.Item1; 155 var selectedVarNames = t.Item2; 156 foreach (var selectedVarName in selectedVarNames) { 157 networkDefinition += Environment.NewLine + selectedVarName + " -> " + name; 137 for (int i = 0; i < variableNames.Length; i++) { 138 var name = variableNames[i]; 139 var selectedVarNames = inputVarNames[i]; 140 var selectedRelevances = relevances[i]; 141 for (int j = 0; j < selectedVarNames.Length; j++) { 142 var selectedVarName = selectedVarNames[j]; 143 var selectedRelevance = selectedRelevances[j]; 144 networkDefinition += Environment.NewLine + selectedVarName + " -> " + name + 145 string.Format(CultureInfo.InvariantCulture, " [label={0:N3}]", selectedRelevance); 158 146 } 159 147 } 160 148 networkDefinition += Environment.NewLine + "}"; 161 149 162 // return a random permutation of all variables 150 // return a random permutation of all variables (to mix lvl0, lvl1, ... variables) 163 151 var allVars = lvl0.Concat(lvl1).Concat(lvl2).Concat(lvl3).ToList(); 164 152 var orderedVars = allVars.Zip(variableNames, Tuple.Create).OrderBy(t => t.Item2).Select(t => t.Item1).ToList(); … … 167 155 } 168 156 157 private List<List<double>> CreateVariables(List<List<double>> allowedInputs, int numVars, List<string[]> inputVarNames, List<string> description, List<double[]> relevances) { 158 var res = new List<List<double>>(); 159 for (int c = 0; c < numVars; c++) { 160 string[] selectedVarNames; 161 double[] relevance; 162 var x = GenerateRandomFunction(random, allowedInputs, out selectedVarNames, out relevance); 163 var sigma = x.StandardDeviation(); 164 var noisePrng = new NormalDistributedRandom(random, 0, sigma * Math.Sqrt(noiseRatio / (1.0 - noiseRatio))); 165 res.Add(x.Select(t => t + noisePrng.NextDouble()).ToList()); 166 Array.Sort(selectedVarNames, relevance); 167 inputVarNames.Add(selectedVarNames); 168 relevances.Add(relevance); 169 var desc = string.Format("f({0})", string.Join(",", selectedVarNames)); 170 // for the relevance information order variables by decreasing relevance 171 var relevanceStr = string.Join(", ", 172 selectedVarNames.Zip(relevance, Tuple.Create) 173 .OrderByDescending(t => t.Item2) 174 .Select(t => string.Format(CultureInfo.InvariantCulture, "{0}: {1:N3}", t.Item1, t.Item2))); 175 description.Add(string.Format(" ~ N({0}, {1:N3}) [Relevances: {2}]", desc, noisePrng.Sigma, relevanceStr)); 176 } 177 return res; 178 } 179 169 180 // sample the input variables that are actually used and sample from a Gaussian process 170 private IEnumerable<double> GenerateRandomFunction(IRandom rand, List<List<double>> xs, out string[] selectedVarNames ) {181 private IEnumerable<double> GenerateRandomFunction(IRandom rand, List<List<double>> xs, out string[] selectedVarNames, out double[] relevance) { 171 182 double r = -Math.Log(1.0 - rand.NextDouble()) * 2.0; // r is exponentially distributed with lambda = 2 172 183 int nl = (int)Math.Floor(1.5 + r); // number of selected vars is likely to be between three and four … … 178 189 var selectedVars = selectedIdx.Select(i => xs[i]).ToArray(); 179 190 selectedVarNames = selectedIdx.Select(i => VariableNames[i]).ToArray(); 180 return SampleGaussianProcess(random, selectedVars );181 } 182 183 private IEnumerable<double> SampleGaussianProcess(IRandom random, List<double>[] xs ) {191 return SampleGaussianProcess(random, selectedVars, out relevance); 192 } 193 194 private IEnumerable<double> SampleGaussianProcess(IRandom random, List<double>[] xs, out double[] relevance) { 184 195 int nl = xs.Length; 185 196 int nRows = xs.First().Count; … … 218 229 alglib.ablas.rmatrixmv(nRows, nRows, K, 0, 0, 0, u, 0, ref y, 0); 219 230 231 // calculate variable relevance 232 // as per Rasmussen and Williams "Gaussian Processes for Machine Learning" page 106: 233 // ,,For the squared exponential covariance function [...] the l1, ..., lD hyperparameters 234 // play the role of characteristic length scales [...]. Such a covariance function implements 235 // automatic relevance determination (ARD) [Neal, 1996], since the inverse of the length-scale 236 // determines how relevant an input is: if the length-scale has a very large value, the covariance 237 // will become almost independent of that input, effectively removing it from inference.'' 238 relevance = l.Select(li => 1.0 / li).ToArray(); 239 220 240 return y; 221 241 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VariableNetworks/VariableNetworkInstanceProvider.cs
r14229 r14277 49 49 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 50 50 var numVariables = new int[] { 10, 20, 50, 100 }; 51 var noiseRatios = new double[] { 0 .01, 0.05, 0.1 };51 var noiseRatios = new double[] { 0, 0.01, 0.05, 0.1 }; 52 52 var rand = new MersenneTwister((uint)Seed); // use fixed seed for deterministic problem generation 53 53 return (from size in numVariables -
branches/symbreg-factors-2650/HeuristicLab.Tests/Builder.testsettings
r7915 r14277 3 3 <Description>Test settings to run unit tests on the HL build server.</Description> 4 4 <Deployment> 5 <DeploymentItem filename="HeuristicLab.Tests\HeuristicLab-3.3\Resources\" />6 5 <DeploymentItem filename="bin\" /> 7 6 </Deployment> … … 27 26 </AgentRule> 28 27 </Execution> 28 <Properties /> 29 29 </TestSettings> -
branches/symbreg-factors-2650/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphLayoutTest.cs
r14276 r14277 29 29 public class IGraphLayoutTest { 30 30 [TestMethod] 31 public void TestFruchtermanReingold() { 31 [TestCategory("ExtLibs")] 32 [TestCategory("ExtLibs.igraph")] 33 [TestProperty("Time", "short")] 34 public void IGraphWrappersLayoutFruchtermanReingoldTest() { 32 35 var graph = new Graph(5, new[] { 33 36 Tuple.Create(0, 1), -
branches/symbreg-factors-2650/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersGraphTest.cs
r14276 r14277 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.IGraph.Wrappers; … … 27 28 namespace HeuristicLab.Tests { 28 29 [TestClass] 30 [DeploymentItem("igraph-0.8.0-pre-x86.dll")] 31 [DeploymentItem("igraph-0.8.0-pre-x64.dll")] 29 32 public class IGraphWrappersGraphTest { 30 33 [TestMethod] 31 public void IGraphWrappersGraphConstructionAndFinalization() { 34 [TestCategory("ExtLibs")] 35 [TestCategory("ExtLibs.igraph")] 36 [TestProperty("Time", "short")] 37 public void IGraphWrappersGraphConstructionAndFinalizationTest() { 32 38 var graph = new Graph(5, new[] { 33 39 Tuple.Create(0, 1), … … 51 57 52 58 [TestMethod] 53 public void TestDensity() { 59 [TestCategory("ExtLibs")] 60 [TestCategory("ExtLibs.igraph")] 61 [TestProperty("Time", "short")] 62 public void IGraphWrappersGraphDensityTest() { 54 63 var graph = new Graph(5, new[] { 55 64 Tuple.Create(0, 1), … … 82 91 83 92 [TestMethod] 84 public void TestPageRank() { 93 [TestCategory("ExtLibs")] 94 [TestCategory("ExtLibs.igraph")] 95 [TestProperty("Time", "short")] 96 public void IGraphWrappersGraphPageRankTest() { 85 97 var graph = new Graph(4, new[] { 86 98 Tuple.Create(0, 1), … … 125 137 Assert.AreEqual(0.173, ranks[3], 0.01); 126 138 } 139 140 [TestMethod] 141 [TestCategory("ExtLibs")] 142 [TestCategory("ExtLibs.igraph")] 143 [TestProperty("Time", "short")] 144 public void IGraphWrappersGraphBreadthFirstWalkTest() { 145 var graph = new Graph(4, new[] { 146 Tuple.Create(0, 1), 147 Tuple.Create(0, 2), 148 Tuple.Create(1, 2), 149 Tuple.Create(2, 0), 150 Tuple.Create(3, 2), 151 }, directed: true); 152 var visited = new HashSet<int>(); 153 BreadthFirstHandler handler = (graph1, currentVertexId, previousVertexId, nextVertexId, rank, distance, tag) => { 154 visited.Add(currentVertexId); 155 return false; 156 }; 157 graph.BreadthFirstWalk(handler, 0, DirectedWalkMode.All, true, null); 158 Assert.AreEqual(4, visited.Count); 159 Assert.IsTrue(visited.Contains(0)); 160 Assert.IsTrue(visited.Contains(1)); 161 Assert.IsTrue(visited.Contains(2)); 162 Assert.IsTrue(visited.Contains(3)); 163 } 164 165 [TestMethod] 166 [TestCategory("ExtLibs")] 167 [TestCategory("ExtLibs.igraph")] 168 [TestProperty("Time", "short")] 169 public void IGraphWrappersGraphDepthFirstWalkTest() { 170 var graph = new Graph(4, new[] { 171 Tuple.Create(0, 1), 172 Tuple.Create(0, 2), 173 Tuple.Create(1, 2), 174 Tuple.Create(2, 0), 175 Tuple.Create(3, 2), 176 }, directed: true); 177 var visited = new HashSet<int>(); 178 DepthFirstHandler handler = (graph1, vertexId, distance, tag) => { 179 visited.Add(vertexId); 180 return false; 181 }; 182 graph.DepthFirstWalk(handler, handler, 0, DirectedWalkMode.All, true, null); 183 Assert.AreEqual(4, visited.Count); 184 Assert.IsTrue(visited.Contains(0)); 185 Assert.IsTrue(visited.Contains(1)); 186 Assert.IsTrue(visited.Contains(2)); 187 Assert.IsTrue(visited.Contains(3)); 188 } 127 189 } 128 190 } -
branches/symbreg-factors-2650/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersMatrixTest.cs
r14276 r14277 27 27 public class IGraphWrappersMatrixTest { 28 28 [TestMethod] 29 public void IGraphWrappersMatrixConstructionAndFinalization() { 29 [TestCategory("ExtLibs")] 30 [TestCategory("ExtLibs.igraph")] 31 [TestProperty("Time", "short")] 32 public void IGraphWrappersMatrixConstructionAndFinalizationTest() { 30 33 var matrix = new Matrix(3, 2); 31 34 Assert.AreEqual(3, matrix.Rows); … … 37 40 Assert.AreEqual(2, other.Columns); 38 41 Assert.AreEqual(4, other[0, 0]); 42 43 var mat = new double[,] { 44 { 1, 2, 3 }, 45 { 4, 5, 6} 46 }; 47 matrix = new Matrix(mat); 48 Assert.AreEqual(2, matrix.Rows); 49 Assert.AreEqual(3, matrix.Columns); 50 var test = matrix.ToMatrix(); 51 for (var i = 0; i < matrix.Rows; i++) 52 for (var j = 0; j < matrix.Columns; j++) { 53 Assert.AreEqual(mat[i, j], matrix[i, j]); 54 Assert.AreEqual(mat[i, j], test[i, j]); 55 } 39 56 } 40 57 41 58 [TestMethod] 59 [TestCategory("ExtLibs")] 60 [TestCategory("ExtLibs.igraph")] 61 [TestProperty("Time", "short")] 42 62 public void IGraphWrappersMatrixGetSetTest() { 43 63 var matrix = new Matrix(3, 2); … … 61 81 Assert.AreEqual(matrix[i, j], netmat[i, j]); 62 82 } 83 84 [TestMethod] 85 [TestCategory("ExtLibs")] 86 [TestCategory("ExtLibs.igraph")] 87 [TestProperty("Time", "short")] 88 public void IGraphWrappersMatrixFillTest() { 89 var matrix = new Matrix(3, 2); 90 matrix.Fill(2.6); 91 Assert.AreEqual(2.6, matrix[0, 0]); 92 Assert.AreEqual(2.6, matrix[0, 1]); 93 Assert.AreEqual(2.6, matrix[1, 0]); 94 Assert.AreEqual(2.6, matrix[1, 1]); 95 Assert.AreEqual(2.6, matrix[2, 0]); 96 Assert.AreEqual(2.6, matrix[2, 1]); 97 } 98 99 [TestMethod] 100 [TestCategory("ExtLibs")] 101 [TestCategory("ExtLibs.igraph")] 102 [TestProperty("Time", "short")] 103 public void IGraphWrappersMatrixTransposeTest() { 104 var matrix = new Matrix(3, 2); 105 matrix.Transpose(); 106 Assert.AreEqual(2, matrix.Rows); 107 Assert.AreEqual(3, matrix.Columns); 108 } 109 110 [TestMethod] 111 [TestCategory("ExtLibs")] 112 [TestCategory("ExtLibs.igraph")] 113 [TestProperty("Time", "short")] 114 public void IGraphWrappersMatrixScaleTest() { 115 var matrix = new Matrix(3, 2); 116 matrix[0, 0] = matrix[0, 1] = 4; 117 matrix[1, 0] = 3; 118 matrix[1, 1] = 2; 119 matrix[2, 0] = 1.5; 120 matrix[2, 1] = -0.5; 121 matrix.Scale(2); 122 Assert.AreEqual(8, matrix[0, 0]); 123 Assert.AreEqual(8, matrix[0, 1]); 124 Assert.AreEqual(6, matrix[1, 0]); 125 Assert.AreEqual(4, matrix[1, 1]); 126 Assert.AreEqual(3, matrix[2, 0]); 127 Assert.AreEqual(-1, matrix[2, 1]); 128 } 63 129 } 64 130 } -
branches/symbreg-factors-2650/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersVectorTest.cs
r14276 r14277 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.IGraph.Wrappers; 23 24 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 27 28 public class IGraphWrappersVectorTest { 28 29 [TestMethod] 29 public void IGraphWrappersVectorConstructionAndFinalization() { 30 [TestCategory("ExtLibs")] 31 [TestCategory("ExtLibs.igraph")] 32 [TestProperty("Time", "short")] 33 public void IGraphWrappersVectorConstructionAndFinalizationTest() { 30 34 var vector = new Vector(7); 31 35 Assert.AreEqual(7, vector.Length); … … 35 39 Assert.AreEqual(7, other.Length); 36 40 Assert.AreEqual(4, other[0]); 41 42 var myvec = new double[] { 1, 2, 3 }; 43 vector = new Vector(myvec); 44 Assert.AreEqual(3, vector.Length); 45 Assert.AreEqual(myvec[0], vector[0]); 46 Assert.AreEqual(myvec[1], vector[1]); 47 Assert.AreEqual(myvec[2], vector[2]); 37 48 } 38 49 39 50 [TestMethod] 51 [TestCategory("ExtLibs")] 52 [TestCategory("ExtLibs.igraph")] 53 [TestProperty("Time", "short")] 40 54 public void IGraphWrappersVectorGetSetTest() { 41 55 var vector = new Vector(5); … … 55 69 Assert.AreEqual(vector[i], netmat[i]); 56 70 } 71 72 [TestMethod] 73 [TestCategory("ExtLibs")] 74 [TestCategory("ExtLibs.igraph")] 75 [TestProperty("Time", "short")] 76 public void IGraphWrappersVectorFillTest() { 77 var vector = new Vector(5); 78 vector.Fill(2.3); 79 Assert.IsTrue(new[] { 2.3, 2.3, 2.3, 2.3, 2.3 }.SequenceEqual(vector.ToArray())); 80 } 81 82 [TestMethod] 83 [TestCategory("ExtLibs")] 84 [TestCategory("ExtLibs.igraph")] 85 [TestProperty("Time", "short")] 86 public void IGraphWrappersVectorReverseTest() { 87 var vector = new Vector(5); 88 vector[0] = vector[1] = 4; 89 vector[2] = 3; 90 vector[3] = 1.5; 91 vector[4] = -0.5; 92 vector.Reverse(); 93 Assert.IsTrue(new[] { -0.5, 1.5, 3, 4, 4 }.SequenceEqual(vector.ToArray())); 94 } 95 96 [TestMethod] 97 [TestCategory("ExtLibs")] 98 [TestCategory("ExtLibs.igraph")] 99 [TestProperty("Time", "short")] 100 public void IGraphWrappersVectorShuffleTest() { 101 var vector = new Vector(5); 102 vector[0] = vector[1] = 4; 103 vector[2] = 3; 104 vector[3] = 1.5; 105 vector[4] = -0.5; 106 vector.Shuffle(); 107 Assert.IsFalse(new[] { -0.5, 1.5, 3, 4, 4 }.SequenceEqual(vector.ToArray())); 108 Assert.IsFalse(new[] { 4, 4, 3, 1.5, -0.5 }.SequenceEqual(vector.ToArray())); 109 } 110 111 [TestMethod] 112 [TestCategory("ExtLibs")] 113 [TestCategory("ExtLibs.igraph")] 114 [TestProperty("Time", "short")] 115 public void IGraphWrappersVectorScaleTest() { 116 var vector = new Vector(5); 117 vector[0] = vector[1] = 4; 118 vector[2] = 3; 119 vector[3] = 1.5; 120 vector[4] = -0.5; 121 vector.Scale(2); 122 Assert.IsTrue(new double[] { 8, 8, 6, 3, -1 }.SequenceEqual(vector.ToArray())); 123 } 57 124 } 58 125 } -
branches/symbreg-factors-2650/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r14276 r14277 219 219 <Private>False</Private> 220 220 </Reference> 221 <Reference Include="HeuristicLab.igraph-0.8.0-pre, Version=0.8.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 222 <SpecificVersion>False</SpecificVersion> 223 <HintPath>..\bin\HeuristicLab.igraph-0.8.0-pre.dll</HintPath> 221 <Reference Include="HeuristicLab.IGraph-0.8.0-pre, Version=0.8.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 222 <SpecificVersion>False</SpecificVersion> 223 <HintPath>..\bin\HeuristicLab.IGraph-0.8.0-pre.dll</HintPath> 224 <Private>False</Private> 224 225 </Reference> 225 226 <Reference Include="HeuristicLab.MainForm-3.3"> … … 565 566 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\SubtreeCrossoverTest.cs" /> 566 567 <Compile Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4\Util.cs" /> 567 <Compile Include="HeuristicLab.IGraph\IGraphWrappersGraphTest.cs" />568 <Compile Include="HeuristicLab.IGraph\IGraphLayoutTest.cs" />569 <Compile Include="HeuristicLab.IGraph\IGraphWrappersVectorTest.cs" />570 <Compile Include="HeuristicLab.IGraph\IGraphWrappersMatrixTest.cs" />571 568 <Compile Include="HeuristicLab.Persistence-3.3\StorableAttributeTests.cs" /> 572 569 <Compile Include="HeuristicLab.Persistence-3.3\UseCases.cs" /> -
branches/symbreg-factors-2650/HeuristicLab/3.3/HeuristicLab-3.3.csproj
r14207 r14277 226 226 </PostBuildEvent> 227 227 </PropertyGroup> 228 <PropertyGroup>229 <PostBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)230 set ProjectDir=$(ProjectDir)231 set SolutionDir=$(SolutionDir)232 set OutDir=$(OutDir)233 set TargetDir=$(TargetDir)234 set Platform=$(PlatformName)235 set Configuration=$(ConfigurationName)236 237 call "$(SolutionDir)MergeConfigs.cmd"</PostBuildEvent>238 </PropertyGroup>239 228 </Project>
Note: See TracChangeset
for help on using the changeset viewer.