forked from thesiddharth/dpsvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.cpp
More file actions
43 lines (32 loc) · 922 Bytes
/
parse.cpp
File metadata and controls
43 lines (32 loc) · 922 Bytes
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
#include "parse.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
void populate_data(vector<float> &x, vector<int> &y, int num_train_data, int num_attributes,char input_file_name[200] ) {
ifstream file(input_file_name);
if(!file.is_open())
{
cout << "Couldn't open file\n";
exit(-1);
}
//std::vector<std::string> result;
string line;
int curr_example_num = 0;
while (curr_example_num < num_train_data)
{
getline(file,line);
stringstream lineStream(line);
string cell;
getline(lineStream,cell,',');
y[curr_example_num] = stoi(cell);
int curr_attr_num = 0;
while(getline(lineStream,cell,','))
{
x[(curr_example_num * num_attributes) + curr_attr_num++] = stof(cell);
}
++curr_example_num;
}
}