Thursday, December 26, 2019

Rotation of Matrix Graphs


ResFun[m_]:=ResourceFunction["VertexCoordinateList"][AdjacencyGraph[
ExampleData[{"Matrix",m},"Matrix"]["PatternArray"]]];
RotM[a_,m_]:=RotationTransform[a,{0,0}]/@ResFun[m]//N;
RotMGraph[m_,n_]:=Table[GraphPlot[AdjacencyGraph[
ExampleData[{"Matrix",m},"Matrix"]["PatternArray"],
VertexStyle->Transparent,VertexShape->"",
DirectedEdges->False],PlotStyle->Opacity[.6],
EdgeStyle->ColorData["BrightBands"][Cos[Pi*i/n]^2],
VertexCoordinates->RotM[i*Pi/n,m]],{i,2n}];
Show[RotMGraph["Morandini/robot",11],ImageSize->700]


! Exercises with Graph Data & Matrix Data

RTG[a_,m_]:=RotationTransform[a,
{0,0}]/@ResourceFunction["VertexCoordinateList"][AG[m]]//N;
Show[Table[GraphPlot[AG["HB/can_73"],ImageSize->500,
EdgeStyle->ColorData["BrightBands"][Cos[Pi*i/6]^2],
VertexShape->"",VertexCoordinates->RTG[i*Pi/9,
"HB/can_73"]],{i,18}]]

Exercises 2 with Graph Data & 3D Geometry Data


GraphPlot[RandomGraph[WattsStrogatzGraphDistribution[3971,
0.001,3]],EdgeStyle->Opacity[.1],
EdgeShapeFunction->"Line",VertexStyle->Opacity[.3],
VertexCoordinates->ExampleData[{"Geometry3D",
"Galleon"},"VertexData"],ImageSize->700]


Exercises with Graph Data & 3D Geometry Data


RG[a_,b_,figure_]:=GraphPlot3D[RandomGraph[BernoulliGraphDistribution[a,b],
VertexCoordinates->ExampleData[{"Geometry3D",figure},
"VertexData"][[1;;a]]],EdgeShapeFunction->"Line",ImageSize->500,
VertexStyle->Darker[Green,.4],EdgeStyle->Opacity[.1]];
RG[3363,.0003,"Beethoven"]




Exercises with Geometry3D Data


OD=ExampleData[{"Geometry3D",
"CastleWall"},"VertexData"];
Graphics3D[Table[{Hue[i/Length[OD]],
Sphere[OD[[i]],3]},{i,Length[OD]}],
ImageSize->{600,500},Boxed->False]


Exercises with Statistics Tests 3


FRT[d_,v_]:=FisherRatioTest[#,v,"TestStatistic",
VerifyTestAssumptions -> None]&/@d;
d=RandomVariate[NormalDistribution[],{10^4,10^2}];
SmoothHistogram[{FRT[d,1],FRT[d,3]},ImageSize->500,
Filling->Axis,PlotStyle->{Blue,Red},GridLines->Automatic,
PlotLegends->{"H0 is True","H0 is False"}]


Exercises with Statistics Tests 2


NDV=RandomVariate[NormalDistribution[0.,2.],10^3];
ListLinePlot[NDV,ImageSize->600,PlotLabel->Variance[NDV]]
{TableForm[Table[FisherRatioTest[NDV,4.5,p],
{p,{"TestConclusion","TestDataTable"}}] ],
TableForm[Table[FisherRatioTest[NDV,4.5,p,
AlternativeHypothesis ->"Greater"],
{p,{"TestConclusion","TestDataTable"}}]]}


Exercises with Statistics Tests


ND=RandomVariate[NormalDistribution[],{2,2*10^2}];
ListLinePlot[ND,Filling->Axis,ImageSize->600,
PlotStyle->{LightBlue,LightGray},GridLines->Automatic]
TableForm[Table[FisherRatioTest[ND,Automatic,p],
{p,{"HypothesisTestData","TestConclusion","TestDataTable"}}]]


RevolutionPlot3D Examples


Table[RevolutionPlot3D[{{Cos[u],0,u^2/6},
{2Sin[u/2],0,u^2/6},{3Cos[u/3],0,u^2/6}},
{u,0,2Pi},PlotRange->All,PlotPoints->p,
PlotStyle->Opacity[.5],ColorFunction->Function[{x,y,z},
ColorData["CoffeeTones"][Cos[49x+64y]Sin[81z]]],
Mesh->False,Axes->False,Boxed->False,
ImageSize->300],{p,{10,130}}]


