Skip to content

Commit

Permalink
Merge pull request #1 from sniekum/master
Browse files Browse the repository at this point in the history
Merging from upstream before taking ownership.
  • Loading branch information
Joshua Whitley committed Feb 24, 2019
2 parents ef8fd55 + ff40451 commit 9be6d59
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 73 deletions.
93 changes: 93 additions & 0 deletions .circleci/config.yaml
@@ -0,0 +1,93 @@
version: 2
jobs:
kinetic:
docker:
- image: autonomoustuff/docker-builds:kinetic-ros-base
steps:
- checkout
- run:
name: Set Up Container
command: |
apt-get update -qq
source `find /opt/ros -name setup.bash | sort | head -1`
rosdep install --from-paths . --ignore-src -y
cd ..
catkin init
catkin config --extend /opt/ros/$ROS_DISTRO
- run:
name: Build
command: |
cd ..
catkin build
- run:
name: Run Tests
command: |
source `find /opt/ros -name setup.bash | sort | head -1`
cd ..
catkin run_tests
catkin_test_results
working_directory: ~/src

lunar:
docker:
- image: autonomoustuff/docker-builds:lunar-ros-base
steps:
- checkout
- run:
name: Set Up Container
command: |
apt-get update -qq
source `find /opt/ros -name setup.bash | sort | head -1`
rosdep install --from-paths . --ignore-src -y
cd ..
catkin init
catkin config --extend /opt/ros/$ROS_DISTRO
- run:
name: Build
command: |
cd ..
catkin build
- run:
name: Run Tests
command: |
source `find /opt/ros -name setup.bash | sort | head -1`
cd ..
catkin run_tests
catkin_test_results
working_directory: ~/src

melodic:
docker:
- image: autonomoustuff/docker-builds:melodic-ros-base
steps:
- checkout
- run:
name: Set Up Container
command: |
apt-get update -qq
source `find /opt/ros -name setup.bash | sort | head -1`
rosdep install --from-paths . --ignore-src -y
cd ..
catkin init
catkin config --extend /opt/ros/$ROS_DISTRO
- run:
name: Build
command: |
cd ..
catkin build
- run:
name: Run Tests
command: |
source `find /opt/ros -name setup.bash | sort | head -1`
cd ..
catkin run_tests
catkin_test_results
working_directory: ~/src

workflows:
version: 2
ros_build:
jobs:
- kinetic
- lunar
- melodic
14 changes: 9 additions & 5 deletions CMakeLists.txt
Expand Up @@ -2,7 +2,11 @@
cmake_minimum_required(VERSION 2.8.3)
project(ml_classifiers)

find_package(catkin REQUIRED COMPONENTS message_generation std_msgs rospy roscpp pluginlib)
find_package(catkin REQUIRED
COMPONENTS message_generation std_msgs roscpp pluginlib)
find_package(Eigen3 REQUIRED)

set(Eigen3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIRS})

