See classification using Topological features here: https://community.wolfram.com/groups/-/m/t/3202910
ABSTRACT (original article): Asphaltenes are organic compounds that aggregate in crude oil with two dominant molecular architectures: archipelago and continental. Continental architectures possess a single uniform island structure composed of aromatic rings in contrast to archipelago architectures with aromatic cores interconnected through aliphatic chains. The structural composition of asphaltenes varies globally due to geographical differences, posing challenges in their classification due to a lack of uniformity. This study is the first known exploration of using image-based supervised machine learning, particularly the ResNet-50 neural network, for the binary classification of asphaltenes into continental and archipelago motifs. 255 continental and archipelago models underwent structural augmentations to create a sample size of 1,530 asphaltene structures that is robust enough for accurate results in both the training and testing portions of the machine learning. These augmentations included the repeated addition of carbons until a complete pentane chain was added to a specified carbon on each asphaltene structure. Using Mathematica, supervised ResNet-50 image-based classification was used on both original and augmented structure datasets to classify as either archipelago or continental. The classification was also implemented using topological similarity searching for association between atoms and the distance between them for further molecule identification. This study demonstrates the surprising effectiveness of image-based classification compared to traditional topological feature-based methods. Our results reveal that deep learning techniques, especially image-based approaches, provide novel and insightful ways to differentiate complex molecular structures like asphaltenes, challenging the traditional reliance on topological features alone. This research opens new avenues in chemical analysis and molecular characterization, highlighting the potential of machine learning in complex molecular systems. CITATION (original article): Arun K. Sharma, Selsela Arsala, James Brady, Madison Franke, Shelby Franke, Supreet Gandhok, Simon-Olivier Gingras, Ana Gomez, Katelyn Huie, Kayla Katz, Samantha Kozlo, Mateo Longoria, Levi Molnar, Nathaly Peña, Sarina Regis, Machine learning to identify structural motifs in asphaltenes, Results in Chemistry, 7, 2024, 101551, https://doi.org/10.1016/j.rechem.2024.101551.
Introduction
Introduction
Asphaltenes are organic compounds that aggregate in crude oil with two dominant molecular architectures : archipelago and continental. Continental architectures possess a single uniform island structure composed of aromatic rings in contrast to archipelago architectures with aromatic cores interconnected through aliphatic chains. The structural composition of asphaltenes varies globally due to geographical differences, posing challenges in their classification due to a lack of uniformity. This study is the first known exploration of using image - based supervised machine learning, particularly the ResNet - 50 neural network, for the binary classification of asphaltenes into continental and archipelago motifs. 255 continental and archipelago models underwent structural augmentations to create a sample size of 1, 530 asphaltene structures that is robust enough for accurate results in both the training and testing portions of the machine learning. These augmentations included the repeated addition of carbons until a complete pentane chain was added to a specified carbon on each asphaltene structure. Using Mathematica, supervised ResNet - 50 image - based classification was used on both original and augmented structure datasets to classify as either archipelago or continental. The classification was also implemented using topological similarity searching for association between atoms and the distance between them for further molecule identification. This study demonstrates the surprising effectiveness of image - based classification compared to traditional topological feature - based methods.
Set up Random Seed
Set up Random Seed
In[]:=
SeedRandom["Asphaltenes",Method->"MersenneTwister"];
Import files
Import files
Original structures with augmented: Composite
Original structures with augmented: Composite
In[]:=
SetDirectory[NotebookDirectory[]]
In[]:=
contis=Flatten@Join@Import["./Continentals-Augmented-5-Edits-Complete.mx"];
In[]:=
archis=Flatten@Join@Import["./Archipelagos-Augmented-5-Edits-Complete.mx"];
In[]:=
Length/@{contis,archis}
Out[]=
{1116,414}
Options for all plots
Options for all plots
In[]:=
Needs["StatisticalPlots`"];SetOptions[{PairwiseScatterPlot,ArrayPlot,MatrixPlot,ListLinePlot,ListPlot,Histogram,BarChart,BoxWhiskerChart,DistributionChart,BubbleChart,PairedHistogram},BaseStyle->{FontFamily->Times,FontSize->12,FontColor->Black},LabelStyle->{FontFamily->Times,FontColor->Black},FrameStyle->Black];
Transfer Learning for asphaltene classification, ResNet-50
Transfer Learning for asphaltene classification, ResNet-50
Label molecules and convert Graphics to Images
Label molecules and convert Graphics to Images
The molecule pictures are Graphics objects - while the NN needs Image objects. Convert graphics to images with Image function.
In[]:=
archipelagoImages=Image/@(MoleculePlot/@archis);
In[]:=
continentalImages=Image/@(MoleculePlot/@contis);
In[]:=
archiImagesLabels=Thread[archipelagoImages->"archi"];
In[]:=
contiImagesLabels=Thread[continentalImages->"conti"];
Prepare multiple training and testing Sets
Prepare multiple training and testing Sets
Repeat the training specified number of times.
In[]:=
numberIndependentSets=10;archiSets=Table[ResourceFunction["TrainTestSplit"][archiImagesLabels],numberIndependentSets];(*Allthefirstlistsaretrainingandthesecondonesaretesting*)
In[]:=
contiSets=Table[ResourceFunction["TrainTestSplit"][contiImagesLabels],numberIndependentSets];(*Allthefirstlistsaretrainingandthesecondonesaretesting*)
Gather all the archipelago training sets
In[]:=
archiTrainings=archiSets[[All,1]];
Gather all the archipelago testing sets
In[]:=
archiTests=archiSets[[All,2]];
Gather all the continental training sets
In[]:=
contiTrainings=contiSets[[All,1]];
Gather all the continental testing sets
In[]:=
contiTests=contiSets[[All,2]];
Join all the archipelago and continental training sets to create asphaltene training sets.
In[]:=
asphalteneTrainingSets=RandomSample/@Flatten/@Transpose[{archiTrainings,contiTrainings}];
Join all the archipelago and continental testing sets to create asphaltene testing sets.
In[]:=
asphalteneTestingSets=RandomSample/@Flatten/@Transpose[{archiTests,contiTests}];
Verify that all sets are composed of the same length
In[]:=
Length/@asphalteneTrainingSets
Out[]=
{1224,1224,1224,1224,1224,1224,1224,1224,1224,1224}
In[]:=
Length/@asphalteneTestingSets
Out[]=
{306,306,306,306,306,306,306,306,306,306}
Training Function
Training Function
Remove the linear layer from the pre-trained net.Remove the final classification layers of the trained net and we will replace them with the layers specific to this new task.Notice that the LinearLayer and SoftmaxLayer have been removed.
In[]:=
rn50Trainer[trainData_List]:=Module[{net,tempNet,newNet,trainedNet},net=NetModel["ResNet-50 Trained on ImageNet Competition Data"];tempNet=NetDrop[net,-2];newNet=NetAppend[tempNet,{"linearNew"->LinearLayer[],"softmax"->SoftmaxLayer[]},"Output"->NetDecoder[{"Class",{"archi","conti"}}]];trainedNet=NetTrain[newNet,trainData,All,LearningRateMultipliers->{"linearNew"->1,_->0},TargetDevice->"GPU",TrainingStoppingCriterion->"Loss",ValidationSet->Scaled[0.1]];Return[trainedNet];]
Train RN50 on each training set
Train RN50 on each training set
In[]:=
trainedNetsRN50=rn50Trainer/@asphalteneTrainingSets;
Analysis of independent trainings
Analysis of independent trainings
The total time spent training, in seconds
trainingTimes=#["TotalTrainingTime"]&/@trainedNetsRN50
Out[]=
{33.6592,33.3195,33.3345,34.4599,33.5403,26.7896,33.4416,33.5969,33.341,34.2949}
The mean number of input examples processed per second
examplesPerSecond=#["MeanExamplesPerSecond"]&/@trainedNetsRN50;
The mean loss obtained on the ValidationSet for the most recent validation measurement
validationLoss=#["ValidationLoss"]&/@trainedNetsRN50;
totalRounds=#["TotalRounds"]&/@trainedNetsRN50;(*TableForm[{{"Set 1","Set 2","Set 3","Set 4","Set 5"},trainingTimes,examplesPerSecond,validationLoss,totalRounds},TableHeadings->{{"Model","Training Times (s)","ExamplesPerSecond","ValidationLoss","TotalRounds"}},TableDirections->Row]*)
In[]:=
trainingTimesRounds=ListPlot[Transpose[{totalRounds,trainingTimes}],PlotMarkers->"OpenMarkers",PlotTheme->"Detailed",FrameLabel->{"Traning Rounds","Training Time(s)"}]
In[]:=
Export["./training-Time-Rounds-RN50-Composite.svg",trainingTimesRounds]
Out[]=
./training-Time-Rounds-RN50-Composite.svg
In[]:=
validationErrorRatePlot=ListLinePlot[#["ValidationMeasurementsLists"]["ErrorRate"]&/@trainedNetsRN50,PlotLegends->Table[StringJoin["Set ",ToString[i]],{i,numberIndependentSets}],FrameLabel->{"Rounds","Error %"},PlotMarkers->Automatic,PlotTheme->"Detailed",PlotRange->All](*PlotLabel->"Validation Error Rate",*)
Classifier Measurements
Classifier Measurements
Gather measurements to document efficacy of classification
F1 score for each class, more sense if you are analyzing each network in more detail
Precision score for each class, more sense if you are analyzing each network in more detail
Time needed to classify one example of the test set
Marginal time to classify one example in a batch
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Machine learning to identify structural motifs in asphaltenes through ResNet-50
by Arunkumar Sharma
Wolfram Community, STAFF PICKS, July 1, 2024
https://community.wolfram.com/groups/-/m/t/3202949
by Arunkumar Sharma
Wolfram Community, STAFF PICKS, July 1, 2024
https://community.wolfram.com/groups/-/m/t/3202949