-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfile.HowtoContribute.html
185 lines (134 loc) · 10.2 KB
/
file.HowtoContribute.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>
File: HowToContribute
— FSelector Documentation
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
relpath = '';
if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
if (window.top.frames.main) document.body.className = 'frames';
</script>
<div id="header">
<div id="menu">
<a href="_index.html" title="Index">Index</a> »
<span class="title">File: HowToContribute</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a id="class_list_link" href="#">Class List</a>
<a id="method_list_link" href="#">Method List</a>
<a id="file_list_link" href="#">File List</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><div id='filecontents'><h2>How to add your own feature selection algorithms</h2>
<p><strong>Baisc steps</strong></p>
<pre class="code ruby"><code>1. Require the FSelector gem
2. Derive a subclass from a base class (Base, BaseDiscrete, BaseContinuous and etc.)
3. Set your own feature selection algorithm with one of the following two types:
:feature_weighting # if it outputs weight for each feature
:feature_subset_selection # if it outputs a subset of original feature set
4. Depending on your algorithm type, override one of the following two interfaces:
calc_contribution() # if it belongs to the type of feature weighting algorithms
get_feature_subset() # if it belongs to the type of feature subset selection algorithms
</code></pre>
<p><strong>Example</strong></p>
<pre class="code ruby"><code><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>fselector</span><span class='tstring_end'>'</span></span> <span class='comment'># step 1
</span>
<span class='kw'>module</span> <span class='const'>FSelector</span>
<span class='comment'># create a new algorithm belonging to the type of feature weighting
</span> <span class='comment'># to this end, simply override the calc_contribution() in Base class
</span> <span class='kw'>class</span> <span class='const'>NewAlgo_Weight</span> <span class='op'><</span> <span class='const'>Base</span> <span class='comment'># step 2
</span> <span class='comment'># set the algorithm type
</span> <span class='ivar'>@algo_type</span> <span class='op'>=</span> <span class='symbol'>:feature_weighting</span> <span class='comment'># step 3
</span>
<span class='comment'># add your own initialize() here if necessary
</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># the algorithm assigns feature weight randomly
</span> <span class='kw'>def</span> <span class='id identifier rubyid_calc_contribution'>calc_contribution</span><span class='lparen'>(</span><span class='id identifier rubyid_f'>f</span><span class='rparen'>)</span> <span class='comment'># step 4
</span> <span class='id identifier rubyid_s'>s</span> <span class='op'>=</span> <span class='id identifier rubyid_rand'>rand</span>
<span class='comment'># set the score (s) of feature (f) for class (:BEST is the best score among all classes)
</span> <span class='id identifier rubyid_set_feature_score'>set_feature_score</span><span class='lparen'>(</span><span class='id identifier rubyid_f'>f</span><span class='comma'>,</span> <span class='symbol'>:BEST</span><span class='comma'>,</span> <span class='id identifier rubyid_s'>s</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span> <span class='comment'># NewAlgo_Weight
</span>
<span class='comment'># create a new algorithm belonging to the type of feature subset selection
</span> <span class='comment'># to this end, simly override the get_feature_subset() in Base class
</span> <span class='kw'>class</span> <span class='const'>NewAlgo_Subset</span> <span class='op'><</span> <span class='const'>Base</span> <span class='comment'># step 2
</span> <span class='comment'># set the algorithm type
</span> <span class='ivar'>@algo_type</span> <span class='op'>=</span> <span class='symbol'>:feature_subset_selection</span> <span class='comment'># step 3
</span>
<span class='comment'># add your own initialize() here if necessary
</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># the algorithm returns a random half-size subset of the orignal one
</span> <span class='kw'>def</span> <span class='id identifier rubyid_get_feature_subset'>get_feature_subset</span> <span class='comment'># step 4
</span> <span class='id identifier rubyid_org_features'>org_features</span> <span class='op'>=</span> <span class='id identifier rubyid_get_features'>get_features</span>
<span class='id identifier rubyid_subset'>subset</span> <span class='op'>=</span> <span class='id identifier rubyid_org_features'>org_features</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span><span class='lparen'>(</span><span class='id identifier rubyid_org_features'>org_features</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='op'>/</span><span class='int'>2</span><span class='rparen'>)</span>
<span class='id identifier rubyid_subset'>subset</span>
<span class='kw'>end</span>
<span class='kw'>end</span> <span class='comment'># NewAlgo_Subset
</span><span class='kw'>end</span> <span class='comment'># module
</span></code></pre>
<p><strong>Test your algorithms</strong></p>
<pre class="code ruby"><code><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>fselector</span><span class='tstring_end'>'</span></span>
<span class='comment'># example 1
</span>
<span class='comment'># use NewAlgo_Weighting
</span><span class='id identifier rubyid_r1'>r1</span> <span class='op'>=</span> <span class='const'>FSelector</span><span class='op'>::</span><span class='const'>NewAlgo_Weight</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_r1'>r1</span><span class='period'>.</span><span class='id identifier rubyid_data_from_csv'>data_from_csv</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>test/iris.csv</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_r1'>r1</span><span class='period'>.</span><span class='id identifier rubyid_select_feature_by_rank!'>select_feature_by_rank!</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'><=1</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_r1'>r1</span><span class='period'>.</span><span class='id identifier rubyid_get_features'>get_features</span>
<span class='comment'># example 2
</span>
<span class='comment'># use NewAlgo_Subset
</span><span class='id identifier rubyid_r2'>r2</span> <span class='op'>=</span> <span class='const'>FSelector</span><span class='op'>::</span><span class='const'>NewAlgo_Subset</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_r2'>r2</span><span class='period'>.</span><span class='id identifier rubyid_data_from_csv'>data_from_csv</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>test/iris.csv</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_r2'>r2</span><span class='period'>.</span><span class='id identifier rubyid_select_feature!'>select_feature!</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_r2'>r2</span><span class='period'>.</span><span class='id identifier rubyid_get_features'>get_features</span>
</code></pre>
<h2>How to become a contributor of FSelector on GitHub</h2>
<p><strong>Set up your repository</strong></p>
<pre class="code ruby"><code>1. Go to https://github.com/need47/fselector and click the "Fork" button
2. Clone your fork to your local machine:
git clone [email protected]:yourGitUserName/fselector.git
3. Assign the original repository to a remote called "upstream":
cd fselector
git remote add upstream git://github.com/need47/fselector.git
4. Get updates from the "upstream" and merge to your local repository:
git fetch upstream
git merge upstream/master
</code></pre>
<p><strong>Develop features</strong></p>
<pre class="code ruby"><code>1. Create and checkout a feature branch to house your edits:
git checkout -b branchName
2. Add your own feature selection algorithm:
git add yourAlgorithm.rb
git commit -m "your commit message"
3. Push your branch to GitHub:
git push origin branchName
4. Visit your forked project on GitHub and switch to your branhName branch
5. Click the "Pull Request" button to request that your features to be merged to the "upstream" master
</code></pre>
</div></div>
<div id="footer">
Generated on Mon Nov 5 11:19:43 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.5 (ruby-1.9.3).
</div>
</body>
</html>