This repository has been archived by the owner on Nov 19, 2020. It is now read-only.
/
Identification.cs
90 lines (79 loc) · 2.5 KB
/
Identification.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Accord Statistics Library
// The Accord.NET Framework
// http://accord-framework.net
//
// Copyright © César Souza, 2009-2017
// cesarsouza at gmail.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
#if !NETSTANDARD1_4
namespace Accord.Statistics.Filters
{
using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Collections.Generic;
/// <summary>
/// Identification filter.
/// </summary>
///
/// <remarks>
/// <para>
/// The identification filter adds a new column to the data containing an
/// unique id for each of the samples (rows) in the data table (or matrix).</para>
/// </remarks>
///
[Serializable]
public class Identification : IFilter
{
/// <summary>
/// Gets or sets the name of the column used
/// to store row indices.
/// </summary>
///
public String ColumnName { get; set; }
/// <summary>
/// Creates a new identification filter.
/// </summary>
///
public Identification()
{
ColumnName = "Id";
}
/// <summary>
/// Creates a new identification filter.
/// </summary>
///
public Identification(String columnName)
{
ColumnName = columnName;
}
/// <summary>
/// Applies the filter to the DataTable.
/// </summary>
///
public DataTable Apply(DataTable data)
{
DataTable result = data.Copy();
result.Columns.Add(ColumnName, typeof(int));
for (int i = 0; i < result.Rows.Count; i++)
result.Rows[i][ColumnName] = i;
return result;
}
}
}
#endif