%% Flux Vacua - Rigid CY - Tau - Lazy witness complex
%% Section  4 of the paper TDAvacua
%% uses javaplex

clc; 
clear; 
close all;
%% Flux Vacua Rigid CY : Lazy Witness complex

%% set the parameters

max_dimension=2
num_landmark_points=140 %140
nu=1;
num_divisions=100
over_integers=2

% create the set of points
load ('TauRigidCY.mat')
point_cloud = TauRigidCY;
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 * 8;

% 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 = 'TauRigidCY';
options.max_filtration_value = max_filtration_value;
options.max_dimension = max_dimension - 1;
options.side_by_side = true;
options.caption='Rigid CY';
plot_barcodes(intervals, options);

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

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