Skip to content

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencwilliams committed Sep 24, 2009
0 parents commit efb076b
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2009 Indiana University

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
objects = \
binary_matrix.o \
binary_vector.o \
degrees_dir.o \
degrees_und.o \
matrix_printf.o \
vector_printf.o
bct: $(objects)
libtool -static -o libbct.a $(objects)
binary_matrix.o:
cc -c binary_matrix.cpp
binary_vector.o:
cc -c binary_vector.cpp
degrees_dir.o:
cc -c degrees_dir.cpp
degrees_und.o:
cc -c degrees_und.cpp
matrix_printf.o:
cc -c matrix_printf.cpp
vector_printf.o:
cc -c vector_printf.cpp
clean:
-rm libbct.a $(objects)
7 changes: 7 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bct-cpp is a C++ port of the Brain Connectivity Toolbox, a set of MATLAB
functions and neuroanatomical data sets useful in the analysis of structural
or functional brain networks.

See <http://www.brain-connectivity-toolbox.net/> for more information.

See LICENSE for information about bct-cpp's license.
35 changes: 35 additions & 0 deletions bct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef BCT_H
#define BCT_H

#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>

namespace bct {
const double EPSILON = 1e-6; // Used for floating-point equality comparisons

// Density, degree, and assortativity
gsl_vector* degrees_und(const gsl_matrix*);
gsl_vector* degrees_dir_in(const gsl_matrix*);
gsl_vector* degrees_dir_out(const gsl_matrix*);
gsl_vector* degrees_dir(const gsl_matrix*);

// Clustering

// Paths, distances, and cycles

// Centrality

// Motifs

// Modularity and community structure

// Utility
gsl_vector* binary_vector(const gsl_vector*);
gsl_matrix* binary_matrix(const gsl_matrix*);

// Debugging
void vector_printf(const gsl_vector*, const char*);
void matrix_printf(const gsl_matrix*, const char*);
};

#endif
17 changes: 17 additions & 0 deletions binary_matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "bct.h"
#include <gsl/gsl_matrix.h>

/*
* Returns a binary copy of the given matrix.
*/
gsl_matrix* bct::binary_matrix(const gsl_matrix* m) {
gsl_matrix* bm = gsl_matrix_calloc(m->size1, m->size2);
for (int i = 0; i < m->size1; i++) {
for (int j = 0; j < m->size2; j++) {
if (abs(gsl_matrix_get(m, i, j)) > EPSILON) {
gsl_matrix_set(bm, i, j, 1.0);
}
}
}
return bm;
}
15 changes: 15 additions & 0 deletions binary_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "bct.h"
#include <gsl/gsl_vector.h>

/*
* Returns a binary copy of the given vector.
*/
gsl_vector* bct::binary_vector(const gsl_vector* v) {
gsl_vector* bv = gsl_vector_calloc(v->size);
for (int i = 0; i < v->size; i++) {
if (abs(gsl_vector_get(v, i)) > EPSILON) {
gsl_vector_set(bv, i, 1.0);
}
}
return bv;
}
43 changes: 43 additions & 0 deletions degrees_dir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "bct.h"
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>

/*
* Computes the in-degree for each node in a directed binary matrix. Weights
* are discarded. Results are returned in a vector where each element is the
* in-degree of the corresponding node.
*/
gsl_vector* bct::degrees_dir_in(const gsl_matrix* m) {

// Calculated the same way as degrees_und
return degrees_und(m);
}

/*
* Computes the out-degree for each node in a directed binary matrix. Weights
* are discarded. Results are returned in a vector where each element is the
* out-degree of the corresponding node.
*/
gsl_vector* bct::degrees_dir_out(const gsl_matrix* m) {
gsl_matrix* bm = binary_matrix(m);
gsl_vector* out_degrees = gsl_vector_calloc(bm->size1);
for (int i = 0; i < bm->size2; i++) {
gsl_vector_const_view column = gsl_matrix_const_column(bm, i);
gsl_vector_add(out_degrees, &column.vector);
}
gsl_matrix_free(bm);
return out_degrees;
}

/*
* Computes the degree for each node in a directed binary matrix. Weights are
* discarded. Results are returned in a vector where each element is the degree
* of the corresponding node.
*/
gsl_vector* bct::degrees_dir(const gsl_matrix* m) {
gsl_vector* in_degrees = degrees_dir_in(m);
gsl_vector* out_degrees = degrees_dir_out(m);
gsl_vector_add(in_degrees, out_degrees);
gsl_vector_free(out_degrees);
return in_degrees;
}
19 changes: 19 additions & 0 deletions degrees_und.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "bct.h"
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>

/*
* Computes the degree for each node in an undirected binary matrix. Weights
* are discarded. Results are returned in a vector where each element is the
* degree of the corresponding node.
*/
gsl_vector* bct::degrees_und(const gsl_matrix* m) {
gsl_matrix* bm = binary_matrix(m);
gsl_vector* degrees = gsl_vector_calloc(bm->size2);
for (int i = 0; i < bm->size1; i++) {
gsl_vector_const_view row = gsl_matrix_const_row(bm, i);
gsl_vector_add(degrees, &row.vector);
}
gsl_matrix_free(bm);
return degrees;
}
17 changes: 17 additions & 0 deletions matrix_printf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "bct.h"
#include <cstdio>
#include <gsl/gsl_matrix.h>

/*
* Prints a matrix using the given format for each element. This is only
* provided for debugging purposes. In other cases, use gsl_matrix_fprintf.
*/
void bct::matrix_printf(const gsl_matrix* m, const char* format) {
for (int i = 0; i < m->size1; i++) {
for (int j = 0; j < m->size2; j++) {
std::printf(format, gsl_matrix_get(m, i, j));
std::printf(" ");
}
std::printf("\n");
}
}
15 changes: 15 additions & 0 deletions vector_printf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "bct.h"
#include <cstdio>
#include <gsl/gsl_vector.h>

/*
* Prints a vector using the given format for each element. This is only
* provided for debugging purposes. In other cases, use gsl_vector_fprintf.
*/
void bct::vector_printf(const gsl_vector* v, const char* format) {
for (int i = 0; i < v->size; i++) {
std::printf(format, gsl_vector_get(v, i));
std::printf(" ");
}
std::printf("\n");
}

0 comments on commit efb076b

Please sign in to comment.