CITE THIS NOTEBOOK: A study of bees that are tricked into sex by Nik Fadzly N Rosely. Wolfram Community OCT 6 2022.
ORIGINAL PRESENTATION: Nik Fadzly, Using Mathematica to Study Bees That Are Tricked into Sex. Wolfram Technology Conference, https://www.wolfram.com/broadcast/video.php?v=3565.

Introduction

Plants employ a variety of tactics to encourage the spread of their seed and/or pollen. In the natural world, some of the more popular techniques involve using an animal or the wind. Few species of plants use dishonest signals, but the majority of methods rely on either direct or indirect signalling. The bee orchids (genus Ophrys) are one of the most notable examples. Each Ophrys species has flowers that imitate sexually receptive females (bees) and trick real amorous male bees into pseudo-copulating with them. This phenomenon is called a Pouyannian mimicry. In addition to the visual and tactile signals, these flowers also release pseudo-pheromones (allomone) that resemble the sexual pheromones of bees’ female counterparts . They would try to mate with the bloom, which would result in pollen being transferred to their head or abdomen. The pollen is subsequently moved to an other flower of the same orchid species when the bees try another falsified copulation.
Males are drawn to the labellum’s allomone as well as its morphological signals, which include its colour, form, and hair structures that mimic those of a real female bee. Bees and humans have radically distinct perspectives on the electromagnetic spectrum. Further supporting the relevance of the flowers’ morphology are extensive research conducted in the North Hemisphere on how bee eyesight influences the evolution of floral colour, the Ophrys’ deceit could have a secondary benefit, preventing herbivorous animals from consuming the orchids due to the pseudo-bee design. While there have been several studies on the co-evolution of these orchids and bees, we would want to examine the subject from a different angle.
In this simple research, we examine two objectives related to the Bee Orchids’ Pouyannian technique. For the first objective, we sought to determine if the orchids’ trickery might deceive machine learning (ML). For the second objective, we used ML to examine the fundamental differences between Ophrys orchids and bees.

Method

