-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes deprecated cluster_bingham.m and bingham_mlesac.m #3
Open
madratman
wants to merge
6
commits into
SebastianRiedel:master
Choose a base branch
from
madratman:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc8304d
fixed deprecated bingham_fit_mlesac.m
madratman 2214522
fixed deprecated bingham_cluster.m
madratman 29938dd
adds comments, fixes upper bound back to 100
madratman 5b0ed1d
comments and cleanup for mlesac.m
madratman 3d5eff6
changes directory to undeprecate
madratman b29e566
accomodates previous PR, minor changes
madratman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function [B weights] = bingham_cluster(X, min_points) | ||
% [B weights] = bingham_cluster(X, min_points) -- where each B(i) contains fields V, Z, F | ||
|
||
if nargin < 2 | ||
min_points = 20; | ||
end | ||
|
||
for i=1:100 %max no of clusters | ||
fprintf('Bingham distrubution #: %d', i); | ||
[B(i) outliers] = bingham_fit_mlesac(X); | ||
% outliers is a row vector | ||
weights(i) = size(X,1) - length(outliers); | ||
|
||
fprintf('no of points left are', weights(i)); | ||
% weight of a particular bingham is no of points left - no of ouliers | ||
if length(outliers) < min_points | ||
break; | ||
end | ||
X_updater = zeros(length(outliers), size(X,2)); | ||
% initialize the outlier data for next iteration to zeros | ||
for j = 1:length(outliers) | ||
X_updater(j,:) = X(outliers(j),:); | ||
end | ||
% get them outliers | ||
X = X_updater; | ||
% update the outliers for the next iteration | ||
end |
137 changes: 66 additions & 71 deletions
137
matlab/deprecated/bingham_fit_mlesac.m → matlab/bingham_fit_mlesac.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,66 @@ | ||
function [B outliers] = bingham_fit_mlesac(X) | ||
% [B outliers] = bingham_fit_mlesac(X) -- where B = B.{V, Z, F} | ||
|
||
d = size(X,1); | ||
n = size(X,2); | ||
|
||
iter = 100; | ||
p0 = 1 / surface_area_hypersphere(d-1); % uniform density for outliers | ||
logp0 = log(p0); | ||
|
||
pmax = -inf; | ||
|
||
for i=1:iter | ||
|
||
% pick d points at random from X | ||
r = randperm(n); | ||
r = r(1:d); | ||
Xi = X(:,r); | ||
|
||
% fit a Bingham to the d points | ||
[V Z F] = bingham_fit(Xi); | ||
%[V Z F] = bingham_fit_scatter(Xi*Xi') | ||
|
||
% compute data log likelihood | ||
logp = 0; | ||
for j=1:n | ||
p = bingham_pdf(X(:,j), V, Z, F); | ||
if p > p0 | ||
logp = logp + log(p); | ||
else | ||
logp = logp + logp0; | ||
end | ||
end | ||
|
||
if logp > pmax | ||
pmax = logp; | ||
B.V = V; | ||
B.Z = Z; | ||
B.F = F; | ||
|
||
%fprintf('*** found new best with log likelihood %f ***\n', logp); | ||
|
||
%figure(20); | ||
%plot_bingham_3d(V,Z,F,X'); | ||
%figure(21); | ||
%plot_bingham_3d_projections(V,Z,F); | ||
|
||
end | ||
end | ||
|
||
% find inliers/outliers and fit the Bingham to all the inliers | ||
|
||
L = zeros(1,n); | ||
for j=1:n | ||
p = bingham_pdf(X(:,j), B.V, B.Z, B.F); | ||
if p > p0 | ||
L(j) = 1; | ||
else | ||
L(j) = 0; | ||
end | ||
end | ||
|
||
inliers = find(L); | ||
outliers = find(~L); | ||
|
||
[B.V B.Z B.F] = bingham_fit(X(:,inliers)); | ||
|
||
|
||
|
||
|
||
|
||
function [B outliers] = bingham_fit_mlesac(X) | ||
% [B outliers] = bingham_fit_mlesac(X) -- where B = B.{V, Z, F} | ||
X = X'; | ||
d = size(X,1); | ||
n = size(X,2); | ||
|
||
iter = 100; | ||
p0 = 1 / surface_area_hypersphere(d-1); % uniform density for outliers | ||
logp0 = log(p0); | ||
|
||
pmax = -inf; | ||
|
||
for i=1:iter | ||
fprintf('mlesac iteration: %d', i); | ||
|
||
% pick d points at random from X -> put them into X_1, X_2, X_3, X_4 | ||
r = randperm(n); | ||
r = r(1:d); | ||
for j=1:d | ||
eval(['X_' num2str(j) '= X(:,r(j));']) | ||
end | ||
X_combined = [X_1 X_2 X_3 X_4]; | ||
X_combined = X_combined'; | ||
|
||
% fit a Bingham to the d points | ||
bing_X_combined = bingham_fit(X_combined); | ||
|
||
% compute data log likelihood | ||
logp = 0; | ||
for j=1:n | ||
p = bingham_pdf(X(:,j)', bing_X_combined); | ||
if p > p0 | ||
logp = logp + log(p); | ||
else | ||
logp = logp + logp0; | ||
end | ||
end | ||
|
||
% update the threshold | ||
if logp > pmax | ||
pmax = logp; | ||
end | ||
|
||
end | ||
|
||
% find inliers/outliers | ||
L = zeros(1,n); | ||
for j=1:n | ||
p = bingham_pdf(X(:,j)', bing_X_combined); | ||
if p > p0 | ||
L(j) = 1; | ||
else | ||
L(j) = 0; | ||
end | ||
end | ||
|
||
inliers = find(L); | ||
outliers = find(~L); | ||
fprintf('no of outliers were %d', outliers); | ||
|
||
% fit a Bingham to all the inliers | ||
bing_return = bingham_fit(X(:,inliers)'); | ||
B = bing_return; | ||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add condition for first iteration