コード例 #1
0
        void Copy(bool cut)
        {
            if (Grid.SelectedCells.Count == 0)
            {
                return;
            }

            var minRowIndex = int.MaxValue;
            var minColIndex = int.MaxValue;
            var maxRowIndex = int.MinValue;
            var maxColIndex = int.MinValue;

            foreach (DataGridViewCell c in Grid.SelectedCells)
            {
                minRowIndex = Math.Min(c.RowIndex, minRowIndex);
                minColIndex = Math.Min(c.ColumnIndex, minColIndex);
                maxRowIndex = Math.Max(c.RowIndex, maxRowIndex);
                maxColIndex = Math.Max(c.ColumnIndex, maxColIndex);
            }

            var m = new StringMatrix(maxRowIndex - minRowIndex + 1, maxColIndex - minColIndex + 1);

            foreach (DataGridViewCell c in Grid.SelectedCells)
            {
                var mri = c.RowIndex - minRowIndex;
                var mci = c.ColumnIndex - minColIndex;
                m.Rows[mri][mci] = GetCellText(c);
                if (cut && !c.ReadOnly)
                {
                    c.Value = null;
                }
            }

            Clipboard.SetText(m.Tsv, TextDataFormat.UnicodeText);
        }
コード例 #2
0
        public void StringMatrixExtensions_ToF64Matrix()
        {
            var stringMatrix = new StringMatrix(InputData, 2, 3);
            var actual       = stringMatrix.ToF64Matrix();

            Assert.AreEqual(new F64Matrix(InputData.Select(v => FloatingPointConversion.ToF64(v)).ToArray(), 2, 3), actual);
        }
コード例 #3
0
        protected override void OnContentChanged()
        {
            base.OnContentChanged();
            if (Content == null)
            {
                parametersView.Content       = null;
                covarianceMatrixView.Content = null;
            }
            else
            {
                // format numbers to make them easier to read
                var w = new StringArray(Content.W.Select(x => $"{x:e4}").ToArray());
                w.ElementNames         = Content.ParameterNames;
                parametersView.Content = w;

                // format all numbers in matrix
                var cStr = new string[Content.C.GetLength(0), Content.C.GetLength(1)];
                for (int i = 0; i < Content.C.GetLength(0); i++)
                {
                    for (int j = 0; j < Content.C.GetLength(0); j++)
                    {
                        cStr[i, j] = $"{Content.C[i, j]:e4}";
                    }
                }
                var c = new StringMatrix(cStr);
                c.RowNames    = Content.ParameterNames;
                c.ColumnNames = Content.ParameterNames;
                covarianceMatrixView.Content = c;
            }
        }
コード例 #4
0
        public void CrazyWrite()
        {
            var s = "\"123\"\t100\r\n1,2,3\t45,45'\r\n\"\"\"69,\t69\"\"\"\t\"a\t\r\nb\"\r\n";
            var m = StringMatrix.FromTsv(s);
            var t = m.Tsv;

            Assert.AreEqual(s, t);
        }
コード例 #5
0
        public void F64MatrixExtensions_ToStringMatrix()
        {
            var matrix = new F64Matrix(InputData, 2, 3);
            var actual = matrix.ToStringMatrix();

            var expected = new StringMatrix(InputData.Select(v => FloatingPointConversion.ToString(v)).ToArray(), 2, 3);

            Assert.AreEqual(expected, actual);
        }
コード例 #6
0
        public void StringMatrixExtensions_CombineStringMatrices_Cols()
        {
            var matrix1 = new StringMatrix(m_inputData, 2, 3);
            var matrix2 = new StringMatrix(m_inputData, 2, 3);

            var actual = matrix1.CombineCols(matrix2);

            Assert.AreEqual(new StringMatrix(m_combineDataCols, 2, 6), actual);
        }
コード例 #7
0
        public void StringMatrixExtensions_CombineStringMatrices_Rows()
        {
            var matrix1 = new StringMatrix(InputData, 2, 3);
            var matrix2 = new StringMatrix(InputData, 2, 3);

            var actual = matrix1.CombineRows(matrix2);

            Assert.AreEqual(new StringMatrix(CombineDataRows, 4, 3), actual);
        }
コード例 #8
0
        public void StringMatrixExtensions_Map()
        {
            var matrix = new StringMatrix(InputData.ToArray(), 2, 3);

            matrix.Map(() => "10");

            var expected = Enumerable.Range(0, matrix.Data().Length).Select(v => "10").ToArray();

            CollectionAssert.AreEqual(expected, matrix.Data());
        }
コード例 #9
0
        public void StringMatrixExtensions_VectorAndVector()
        {
            var v1 = new string[] { "1", "2", "3", "4" };
            var v2 = new string[] { "1", "2", "3", "4" };

            var actual   = v1.CombineCols(v2);
            var expected = new StringMatrix(new string[] { "1", "1", "2", "2", "3", "3", "4", "4" }, 4, 2);

            Assert.AreEqual(expected, actual);
        }
コード例 #10
0
        public void StringMatrix_Rows_Predefined()
        {
            var sut    = CreateFeatures();
            var actual = new StringMatrix(2, 3);

            sut.Rows(new int[] { 0, 2 }, actual);
            var expected = GetExpectedRowSubMatrix();

            Assert.IsTrue(expected.Equals(actual));
        }
