Skip to content

Commit

Permalink
copy from SVN
Browse files Browse the repository at this point in the history
  • Loading branch information
kunegis committed Nov 11, 2015
1 parent 7a0bccb commit e85e6ca
Show file tree
Hide file tree
Showing 176 changed files with 10,076 additions and 4 deletions.
7 changes: 3 additions & 4 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

{project} Copyright (C) {year} {fullname}
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand All @@ -672,4 +672,3 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ Matlab. It is part of the KONECT project (Koblenz Network Collection)

http://konect.uni-koblenz.de/

## Installation

The toolbox consists entirely of *.m files. To use it, add this
directory to the Matlab path, e.g., using addpath().

## Requirements

Some functions need BGL, the Boost Graph Library.

Installation of BGL:
* Download version 4.0.1 from website (newer versions may not work)
* unzip it
* (on some systems: install libstdc++5 from http://packages.debian.org/stable/base/libstdc++5)
* symlink the unzipped matlab_bgl to here

## License

Written by Jérome Kunegis at the University of Koblenz-Landau.

The KONECT Toolbox is free software: you can redistribute it and/or modify it under the
Expand Down
100 changes: 100 additions & 0 deletions m/@konect_timer/konect_timer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
%
% Timer class. This is used to output the remaining time on the log
% of a long computation. See konect_clusco.m for example usage.
%
% Note: it is important to assign the result of konect_timer_tick()
% to the timer object.
%
% ABOUT
% This file is part of the KONECT Matlab Toolbox version 0.3.
% konect.uni-koblenz.de
% (c) Jerome Kunegis 2014; this is Free Software released under
% the GPLv3, see COPYING.
%

classdef konect_timer

properties
time_begin
time_last
time_threshold
n
count_my;
end

methods

% Create a timer with N iterations.
function this = konect_timer(n)
persistent count;

if (n < 0)
count = count - 1;
return;
end

this.time_begin = clock;
this.time_last = this.time_begin;
this.n = n;
if ~size(count), count = 0; end;
this.count_my = count;
count = count + 1;
this.time_threshold = 10; % seconds
end

function this = konect_timer_tick(this, i)

assert(i >= 0);

time_now = clock;

time_diff = etime(time_now, this.time_last);
if (time_diff < this.time_threshold)
return;
end

this.time_last = time_now;

time_diff = etime(time_now, this.time_begin);
left = time_diff * (this.n - i + 1) / (i - 1);
text = konect_timer_text(this, left);
if this.count_my > 0
fprintf(1, '%d of %d {%s left}\n', i - 1, this.n, text);
else
fprintf(1, '%d of %d [%s left]\n', i - 1, this.n, text);
end
end

function text = konect_timer_text(this, t)
if t < 60
text = sprintf('%ds', floor(t));
elseif t < 3600
text = sprintf('%d:%02d', floor(t/60), mod(floor(t), 60));
elseif t < 3600 * 24
text = sprintf('%d:%02d:%02d', floor(t/3600), mod(floor(t/60), 60), mod(floor(t), 60));
else
text = sprintf('%dd %02d:%02d:%02d', floor(t/3600/24), mod(floor(t/3600), 24), mod(floor(t/60), 60), mod(floor(t), 60));
end
end

function this = konect_timer_end(this)
e = etime(this.time_last, this.time_begin);
if e ~= 0
text = konect_timer_text(this, 0);
if this.count_my > 0
fprintf(1, '%d of %d {%s left}\n', this.n, this.n, text);
else
fprintf(1, '%d of %d [%s left]\n', this.n, this.n, text);
end
end
konect_timer(-1);
end

% Set new value of N, i.e. of the total number of
% iterations
function this = konect_timer_set(this, n_new)
this.n = n_new;
end

end
end
26 changes: 26 additions & 0 deletions m/konect_absx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%
% Wrapper for abs() that also accepts sparse logical matrices and just
% returns them, as opposed to abs() which does not work for logical
% matrices.
%
% RESULT
% ret Absolute value of the argument matrix
%
% PARAMETERS
% A Matrix of which the absolute value is to be computed;
% may be a logical matrix
%
% ABOUT
% This file is part of the KONECT Matlab Toolbox version 0.3.
% konect.uni-koblenz.de
% (c) Jerome Kunegis 2014; this is Free Software released under
% the GPLv3, see COPYING.
%

function ret = konect_absx(A)

if islogical(A)
ret = A;
else
ret = abs(A);
end
47 changes: 47 additions & 0 deletions m/konect_ap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
%
% Compute the average precision.
%
% If target is not a 0/1 vector, its values are rounded to 0 or 1.
%
% PARAMETERS
% prediction (e*1) Prediction scores
% target (e*1) Correct scores
%
% RESULT
% ret The average precision
%
% ABOUT
% This file is part of the KONECT Matlab Toolbox version 0.3.
% konect.uni-koblenz.de
% (c) Jerome Kunegis 2014; this is Free Software released under
% the GPLv3, see COPYING.
%

function ret = konect_ap(prediction, target)

if length(prediction) ~= length(target), error('*** both vectors must have same length'); end;

e = length(prediction);

% Round target to 0/1
target = target > 0;

% Randomize order
p = randperm(e);
prediction = prediction(p);
target = target(p);

% Compte MAP
[tmp,i] = sort(-prediction);
a = target(i);
p_sum = 0;
nz = 0;

for j = 1 : e
if a(j) ~= 0
nz = nz + a(j);
p_sum = p_sum + a(j) * nz / j;
end;
end;

ret = p_sum / nz;
17 changes: 17 additions & 0 deletions m/konect_ap_sorted.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%
% Compute the average precision, given only the 0/1 vector sorted by
% scores, which don't have to be given.
%
% PARAMETERS
% t (e*1) The 0/1 vector, ranked by descending scores
%
% ABOUT
% This file is part of the KONECT Matlab Toolbox version 0.3.
% konect.uni-koblenz.de
% (c) Jerome Kunegis 2014; this is Free Software released under
% the GPLv3, see COPYING.
%

function ap = konect_ap_sorted(t)

ap = mean((1:sum(t))' ./ find(t));
56 changes: 56 additions & 0 deletions m/konect_auc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
%
% The area under the ROC curve, i.e. the AUC.
%
% If target is not a 0/1 vector, its values are rounded to 0 or 1.
%
% PARAMETERS
% prediction (e*1) vector of predicted scores
% target (e*1) vector of values to be predicted
%
% RESULT
% ret The AUC
%
% ABOUT
% This file is part of the KONECT Matlab Toolbox version 0.3.
% konect.uni-koblenz.de
% (c) Jerome Kunegis 2014; this is Free Software released under
% the GPLv3, see COPYING.
%

function ret = konect_auc(prediction, target)

assert(length(prediction) == length(target));

% All values passed are finite
assert(sum(~isfinite(prediction)) == 0);
assert(sum(~isfinite(target)) == 0);

target = target > 0;

e = length(prediction);
k = sum(target);

if k == e | k == 0
ret = 0;
return;
end

% Randomize order
p = randperm(e);
prediction = prediction(p);
target = target(p);

[tmp,x] = sort(prediction, 'descend');
a = target(x);

s = 0;
c = e-k;
for i = 1 : e
if a(i) == 0
c = c - 1;
else
s = s + c;
end
end

ret = s / (k * (e-k));
Loading

0 comments on commit e85e6ca

Please sign in to comment.