Skip to content

Commit ea4b74a

Browse files
authored
Add files via upload
1 parent 45515a0 commit ea4b74a

File tree

3 files changed

+247
-98
lines changed

3 files changed

+247
-98
lines changed

dataset.cpp

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,54 @@
1010
void DataSet::ReadCSVFile(std::string file_name) {
1111

1212
std::ifstream file(file_name.c_str());
13-
if (!file) {
13+
14+
if (!file)
15+
{
1416
file.open(file_name.c_str());
1517
}
1618
if (!file) {
17-
std::cerr << "Error No" << file_name << " found. " << std::endl;
19+
std::cerr << "Error: No " << file_name << " found ." << std::endl;
1820

1921
}
2022

2123
std::stringstream buffer;
2224
buffer << file.rdbuf();
2325
std::string line;
26+
2427
std::vector<std::string>lines;
25-
while (getline(buffer, line, '\n')) {
26-
lines.push_back(line);
28+
while (getline(buffer, line,'\n')) {
29+
//std::cout << line << std::endl;
30+
//std::cout << "ses" << std::endl;
31+
lines.push_back(line);
2732
}
2833

29-
//the other lines contain the features for each floaer
3034

31-
for (int i = 1; i < lines.size(); ++i) {
32-
std::vector<float>features =ReadCSVLine(lines[i]);
33-
x1_.push_back(features[0]);
34-
x2_.push_back(features[1]);
35-
x3_.push_back(features[2]);
36-
x4_.push_back(features[3]);
37-
y_.push_back(features[4]);
35+
//std::cout<<"lines-size "<< lines.size() << std::endl;
36+
///the other lines contain the features for each flower
37+
38+
for (int i = 1; i < lines.size(); ++i) {
39+
40+
//std::cout << lines[i] << std::endl;
41+
std::vector<float>features = ReadCSVLine(lines[i]);
42+
43+
44+
45+
mean_.push_back(features[0]);
46+
stdev_.push_back(features[1]);
47+
kurtosis_.push_back(features[2]);
48+
skewness_.push_back(features[3]);
49+
snr_.push_back(features[4]);
50+
dmsnr_.push_back(features[5]);
51+
kurtosissnr_.push_back(features[6]);
52+
skewsnr_.push_back(features[7]);
53+
class_.push_back(features[8]);
3854

3955
}
56+
4057
}
4158

42-
std::vector<float>DataSet::ReadCSVLine(std::string line) {
59+
60+
std::vector<float> DataSet::ReadCSVLine(std::string line) {
4361
std::vector<float> line_data;
4462
std::stringstream lineStream(line);
4563
std::string cell;
@@ -48,36 +66,9 @@ std::vector<float>DataSet::ReadCSVLine(std::string line) {
4866
if (cell != "setosa" && cell != "versicolor" && cell != "virginica") {
4967
line_data.push_back(std::stod(cell.c_str()));
5068
}
51-
else {
52-
if (cell == "setosa") {
53-
line_data.push_back(0.0f);
54-
}
55-
else if (cell == "versicolor") {
56-
line_data.push_back(1.0f);
57-
}
58-
else {
59-
line_data.push_back(2.0f);
60-
}
61-
}
69+
6270
}
63-
return line_data;
6471

72+
//std::cout << "Line data size: " << line_data.size() << std::endl;
73+
return line_data;
6574
}
66-
67-
68-
std::initializer_list<float> DataSet::input(float petal_length, float petal_width, float sepal_length, float sepal_width) {
69-
return { petal_length,petal_width,sepal_length,sepal_width };
70-
}
71-
72-
std::string DataSet::output(std::vector<float> one_hot_encoding_species) {
73-
if (one_hot_encoding_species[0] == 1) {
74-
return "setosa";
75-
}
76-
else if (one_hot_encoding_species[1] == 1) {
77-
return "versicolor";
78-
}
79-
else {
80-
return "virginica";
81-
}
82-
}
83-

dataset.h

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,72 @@
11
#pragma once
2-
32
#include<iostream>
43
#include<string>
54
#include<vector>
65
#include<unordered_map>
76
#include<initializer_list>
87

98

9+
1010
class DataSetMetaData {
1111

1212
friend class DataSet;
13-
private:
14-
float sepal_length;
15-
float sepal_width;
16-
float petal_length;
17-
float petal_width;
18-
std::string species;
13+
14+
1915
};
2016

17+
18+
2119
class DataSet {
2220

21+
22+
2323
public:
2424

25-
//read the given csv file and complete_x and y_
25+
//read the given csv file and complete x_ and y_
26+
2627
void ReadCSVFile(std::string file_name);
28+
2729

30+
//Construct a dataset from the given csv file path
2831

29-
//Construct a data set from the given csv file path
3032
DataSet(std::string file_name) {
3133
ReadCSVFile(file_name);
34+
35+
//std::cout << "YES COME" << std::endl;
3236
}
3337

34-
///getters
38+
//getters
3539

36-
std::vector<float>& x1() { return x1_; }
37-
std::vector<float>& x2() { return x2_; }
38-
std::vector<float>& x3() { return x3_; }
39-
std::vector<float>& x4() { return x4_;}
40-
std::vector<float& y() { return y_; }
40+
std::vector<float>mean() { return mean_; };
41+
std::vector<float>stdev() { return stdev_; };
42+
std::vector<float>kurtosis() { return kurtosis_; };
43+
std::vector<float>skewness() { return skewness_; };
44+
std::vector<float>snr() { return snr_; };
45+
std::vector<float>dmsnr() { return dmsnr_; };
46+
std::vector<float>kurtosissnr() { return kurtosissnr_; };
47+
std::vector<float>skewsnr() { return skewsnr_; };
48+
std::vector<float>clas() { return class_; };
4149

50+
4251

4352

44-
///convert one csv line to a vector of float
53+
//convert one csv line to a vector of float
4554

46-
std::vector<float>ReadCSVLine(std::string line);
47-
///normalize a human input using the data set metadata
48-
std::initializer_list<float>input(float petal_length,float peta_width,float sepal_length,float sepal_width);
55+
std::vector<float> ReadCSVLine(std::string line);
4956

50-
std::string output(std::vector<float>one_hot_encoding_species);
57+
5158

5259
private:
5360
DataSetMetaData data_set_metadata;
54-
std::vector<float>x1_;
55-
std::vector<float>x2_;
56-
std::vector < float>x3_;
57-
std::vector<float>x4_;
58-
std::vector<float>y_;
59-
};
60-
61+
std::vector<float>mean_;
62+
std::vector<float>stdev_;
63+
std::vector<float>kurtosis_;
64+
std::vector<float>skewness_;
65+
std::vector<float>snr_;
66+
std::vector<float>dmsnr_;
67+
std::vector<float>kurtosissnr_;
68+
std::vector<float>skewsnr_;
69+
70+
std::vector<float>class_;
71+
72+
};

0 commit comments

Comments
 (0)