コード例 #11
0
        public void StringMatrix_Columns_Predefined()
        {
            var sut    = CreateFeatures();
            var actual = new StringMatrix(3, 2);

            sut.Columns(new int [] { 0, 2 }, actual);
            var expected = GetExpectedColSubMatrix();

            Assert.IsTrue(expected.Equals(actual));
        }
コード例 #12
0
        public void ClearGrid()
        {
            // Clear grid control
            StringGrid.ColumnDefinitions.Clear();
            StringGrid.RowDefinitions.Clear();
            StringGrid.Children.Clear();

            StringMatrix?.Clear();
            Header?.Clear();
        }
コード例 #13
0
        public void StringMatrixExtensions_CombineStringMatrixAndVector()
        {
            var matrix = new StringMatrix(m_inputData, 2, 3);
            var vector = new string[] { "3", "6" };

            var expected = new StringMatrix(new string[] { "1", "2", "3", "3",
                                                           "4", "5", "6", "6" }, 2, 4);
            var actual = matrix.CombineCols(vector);

            Assert.AreEqual(expected, actual);
        }
コード例 #14
0
        public void StringMatrixExtensions_CombineStringVectorAndMatrixAnd()
        {
            var matrix = new StringMatrix(InputData, 2, 3);
            var vector = new string[] { "3", "6" };

            var expected = new StringMatrix(new string[] { "3", "1", "2", "3",
                                                           "6", "4", "5", "6", }, 2, 4);
            var actual = vector.CombineCols(matrix);

            Assert.AreEqual(expected, actual);
        }
コード例 #15
0
ファイル: OKBProblemView.cs プロジェクト: lulzzz/HeuristicLab
        private void downloadCharacteristicsButton_Click(object sender, EventArgs e)
        {
            var values  = RunCreationClient.Instance.GetCharacteristicValues(Content.ProblemId).ToList();
            var content = new StringMatrix(values.Count, 3);

            for (var i = 0; i < values.Count; i++)
            {
                content[i, 0] = values[i].Name;
                content[i, 1] = values[i].GetValue();
                content[i, 2] = values[i].GetType().Name;
            }
            characteristicsMatrixView.Content = content;
            SetEnabledStateOfControls();
        }
コード例 #16
0
        private void UpdateEstimatedValues()
        {
            if (InvokeRequired)
            {
                Invoke((Action)UpdateEstimatedValues);
            }
            else
            {
                StringMatrix matrix = null;
                if (Content != null)
                {
                    string[,] values = new string[Content.ProblemData.Dataset.Rows, 7];

                    double[] target             = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
                    var      estimated          = Content.EstimatedValues.GetEnumerator();
                    var      estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
                    var      estimated_test     = Content.EstimatedTestValues.GetEnumerator();

                    foreach (var row in Content.ProblemData.TrainingIndices)
                    {
                        estimated_training.MoveNext();
                        values[row, 3] = estimated_training.Current.ToString();
                    }

                    foreach (var row in Content.ProblemData.TestIndices)
                    {
                        estimated_test.MoveNext();
                        values[row, 4] = estimated_test.Current.ToString();
                    }

                    foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows))
                    {
                        estimated.MoveNext();
                        double est = estimated.Current;
                        double res = Math.Abs(est - target[row]);
                        values[row, 0] = row.ToString();
                        values[row, 1] = target[row].ToString();
                        values[row, 2] = est.ToString();
                        values[row, 5] = Math.Abs(res).ToString();
                        values[row, 6] = Math.Abs(res / target[row]).ToString();
                    }

                    matrix              = new StringMatrix(values);
                    matrix.ColumnNames  = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Absolute Error (all)", "Relative Error (all)" };
                    matrix.SortableView = true;
                }
                matrixView.Content = matrix;
            }
        }
 protected virtual void UpdateEstimatedValues()
 {
     if (InvokeRequired)
     {
         Invoke((Action)UpdateEstimatedValues);
     }
     else
     {
         StringMatrix matrix = null;
         if (Content != null)
         {
             matrix = CreateValueMatrix();
         }
         matrixView.Content = matrix;
     }
 }
コード例 #18
0
        void PasteAt(int rowIndex, int colIndex)
        {
            if (Grid.Columns.Count == 0)
            {
                return;
            }

            var clip = Clipboard.GetDataObject();
            var data = clip.GetData(DataFormats.UnicodeText);

            if (data == null)
            {
                return;
            }
            var tsv = data.ToString();

            var m = StringMatrix.FromTsv(tsv);

            var editedRows = new List <int> ();

            for (var mri = 0; mri < m.Rows.Count; mri++)
            {
                var ri = mri + rowIndex;
                while (ri >= Grid.Rows.Count - 1)                   // -1 to keep the insert row
                {
                    Grid.Rows.Add();
                }
                editedRows.Add(ri);
                var r  = Grid.Rows[ri];
                var mr = m.Rows[mri];
                for (var mci = 0; mci < mr.Count; mci++)
                {
                    var ci = colIndex + mci;
                    if (ci >= Grid.Columns.Count)
                    {
                        continue;
                    }
                    if (Grid.Columns[ci].ReadOnly)
                    {
                        continue;
                    }
                    r.Cells[ci].Value = mr[mci];
                }
            }

            RunRows(editedRows);
        }