We chose Wolfram Mathematica as the main Machine Learning (ML) platform to test the first objective. . Mathematica performs an automated algorithm selection process. Additionally, Wolfram Server handles a large portion of the backend computation, which lessens the effort and learning requirements on the physical machine. Using Google Images, we first compiled images of O. apifera, O. Insectifera, O. bombyliflora, and O. speculum. Regarding the bee pollinators, we looked through pictures of typical bees and wasps that are frequently associated with the pseudo-copulation with orchids. In order to make the categorising process simpler, we grouped all of the photographs into the bees category without making a distinction between bees and wasps. This is acceptable as the main objective is to evaluate the ML’s ability to distinguish between flowers and bees.
Using Google Chrome’s Fatkun Batch Download extension, we downloaded the photos. We began with around 400 photographs for each of the categories, totaling 2000 images. To choose the finest photographs for ML, we examined the images. We listed a few requirements for the bees and orchids. Images must be sharp and narrowly focused on the creature. To avoid the algorithm from classifying the same species again, several species on a single picture were also eliminated. Images must have an anterior or lateral perspective. Object images that were captured from a distance of more than one metre were also disregarded. Watermarked images were also eliminated. We also made sure the appropriate species of orchids were chosen and put in their appropriate groups.
We had 113 for O. apifera, 243 for O. bombyliflora, 264 for O. insectifera, 253 for O. speculum, and 122 for the bees for the final selection of the photographs utilised. To train and test the model simultaneously in Mathematica, we utilised the Classify function (for more details, see https://reference.wolfram.com/language/ref/Classify.html). This machine learning approach is known as supervised learning. 
​
We tested the precision of our classify model. We compared the confusion matrix, area under the receiver operating characteristic curve (AUC), mean cross-entropy, and accuracy and accuracy baseline . A model is perfect if its accuracy is 100%, which is measured in percentages. Baseline accuracy is accuracy based on the most basic model of assumption. In our instance, the technique that makes predictions for a dataset using heuristics, summary statistics, randomness, or machine learning is the accuracy baseline. The accuracy value is compared with the accuracy at the baseline. The difference between two probability distributions for a given random variable or series of occurrences is measured by mean cross-entropy. Any result more than two is regarded as faulty, with 0.00 being the ideal forecast. Anything less than 0.5 can be viewed as a failure for the AUC, with 0.9 to 1.0 being regarded to be extremely good. The Type I and Type II mistake are explained using the confusion matrix.
​
The machine’s ability to identify between bees and orchids using essential traits was our second goal. For further details, see https://reference.wolfram.com/language/ref/ImageKeypoints.html. We utilised ImageKeypoints and ImageHighlights. To describe it simply, ML finds the object in a photo that has the most noticeable feature. The leaf’s or the wings’ edges in our illustration might be the characteristic. It could possibly be the way some bees’ abdomens are covered with hair. The number of key points in a given image might range from hundreds to thousands, depending on how complex the objects are. We restrict the number of crucial points in this study to the 100th strongest points. The essential points are derived using a variety of methodologies, and they are emphasised using SURF (Speeded Up Robust Features). SURF is a quick and reliable method for comparing photos. It incorporates the direction of the points as well as a circular sample of the pixels. We chose the best photograph for each of the orchids and two photos for the bees since the goal is to identify similarity important spots.

Code for the classification

For this analysis, we compared the classification accuracy between the species Ophrys apifera (apifera)against a collection of bees and wasps(bees). The training and test data were separated using the 80:20 ratio.
SetDirectory[NotebookDirectory[]];​​apifera=FileNames[All,(*writethelocationofyourfolderhere*)];
bees=FileNames[All,(*writethelocationofyourfolderhere*)];
In[]:=
DataApifera=apifera[[#]]"apifera"&/@Range[Length@apifera];
In[]:=
DataBees=bees[[#]]"bees"&/@Range[Length@bees];
In[]:=
Data=Union[DataApifera,DataBees];
In[]:=
myData=Import@Data[[#]][[1]]->Data[[#]][[2]]&/@Range[Length@Data];
In[]:=
sampleSize=IntegerPart[Length@myData*0.8];​​myDataTrain=RandomSample[myData,sampleSize];​​myDataTest=Complement[myData,myDataTrain];
In[]:=
myClassify=Classify[myDataTrain]
In[]:=
myAccuracyDiag=ClassifierMeasurements[myClassify,myDataTest];​​myAccuracyDiag["Report"]
In[]:=
myAccuracyDiag["AreaUnderROCCurve"]

Code for the ImageKey Highlights using SURF

In[]:=
img2=
;
points=ImageKeypoints[​​img2,{"Position","Scale","Orientation","ContrastSign"},​​MaxFeatures->100];​​scalefactor=2.5;​​HighlightImage[img2,​​Table[{{If[p[[4]]==1,Yellow,Red],​​Circle[p[[1]],p[[2]]*scalefactor],​​Line[{p[[1]],​​p[[1]]+p[[2]]*scalefactor*{Cos[p[[3]]],Sin[p[[3]]]}}]}},{p,​​points}]]
The highlights shows that the ML algorithm does highlights the most relevant parts of the orchids that closely resembles the bees (The thorax, body and the wings).

Conclusion

In conclusion, applying ML is a useful technique for analysing the main ideas and findings of morphological studies of plants. More crucially, despite how distinctive the imitation was, it failed to completely fool the ML algorithm. Our techniques, however, come with a number of limitations. First off, because our sample is only comprised of images acquired from internet databases, it is possible that they may be misclassified without proper verification. We think that the categorization approach and the essential details and highlights would have generated a far more accurate result if someone were to reproduce this method using genuine photographs of both orchids and bees (taken from a specific angle and distance). Additionally, there are a few species of Ophrys, each with a wide range of patterns and hues, so our sample size is small. Third, we failed to separate particular bees into their own distinct Ophrys species. We would want to urge further scholars to apply our recommended technique to a bigger dataset. Additionally, we are analysing the essential traits of the tropical country’s orchids and comparing their labellum structures to those of terrestrial and epiphytic orchids in great detail. We also think that since our method only employs the most fundamental ML with Wolfram Mathematica, utilising a more sophisticated ML methodology like Keras or Tensorflow would result in greater accuracy. In further research, we hope to use computer vision (CV) to track the behaviour of the insects that are lured by these flowers.

Reference

Fadzly, N., Zuharah, W. F., & Jenn Ney, J. W. (2021). Can plants fool artificial intelligence? Using machine learning to compare between bee orchids and bees. Plant signaling & behavior, 16(10), 1935605.