[mlpack-git] [mlpack] Problem Linking MLPACK on Mac (#441)
Emmanuel John
notifications at github.com
Sat Jun 6 15:50:24 EDT 2015
`Graph::sparsifyGraph()` is my function.
void Graph::sparsifyGraph(){
for(Node& nod: nodes){
std::vector<Edge> edges;
double total =0;
for(Neighbor& nb:neighbors(nod.getNodeId())){
if(nod.getNodeId() > nb.nodeId) continue;
Edge edge(nod, getNode(nb.nodeId), nb.algebraicDist);
total+=nb.algebraicDist;
edges.push_back(edge);
}
/*const double mean = total/edges.size();
//sort the edges according to the algebraic distance
sort(edges.begin(), edges.end(),SortByAlgebraicDistance());
int p = edges.size() * 0.5;
double median =0;
if(p%2==0){
median = (edges[p-1].weight + edges[p].weight) *0.5;
}else{
median = edges[p-1].weight;
}
std::cout<<mean<<" "<<median<<std::endl;*/
//lets try k-means
using namespace mlpack::kmeans;
using namespace mlpack::metric;
// The dataset we are clustering.
arma::mat data(1, edges.size());
int col =0;
for(Edge& e: edges){
//std::cout<<e<<std::endl;
data(0,col) = e.weight;
col++;
}
// The number of clusters we are getting.
size_t clusters = 5;
// The centroids will be stored in this matrix.
// The assignments will be stored in this vector.
arma::Col<size_t> assignments;
// Initialize with the default arguments.
//KMeans<SquaredEuclideanDistance,RefinedStart, MaxVarianceNewCluster> k;
KMeans<> k;
//RefinedStart k;
k.Cluster(data, clusters, assignments);
for(int i =0;i<edges.size();i++){
std::cout<<edges[i].weight<<" "<<assignments(i)<<std::endl;
}
//std::cout<<edges.size()<<" "<<assignments.size()<<std::endl;
//exit(0);
}
}
This is what my Makefile look like:
# Warnings frequently signal eventual errors:
CXXFLAGS=-std=c++11 -g -O3 #-W -Wall -Weffc++ -Wextra -pedantic -O3
#Includes
INCLUDES=-I/usr/include/libxml2/ -I/usr/local/include/mlpack -I/Users/emmanueljohn/libs/NetworKit/include
LFLAGS=-L/Users/emmanueljohn/libs/NetworKit
#Linker flags for both OS X and Linux
LDFLAGS=-lexpat -fopenmp -lmlpack #-lNetworKit
# Generates list of object files from all the
# source files in directory
OBJS = $(addsuffix .o, $(basename $(shell find *.cpp)))
DEPS = $(OBJS:.o=.d)
# Set executable name
EXEC = run
# Declare the phony targets
.PHONY: echo clean r clang gcc setclang setgcc vg
# Phony targets to run dependencies in order
gcc: | setgcc $(EXEC)
clang: | setclang $(EXEC)
# For use with the clang static analyzer by
# using the environment variable for CXX
sb: | $(clean) $(EXEC)
vg: $(EXEC)
valgrind ./$(EXEC)
# Run the executable
r:
./$(EXEC)
clean:
rm -rf $(OBJS)
rm -rf $(DEPS)
rm -rf $(EXEC)
# Phony target to use clang for compile and linking
setclang:
@echo "Setting clang"
$(eval CXX = clang++)
$(eval CXX_LINK = clang++)
# Phony target to use g++ for compile and linking
setgcc:
@echo "Setting g++"
$(eval CXX = g++-4.8)
$(eval CXX_LINK = g++-4.8)
# $< refers to the first dependency
# Uses static pattern rule to keep from compiling all
# objects every time.
$(OBJS): %.o: %.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) $(LFLAGS) -c $< -o $@
$(DEPS): %.d: %.cpp
@echo "Generating "$@
@set -e; rm -f $@; \
g++-4.8 -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
#g++ -o LibDemo -std=c++11 -I/home/emmanuj/libs/networkit/include - L/home/emmanuj/libs/networkit/ LibDemo.cpp -lNetworKit -fopenmp
# $@ refers to the target
$(EXEC): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(INCLUDES) $(LFLAGS) $(LDFLAGS)
include $(DEPS)
---
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/issues/441#issuecomment-109643580
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20150606/d729cc74/attachment.html>
More information about the mlpack-git
mailing list