コード例 #19
0
        protected override void UpdateEstimatedValues()
        {
            if (InvokeRequired)
            {
                Invoke((Action)UpdateEstimatedValues);
            }
            else
            {
                StringMatrix matrix = null;
                if (Content != null)
                {
                    string[,] values = new string[Content.ProblemData.Dataset.Rows, 6];
                    double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
                    double[] estimatedClassValue = Content.EstimatedClassValues.ToArray();
                    double[] estimatedValues     = Content.EstimatedValues.ToArray();
                    for (int row = 0; row < target.Length; row++)
                    {
                        values[row, 0] = row.ToString();
                        values[row, 1] = target[row].ToString();
                        values[row, 2] = estimatedClassValue[row].ToString();
                        values[row, 5] = estimatedValues[row].ToString();
                    }

                    var estimatedTraining = Content.EstimatedTrainingClassValues.GetEnumerator();
                    estimatedTraining.MoveNext();
                    foreach (var trainingRow in Content.ProblemData.TrainingIndices)
                    {
                        values[trainingRow, 3] = estimatedTraining.Current.ToString();
                        estimatedTraining.MoveNext();
                    }
                    var estimatedTest = Content.EstimatedTestClassValues.GetEnumerator();
                    estimatedTest.MoveNext();
                    foreach (var testRow in Content.ProblemData.TestIndices)
                    {
                        values[testRow, 4] = estimatedTest.Current.ToString();
                        estimatedTest.MoveNext();
                    }

                    matrix              = new StringMatrix(values);
                    matrix.ColumnNames  = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, ESTIMATEDVALUES_DISCRIMINANT_SERIES_NAME };
                    matrix.SortableView = true;
                }
                matrixView.Content = matrix;
            }
        }
コード例 #20
0
        public void CrazyRead()
        {
            var m = StringMatrix.FromTsv("\"123\"\t100\r\n1,2,3\t45,45'\r\n\"\"\"69,\t69\"\"\"\t\"a\t\r\nb\"\r\n");

            Assert.AreEqual(3, m.Rows.Count);

            Assert.AreEqual(2, m.Rows[0].Count);
            Assert.AreEqual("\"123\"", m.Rows[0][0]);
            Assert.AreEqual("100", m.Rows[0][1]);

            Assert.AreEqual(2, m.Rows[1].Count);
            Assert.AreEqual("1,2,3", m.Rows[1][0]);
            Assert.AreEqual("45,45'", m.Rows[1][1]);

            Assert.AreEqual(2, m.Rows[2].Count);
            Assert.AreEqual("\"69,\t69\"", m.Rows[2][0]);
            Assert.AreEqual("a\t\r\nb", m.Rows[2][1]);
        }
コード例 #21
0
 protected override void OnContentChanged()
 {
     base.OnContentChanged();
     if (Content == null)
     {
         rowsTextBox.Text            = string.Empty;
         columnsTextBox.Text         = string.Empty;
         numericColumnsTextBox.Text  = string.Empty;
         nominalColumnsTextBox5.Text = string.Empty;
         missingValuesTextBox.Text   = string.Empty;
         totalValuesTextBox.Text     = string.Empty;
         stringMatrixView.Content    = null;
         statisticsMatrix            = null;
     }
     else
     {
         UpdateData();
     }
 }
コード例 #22
0
        protected virtual StringMatrix CreateValueMatrix()
        {
            string[,] values = new string[Content.ProblemData.Dataset.Rows, 8];

            double[] target             = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
            var      estimated          = Content.EstimatedValues.GetEnumerator();
            var      estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
            var      estimated_test     = Content.EstimatedTestValues.GetEnumerator();

            foreach (var row in Content.ProblemData.TrainingIndices)
            {
                estimated_training.MoveNext();
                values[row, 3] = estimated_training.Current.ToString();
            }

            foreach (var row in Content.ProblemData.TestIndices)
            {
                estimated_test.MoveNext();
                values[row, 4] = estimated_test.Current.ToString();
            }

            foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows))
            {
                estimated.MoveNext();
                double est = estimated.Current;
                double res = target[row] - est;
                values[row, 0] = row.ToString();
                values[row, 1] = target[row].ToString();
                values[row, 2] = est.ToString();
                values[row, 5] = res.ToString();
                values[row, 6] = Math.Abs(res).ToString();
                values[row, 7] = Math.Abs(res / target[row]).ToString();
            }

            var matrix = new StringMatrix(values);

            matrix.ColumnNames  = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Residuals (all)", "Absolute Error (all)", "Relative Error (all)" };
            matrix.SortableView = true;
            return(matrix);
        }
