%% BPS spectra in the Conifold - Log degeneracies - noncommutative chamber - Lazy Witness
%% Section  6 of the paper barcodes&walls

clc; 
clear; 
close all;
%% BPS Conifold Log : Lazy Witness complex

%% set the parameters

max_dimension=2
num_landmark_points=200
nu=1;
num_divisions=100
over_integers=2

% create the set of points
load ('ConifoldNCDTLog.mat')
point_cloud = ConifoldNCDTLog;
size(point_cloud)

% create landmark selector using MaxMin algorithm

landmark_selector= api.Plex4.createMaxMinSelector(point_cloud,num_landmark_points);

% or using the random algorithm

%landmark_selector=api.Plex4.createRandomSelector(point_cloud,num_landmark_points);

% define the max distance between points and the landmark subset, and use
% that to select a max filtration value

R = landmark_selector.getMaxDistanceFromPointsToLandmarks()
max_filtration_value = R * 1;

% create a lazy witness stream complex
stream=streams.impl.LazyWitnessStream(landmark_selector.getUnderlyingMetricSpace(),landmark_selector,max_dimension,max_filtration_value,nu,num_divisions);
stream.finalizeStream()

num_simplices = stream.getSize()


% get persistence algorithm over Z/nZ
persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, over_integers);

% compute the intervals
intervals= persistence.computeIntervals(stream);

% create the barcode plots
options.filename = 'ConifoldLazyNCDTLogBarcodes';
options.max_filtration_value = max_filtration_value;
options.max_dimension = max_dimension - 1;
options.side_by_side = true;
options.caption='NCCR chamber';
plot_barcodes(intervals, options);

% get the infinite barcodes
infinite_barcodes = intervals.getInfiniteIntervals();

% print out betti numbers array
betti_numbers_array = infinite_barcodes.getBettiSequence()