add_message_files(FILES
ClassDataPoint.msg
Expand All @@ -16,10 +20,10 @@ add_service_files(FILES
generate_messages(DEPENDENCIES std_msgs)

catkin_package(
DEPENDS Eigen3
CATKIN_DEPENDS message_runtime std_msgs rospy roscpp pluginlib
INCLUDE_DIRS include
LIBRARIES ZeroClassifier NearestNeighborClassifier SVMClassifier
DEPENDS Eigen3
CATKIN_DEPENDS message_runtime std_msgs roscpp pluginlib
INCLUDE_DIRS include
LIBRARIES ZeroClassifier NearestNeighborClassifier SVMClassifier
)

add_definitions(${EIGEN3_DEFINITIONS})
Expand Down
1 change: 0 additions & 1 deletion Makefile

This file was deleted.

26 changes: 0 additions & 26 deletions mainpage.dox

This file was deleted.

18 changes: 9 additions & 9 deletions nodes/classifier_server.cpp
Expand Up @@ -53,13 +53,13 @@ using namespace ml_classifiers;
using namespace std;


map<string,Classifier*> classifier_list;
map<string, boost::shared_ptr<Classifier>> classifier_list;
pluginlib::ClassLoader<Classifier> c_loader("ml_classifiers", "ml_classifiers::Classifier");

bool createHelper(string class_type, Classifier* &c)
bool createHelper(string class_type, boost::shared_ptr<Classifier>& c)
{
try{
c = c_loader.createClassInstance(class_type);
c = c_loader.createInstance(class_type);
}
catch(pluginlib::PluginlibException& ex){
ROS_ERROR("Classifer plugin failed to load! Error: %s", ex.what());
Expand All @@ -73,16 +73,16 @@ bool createCallback(CreateClassifier::Request &req,
CreateClassifier::Response &res )
{
string id = req.identifier;
Classifier *c;
boost::shared_ptr<Classifier> c;

if(!createHelper(req.class_type, c)){
if (!createHelper(req.class_type, c)){
res.success = false;
return false;
}

if(classifier_list.find(id) != classifier_list.end()){
if (classifier_list.find(id) != classifier_list.end()){
cout << "WARNING: ID already exists, overwriting: " << req.identifier << endl;
delete classifier_list[id];
classifier_list.erase(id);
}
classifier_list[id] = c;

Expand Down Expand Up @@ -160,7 +160,7 @@ bool loadCallback(LoadClassifier::Request &req,
{
string id = req.identifier;

Classifier *c;
boost::shared_ptr<Classifier> c;
if(!createHelper(req.class_type, c)){
res.success = false;
return false;
Expand All @@ -173,7 +173,7 @@ bool loadCallback(LoadClassifier::Request &req,

if(classifier_list.find(id) != classifier_list.end()){
cout << "WARNING: ID already exists, overwriting: " << req.identifier << endl;
delete classifier_list[id];
classifier_list.erase(id);
}
classifier_list[id] = c;

Expand Down
22 changes: 10 additions & 12 deletions package.xml
@@ -1,4 +1,5 @@
<package>
<?xml version="1.0"?>
<package format="2">
<name>ml_classifiers</name>
<version>0.3.1</version>
<description>ml_classifiers</description>
Expand All @@ -10,22 +11,19 @@
<url type="website">http://ros.org/wiki/ml_classifiers</url>

<author>Scott Niekum</author>
<author email="jwhitley@autonomoustuff.com">Joshua Whitley</author>

<buildtool_depend>catkin</buildtool_depend>

<build_depend>std_msgs</build_depend>
<build_depend>rospy</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>roslib</build_depend>
<build_depend>pluginlib</build_depend>
<build_depend>message_generation</build_depend>

<run_depend>std_msgs</run_depend>
<run_depend>rospy</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>roslib</run_depend>
<run_depend>pluginlib</run_depend>
<run_depend>message_runtime</run_depend>
<depend>std_msgs</depend>
<depend>roscpp</depend>
<depend>roslib</depend>
<depend>pluginlib</depend>
<depend>eigen</depend>

<exec_depend>message_runtime</exec_depend>

<export>
<ml_classifiers plugin="${prefix}/default_classifiers_plugin.xml"/>
Expand Down
14 changes: 7 additions & 7 deletions src/nearest_neighbor_classifier.cpp
Expand Up @@ -42,9 +42,9 @@
#include "ml_classifiers/nearest_neighbor_classifier.h"
#include <pluginlib/class_list_macros.h>

PLUGINLIB_DECLARE_CLASS(ml_classifiers, NearestNeighborClassifier, ml_classifiers::NearestNeighborClassifier, ml_classifiers::Classifier)
#include <string>

using namespace std;
PLUGINLIB_EXPORT_CLASS(ml_classifiers::NearestNeighborClassifier, ml_classifiers::Classifier)

namespace ml_classifiers{

Expand All @@ -56,9 +56,9 @@ namespace ml_classifiers{

bool NearestNeighborClassifier::load(const std::string filename){return false;}

void NearestNeighborClassifier::addTrainingPoint(string target_class, const std::vector<double> point)
void NearestNeighborClassifier::addTrainingPoint(std::string target_class, const std::vector<double> point)
{
class_data[target_class].push_back(point);
class_data[target_class].push_back(point);
}

void NearestNeighborClassifier::train(){}
Expand All @@ -68,15 +68,15 @@ namespace ml_classifiers{
class_data.clear();
}

string NearestNeighborClassifier::classifyPoint(const std::vector<double> point)
std::string NearestNeighborClassifier::classifyPoint(const std::vector<double> point)
{
size_t dims = point.size();
double min_diff=0;
string ans;
std::string ans;
bool first = true;

for(ClassMap::iterator iter = class_data.begin(); iter != class_data.end(); iter++){
string cname = iter->first;
std::string cname = iter->first;
CPointList cpl = iter->second;

for(size_t i=0; i<cpl.size(); i++){
Expand Down
17 changes: 8 additions & 9 deletions src/svm_classifier.cpp
Expand Up @@ -41,11 +41,10 @@

#include "ml_classifiers/svm_classifier.h"
#include <pluginlib/class_list_macros.h>
#include <math.h>
#include <cmath>
#include <string>

PLUGINLIB_DECLARE_CLASS(ml_classifiers, SVMClassifier, ml_classifiers::SVMClassifier, ml_classifiers::Classifier)

using namespace std;
PLUGINLIB_EXPORT_CLASS(ml_classifiers::SVMClassifier, ml_classifiers::Classifier)

namespace ml_classifiers{

Expand All @@ -57,7 +56,7 @@ namespace ml_classifiers{

bool SVMClassifier::load(const std::string filename){return false;}

void SVMClassifier::addTrainingPoint(string target_class, const std::vector<double> point)
void SVMClassifier::addTrainingPoint(std::string target_class, const std::vector<double> point)
{
class_data[target_class].push_back(point);
}
Expand Down Expand Up @@ -94,7 +93,7 @@ namespace ml_classifiers{
label_int_to_str.clear();
int label_n = 0;
for(ClassMap::iterator iter = class_data.begin(); iter != class_data.end(); iter++){
string cname = iter->first;
std::string cname = iter->first;
label_str_to_int[cname] = label_n;
label_int_to_str[label_n] = cname;
//cout << "MAP: " << label_n << " " << cname << " Size: " << iter->second.size() << endl;
Expand Down Expand Up @@ -136,7 +135,7 @@ namespace ml_classifiers{
//Put the training data into the svm_problem
int n = 0;
for(ClassMap::iterator iter = class_data.begin(); iter != class_data.end(); iter++){
string cname = iter->first;
std::string cname = iter->first;
CPointList cpl = iter->second;

//Account for bug in libSVM with classes with only 1 data point by duplicating it.
Expand Down Expand Up @@ -189,7 +188,7 @@ namespace ml_classifiers{
}

//Grid Search for best C and gamma params
int n_folds = min(10, n_data); //Make sure there at least as many points as folds
int n_folds = std::min(10, n_data); //Make sure there at least as many points as folds
double *resp = new double[n_data];
double best_accy = 0.0;
double best_g = 0.0;
Expand Down Expand Up @@ -264,7 +263,7 @@ namespace ml_classifiers{
scaling_factors = NULL;
}

string SVMClassifier::classifyPoint(const std::vector<double> point)
std::string SVMClassifier::classifyPoint(const std::vector<double> point)
{
//Copy the point to be classified into an svm_node
int dims = point.size();
Expand Down
8 changes: 4 additions & 4 deletions src/zero_classifier.cpp
Expand Up @@ -42,9 +42,9 @@
#include "ml_classifiers/zero_classifier.h"
#include <pluginlib/class_list_macros.h>

PLUGINLIB_DECLARE_CLASS(ml_classifiers, ZeroClassifier, ml_classifiers::ZeroClassifier, ml_classifiers::Classifier)
#include <string>

using namespace std;
PLUGINLIB_EXPORT_CLASS(ml_classifiers::ZeroClassifier, ml_classifiers::Classifier)

namespace ml_classifiers{

Expand All @@ -53,10 +53,10 @@ namespace ml_classifiers{

void ZeroClassifier::save(const std::string filename){}
bool ZeroClassifier::load(const std::string filename){return false;}
void ZeroClassifier::addTrainingPoint(string target_class, const std::vector<double> point){}
void ZeroClassifier::addTrainingPoint(std::string target_class, const std::vector<double> point){}
void ZeroClassifier::train(){}
void ZeroClassifier::clear(){}
string ZeroClassifier::classifyPoint(const std::vector<double> point){return "0";}
std::string ZeroClassifier::classifyPoint(const std::vector<double> point){return "0";}

}

0 comments on commit 9be6d59

Please sign in to comment.