コード例 #23
0
        private StringMatrix CreateValueMatrix()
        {
            if (Content == null || Content.Id == Guid.Empty || !HiveAdminClient.Instance.Jobs.ContainsKey(Content.Id))
            {
                return(new StringMatrix());
            }

            var jobs      = HiveAdminClient.Instance.Jobs[Content.Id];
            var resources = HiveAdminClient.Instance.Resources;

            string[,] values = new string[jobs.Count, 13];

            for (int i = 0; i < jobs.Count; i++)
            {
                var job = jobs.ElementAt(i);
                values[i, 0]  = job.Job.State.ToString();
                values[i, 1]  = job.ExecutionState.ToString();
                values[i, 2]  = job.ExecutionTime.ToString();
                values[i, 3]  = job.Job.DateCreated.ToString();
                values[i, 4]  = job.Job.OwnerUsername;
                values[i, 5]  = job.Job.Name;
                values[i, 6]  = job.Job.JobCount.ToString();
                values[i, 7]  = (job.Job.JobCount - job.Job.CalculatingCount - job.Job.FinishedCount).ToString();
                values[i, 8]  = job.Job.CalculatingCount.ToString();
                values[i, 9]  = job.Job.FinishedCount.ToString();
                values[i, 10] = job.Job.Description;
                values[i, 11] = job.Job.Id.ToString();
                values[i, 12] = job.Job.OwnerUserId.ToString();
            }

            var matrix = new StringMatrix(values);

            matrix.ColumnNames  = new string[] { JOB_STATE, JOB_EXECUTIONSTATE, JOB_EXECUTIONTIME, JOB_DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_WAITINGTASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID };
            matrix.SortableView = true;
            return(matrix);
        }
    protected override void UpdateEstimatedValues() {
      if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
      else {
        StringMatrix matrix = null;
        if (Content != null) {
          string[,] values = new string[Content.ProblemData.Dataset.Rows, 6];
          double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
          double[] estimatedClassValue = Content.EstimatedClassValues.ToArray();
          double[] estimatedValues = Content.EstimatedValues.ToArray();
          for (int row = 0; row < target.Length; row++) {
            values[row, 0] = row.ToString();
            values[row, 1] = target[row].ToString();
            values[row, 2] = estimatedClassValue[row].ToString();
            values[row, 5] = estimatedValues[row].ToString();
          }

          var estimatedTraining = Content.EstimatedTrainingClassValues.GetEnumerator();
          estimatedTraining.MoveNext();
          foreach (var trainingRow in Content.ProblemData.TrainingIndices) {
            values[trainingRow, 3] = estimatedTraining.Current.ToString();
            estimatedTraining.MoveNext();
          }
          var estimatedTest = Content.EstimatedTestClassValues.GetEnumerator();
          estimatedTest.MoveNext();
          foreach (var testRow in Content.ProblemData.TestIndices) {
            values[testRow, 4] = estimatedTest.Current.ToString();
            estimatedTest.MoveNext();
          }

          matrix = new StringMatrix(values);
          matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, ESTIMATEDVALUES_DISCRIMINANT_SERIES_NAME };
          matrix.SortableView = true;
        }
        matrixView.Content = matrix;
      }
    }
