Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 271 lines (241 sloc) 5.39 kb
116cfc3 @JohnLangford Missing .h/.cc files.
authored
1 #include <pthread.h>
fedec17 @JohnLangford made compile on fedora 11
authored
2 #include <stdio.h>
8750abd improvements to logistic and active from Nikos
John Langford authored
3 #include <float.h>
e31a522 @JohnLangford nuked multisource code
authored
4 #include <iostream>
3cda925 @JohnLangford initialization function isolated
authored
5 #include <math.h>
6dc3ddd @JohnLangford nearly all state now addressable
authored
6 #include <assert.h>
7
116cfc3 @JohnLangford Missing .h/.cc files.
authored
8 #include "global_data.h"
6dc3ddd @JohnLangford nearly all state now addressable
authored
9 #include "simple_label.h"
10 #include "parser.h"
11 #include "gd.h"
116cfc3 @JohnLangford Missing .h/.cc files.
authored
12
39d0693 @JohnLangford add -std=c++0x and deal with all kinds of type and namespace issues
authored
13 using namespace std;
14
0c42b7f @JohnLangford sender working again now
authored
15 struct global_prediction {
16 float p;
17 float weight;
18 };
19
20 int really_read(int sock, void* in, size_t count)
e31a522 @JohnLangford nuked multisource code
authored
21 {
0c42b7f @JohnLangford sender working again now
authored
22 char* buf = (char*)in;
23 size_t done = 0;
24 int r = 0;
25 while (done < count)
e31a522 @JohnLangford nuked multisource code
authored
26 {
0c42b7f @JohnLangford sender working again now
authored
27 if ((r = read(sock,buf,count-done)) == 0)
28 return 0;
29 else
30 if (r < 0)
31 {
32 cerr << "argh! bad read! on message from " << sock << endl;
33 perror(NULL);
34 exit(0);
35 }
36 else
37 {
38 done += r;
39 buf += r;
40 }
e31a522 @JohnLangford nuked multisource code
authored
41 }
0c42b7f @JohnLangford sender working again now
authored
42 return done;
e31a522 @JohnLangford nuked multisource code
authored
43 }
44
0c42b7f @JohnLangford sender working again now
authored
45 void get_prediction(int sock, float& res, float& weight)
46 {
47 global_prediction p;
48 int count = really_read(sock, &p, sizeof(p));
49 res = p.p;
50 weight = p.weight;
51
52 assert(count == sizeof(p));
53 }
54
55 void send_prediction(int sock, global_prediction p)
e31a522 @JohnLangford nuked multisource code
authored
56 {
57 if (write(sock, &p, sizeof(p)) < (int)sizeof(p))
58 {
0c42b7f @JohnLangford sender working again now
authored
59 cerr << "argh! bad global write! " << sock << endl;
e31a522 @JohnLangford nuked multisource code
authored
60 perror(NULL);
61 exit(0);
62 }
63 }
64
b7ba3f3 partially implemented backprop
John Langford authored
65 void binary_print_result(int f, float res, float weight, v_array<char> tag)
116cfc3 @JohnLangford Missing .h/.cc files.
authored
66 {
84d09d6 @JohnLangford Half of cluster parallel once again working.
authored
67 if (f >= 0)
68 {
b7ba3f3 partially implemented backprop
John Langford authored
69 global_prediction ps = {res, weight};
0c42b7f @JohnLangford sender working again now
authored
70 send_prediction(f, ps);
84d09d6 @JohnLangford Half of cluster parallel once again working.
authored
71 }
116cfc3 @JohnLangford Missing .h/.cc files.
authored
72 }
73
6dc3ddd @JohnLangford nearly all state now addressable
authored
74 void print_tag(int f, v_array<char> tag)
75 {
76 char temp[30];
77 ssize_t t;
78 if (tag.begin != tag.end){
79 temp[0] = ' ';
80 t = write(f, temp, 1);
81 if (t != 1)
82 cerr << "write error" << endl;
83 t = write(f, tag.begin, sizeof(char)*tag.index());
84 if (t != (ssize_t) (sizeof(char)*tag.index()))
85 cerr << "write error" << endl;
86 }
87 }
88
b7ba3f3 partially implemented backprop
John Langford authored
89 void print_result(int f, float res, float weight, v_array<char> tag)
116cfc3 @JohnLangford Missing .h/.cc files.
authored
90 {
91 if (f >= 0)
92 {
93 char temp[30];
5d424bd @JohnLangford fix silly extra space
authored
94 int num = sprintf(temp, "%f", res);
116cfc3 @JohnLangford Missing .h/.cc files.
authored
95 ssize_t t;
96 t = write(f, temp, num);
97 if (t != num)
98 cerr << "write error" << endl;
6dc3ddd @JohnLangford nearly all state now addressable
authored
99 print_tag(f, tag);
100 temp[0] = '\n';
101 t = write(f, temp, 1);
102 if (t != 1)
103 cerr << "write error" << endl;
104 }
105 }
106
a19087e @JohnLangford added print_text for searn reduction
authored
107 void print_raw_text(int f, string s, v_array<char> tag)
108 {
109 if (f < 0)
110 return;
111
112 ssize_t t;
113 int num = s.length();
114 t = write(f, s.c_str(), num);
115 if (t != num)
116 cerr << "write error" << endl;
117 print_tag(f, tag);
118 char temp = '\n';
119 t = write(f, &temp, 1);
120 if (t != 1)
121 cerr << "write error" << endl;
122 }
123
6dc3ddd @JohnLangford nearly all state now addressable
authored
124 void active_print_result(int f, float res, float weight, v_array<char> tag)
125 {
126 if (f >= 0)
127 {
128 char temp[30];
129 int num = sprintf(temp, "%f", res);
130 ssize_t t;
131 t = write(f, temp, num);
132 if (t != num)
133 cerr << "write error" << endl;
134 print_tag(f, tag);
135 if(weight >= 0)
2d26611 Nikos active learning patches
John Langford authored
136 {
137 num = sprintf(temp, " %f", weight);
138 t = write(f, temp, num);
139 if (t != num)
140 cerr << "write error" << endl;
141 }
116cfc3 @JohnLangford Missing .h/.cc files.
authored
142 temp[0] = '\n';
143 t = write(f, temp, 1);
144 if (t != 1)
145 cerr << "write error" << endl;
146 }
147 }
148
6dc3ddd @JohnLangford nearly all state now addressable
authored
149 void print_lda_result(vw& all, int f, float* res, float weight, v_array<char> tag)
c13ae76 synced lda
John Langford authored
150 {
151 if (f >= 0)
152 {
153 char temp[30];
154 ssize_t t;
155 int num;
6dc3ddd @JohnLangford nearly all state now addressable
authored
156 for (size_t k = 0; k < all.lda; k++)
c13ae76 synced lda
John Langford authored
157 {
158 num = sprintf(temp, "%f ", res[k]);
159 t = write(f, temp, num);
160 if (t != num)
161 cerr << "write error" << endl;
162 }
6dc3ddd @JohnLangford nearly all state now addressable
authored
163 print_tag(f, tag);
c13ae76 synced lda
John Langford authored
164 temp[0] = '\n';
165 t = write(f, temp, 1);
166 if (t != 1)
167 cerr << "write error" << endl;
168 }
169 }
170
5136dca @JohnLangford marked nonreentrant parts
authored
171 void set_mm(shared_data* sd, double label)
cefb32e @JohnLangford Added versioning to output files and made min_prediction and max_pred…
authored
172 {
5136dca @JohnLangford marked nonreentrant parts
authored
173 sd->min_label = min(sd->min_label, label);
8750abd improvements to logistic and active from Nikos
John Langford authored
174 if (label != FLT_MAX)
5136dca @JohnLangford marked nonreentrant parts
authored
175 sd->max_label = max(sd->max_label, label);
cefb32e @JohnLangford Added versioning to output files and made min_prediction and max_pred…
authored
176 }
177
5136dca @JohnLangford marked nonreentrant parts
authored
178 void noop_mm(shared_data* sd, double label)
cefb32e @JohnLangford Added versioning to output files and made min_prediction and max_pred…
authored
179 {}
116cfc3 @JohnLangford Missing .h/.cc files.
authored
180
3cda925 @JohnLangford initialization function isolated
authored
181 vw::vw()
182 {
6dc3ddd @JohnLangford nearly all state now addressable
authored
183 sd = (shared_data *) malloc(sizeof(shared_data));
184 sd->queries = 0;
185 sd->example_number = 0;
186 sd->weighted_examples = 0.;
187 sd->old_weighted_examples = 0.;
188 sd->weighted_labels = 0.;
189 sd->total_features = 0;
190 sd->sum_loss = 0.0;
191 sd->sum_loss_since_last_dump = 0.0;
192 sd->dump_interval = exp(1.);
193 sd->gravity = 0.;
194 sd->contraction = 1.;
195 sd->min_label = 0.;
196 sd->max_label = 1.;
197 sd->t = 1.;
198 sd->binary_label = false;
5136dca @JohnLangford marked nonreentrant parts
authored
199 sd->k = 0;
200
6dc3ddd @JohnLangford nearly all state now addressable
authored
201 p = new_parser();
8e3cb38 @hal3 moved label_parser into parser, added example functions for alloc, de…
hal3 authored
202 p->lp = (label_parser*)malloc(sizeof(label_parser));
203 *(p->lp) = simple_label;
204
6dc3ddd @JohnLangford nearly all state now addressable
authored
205 reg_mode = 0;
5136dca @JohnLangford marked nonreentrant parts
authored
206
6dc3ddd @JohnLangford nearly all state now addressable
authored
207 bfgs = false;
208 hessian_on = false;
209 sequence = false;
210 stride = 1;
211 num_bits = 18;
212 default_bits = true;
213 daemon = false;
214 num_children = 10;
215 lda_alpha = 0.1;
216 lda_rho = 0.1;
217 lda_D = 10000.;
218 minibatch = 1;
219 span_server = "";
220 m = 15;
221
222 driver = drive_gd;
e9cee58 @JohnLangford rejiggered reductions for library
authored
223 learn = learn_gd;
224 finish = finish_gd;
5136dca @JohnLangford marked nonreentrant parts
authored
225 set_minmax = set_mm;
226
6dc3ddd @JohnLangford nearly all state now addressable
authored
227 power_t = 0.5;
228 eta = 10;
229 numpasses = 1;
230 rel_threshold = 0.001;
231 rank = 0;
232
233 final_prediction_sink.begin = final_prediction_sink.end=final_prediction_sink.end_array = NULL;
234 raw_prediction = -1;
235 print = print_result;
a19087e @JohnLangford added print_text for searn reduction
authored
236 print_text = print_raw_text;
6dc3ddd @JohnLangford nearly all state now addressable
authored
237 lda = 0;
238 random_weights = false;
239 per_feature_regularizer_input = "";
240 per_feature_regularizer_output = "";
241 per_feature_regularizer_text = "";
5136dca @JohnLangford marked nonreentrant parts
authored
242
6dc3ddd @JohnLangford nearly all state now addressable
authored
243 nonormalize = false;
244 l1_lambda = 0.0;
245 l2_lambda = 0.0;
246
247 eta_decay_rate = 1.0;
248 initial_weight = 0.0;
249
250 unique_id = 0;
251 total = 1;
252 node = 0;
4719376 @Smerity Small fix: uninitialized skip argument resulted in segfaults
Smerity authored
253
6dc3ddd @JohnLangford nearly all state now addressable
authored
254 ngram = 0;
4719376 @Smerity Small fix: uninitialized skip argument resulted in segfaults
Smerity authored
255 skips = 0;
6dc3ddd @JohnLangford nearly all state now addressable
authored
256
257 adaptive = false;
258 add_constant = true;
259 exact_adaptive_norm = false;
260 audit = false;
261 active = false;
262 active_c0 = 8.;
263 active_simulation = false;
264 reg.weight_vectors = NULL;
265 reg.regularizers = NULL;
266 pass_length = (size_t)-1;
406de98 @JohnLangford fixed library to really work on example
authored
267 passes_complete = 0;
6dc3ddd @JohnLangford nearly all state now addressable
authored
268
269 save_per_pass = false;
3cda925 @JohnLangford initialization function isolated
authored
270 }
Something went wrong with that request. Please try again.