Skip to content

Commit

Permalink
fixes to compilation and output
Browse files Browse the repository at this point in the history
  • Loading branch information
petergjoel committed Jun 21, 2019
1 parent 7ab382a commit 66ae9a0
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 12 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ project(libprlearn VERSION 1.0.0 LANGUAGES CXX)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wpedantic")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG -Wall -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wpedantic -static-libgcc -static-libstdc++")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG -Wall -Wpedantic -static-libgcc -static-libstdc++")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

#actual library
add_subdirectory(src)
7 changes: 6 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)


add_library(prlearn ${HEADER_FILES} MLearning.cpp SimpleMLearning.cpp RefinementTree.cpp structs.cpp)
add_library(prlearn SHARED ${HEADER_FILES} MLearning.cpp SimpleMLearning.cpp RefinementTree.cpp structs.cpp)
add_library(prlearnStatic STATIC ${HEADER_FILES} MLearning.cpp SimpleMLearning.cpp RefinementTree.cpp structs.cpp)

target_include_directories (prlearn PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories (prlearnStatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(prlearnStatic PROPERTIES OUTPUT_NAME prlearn)


install(TARGETS prlearn
LIBRARY DESTINATION lib
Expand Down
13 changes: 12 additions & 1 deletion src/MLearning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <memory>
#include <algorithm>
#include <iostream>
#include <iomanip>

namespace prlearn {

Expand Down Expand Up @@ -176,6 +177,7 @@ namespace prlearn {
}

void MLearning::print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& edge_map, const std::vector<MLearning>& clouds) const {
s << std::setprecision (std::numeric_limits<double>::digits10 + 1);
for (size_t i = 0; i < tabs; ++i) s << "\t";
s << "{";
bool first = true;
Expand Down Expand Up @@ -210,7 +212,16 @@ namespace prlearn {
s << "}";
} else {
for (size_t i = 0; i < tabs; ++i) s << "\t";
s << _q.avg();
if(_q.cnt() > 0)
{
auto v = _q.avg();
if(!std::isinf(v) && !std::isnan(v))
s << v;
else
s << "\"inf\"";
}
else
s << "\"inf\"";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MLearning.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <map>
#include <limits>

namespace prlearn {
namespace prlearn {

class MLearning {
public:
Expand Down
9 changes: 8 additions & 1 deletion src/RefinementTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@

#include "RefinementTree.h"
#include <limits>
#include <iomanip>

namespace prlearn {

RefinementTree::RefinementTree() {
}

void RefinementTree::print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& edge_map) const {
s << std::setprecision (std::numeric_limits<double>::digits10 + 1);
for (size_t i = 0; i < tabs; ++i) s << "\t";
s << "{";
bool first = true;
Expand Down Expand Up @@ -121,7 +124,11 @@ namespace prlearn {
for (size_t i = 0; i < tabs; ++i) s << "\t";
s << "}";
} else {
s << _predictor._q.avg();
auto v = _predictor._q.avg();
if(!std::isinf(v) && !std::isnan(v))
s << _predictor._q.avg();
else
s << "\"inf\"";
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/SimpleMLearning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include "SimpleMLearning.h"
#include <iomanip>

namespace prlearn {
SimpleMLearning::~SimpleMLearning() {
Expand Down Expand Up @@ -58,6 +59,7 @@ namespace prlearn {
}

void SimpleMLearning::print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& label_map, const std::vector<SimpleMLearning>& other) const {
s << std::setprecision (std::numeric_limits<double>::digits10 + 1);
for (size_t i = 0; i < tabs; ++i) s << "\t";
s << "{\"id\":" << (this - other.data()) << ",";
bool first = true;
Expand All @@ -69,7 +71,13 @@ namespace prlearn {
for (size_t i = 0; i < tabs + 1; ++i) s << "\t";
s << "\"";
s << label_map[el._label];
s << "\":{\"val\":" << el._q.avg() << ",\"succs\":[";
s << "\":{\"val\":";
auto v = el._q.avg();
if(!std::isinf(v) && !std::isnan(v))
s << v;
else
s << "\"inf\"";
s << ",\"succs\":[";
bool f = true;
for(auto& e : el._succssors)
{
Expand Down
17 changes: 12 additions & 5 deletions src/SimpleRegressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
#ifndef SIMPLEREGRESSOR_H
#define SIMPLEREGRESSOR_H

#include "propts.h"
#include "structs.h"

#include <limits>
#include <vector>
#include <map>

#include "propts.h"
#include "structs.h"
#include <iomanip>

namespace prlearn {

Expand Down Expand Up @@ -73,10 +74,11 @@ namespace prlearn {
res->_value.cnt() = std::min<size_t>(res->_cnt, options._q_learn_rate);
res->_cnt += 1;
res->_value += nval;
assert(res->_value._avg >= 0);
assert(res->_value.avg() >= 0);
}

void print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& label_map) const {
s << std::setprecision (std::numeric_limits<double>::digits10 + 1);
for (size_t i = 0; i < tabs; ++i) s << "\t";
s << "{";
bool first = true;
Expand All @@ -85,7 +87,12 @@ namespace prlearn {
first = false;
s << "\n";
for (size_t t = 0; t < tabs; ++t) s << "\t";
s << "\"" << label_map[w._label] << "\" : " << w._value.avg();
s << "\"" << label_map[w._label] << "\" : ";
auto v = w._value.avg();
if(!std::isinf(v) && !std::isnan(v))
s << v;
else
s << "\"inf\"";
}
s << "\n";
for (size_t i = 0; i < tabs; ++i) s << "\t";
Expand Down

0 comments on commit 66ae9a0

Please sign in to comment.