コード例 #25
0
 /// <summary>
 /// Transforms the matrix using the transform function. Values in matrix are replaced.
 /// </summary>
 /// <param name="matrix"></param>
 /// <param name="transformFunc"></param>
 /// <returns></returns>
 public static StringMatrix Transform(this StringMatrix matrix,
                                      Action <StringMatrix, StringMatrix> transformFunc)
 {
     transformFunc(matrix, matrix);
     return(matrix);
 }
        protected override void UpdateEstimatedValues()
        {
            if (InvokeRequired)
            {
                Invoke((Action)UpdateEstimatedValues);
                return;
            }
            if (Content == null)
            {
                matrixView.Content = null;
                return;
            }

            int[]    indices;
            double[] estimatedClassValues;

            switch (SamplesComboBox.SelectedItem.ToString())
            {
            case SamplesComboBoxAllSamples: {
                indices = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray();
                estimatedClassValues = Content.EstimatedClassValues.ToArray();
                break;
            }

            case SamplesComboBoxTrainingSamples: {
                indices = Content.ProblemData.TrainingIndices.ToArray();
                estimatedClassValues = Content.EstimatedTrainingClassValues.ToArray();
                break;
            }

            case SamplesComboBoxTestSamples: {
                indices = Content.ProblemData.TestIndices.ToArray();
                estimatedClassValues = Content.EstimatedTestClassValues.ToArray();
                break;
            }

            default:
                throw new ArgumentException();
            }

            int classValuesCount = Content.ProblemData.Classes;
            int solutionsCount   = Content.ClassificationSolutions.Count();

            string[,] values = new string[indices.Length, 5 + classValuesCount + solutionsCount];
            double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
            List <List <double?> > estimatedValuesVector = GetEstimatedValues(SamplesComboBox.SelectedItem.ToString(), indices,
                                                                              Content.ClassificationSolutions);

            for (int i = 0; i < indices.Length; i++)
            {
                int row = indices[i];
                values[i, 0] = row.ToString();
                values[i, 1] = target[row].ToString();
                //display only indices and target values if no models are present
                if (solutionsCount > 0)
                {
                    values[i, 2] = estimatedClassValues[i].ToString();
                    values[i, 3] = (target[row].IsAlmost(estimatedClassValues[i])).ToString();
                    var groups =
                        estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
                    var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum();
                    // take care of divide by zero
                    if (estimationCount != 0)
                    {
                        values[i, 4] = (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();
                    }
                    else
                    {
                        values[i, 4] = double.NaN.ToString();
                    }
                    for (int classIndex = 0; classIndex < Content.ProblemData.Classes; classIndex++)
                    {
                        var group = groups.Where(g => g.Key == Content.ProblemData.ClassValues.ElementAt(classIndex)).SingleOrDefault();
                        if (group == null)
                        {
                            values[i, 5 + classIndex] = 0.ToString();
                        }
                        else
                        {
                            values[i, 5 + classIndex] = group.Count.ToString();
                        }
                    }
                    for (int modelIndex = 0; modelIndex < estimatedValuesVector[i].Count; modelIndex++)
                    {
                        values[i, 5 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
                                                             ? string.Empty
                                                             : estimatedValuesVector[i][modelIndex].ToString();
                    }
                }
            }

            StringMatrix  matrix      = new StringMatrix(values);
            List <string> columnNames = new List <string>()
            {
                "Id", TargetClassValuesColumnName, EstimatedClassValuesColumnName, CorrectClassificationColumnName, ConfidenceColumnName
            };

            columnNames.AddRange(Content.ProblemData.ClassNames);
            columnNames.AddRange(Content.Model.Models.Select(m => m.Name));
            matrix.ColumnNames  = columnNames;
            matrix.SortableView = true;
            matrixView.Content  = matrix;
        }
コード例 #27
0
ファイル: Euler11.cs プロジェクト: gorauskas/Euler.Net
        public void Solve() {
            StringMatrix str_matrix = new StringMatrix(string_matrix);
            str_matrix.CalculateIntMatrix();
            str_matrix.CalculateGreatestProductOf4AdjacentNumbers();

            Util.WL("The greatest product of four adjacent numbers in the grid is: ");
            Util.WL("P: {0}; Loc: {1},{2}; Seq: {3}"
                    .FormatWith(str_matrix.Product, str_matrix.X, str_matrix.Y, str_matrix.Sequence.ListToString()));

        }
    protected override void UpdateEstimatedValues() {
      if (InvokeRequired) {
        Invoke((Action)UpdateEstimatedValues);
        return;
      }
      if (Content == null) {
        matrixView.Content = null;
        return;
      }

      int[] indices;
      double[] estimatedClassValues;

      switch (SamplesComboBox.SelectedItem.ToString()) {
        case SamplesComboBoxAllSamples: {
            indices = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray();
            estimatedClassValues = Content.EstimatedClassValues.ToArray();
            break;
          }
        case SamplesComboBoxTrainingSamples: {
            indices = Content.ProblemData.TrainingIndices.ToArray();
            estimatedClassValues = Content.EstimatedTrainingClassValues.ToArray();
            break;
          }
        case SamplesComboBoxTestSamples: {
            indices = Content.ProblemData.TestIndices.ToArray();
            estimatedClassValues = Content.EstimatedTestClassValues.ToArray();
            break;
          }
        default:
          throw new ArgumentException();
      }

      int classValuesCount = Content.ProblemData.Classes;
      int solutionsCount = Content.ClassificationSolutions.Count();
      string[,] values = new string[indices.Length, 5 + classValuesCount + solutionsCount];
      double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
      List<List<double?>> estimatedValuesVector = GetEstimatedValues(SamplesComboBox.SelectedItem.ToString(), indices,
                                                            Content.ClassificationSolutions);

      for (int i = 0; i < indices.Length; i++) {
        int row = indices[i];
        values[i, 0] = row.ToString();
        values[i, 1] = target[row].ToString();
        //display only indices and target values if no models are present
        if (solutionsCount > 0) {
          values[i, 2] = estimatedClassValues[i].ToString();
          values[i, 3] = (target[row].IsAlmost(estimatedClassValues[i])).ToString();
          var groups =
            estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
          var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum();
          // take care of divide by zero
          if (estimationCount != 0) {
            values[i, 4] = (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();
          } else {
            values[i, 4] = double.NaN.ToString();
          }
          for (int classIndex = 0; classIndex < Content.ProblemData.Classes; classIndex++) {
            var group = groups.Where(g => g.Key == Content.ProblemData.ClassValues.ElementAt(classIndex)).SingleOrDefault();
            if (group == null) values[i, 5 + classIndex] = 0.ToString();
            else values[i, 5 + classIndex] = group.Count.ToString();
          }
          for (int modelIndex = 0; modelIndex < estimatedValuesVector[i].Count; modelIndex++) {
            values[i, 5 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
                                                             ? string.Empty
                                                             : estimatedValuesVector[i][modelIndex].ToString();
          }
        }
      }

      StringMatrix matrix = new StringMatrix(values);
      List<string> columnNames = new List<string>() { "Id", TargetClassValuesColumnName, EstimatedClassValuesColumnName, CorrectClassificationColumnName, ConfidenceColumnName };
      columnNames.AddRange(Content.ProblemData.ClassNames);
      columnNames.AddRange(Content.Model.Models.Select(m => m.Name));
      matrix.ColumnNames = columnNames;
      matrix.SortableView = true;
      matrixView.Content = matrix;
    }
コード例 #29
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.ZoomDistance = 100F;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            glwfc.BackColor = Color.FromArgb(0, 0, 20);
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(120f, 0, 0f), 1F);
            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 20.0f);
            };

            // this bit is eye candy just to show its working

            items.Add(new GLColorShaderWorld(), "COSW");
            GLRenderState rl = GLRenderState.Lines(1);

            rObjects.Add(items.Shader("COSW"),
                         GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                              GLShapeObjectFactory.CreateLines(new Vector3(-40, 0, -40), new Vector3(-40, 0, 40), new Vector3(10, 0, 0), 9),
                                                              new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green })
                         );


            rObjects.Add(items.Shader("COSW"),
                         GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                              GLShapeObjectFactory.CreateLines(new Vector3(-40, 0, -40), new Vector3(40, 0, -40), new Vector3(0, 0, 10), 9),
                                                              new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green })
                         );


            items.Add(new GLTexture2D(Properties.Resources.moonmap1k, SizedInternalFormat.Rgba8), "moon");
            items.Add(new GLTexturedShaderObjectTranslation(), "TEX");

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");     // def binding of 0

            // Pass vertex data thru a vertex shader which stores into a block

            vecoutbuffer = new GLStorageBlock(30, true);
            vecoutbuffer.AllocateBytes(32000, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy);       // set size of vec buffer

            ComputeShader csn = new ComputeShader();

            csn.Run();
            GLMemoryBarrier.All();

            // test consistency between row/columns of matrix4 of code and glsl
            int count = vecoutbuffer.ReadInt(0);

            System.Diagnostics.Debug.WriteLine("Count is " + count);

            {
                float[] mat4 = vecoutbuffer.ReadFloats(16, 16);
                System.Diagnostics.Debug.WriteLine("Compare mat4 constructor via order of floats:");
                for (int i = 0; i < mat4.Length; i++)
                {
                    System.Diagnostics.Debug.Write(string.Format("{0} = {1}, ", i, mat4[i]));
                }
                System.Diagnostics.Debug.WriteLine("");
            }

            {
                Vector2[] vec2 = vecoutbuffer.ReadVector2s(4, 2);
                System.Diagnostics.Debug.WriteLine($"Vec2a = inc {vec2[0].X.Degrees()} az {vec2[0].Y.Degrees()}");
            }

            Matrix4[] mat4r = vecoutbuffer.ReadMatrix4s(32, 32); // read all matrixes

            System.Diagnostics.Debug.WriteLine("Test mat constructor =" + Environment.NewLine + mat4r[0].ToString());
            System.Diagnostics.Debug.WriteLine("Row0 is " + mat4r[0].Row0.ToString());
            System.Diagnostics.Debug.WriteLine("Should be 20000 = " + mat4r[0][2, 3]);

            int id = 1;

            System.Diagnostics.Debug.WriteLine("Identity matrix = " + Environment.NewLine + mat4r[id++].ToString());

            {
                Matrix4 xrotpi4 = Matrix4.CreateRotationX(0.7853f);     // demo that Matrix4.Create is the same values as mat4rotatex
                System.Diagnostics.Debug.WriteLine("Rotate X Pi/4 =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], xrotpi4) + Environment.NewLine + mat4r[id].ToString());
                id++;
            }

            {
                Matrix4 yrotpi4 = Matrix4.CreateRotationY(0.7853f);
                System.Diagnostics.Debug.WriteLine("Rotate Y Pi/4 =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], yrotpi4) + Environment.NewLine + mat4r[id].ToString());
                id++;
            }

            {
                Matrix4 zrotpi4 = Matrix4.CreateRotationZ(0.7853f);
                System.Diagnostics.Debug.WriteLine("Rotate Z Pi/4 =" + GLStaticsMatrix4.ApproxEquals(mat4r[4], zrotpi4) + Environment.NewLine + mat4r[4].ToString());
                id++;
            }

            {   // test:
                //Matrix4 xrot = Matrix4.CreateRotationX((float)(Math.PI / 2));
                //Matrix4 r1 = new Matrix4(0, 0, 0, 0,
                //                         0, 0, 0, 0,
                //                         0, 0, 1, 0,
                //                         0, 0, 0, 1);
                //r1 = new Matrix4(new Matrix3())
                //Matrix4 r2 = r1 * xrot;
                //System.Diagnostics.Debug.WriteLine($"rotate z=+1 around x by 90\n{r1}\n{r2} ");
            }
            // X Y
            {
                Matrix4 xrot = Matrix4.CreateRotationX(0.7853f);     // demo that Matrix4.Create is the same values as mat4rotatex
                Matrix4 yrot = Matrix4.CreateRotationY(0.5f);
                Matrix4 res  = Matrix4.Identity;
                res = res * xrot;
                res = res * yrot;
                System.Diagnostics.Debug.WriteLine("Rotate XY Manu =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], res) + Environment.NewLine + mat4r[id].ToString());
                id++;
                System.Diagnostics.Debug.WriteLine("Rotate XY Auto =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], res) + Environment.NewLine + mat4r[id].ToString());
                id++;
                res = Matrix4.Identity;
                res = res * yrot;
                res = res * xrot;
                System.Diagnostics.Debug.WriteLine("Rotate YX Manu =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], res) + Environment.NewLine + mat4r[id].ToString());
                id++;
                System.Diagnostics.Debug.WriteLine("Rotate YX Auto =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], res) + Environment.NewLine + mat4r[id].ToString());
                id++;
            }

            // mat4 translation
            {
                Matrix4 trans = Matrix4.CreateTranslation(10, 20, 30);
                System.Diagnostics.Debug.WriteLine("Translation =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], trans) + Environment.NewLine + mat4r[id].ToString());
                id++;
            }

            // mat4translation with matrix
            {
                Matrix4 yrot05       = Matrix4.CreateRotationY(0.5f);
                Matrix4 trans        = Matrix4.CreateTranslation(10, 20, 30);
                Matrix4 rotplustrans = Matrix4.Mult(yrot05, trans);
                System.Diagnostics.Debug.WriteLine("Rot Translation =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], rotplustrans) + Environment.NewLine + mat4r[id].ToString());
                id++;
            }

            {
                Matrix4 trans   = Matrix4.CreateTranslation(10, 20, 30);
                Matrix4 rotxm90 = Matrix4.CreateRotationX(-90f.Radians());
                Matrix4 roty90  = Matrix4.CreateRotationY(90f.Radians());
                Matrix4 mscale  = Matrix4.CreateScale(1, 2, 3);

                Matrix4 res = Matrix4.Identity;
                res = res * mscale;
                res = res * rotxm90;
                res = res * roty90;
                res = res * trans;
                System.Diagnostics.Debug.WriteLine("Trans rot scale =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], res) + Environment.NewLine + mat4r[id].ToString());
                id++;
                //System.Diagnostics.Debug.WriteLine(transrotscale.ToString());

                System.Diagnostics.Debug.WriteLine("Trans rot scale2 =" + GLStaticsMatrix4.ApproxEquals(mat4r[id], res) + Environment.NewLine + mat4r[id].ToString());
                id++;
            }


            Vector4[] vec4r = vecoutbuffer.ReadVector4s(32 + 13 * 64, 2); // read all vec4 (N matrices between)

            {
                System.Diagnostics.Debug.WriteLine($"Vec4 {vec4r[0]}");
            }



            {
                StringMatrix rox = new StringMatrix("1", "0", "0", "0",
                                                    "0", "cx", "sx", "0",
                                                    "0", "-sx", "cx", "0",
                                                    "0", "0", "0", "1");
                StringMatrix roxm90 = new StringMatrix("1", "0", "0", "0",
                                                       "0", "0", "-1", "0",
                                                       "0", "1", "0", "0",
                                                       "0", "0", "0", "1");
                StringMatrix roy = new StringMatrix("cy", "0", "-sy", "0",
                                                    "0", "1", "0", "0",
                                                    "sy", "0", "cy", "0",
                                                    "0", "0", "0", "1");
                StringMatrix res = StringMatrix.Mult(roxm90, roy);
                string       r   = res.ToString(true);
                System.Diagnostics.Debug.WriteLine($"{r}");
                r = res.ToList();
                System.Diagnostics.Debug.WriteLine($"{r}");

                res = StringMatrix.Mult(rox, roy);
                r   = res.ToString(true);
                System.Diagnostics.Debug.WriteLine($"{r}");

                StringVector4 v4a   = new StringVector4("a", "-1", "c", "d");
                StringVector4 resv4 = StringMatrix.Mult(rox, v4a);
                r = resv4.ToString(true);
                System.Diagnostics.Debug.WriteLine($"{r}");
            }


            //    System.Di
            //    agnostics.Debug.WriteLine(rotplustransscale.ToString());
        }
コード例 #30
0
    private void getDataAsMatrixToolStripMenuItem_Click(object sender, EventArgs e) {
      int xCol = Matrix.ColumnNames.ToList().IndexOf(xAxisValue);
      int yCol = Matrix.ColumnNames.ToList().IndexOf(yAxisValue);

      var grouped = new Dictionary<string, List<string>>();
      Dictionary<double, string> reverseMapping = null;
      if (categoricalMapping.ContainsKey(xCol))
        reverseMapping = categoricalMapping[xCol].ToDictionary(x => x.Value, y => y.Key.ToString());
      foreach (var run in Content.Where(r => r.Visible)) {
        var x = GetValue(run, xAxisValue);
        object y;
        if (categoricalMapping.ContainsKey(yCol))
          y = Content.GetValue(run, yAxisValue);
        else y = GetValue(run, yAxisValue);
        if (!(x.HasValue && y != null)) continue;

        var category = reverseMapping == null ? x.Value.ToString() : reverseMapping[x.Value];
        if (!grouped.ContainsKey(category)) grouped[category] = new List<string>();
        grouped[category].Add(y.ToString());
      }

      if (!grouped.Any()) return;
      var matrix = new StringMatrix(grouped.Values.Max(x => x.Count), grouped.Count) {
        ColumnNames = grouped.Keys.ToArray()
      };
      int i = 0;
      foreach (var col in matrix.ColumnNames) {
        int j = 0;
        foreach (var y in grouped[col])
          matrix[j++, i] = y;
        i++;
      }
      matrix.SortableView = false;
      var view = MainFormManager.MainForm.ShowContent(matrix);
      view.ReadOnly = true;
    }
コード例 #31
0
        private void UpdateData(Dictionary <string, bool> oldVisibility = null)
        {
            var data = Content.PreprocessingData;

            rowsTextBox.Text            = data.Rows.ToString();
            columnsTextBox.Text         = data.Columns.ToString();
            numericColumnsTextBox.Text  = GetColumnCount <double>().ToString();
            nominalColumnsTextBox5.Text = GetColumnCount <string>().ToString();
            missingValuesTextBox.Text   = data.GetMissingValueCount().ToString();
            totalValuesTextBox.Text     = (data.Rows * data.Rows - data.GetMissingValueCount()).ToString();

            var variableNames = Content.PreprocessingData.VariableNames.ToList();

            if (horizontal)
            {
                statisticsMatrix = new StringMatrix(StatisticsNames.Length, Content.PreprocessingData.Columns)
                {
                    RowNames    = StatisticsView.StatisticsNames,
                    ColumnNames = variableNames
                }
            }
            ;
            else
            {
                statisticsMatrix = new StringMatrix(Content.PreprocessingData.Columns, StatisticsNames.Length)
                {
                    RowNames    = variableNames,
                    ColumnNames = StatisticsView.StatisticsNames
                }
            };

            for (int i = 0; i < data.Columns; i++)
            {
                var statistics = GetStatistics(i);
                for (int j = 0; j < statistics.Count; j++)
                {
                    if (horizontal)
                    {
                        statisticsMatrix[j, i] = statistics[j];
                    }
                    else
                    {
                        statisticsMatrix[i, j] = statistics[j];
                    }
                }
            }

            stringMatrixView.Parent.SuspendRepaint();
            stringMatrixView.Content = statisticsMatrix;

            var grid = stringMatrixView.DataGridView;
            int idx  = 0;
            var list = horizontal ? grid.Columns : grid.Rows as IList;

            foreach (DataGridViewBand band in list)
            {
                var variable = variableNames[idx++];
                if (oldVisibility != null)
                {
                    band.Visible = !oldVisibility.ContainsKey(variable) || oldVisibility[variable];
                }
            }
            if (horizontal)
            {
                stringMatrixView.UpdateColumnHeaders();
            }
            else
            {
                stringMatrixView.UpdateRowHeaders();
            }

            stringMatrixView.DataGridView.AutoResizeColumns();
            stringMatrixView.Parent.ResumeRepaint(true);
        }
コード例 #32
0
    private void UpdateEstimatedValues() {
      if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
      else {
        StringMatrix matrix = null;
        if (Content != null) {
          string[,] values = new string[Content.ProblemData.Dataset.Rows, 7];

          double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
          var estimated = Content.EstimatedValues.GetEnumerator();
          var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
          var estimated_test = Content.EstimatedTestValues.GetEnumerator();

          foreach (var row in Content.ProblemData.TrainingIndices) {
            estimated_training.MoveNext();
            values[row, 3] = estimated_training.Current.ToString();
          }

          foreach (var row in Content.ProblemData.TestIndices) {
            estimated_test.MoveNext();
            values[row, 4] = estimated_test.Current.ToString();
          }

          foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) {
            estimated.MoveNext();
            double est = estimated.Current;
            double res = Math.Abs(est - target[row]);
            values[row, 0] = row.ToString();
            values[row, 1] = target[row].ToString();
            values[row, 2] = est.ToString();
            values[row, 5] = Math.Abs(res).ToString();
            values[row, 6] = Math.Abs(res / target[row]).ToString();
          }

          matrix = new StringMatrix(values);
          matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Absolute Error (all)", "Relative Error (all)" };
          matrix.SortableView = true;
        }
        matrixView.Content = matrix;
      }
    }
コード例 #33
0
        private void getDataAsMatrixToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int xCol = Matrix.ColumnNames.ToList().IndexOf(xAxisValue);
            int yCol = Matrix.ColumnNames.ToList().IndexOf(yAxisValue);

            var grouped = new Dictionary <string, List <string> >();
            Dictionary <double, string> reverseMapping = null;

            if (categoricalMapping.ContainsKey(xCol))
            {
                reverseMapping = categoricalMapping[xCol].ToDictionary(x => x.Value, y => y.Key.ToString());
            }
            foreach (var run in Content.Where(r => r.Visible))
            {
                var    x = GetValue(run, xAxisValue);
                object y;
                if (categoricalMapping.ContainsKey(yCol))
                {
                    y = Content.GetValue(run, yAxisValue);
                }
                else
                {
                    y = GetValue(run, yAxisValue);
                }
                if (!(x.HasValue && y != null))
                {
                    continue;
                }

                var category = reverseMapping == null?x.Value.ToString() : reverseMapping[x.Value];

                if (!grouped.ContainsKey(category))
                {
                    grouped[category] = new List <string>();
                }
                grouped[category].Add(y.ToString());
            }

            if (!grouped.Any())
            {
                return;
            }
            var matrix = new StringMatrix(grouped.Values.Max(x => x.Count), grouped.Count)
            {
                ColumnNames = grouped.Keys.ToArray()
            };
            int i = 0;

            foreach (var col in matrix.ColumnNames)
            {
                int j = 0;
                foreach (var y in grouped[col])
                {
                    matrix[j++, i] = y;
                }
                i++;
            }
            matrix.SortableView = false;
            var view = MainFormManager.MainForm.ShowContent(matrix);

            view.ReadOnly = true;
        }
コード例 #34
0
    protected virtual StringMatrix CreateValueMatrix() {
      string[,] values = new string[Content.ProblemData.Dataset.Rows, 7];

      double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
      var estimated = Content.EstimatedValues.GetEnumerator();
      var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
      var estimated_test = Content.EstimatedTestValues.GetEnumerator();

      foreach (var row in Content.ProblemData.TrainingIndices) {
        estimated_training.MoveNext();
        values[row, 3] = estimated_training.Current.ToString();
      }

      foreach (var row in Content.ProblemData.TestIndices) {
        estimated_test.MoveNext();
        values[row, 4] = estimated_test.Current.ToString();
      }

      foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) {
        estimated.MoveNext();
        double est = estimated.Current;
        double res = Math.Abs(est - target[row]);
        values[row, 0] = row.ToString();
        values[row, 1] = target[row].ToString();
        values[row, 2] = est.ToString();
        values[row, 5] = Math.Abs(res).ToString();
        values[row, 6] = Math.Abs(res / target[row]).ToString();
      }

      var matrix = new StringMatrix(values);
      matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Absolute Error (all)", "Relative Error (all)" };
      matrix.SortableView = true;
      return matrix;
    }