public void F64Matrix_GetColumn()
 {
     // matrix is created row wise
     var matrix = new F64Matrix(new double[] { 1, 2, 3,
                                               4, 5, 6 }, 2, 3);
     // returns the column as an array
     var column = matrix.Column(1); // [2, 5]
 }
예제 #2
0
        /// <summary>
        /// Creates a matrix of ordered indices. Each row is ordered after the corresponding feature column.
        /// </summary>
        /// <param name="observations"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        int[][] CreateOrderedElements(F64Matrix observations, int rows)
        {
            var orderedElements = new int[observations.ColumnCount][];

            for (int i = 0; i < observations.ColumnCount; i++)
            {
                var feature = observations.Column(i);
                var indices = Enumerable.Range(0, rows).ToArray();
                feature.SortWith(indices);
                orderedElements[i] = indices;
            }
            return(orderedElements);
        }
        Dictionary <int, double> GetInitialRanking(F64Matrix crossValidatedModelPredictions, double[] targets)
        {
            var ranking            = new Dictionary <int, double>();
            var currentPredictions = new double[crossValidatedModelPredictions.RowCount];

            for (int i = 0; i < crossValidatedModelPredictions.ColumnCount; i++)
            {
                crossValidatedModelPredictions.Column(i, currentPredictions);
                var error = m_metric.Error(targets, currentPredictions);
                ranking.Add(i, error);
            }

            return(ranking.OrderBy(v => v.Value).ToDictionary(v => v.Key, v => v.Value));
        }