-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
210 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"count":{"Cylinders":314.0,"Displacement":314.0,"Horsepower":314.0,"Weight":314.0,"Acceleration":314.0,"Model Year":314.0,"Origin":314.0},"mean":{"Cylinders":5.4777070064,"Displacement":195.3184713376,"Horsepower":104.8694267516,"Weight":2990.2515923567,"Acceleration":15.5592356688,"Model Year":75.898089172,"Origin":1.5732484076},"std":{"Cylinders":1.6997875727,"Displacement":104.331588508,"Horsepower":38.0962144353,"Weight":843.8985961906,"Acceleration":2.7892297519,"Model Year":3.6756424982,"Origin":0.8009883803},"min":{"Cylinders":3.0,"Displacement":68.0,"Horsepower":46.0,"Weight":1649.0,"Acceleration":8.0,"Model Year":70.0,"Origin":1.0},"25%":{"Cylinders":4.0,"Displacement":105.5,"Horsepower":76.25,"Weight":2256.5,"Acceleration":13.8,"Model Year":73.0,"Origin":1.0},"50%":{"Cylinders":4.0,"Displacement":151.0,"Horsepower":94.5,"Weight":2822.5,"Acceleration":15.5,"Model Year":76.0,"Origin":1.0},"75%":{"Cylinders":8.0,"Displacement":265.75,"Horsepower":128.0,"Weight":3608.0,"Acceleration":17.2,"Model Year":79.0,"Origin":2.0},"max":{"Cylinders":8.0,"Displacement":455.0,"Horsepower":225.0,"Weight":5140.0,"Acceleration":24.8,"Model Year":82.0,"Origin":3.0}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* class ModelInfos.h | ||
* user: laitassou | ||
* description | ||
*/ | ||
|
||
#pragma once | ||
|
||
|
||
#include <boost/property_tree/ptree.hpp> | ||
#include <boost/property_tree/json_parser.hpp> | ||
#include <boost/foreach.hpp> | ||
#include <cassert> | ||
#include <exception> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
#include <map> | ||
|
||
|
||
template <class T> class ModelInfos | ||
{ | ||
public: | ||
struct Stats | ||
{ | ||
T mean; | ||
T std; | ||
}; | ||
using json_ptree= boost::property_tree::ptree; | ||
|
||
ModelInfos(const std::string & name); | ||
const T & get_mean(const std::string &label) const; | ||
const T & get_std(const std::string &label) const; | ||
void show(void) const; | ||
void compute_columns(void); | ||
void parse(void); | ||
inline size_t get_depth()const | ||
{ | ||
return input_depth; | ||
}; | ||
|
||
private: | ||
size_t input_depth; | ||
std::map<std::string,struct Stats> labels; | ||
json_ptree pt_json; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#include "../include/ModelInfos.hpp" | ||
|
||
|
||
template <class T> ModelInfos<T>::ModelInfos(const std::string & name):input_depth(0) | ||
{ | ||
|
||
try | ||
{ | ||
//std::stringstream ss; | ||
// send your JSON above to the parser below, but populate ss first | ||
//boost::property_tree::ptree pt; | ||
|
||
std::ifstream jsonFile(name); | ||
boost::property_tree::read_json(jsonFile, pt_json); | ||
|
||
} | ||
catch (std::exception const& e) | ||
{ | ||
std::cout<< e.what()<< std::endl; | ||
} | ||
} | ||
|
||
|
||
template <class T> const T & ModelInfos<T>::get_mean(const std::string &label) const | ||
{ | ||
auto it = labels.find(label); | ||
if(it == labels.end()) | ||
{ | ||
std::cout <<"label: "<< label << "not found" <<std::endl; | ||
return T(0); | ||
} | ||
else{ | ||
return it->second.mean; | ||
} | ||
} | ||
|
||
template <class T> const T & ModelInfos<T>::get_std(const std::string &label) const | ||
{ | ||
auto it = labels.find(label); | ||
if(it == labels.end()) | ||
{ | ||
std::cout <<"label: "<< label << "not found" <<std::endl; | ||
return T(0); | ||
} | ||
else{ | ||
return it->second.std; | ||
} | ||
} | ||
|
||
template <class T> void ModelInfos<T>::show(void) const | ||
{ | ||
using boost::property_tree::ptree; | ||
ptree::const_iterator end = pt_json.end(); | ||
for (ptree::const_iterator it = pt_json.begin(); it != end; ++it) { | ||
std::cout << it->first << " :" <<std::endl; | ||
auto row = it->second; | ||
for(auto & rr :row) | ||
std::cout << rr.first << ":" << rr.second.data()<< std::endl; | ||
} | ||
|
||
// show map | ||
for( auto itr =labels.begin(); itr != labels.end(); ++itr) | ||
{ | ||
std::cout << "label: " <<itr->first << "\n"; | ||
auto row = itr->second; | ||
|
||
std::cout << "stats: "<< itr->second.std << ","<< itr->second.mean << std::endl; | ||
} | ||
} | ||
|
||
|
||
template <class T> void ModelInfos<T>::parse(void) | ||
{ | ||
using boost::property_tree::ptree; | ||
ptree::const_iterator end = pt_json.end(); | ||
for (ptree::const_iterator it = pt_json.begin(); it != end; ++it) | ||
{ | ||
std::cout << it->first << " :" <<std::endl; | ||
|
||
auto row = it->second; | ||
if ((it->first).compare("mean")==0) | ||
{ | ||
|
||
for(auto & rr :row) | ||
{ | ||
struct Stats stat {0,0}; | ||
std::cout << rr.first << ":" << rr.second.data()<< std::endl; | ||
|
||
if (labels.find(rr.first) == labels.end()) | ||
{ | ||
stat.mean = std::stod(rr.second.data()); | ||
labels.insert(std::pair<std::string, struct Stats>(rr.first,stat)); | ||
} | ||
else | ||
{ | ||
stat = labels[rr.first] ; | ||
stat.std = std::stod(rr.second.data()); | ||
labels[rr.first] = stat; | ||
} | ||
stat.mean = std::stod( rr.second.data()); | ||
labels.insert({rr.first,stat}); | ||
} | ||
} | ||
else if ((it->first).compare("std")==0) | ||
{ | ||
for(auto & rr :row){ | ||
struct Stats stat {0,0}; | ||
std::cout << rr.first << ":" << rr.second.data()<< std::endl; | ||
if (labels.find(rr.first) == labels.end()) | ||
{ | ||
stat.std= std::stod(rr.second.data());; | ||
labels.insert(std::pair<std::string, struct Stats>(rr.first,stat)); | ||
} | ||
else | ||
{ | ||
stat = labels[rr.first] ; | ||
stat.std = std::stod(rr.second.data()); | ||
labels[rr.first] = stat; | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
template <class T> void ModelInfos<T>::compute_columns(void) | ||
{ | ||
using boost::property_tree::ptree; | ||
ptree::const_iterator end = pt_json.end(); | ||
for (ptree::const_iterator it = pt_json.begin(); it != end; ++it) { | ||
auto row = it->second; | ||
for(auto & rr :row) | ||
{ | ||
input_depth++; | ||
std::cout << rr.first << ", input_depth :" << input_depth <<std::endl; | ||
} | ||
break; | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
template class ModelInfos<float>; | ||
template class ModelInfos<double>; | ||
template class ModelInfos<int>; | ||
template class ModelInfos<std::string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "../include/Tensor.h" | ||
#include "../include/Tensor.hpp" | ||
|
||
#include <utility> | ||
|
||
|