Examples of MeshFunctions


F[x_,y_,z_]:=Sin[x]+Sin[y]+Cos[z]+Cos[x]*Cos[y]*Sin[z];
ContourPlot3D[F[x,y,z]==0,{x,0,2Pi},{y,0,2Pi},{z,0,2Pi},
ContourStyle->{Blue,Opacity[0.1]},
ImageSize->400,Mesh->36,MeshStyle->{Blue,Gray},
MeshFunctions->{Norm[{#1*#3,#2}]&,Norm[{#2*#3,#1}]& },
Boxed->False,Axes->False,ViewPoint->{5,5,5}]




Surfaces with Function Textures


p[r_,t_]:={Re[r^3*(Cos[t]+I*Sin[t])^3],
Im[r^3*(Cos[t]+I*Sin[t])^3],r*Cos[t]/3};
STPP[cm_,m_]:=ParametricPlot3D[p[r,t],{r,0,1},{t,0,4Pi},
PlotPoints->50,Mesh->None,Boxed->False,Axes->False,
ImageSize->400,ColorFunction->Function[{r,t},
ColorData[cm][Abs[r*Sin[m*t]]]]];
STPP["BrightBands",289]


Molecule Plotting 3


MB=Molecule["O=C(N)CCC(N)C(=O)O"]
Multicolumn[Table[MoleculePlot[MB,
ImageSize->{300,200},PlotTheme ->theme,
Sequence[PlotLegends->Placed[Text[theme],Above]]],
{theme,{"AllAtom","HeavyAtom",
"Aromatic","Monochrome"}}],2]
MoleculePlot[MB,FindGraphPartition[MoleculeGraph[MB]]]


Molecule Plotting 2


MA=Molecule[{Atom["H"],Atom["H"],Atom["N"],Atom["C"],Atom["H"],
Atom["H"],Atom["C"],Atom["O"],Atom["O"],Atom["H"]},
{Bond[{1,3}],Bond[{2,3}],Bond[{3,4}],Bond[{4,5}],Bond[{4,6}],
Bond[{4,7}],Bond[{7,8},"Double"],Bond[{7,9}],Bond[{9,10}]}]
MoleculeValue[MA,{"SMILES","InChI","MolecularMass"}]
MAC=FindGraphCommunities[MoleculeGraph[MA],Method -> "Spectral"]
MoleculePlot[MA,Map[BondList[MA,#]&,MAC]]


Molecule Plotting


MA=Molecule[{Atom["H"],Atom["H"],Atom["N"],Atom["C"],Atom["H"],
Atom["H"],Atom["C"],Atom["O"],Atom["O"],Atom["H"]},
{Bond[{1,3}],Bond[{2,3}],Bond[{3,4}],Bond[{4,5}],Bond[{4,6}],
Bond[{4,7}],Bond[{7,8},"Double"],Bond[{7,9}],Bond[{9,10}]}]
Multicolumn[Table[MoleculePlot3D[Molecule["NCC(=O)O"],
Style["H",RGBColor["steelblue"]],PlotTheme->theme,
Sequence[PlotLegends->Placed[Text[theme],Above],
Method->{"ShrinkWrap"->True},SphericalRegion->False,
ImageSize->300]],{theme,{"SpaceFilling" ,"Wireframe",
"Tubes","BallAndStick"}}],2]


PolarPlot Options


T[n_,\[Theta]_,m_]:=Table[i-1+Cos[n*\[Theta]],{i,m}];
PPN[n_,m_,col1_,col2_]:=PolarPlot[Evaluate[T[n,\[Theta],m]],
{\[Theta],0,2Pi},PlotStyle->{RGBColor[col1],RGBColor[col2]},
Axes->False,ImageSize->400]
{PPN[12,2,"crimson","indigo"],PPN[24,6,"cyan","steelblue"]}



Symbol Plotting


v=Table[{1/Cos[-Pi/2+3Pi*i/100],Tan[-Pi/2+Pi*i/100]},
{i,Join[Range[1,99,1],Range[101,199,1]]}];
L=Table [{v[[i,1]]/(v[[i,1]]^2+v[[i,2]]^2),
v[[i,2]]/(v[[i,1]]^2+v[[i,2]]^2)},{i,198}];
Graphics[Table[Style[Text[CharacterRange["砀","礀"][[i]],
L[[i]]],12,Hue[i/200]],{i,198}],
ImageSize->{600,400},AspectRatio->2/3,Frame->True,
GridLines->Automatic,Background->RGBColor["silver"]]


Function Textures


RP[a_]:=RevolutionPlot3D[{u^3,Cos[a*u],2u^2},{u,0,1},
ColorFunction->Function[{x,y,z},
ColorData["DeepSeaColors"][Cos[169x+144y+121z]]],
PlotRange->{{-1.5,1.5},{-1.5,1.5},{0,2}},
PlotPoints->150,PlotStyle->Opacity[.7],
Mesh->False,Axes->False,Boxed->False,ImageSize->Large];
RP[8]




Exercises with External and Internal Data Files


tem=Import["ExampleData/temperatures.json"];
DateListPlot[Table[{DateList[DateObject[StringJoin["20",
StringTake[Keys[tem][[i]],7;;8],
StringTake[Keys[tem][[i]],1;;2],
StringTake[Keys[tem][[i]],4;;5]],
   DateFormat->{"Year","/","Month","/","Day"}]][[1;;3]],
Values[tem[[i]]]},{i,31}],ColorFunction->"TemperatureMap",
ImageSize->400, GridLines->True]
path="https://data.cityofnewyork.us/resource/";
SE=Import[StringJoin[path,"h7rb-945c.json"],HeaderLines->1];
FL=Keys[SE][[1,{1,26,75,79,80,82,34,35}]]; FL[[1;;5]]
Table[Values[SE[[i,{1,26,75,79,80,82,34,35}]]],{i,1}]


Exercises with Datasets


user="https://olgabelitskaya.github.io/";
data=SemanticImport[StringJoin[user,"c_bank.csv"]];
dataF=Table[DateList[DateObject[data[[i,1]]]][[1;;3]],
{i,Length[data]}];
dataG=Dataset[Table[{dataF[[i]],data[[i,4]]},
{i,Length[data]}]];
dataP=Dataset[Table[{dataF[[i]],data[[i,6]]},
{i,Length[data]}]];
{DateListLogPlot[data[[All,{1,4}]],{{2012,1,1},{2012,4,30}},
PlotStyle->Green,Frame->True,Filling->Axis,ImageSize->300],
KagiChart[data[[All,{1,5}]],Frame->True,ImageSize->400]}
DateListPlot[{data[[All,4]],
MovingAverage[Normal[data[[All,4]]],5]},{2012,1,1},
PlotStyle->{Gray,Green},GridLines->True,ImageSize->{600,400}]



GeometricScene Simple Examples


RandomInstance[GeometricScene[{A1,B1,C1,O1},
{T1==Triangle[Style[{A1,B1,C1},Darker[Blue]]],
Style[CircleThrough[{A1,B1,C1},O1],Darker[Blue]],
Style[O1,Darker[Green,.5]]==TriangleCenter[Style[T1,
Darker[Green]],"Centroid"]}]]


Representation Options


PopupView[ExampleData["Classes"]]
SlideView[ExampleData["Geometry3D"]]
MenuView[(#->GraphData[#])&/@Take[GraphData["Hypercube"],
5],Background->LightGreen]
TabView[(#->ExampleData[#])&/@Take[ExampleData["Geometry3D"],
3],ImageSize->200]


Exercises with Datasets


user="https://raw.githubusercontent.com/OlgaBelitskaya/";
path="machine_learning_engineer_nd009/master/";
data=Import[StringJoin[user,path,
"Machine_Learning_Engineer_ND_P3/customers.csv"]];
Dataset[data[[1;;5]]]
TableForm[data[[2;;5]],TableHeadings->{None,data[[1]]}]
TabView[Table[data[[1,i]]->data[[j,i]],
{j,Range[2,30,1]},{i,Range[3,8,1]}]]
ListLinePlot[Table[data[[All,i]],{i,Range[3,8,1]}],
PlotLegends->data[[1,3;;8]],
PlotStyle->Table[ColorData["BrightBands"][i/6],{i,6}],
Filling->Axis,ImageSize->{900,450},AspectRatio->1/2,
PlotRange->All,GridLines->All]