Computational Mindfulness

Philip Maymin, Fairfield University
Stella Maymin, Greenwich Country Day School

Mindfulness

“Mindfulness is the very simple process of actively noticing new things.” 
- Ellen Langer, the “mother of mindfulness”

Benefits of mindfulness: reduce chronic pain, boost the immune system, relieve stress, reduce depression, anxiety, and addiction, improve working memory, better relationships, improved vision, increased longevity, more youthfulness, etc.

History of Mindfulness Research

String templates are much easier than manual concatenation

GoogleScholarURL[year_,topic_:"mindfulness"]:=StringTemplate["https://scholar.google.com/scholar?q=`2`&hl=en&as_sdt=0%2C7&as_ylo=`1`&as_yhi=`1`"][year,topic]

GoogleScholarURL@2019

But Google is on to us!

StringTake[Import@GoogleScholarURL@2019,72]

Let’s pretend to be human.

session=StartWebSession[];

articles=AssociationMap[First@StringCases[Last@WebExecute[session,{"OpenPage"->GoogleScholarURL@#,"PageSource"}],"About "~~count:Except[" "]..~~" results":>Interpreter["Integer"]@count]&,Range[1960,2019]];

articles=\[LeftAssociation]1960->19,1961->15,1962->24,1963->22,1964->22,1965->19,1966->19,1967->25,1968->38,1969->28,1970->35,1971->31,1972->41,1973->46,1974->53,1975->76,1976->74,1977->79,1978->68,1979->96,1980->97,1981->123,1982->105,1983->142,1984->170,1985->181,1986->204,1987->209,1988->262,1989->262,1990->327,1991->373,1992->399,1993->504,1994->530,1995->664,1996->723,1997->762,1998->1010,1999->1200,2000->1480,2001->1670,2002->2120,2003->2520,2004->3520,2005->3980,2006->4910,2007->6010,2008->7290,2009->8670,2010->9740,2011->13000,2012->15900,2013->20100,2014->24700,2015->28900,2016->32600,2017->35500,2018->31100,2019->26300\[RightAssociation];

DeleteObject@session

DateListPlot[articles,FrameTicks->{{Automatic,None},{List/@Range[1960,2020,5],None}},FrameTicksStyle->18,GridLines->{{{2017}},None},DateFunction->List,Filling->Axis,PlotRange->All,PlotMarkers->Automatic,GridLines->{{2017},None},Epilog->{Red,Opacity[0.6`],Inset[FlipView[(Style[#1,Bold,26]&)/@{"X","Peak Mindfulness?  ->  X"}],{{2017,5,15},articles[2017]},Right]},ImageSize->1200]

Spot the Difference

If mindfulness is the simple act of noticing new things, can we induce mindfulness with a spot-the-difference challenge?

gallery="C:\\Users\\Philip\\Documents\\My Work\\Wolfram\\WTC19\\Data\\gallery\\";

Row[Show[Import[StringTemplate[gallery<>"1572120567\\``.png"]@#],ImageSize->700]&/@{1,2},Spacer[10]]

ImageContents

ImageContents[]

adjust[image_]:=ImageAdjust[image,{0,0.2,1.55}]
quantize[image_]:=ColorQuantize[image,RandomInteger[{8,11}]]
grain[image_]:=ImageGraphics[image,MinColorDistance->.05]
darker[image_]:=ImageRecolor[image,#-> Darker[#,1/2]]&/@Take[DominantColors[image],UpTo[3]]
blurred[image_]:=Blur[image,2]
aquarecolor[image_]:=ImageRecolor[image,#->ColorData["Aquamarine",0.45]]&/@Reverse@Take[Reverse@DominantColors[image],UpTo[3]]
mask[{{col1_,row1_},{col2_,row2_}},{nrows_,ncols_},previous_:None]:=Table[If[nrows-row2<row≤nrows-row1+1&&col1<col≤col2,1,If[previous===None,0,previous[[row,col]]]],{row,nrows},{col,ncols}]
expunge[image_]:=With[{dim=Reverse@ImageDimensions[image],boxes=boundingboxes[image]},With[{background=Fold[mask[#2,dim,#]&,None,boxes]},Inpaint[image,mask[#,dim],Method-> {"TextureSynthesis",Masking->Image[1-background]}]&/@boxes]]
boundingboxes[image_]:=Quiet[Check[List@@@Flatten@Values@Normal@ImageContents[image,All,"BoundingBox"],{}]]
Enlist[l_List]:=l
Enlist[l_]:=List[l]
ImageMapAt[image_,f_,{{x1_,x2_},{y1_,y2_}}]:= ImageCompose[image,#,{x1,y2},{Left,Top}]&/@Enlist@f[ImageTrim[image,{{x1,x2},{y1,y2}}]]
ImageMapAll[image_,f_:None]:=If[f===None,expunge[image],Table[ImageMapAt[image,f,box],{box,boundingboxes[image]}]]
edits={blurred,darker,aquarecolor,grain,quantize,adjust,None};

Show[#,ImageSize->600]&/@ImageMapAll[]

Hyperlink["https://www.wolframcloud.com/obj/stella/spot.me"]

EEG

An EEG (electroencephalogram) measures brain waves, the electrical activity in the brain, using small metal discs placed on the head via a headband. The device records the frequency and patterns of brain waves in different areas of your brain. We used BrainBit.

Hypothesis 1

The EEGs for difficult spot-the-differences should be different from the EEGs for easy spot-the-differences.
We will assume that the difficult ones are the “mindful” state and the easy ones are the “mindless” state.

Example

ListLinePlot[Transpose@SemanticImport@First@FileNames["eeg*.txt",],ImageSize->800,Axes->False,PlotStyle->Thickness[.005]]

Mindfulness web app using Jasonette/Jasonelle

Quantum
Computational Mindfulness

Philip Maymin, Fairfield University
Stella Maymin, Greenwich Country Day School

Quantum Random Numbers

Hypothesis 2

Quantum random numbers will induce more mindfulness than pseudo random numbers, in the same way that the hard spot-the-differences differed from easy spot-the-differences.

First let’s do Rule 30 pseudo-random numbers

Rule30RandomHex[n_]:=(SeedRandom[Method->"Rule30CA"];With[{v=RandomInteger[15,n]},v])

ClearAll@BigArrayPlot;BigArrayPlot[data_,width_:Automatic,height_:Automatic]:=ArrayPlot[data,PlotRangePadding->0,ImagePadding->0,ImageSize->{Replace[width,Automatic->Length@First@data],Replace[height,Automatic->Length@data]},Frame->False]

BigArrayPlot[Rule30RandomHex[{256,512}]]

RandomImage[]

Quantum Time!

ClearAll@QuantumRandomHex;QuantumRandomHex[n_Integer/;n≤1024 2048]:=First@QuantumRandomHex[{1,n}]
QuantumRandomHex[{h_,w_}]:=QuantumRandomHex[{h,w},{Automatic,Automatic}]
QuantumRandomHex[{height_,width_},{length_:Automatic,size_:Automatic},constraint_:15]/;width*height≤1024 2048:=Quiet[Check[Take[Partition[Flatten[IntegerDigits[FromDigits[#,16],16,2Replace[size,Automatic->width/2]]&/@URLExecute["https://qrng.anu.edu.au/API/jsonI.php",{"length"->Replace[length,Automatic->height],"type"->"hex16","size"->Replace[size,Automatic->Ceiling[width/2]]},"RawJSON",TimeConstraint->constraint]@"data"],width],height],Rule30RandomHex[{height,width}]]]

BigArrayPlot[QuantumRandomHex[{256,512}]]

Results

ClearAll@avgeeg;avgeeg[who_,what_:None]:=Mean@Table[Mean@SemanticImport[f][Transpose],{f,FileNames[who~~If[what===None,"","-"~~what]~~"-*.txt",]}]

Grid[Prepend[Join[{Style[#,Bold,26]}&/@{"Stella","Philip"},Partition[With[{blue=avgeeg@#1,green=avgeeg@#2},ListLinePlot[{blue,green},]]&@@@,2],2],Style[#,Bold,26]&/@]]

Thank You!

Philip Maymin, Fairfield University
Stella Maymin, Greenwich Country Day School

Special Thanks To:
Peter K. Lee, Chanmo Park,  Ellen Langer, and the Langer Mindfulness Insitute
Rory Foulger, Mads Bahrami, Stephen Wolfram, and the Wolfram High School Summer Camp