-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.cpp
More file actions
112 lines (89 loc) · 3.25 KB
/
instance.cpp
File metadata and controls
112 lines (89 loc) · 3.25 KB
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
/**************************************************
Programmer : saugata
Date : 20/6/2021
Description :
Header file for instance class and functions.
***************************************************/
#include <string>
#include <vector>
#include <memory>
#include "instance.h"
Instance::Instance( const std::string& name, std::vector<double>* data,
std::vector<double>* expected, std::shared_ptr<std::vector<std::string> >& features,
std::shared_ptr<std::vector<std::string> >& classes )
:name(name), data(data), expected(expected), features(features), classes(classes){
}
Instance::Instance(const Instance& rhs)
:name(rhs.name){
std::vector<double>* t_data = new std::vector<double>();
std::vector<double>* e_data = new std::vector<double>();
for(const double d : *(rhs.data)){
t_data->push_back(d);
}
for(const double e : *(rhs.expected)){
e_data->push_back(e);
}
data = std::unique_ptr<std::vector<double> >(t_data);
expected = std::unique_ptr<std::vector<double> >(e_data);
features = std::shared_ptr<std::vector<std::string> >(rhs.features);
classes = std::shared_ptr<std::vector<std::string> >(rhs.classes);
}
Instance& Instance::operator=( const Instance& rhs){
if( this != &rhs ){
data.reset();
expected.reset();
features.reset();
classes.reset();
std::vector<double>* t_data = new std::vector<double>();
std::vector<double>* e_data = new std::vector<double>();
for(const double d : *(rhs.data)){
t_data->push_back(d);
}
for(const double e : *(rhs.expected)){
e_data->push_back(e);
}
name = rhs.name;
data = std::unique_ptr<std::vector<double> >(t_data);
expected = std::unique_ptr<std::vector<double> >(e_data);
features = std::shared_ptr<std::vector<std::string> >(rhs.features);
classes = std::shared_ptr<std::vector<std::string> >(rhs.classes);
}
return *this;
}
Instance::~Instance(){
data.reset();
expected.reset();
features.reset();
classes.reset();
}
double Instance::operator[]( const int& index) const{
return (*data)[index];
}
double Instance::getExpected( const int& index) const{
return (*expected)[index];
}
size_t Instance::getDataSize() const{
return data->size();
}
size_t Instance::getExpectedSize() const{
return expected->size();
}
std::string Instance::getFeatName(const int& index) const{
return (*features)[index];
}
std::string Instance::getClassName(const int& index) const{
return (*classes)[index];
}
InstanceSet::InstanceSet( std::string name, SetType type, std::vector<Instance> instances)
: name(name), type(type), instances(instances){}
InstanceSet::InstanceSet( std::string name, SetType type)
: name(name), type(type){}
std::string InstanceSet::getName() const{
return name;
}
bool operator==( const InstanceSet& left, const InstanceSet& right){
return left.getName() == right.getName();
}
bool operator==( const InstanceSet& left, const std::string& right){
return left.getName() == right;
}