Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
rapid-mix
RapidLib
Commits
b2ff1268
Commit
b2ff1268
authored
Nov 10, 2016
by
mzed
Browse files
Fixes
#42
kNN serialization seems to be working properly in both directions
parent
267f5dd3
Changes
2
Hide whitespace changes
Inline
Side-by-side
RapidAPI/RapidAPI/main.cpp
View file @
b2ff1268
...
@@ -46,10 +46,12 @@ int main(int argc, const char * argv[]) {
...
@@ -46,10 +46,12 @@ int main(int argc, const char * argv[]) {
classification
myKnnFromString
;
classification
myKnnFromString
;
myKnnFromString
.
putJSON
(
myKnn
.
getJSON
());
myKnnFromString
.
putJSON
(
myKnn
.
getJSON
());
classification
myKnnfromFile
;
myKnnfromFile
.
readJSON
(
filepath2
);
std
::
cout
<<
"before: "
<<
myKnn
.
process
(
inputVec
)[
0
]
<<
std
::
endl
;
std
::
cout
<<
"
knn
before: "
<<
myKnn
.
process
(
inputVec
)[
0
]
<<
std
::
endl
;
std
::
cout
<<
"from string: "
<<
myKnnFromString
.
process
(
inputVec
)[
0
]
<<
std
::
endl
;
std
::
cout
<<
"
knn
from string: "
<<
myKnnFromString
.
process
(
inputVec
)[
0
]
<<
std
::
endl
;
//
std::cout << "from file: " << myKnnfromFile.process(inputVec)[0] << std::endl;
std
::
cout
<<
"
knn
from file: "
<<
myKnnfromFile
.
process
(
inputVec
)[
0
]
<<
std
::
endl
;
return
0
;
return
0
;
}
}
src/modelSet.cpp
View file @
b2ff1268
...
@@ -135,7 +135,6 @@ void modelSet::json2modelSet(Json::Value root) {
...
@@ -135,7 +135,6 @@ void modelSet::json2modelSet(Json::Value root) {
for
(
int
i
=
0
;
i
<
model
[
"whichInputs"
].
size
();
++
i
)
{
//TODO: factor these
for
(
int
i
=
0
;
i
<
model
[
"whichInputs"
].
size
();
++
i
)
{
//TODO: factor these
whichInputs
.
push_back
(
model
[
"whichInputs"
][
i
].
asDouble
());
whichInputs
.
push_back
(
model
[
"whichInputs"
][
i
].
asDouble
());
}
}
if
(
model
[
"modelType"
].
asString
()
==
"Neural Network"
)
{
if
(
model
[
"modelType"
].
asString
()
==
"Neural Network"
)
{
int
numHiddenLayers
=
model
[
"numHiddenLayers"
].
asInt
();
int
numHiddenLayers
=
model
[
"numHiddenLayers"
].
asInt
();
int
numHiddenNodes
=
model
[
"numHiddenNodes"
].
asInt
();
int
numHiddenNodes
=
model
[
"numHiddenNodes"
].
asInt
();
...
@@ -147,16 +146,15 @@ void modelSet::json2modelSet(Json::Value root) {
...
@@ -147,16 +146,15 @@ void modelSet::json2modelSet(Json::Value root) {
double
outBase
=
model
[
"outBase"
].
asDouble
();
double
outBase
=
model
[
"outBase"
].
asDouble
();
myModelSet
.
push_back
(
new
neuralNetwork
(
modelNumInputs
,
whichInputs
,
numHiddenLayers
,
numHiddenNodes
,
weights
,
wHiddenOutput
,
inRanges
,
inBases
,
outRange
,
outBase
));
myModelSet
.
push_back
(
new
neuralNetwork
(
modelNumInputs
,
whichInputs
,
numHiddenLayers
,
numHiddenNodes
,
weights
,
wHiddenOutput
,
inRanges
,
inBases
,
outRange
,
outBase
));
}
else
if
(
model
[
"modelType"
].
asString
()
==
"kNN Classification"
)
{
}
else
if
(
model
[
"modelType"
].
asString
()
==
"kNN Classific
i
ation"
)
{
std
::
vector
<
trainingExample
>
trainingSet
;
std
::
vector
<
trainingExample
>
trainingSet
;
const
Json
::
Value
examples
=
model
[
"examples"
];
const
Json
::
Value
examples
=
model
[
"examples"
];
for
(
int
i
=
0
;
i
<
examples
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
examples
.
size
();
++
i
)
{
trainingExample
tempExample
;
trainingExample
tempExample
;
tempExample
.
input
=
json2vector
(
examples
[
i
][
"features"
]);
tempExample
.
input
=
json2vector
(
examples
[
i
][
"features"
]);
tempExample
.
output
=
json2vector
(
examples
[
i
][
"class"
]);
tempExample
.
output
.
push_back
(
examples
[
i
][
"class"
]
.
asDouble
()
);
trainingSet
.
push_back
(
tempExample
);
trainingSet
.
push_back
(
tempExample
);
}
}
int
k
=
model
[
"k"
].
asInt
();
int
k
=
model
[
"k"
].
asInt
();
myModelSet
.
push_back
(
new
knnClassification
(
modelNumInputs
,
whichInputs
,
trainingSet
,
k
));
myModelSet
.
push_back
(
new
knnClassification
(
modelNumInputs
,
whichInputs
,
trainingSet
,
k
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment