Update on r codes
@@ -176,7 +176,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
|
||||
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
|
||||
@@ -168,10 +168,13 @@ either Python or C++ as programming languages.
|
||||
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
|
||||
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
|
||||
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
|
||||
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
|
||||
|
||||
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing. For example, convert to latex as
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>jupyter nbconvert filename<span style="color: #666666">.</span>ipynb <span style="color: #666666">--</span>to latex
|
||||
</pre></div>
|
||||
<p>
|
||||
This never ends.
|
||||
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
|
||||
formats, ipython notebooks, latex files, pdf files etc.
|
||||
|
||||
|
||||
@@ -163,26 +163,26 @@ MathJax.Hub.Config({
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read<span style="color: #666666">.</span>csv(<span style="color: #BA2121">"src/Hudson_Bay.csv"</span>,header<span style="color: #666666">=</span>T)
|
||||
<!-- code=r (!bc r) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read.csv(<span style="color: #BA2121">"src/Hudson_Bay.csv"</span>,header<span style="color: #666666">=</span><span style="color: #008000">T</span>)
|
||||
fix(HudsonBay)
|
||||
dim(HudsonBay)
|
||||
names(HudsonBay)
|
||||
plot(HudsonBay$Year, HudsonBay$Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
|
||||
attach(HudsonBay)
|
||||
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
|
||||
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>, col<span style="color: #666666">=</span><span style="color: #BA2121">"red"</span>, varwidth<span style="color: #666666">=</span>T, xlab<span style="color: #666666">=</span><span style="color: #BA2121">"Years"</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">"Haresx 1000"</span>)
|
||||
summary(HudsonBay)
|
||||
summary(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
|
||||
library(MASS)
|
||||
library(ISLR)
|
||||
scatter<span style="color: #666666">.</span>smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
|
||||
linearMod <span style="color: #666666">=</span> lm(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span> <span style="color: #666666">~</span> Year)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(linearMod)
|
||||
summary(linearMod)
|
||||
<span style="color: #008000">dim</span>(HudsonBay)
|
||||
<span style="color: #008000">names</span>(HudsonBay)
|
||||
plot(HudsonBay<span style="color: #666666">$</span>Year, HudsonBay<span style="color: #666666">$</span>Hares..x1000.)
|
||||
<span style="color: #008000; font-weight: bold">attach</span>(HudsonBay)
|
||||
plot(Year, Hares..x1000.)
|
||||
plot(Year, Hares..x1000., col<span style="color: #666666">=</span><span style="color: #BA2121">"red"</span>, varwidth<span style="color: #666666">=</span><span style="color: #008000">T</span>, xlab<span style="color: #666666">=</span><span style="color: #BA2121">"Years"</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">"Haresx 1000"</span>)
|
||||
<span style="color: #008000">summary</span>(HudsonBay)
|
||||
<span style="color: #008000">summary</span>(Hares..x1000.)
|
||||
<span style="color: #008000; font-weight: bold">library</span>(MASS)
|
||||
<span style="color: #008000; font-weight: bold">library</span>(ISLR)
|
||||
scatter.smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares..x1000.)
|
||||
linearMod <span style="color: #666666">=</span> lm(Hares..x1000. <span style="color: #666666">~</span> Year)
|
||||
<span style="color: #008000">print</span>(linearMod)
|
||||
<span style="color: #008000">summary</span>(linearMod)
|
||||
plot(linearMod)
|
||||
confint(linearMod)
|
||||
predict(linearMod,data<span style="color: #666666">.</span>frame(Year<span style="color: #666666">=</span>c(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">"confidence"</span>)
|
||||
predict(linearMod,<span style="color: #B00040">data.frame</span>(Year<span style="color: #666666">=</span><span style="color: #B00040">c</span>(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">"confidence"</span>)
|
||||
</pre></div>
|
||||
<p>
|
||||
</div>
|
||||
|
||||
@@ -163,26 +163,26 @@ MathJax.Hub.Config({
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set</span><span style="color: #666666">.</span>seed(<span style="color: #666666">1485</span>)
|
||||
<span style="color: #008000">len</span> <span style="color: #666666">=</span> <span style="color: #666666">24</span>
|
||||
x <span style="color: #666666">=</span> runif(<span style="color: #008000">len</span>)
|
||||
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(<span style="color: #008000">len</span>, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
|
||||
ds <span style="color: #666666">=</span> data<span style="color: #666666">.</span>frame(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
|
||||
<span style="color: #008000">str</span>(ds)
|
||||
<!-- code=r (!bc r) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set.seed</span>(<span style="color: #666666">1485</span>)
|
||||
len <span style="color: #666666">=</span> <span style="color: #666666">24</span>
|
||||
x <span style="color: #666666">=</span> runif(len)
|
||||
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(len, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
|
||||
ds <span style="color: #666666">=</span> <span style="color: #B00040">data.frame</span>(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
|
||||
str(ds)
|
||||
plot( y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span><span style="color: #BA2121">"Known cubic with noise"</span>)
|
||||
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
|
||||
s <span style="color: #666666">=</span> <span style="color: #008000">seq</span>(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
|
||||
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=2</span>, col <span style="color: #666666">=</span><span style="color: #BA2121">"green"</span>)
|
||||
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> I(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #008000">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> T)
|
||||
class(m)
|
||||
summary(m)
|
||||
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
|
||||
power<span style="color: #666666">.</span>se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
|
||||
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> <span style="color: #008000">I</span>(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #B00040">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> <span style="color: #008000">T</span>)
|
||||
<span style="color: #008000">class</span>(m)
|
||||
<span style="color: #008000">summary</span>(m)
|
||||
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(<span style="color: #008000">summary</span>(m)<span style="color: #666666">$</span>coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
|
||||
power.se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(<span style="color: #008000">summary</span>(m)<span style="color: #666666">$</span>coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
|
||||
plot(y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span> <span style="color: #BA2121">"Fitted power model"</span>, sub <span style="color: #666666">=</span> <span style="color: #BA2121">"Blue: fit; green: known"</span>)
|
||||
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
|
||||
s <span style="color: #666666">=</span> <span style="color: #008000">seq</span>(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
|
||||
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=</span> <span style="color: #666666">2</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">"green"</span>)
|
||||
lines(s, predict(m, <span style="color: #008000">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">"blue"</span>)
|
||||
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, paste(<span style="color: #BA2121">"y =x^ ("</span>, power, <span style="color: #BA2121">" +/- "</span>, power<span style="color: #666666">.</span>se, <span style="color: #BA2121">")"</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">""</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
|
||||
lines(s, predict(m, <span style="color: #B00040">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">"blue"</span>)
|
||||
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, <span style="color: #008000">paste</span>(<span style="color: #BA2121">"y =x^ ("</span>, power, <span style="color: #BA2121">" +/- "</span>, power.se, <span style="color: #BA2121">")"</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">""</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
|
||||
</pre></div>
|
||||
<p>
|
||||
</div>
|
||||
|
||||
@@ -176,7 +176,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
|
||||
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p> <br>
|
||||
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
|
||||
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -305,10 +305,13 @@ either Python or C++ as programming languages.
|
||||
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
|
||||
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
|
||||
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
|
||||
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
|
||||
|
||||
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing. For example, convert to latex as
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>jupyter nbconvert filename.ipynb --to latex
|
||||
</pre></div>
|
||||
<p>
|
||||
This never ends.
|
||||
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
|
||||
formats, ipython notebooks, latex files, pdf files etc.
|
||||
</section>
|
||||
@@ -806,26 +809,26 @@ plt.show()
|
||||
<b></b>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">"src/Hudson_Bay.csv"</span>,header=T)
|
||||
<!-- code=r (!bc r) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">"src/Hudson_Bay.csv"</span>,header=<span style="color: #658b00">T</span>)
|
||||
fix(HudsonBay)
|
||||
dim(HudsonBay)
|
||||
names(HudsonBay)
|
||||
plot(HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Year, HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Hares..x1000.)
|
||||
attach(HudsonBay)
|
||||
<span style="color: #8B008B; font-weight: bold">dim</span>(HudsonBay)
|
||||
<span style="color: #8B008B; font-weight: bold">names</span>(HudsonBay)
|
||||
plot(HudsonBay$Year, HudsonBay$Hares..x1000.)
|
||||
<span style="color: #8B008B; font-weight: bold">attach</span>(HudsonBay)
|
||||
plot(Year, Hares..x1000.)
|
||||
plot(Year, Hares..x1000., col=<span style="color: #CD5555">"red"</span>, varwidth=T, xlab=<span style="color: #CD5555">"Years"</span>, ylab=<span style="color: #CD5555">"Haresx 1000"</span>)
|
||||
summary(HudsonBay)
|
||||
summary(Hares..x1000.)
|
||||
library(MASS)
|
||||
library(ISLR)
|
||||
plot(Year, Hares..x1000., col=<span style="color: #CD5555">"red"</span>, varwidth=<span style="color: #658b00">T</span>, xlab=<span style="color: #CD5555">"Years"</span>, ylab=<span style="color: #CD5555">"Haresx 1000"</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">summary</span>(HudsonBay)
|
||||
<span style="color: #8B008B; font-weight: bold">summary</span>(Hares..x1000.)
|
||||
<span style="color: #8B008B; font-weight: bold">library</span>(MASS)
|
||||
<span style="color: #8B008B; font-weight: bold">library</span>(ISLR)
|
||||
scatter.smooth(x=Year, y = Hares..x1000.)
|
||||
linearMod = lm(Hares..x1000. ~ Year)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(linearMod)
|
||||
summary(linearMod)
|
||||
<span style="color: #8B008B; font-weight: bold">summary</span>(linearMod)
|
||||
plot(linearMod)
|
||||
confint(linearMod)
|
||||
predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">"confidence"</span>)
|
||||
predict(linearMod,<span style="color: #00688B; font-weight: bold">data.frame</span>(Year=<span style="color: #00688B; font-weight: bold">c</span>(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">"confidence"</span>)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
@@ -838,26 +841,26 @@ predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<sp
|
||||
<b></b>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #658b00">set</span>.seed(<span style="color: #B452CD">1485</span>)
|
||||
<span style="color: #658b00">len</span> = <span style="color: #B452CD">24</span>
|
||||
x = runif(<span style="color: #658b00">len</span>)
|
||||
y = x^<span style="color: #B452CD">3</span>+rnorm(<span style="color: #658b00">len</span>, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
|
||||
ds = data.frame(x = x, y = y)
|
||||
<span style="color: #658b00">str</span>(ds)
|
||||
<!-- code=r (!bc r) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">set.seed</span>(<span style="color: #B452CD">1485</span>)
|
||||
len = <span style="color: #B452CD">24</span>
|
||||
x = runif(len)
|
||||
y = x^<span style="color: #B452CD">3</span>+rnorm(len, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
|
||||
ds = <span style="color: #00688B; font-weight: bold">data.frame</span>(x = x, y = y)
|
||||
str(ds)
|
||||
plot( y ~ x, main =<span style="color: #CD5555">"Known cubic with noise"</span>)
|
||||
s = seq(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
|
||||
s = <span style="color: #8B008B; font-weight: bold">seq</span>(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
|
||||
lines(s, s^<span style="color: #B452CD">3</span>, lty =<span style="color: #B452CD">2</span>, col =<span style="color: #CD5555">"green"</span>)
|
||||
m = nls(y ~ I(x^power), data = ds, start = <span style="color: #658b00">list</span>(power=<span style="color: #B452CD">1</span>), trace = T)
|
||||
class(m)
|
||||
summary(m)
|
||||
power = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
|
||||
power.se = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
|
||||
m = nls(y ~ <span style="color: #8B008B; font-weight: bold">I</span>(x^power), data = ds, start = <span style="color: #00688B; font-weight: bold">list</span>(power=<span style="color: #B452CD">1</span>), trace = <span style="color: #658b00">T</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">class</span>(m)
|
||||
<span style="color: #8B008B; font-weight: bold">summary</span>(m)
|
||||
power = <span style="color: #8B008B; font-weight: bold">round</span>(<span style="color: #8B008B; font-weight: bold">summary</span>(m)$coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
|
||||
power.se = <span style="color: #8B008B; font-weight: bold">round</span>(<span style="color: #8B008B; font-weight: bold">summary</span>(m)$coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
|
||||
plot(y ~ x, main = <span style="color: #CD5555">"Fitted power model"</span>, sub = <span style="color: #CD5555">"Blue: fit; green: known"</span>)
|
||||
s = seq(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
|
||||
s = <span style="color: #8B008B; font-weight: bold">seq</span>(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
|
||||
lines(s, s^<span style="color: #B452CD">3</span>, lty = <span style="color: #B452CD">2</span>, col = <span style="color: #CD5555">"green"</span>)
|
||||
lines(s, predict(m, <span style="color: #658b00">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">"blue"</span>)
|
||||
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, paste(<span style="color: #CD5555">"y =x^ ("</span>, power, <span style="color: #CD5555">" +/- "</span>, power.se, <span style="color: #CD5555">")"</span>, sep = <span style="color: #CD5555">""</span>), pos = <span style="color: #B452CD">4</span>)
|
||||
lines(s, predict(m, <span style="color: #00688B; font-weight: bold">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">"blue"</span>)
|
||||
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, <span style="color: #8B008B; font-weight: bold">paste</span>(<span style="color: #CD5555">"y =x^ ("</span>, power, <span style="color: #CD5555">" +/- "</span>, power.se, <span style="color: #CD5555">")"</span>, sep = <span style="color: #CD5555">""</span>), pos = <span style="color: #B452CD">4</span>)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -140,7 +140,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
|
||||
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -282,10 +282,13 @@ either Python or C++ as programming languages.
|
||||
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
|
||||
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
|
||||
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
|
||||
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
|
||||
|
||||
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing. For example, convert to latex as
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span>jupyter nbconvert filename.ipynb --to latex
|
||||
</pre></div>
|
||||
<p>
|
||||
This never ends.
|
||||
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
|
||||
formats, ipython notebooks, latex files, pdf files etc.
|
||||
|
||||
@@ -799,26 +802,26 @@ plt.show()
|
||||
<p>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">"src/Hudson_Bay.csv"</span>,header=T)
|
||||
<!-- code=r (!bc r) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">"src/Hudson_Bay.csv"</span>,header=<span style="color: #658b00">T</span>)
|
||||
fix(HudsonBay)
|
||||
dim(HudsonBay)
|
||||
names(HudsonBay)
|
||||
plot(HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Year, HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Hares..x1000.)
|
||||
attach(HudsonBay)
|
||||
<span style="color: #8B008B; font-weight: bold">dim</span>(HudsonBay)
|
||||
<span style="color: #8B008B; font-weight: bold">names</span>(HudsonBay)
|
||||
plot(HudsonBay$Year, HudsonBay$Hares..x1000.)
|
||||
<span style="color: #8B008B; font-weight: bold">attach</span>(HudsonBay)
|
||||
plot(Year, Hares..x1000.)
|
||||
plot(Year, Hares..x1000., col=<span style="color: #CD5555">"red"</span>, varwidth=T, xlab=<span style="color: #CD5555">"Years"</span>, ylab=<span style="color: #CD5555">"Haresx 1000"</span>)
|
||||
summary(HudsonBay)
|
||||
summary(Hares..x1000.)
|
||||
library(MASS)
|
||||
library(ISLR)
|
||||
plot(Year, Hares..x1000., col=<span style="color: #CD5555">"red"</span>, varwidth=<span style="color: #658b00">T</span>, xlab=<span style="color: #CD5555">"Years"</span>, ylab=<span style="color: #CD5555">"Haresx 1000"</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">summary</span>(HudsonBay)
|
||||
<span style="color: #8B008B; font-weight: bold">summary</span>(Hares..x1000.)
|
||||
<span style="color: #8B008B; font-weight: bold">library</span>(MASS)
|
||||
<span style="color: #8B008B; font-weight: bold">library</span>(ISLR)
|
||||
scatter.smooth(x=Year, y = Hares..x1000.)
|
||||
linearMod = lm(Hares..x1000. ~ Year)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(linearMod)
|
||||
summary(linearMod)
|
||||
<span style="color: #8B008B; font-weight: bold">summary</span>(linearMod)
|
||||
plot(linearMod)
|
||||
confint(linearMod)
|
||||
predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">"confidence"</span>)
|
||||
predict(linearMod,<span style="color: #00688B; font-weight: bold">data.frame</span>(Year=<span style="color: #00688B; font-weight: bold">c</span>(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">"confidence"</span>)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
@@ -833,26 +836,26 @@ predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<sp
|
||||
<p>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #658b00">set</span>.seed(<span style="color: #B452CD">1485</span>)
|
||||
<span style="color: #658b00">len</span> = <span style="color: #B452CD">24</span>
|
||||
x = runif(<span style="color: #658b00">len</span>)
|
||||
y = x^<span style="color: #B452CD">3</span>+rnorm(<span style="color: #658b00">len</span>, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
|
||||
ds = data.frame(x = x, y = y)
|
||||
<span style="color: #658b00">str</span>(ds)
|
||||
<!-- code=r (!bc r) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">set.seed</span>(<span style="color: #B452CD">1485</span>)
|
||||
len = <span style="color: #B452CD">24</span>
|
||||
x = runif(len)
|
||||
y = x^<span style="color: #B452CD">3</span>+rnorm(len, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
|
||||
ds = <span style="color: #00688B; font-weight: bold">data.frame</span>(x = x, y = y)
|
||||
str(ds)
|
||||
plot( y ~ x, main =<span style="color: #CD5555">"Known cubic with noise"</span>)
|
||||
s = seq(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
|
||||
s = <span style="color: #8B008B; font-weight: bold">seq</span>(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
|
||||
lines(s, s^<span style="color: #B452CD">3</span>, lty =<span style="color: #B452CD">2</span>, col =<span style="color: #CD5555">"green"</span>)
|
||||
m = nls(y ~ I(x^power), data = ds, start = <span style="color: #658b00">list</span>(power=<span style="color: #B452CD">1</span>), trace = T)
|
||||
class(m)
|
||||
summary(m)
|
||||
power = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
|
||||
power.se = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
|
||||
m = nls(y ~ <span style="color: #8B008B; font-weight: bold">I</span>(x^power), data = ds, start = <span style="color: #00688B; font-weight: bold">list</span>(power=<span style="color: #B452CD">1</span>), trace = <span style="color: #658b00">T</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">class</span>(m)
|
||||
<span style="color: #8B008B; font-weight: bold">summary</span>(m)
|
||||
power = <span style="color: #8B008B; font-weight: bold">round</span>(<span style="color: #8B008B; font-weight: bold">summary</span>(m)$coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
|
||||
power.se = <span style="color: #8B008B; font-weight: bold">round</span>(<span style="color: #8B008B; font-weight: bold">summary</span>(m)$coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
|
||||
plot(y ~ x, main = <span style="color: #CD5555">"Fitted power model"</span>, sub = <span style="color: #CD5555">"Blue: fit; green: known"</span>)
|
||||
s = seq(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
|
||||
s = <span style="color: #8B008B; font-weight: bold">seq</span>(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
|
||||
lines(s, s^<span style="color: #B452CD">3</span>, lty = <span style="color: #B452CD">2</span>, col = <span style="color: #CD5555">"green"</span>)
|
||||
lines(s, predict(m, <span style="color: #658b00">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">"blue"</span>)
|
||||
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, paste(<span style="color: #CD5555">"y =x^ ("</span>, power, <span style="color: #CD5555">" +/- "</span>, power.se, <span style="color: #CD5555">")"</span>, sep = <span style="color: #CD5555">""</span>), pos = <span style="color: #B452CD">4</span>)
|
||||
lines(s, predict(m, <span style="color: #00688B; font-weight: bold">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">"blue"</span>)
|
||||
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, <span style="color: #8B008B; font-weight: bold">paste</span>(<span style="color: #CD5555">"y =x^ ("</span>, power, <span style="color: #CD5555">" +/- "</span>, power.se, <span style="color: #CD5555">")"</span>, sep = <span style="color: #CD5555">""</span>), pos = <span style="color: #B452CD">4</span>)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -145,7 +145,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
|
||||
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -287,10 +287,13 @@ either Python or C++ as programming languages.
|
||||
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
|
||||
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
|
||||
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
|
||||
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
|
||||
|
||||
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing. For example, convert to latex as
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>jupyter nbconvert filename<span style="color: #666666">.</span>ipynb <span style="color: #666666">--</span>to latex
|
||||
</pre></div>
|
||||
<p>
|
||||
This never ends.
|
||||
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
|
||||
formats, ipython notebooks, latex files, pdf files etc.
|
||||
|
||||
@@ -804,26 +807,26 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read<span style="color: #666666">.</span>csv(<span style="color: #BA2121">"src/Hudson_Bay.csv"</span>,header<span style="color: #666666">=</span>T)
|
||||
<!-- code=r (!bc r) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read.csv(<span style="color: #BA2121">"src/Hudson_Bay.csv"</span>,header<span style="color: #666666">=</span><span style="color: #008000">T</span>)
|
||||
fix(HudsonBay)
|
||||
dim(HudsonBay)
|
||||
names(HudsonBay)
|
||||
plot(HudsonBay$Year, HudsonBay$Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
|
||||
attach(HudsonBay)
|
||||
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
|
||||
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>, col<span style="color: #666666">=</span><span style="color: #BA2121">"red"</span>, varwidth<span style="color: #666666">=</span>T, xlab<span style="color: #666666">=</span><span style="color: #BA2121">"Years"</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">"Haresx 1000"</span>)
|
||||
summary(HudsonBay)
|
||||
summary(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
|
||||
library(MASS)
|
||||
library(ISLR)
|
||||
scatter<span style="color: #666666">.</span>smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
|
||||
linearMod <span style="color: #666666">=</span> lm(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span> <span style="color: #666666">~</span> Year)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(linearMod)
|
||||
summary(linearMod)
|
||||
<span style="color: #008000">dim</span>(HudsonBay)
|
||||
<span style="color: #008000">names</span>(HudsonBay)
|
||||
plot(HudsonBay<span style="color: #666666">$</span>Year, HudsonBay<span style="color: #666666">$</span>Hares..x1000.)
|
||||
<span style="color: #008000; font-weight: bold">attach</span>(HudsonBay)
|
||||
plot(Year, Hares..x1000.)
|
||||
plot(Year, Hares..x1000., col<span style="color: #666666">=</span><span style="color: #BA2121">"red"</span>, varwidth<span style="color: #666666">=</span><span style="color: #008000">T</span>, xlab<span style="color: #666666">=</span><span style="color: #BA2121">"Years"</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">"Haresx 1000"</span>)
|
||||
<span style="color: #008000">summary</span>(HudsonBay)
|
||||
<span style="color: #008000">summary</span>(Hares..x1000.)
|
||||
<span style="color: #008000; font-weight: bold">library</span>(MASS)
|
||||
<span style="color: #008000; font-weight: bold">library</span>(ISLR)
|
||||
scatter.smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares..x1000.)
|
||||
linearMod <span style="color: #666666">=</span> lm(Hares..x1000. <span style="color: #666666">~</span> Year)
|
||||
<span style="color: #008000">print</span>(linearMod)
|
||||
<span style="color: #008000">summary</span>(linearMod)
|
||||
plot(linearMod)
|
||||
confint(linearMod)
|
||||
predict(linearMod,data<span style="color: #666666">.</span>frame(Year<span style="color: #666666">=</span>c(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">"confidence"</span>)
|
||||
predict(linearMod,<span style="color: #B00040">data.frame</span>(Year<span style="color: #666666">=</span><span style="color: #B00040">c</span>(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">"confidence"</span>)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
@@ -838,26 +841,26 @@ predict(linearMod,data<span style="color: #666666">.</span>frame(Year<span style
|
||||
<p>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set</span><span style="color: #666666">.</span>seed(<span style="color: #666666">1485</span>)
|
||||
<span style="color: #008000">len</span> <span style="color: #666666">=</span> <span style="color: #666666">24</span>
|
||||
x <span style="color: #666666">=</span> runif(<span style="color: #008000">len</span>)
|
||||
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(<span style="color: #008000">len</span>, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
|
||||
ds <span style="color: #666666">=</span> data<span style="color: #666666">.</span>frame(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
|
||||
<span style="color: #008000">str</span>(ds)
|
||||
<!-- code=r (!bc r) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set.seed</span>(<span style="color: #666666">1485</span>)
|
||||
len <span style="color: #666666">=</span> <span style="color: #666666">24</span>
|
||||
x <span style="color: #666666">=</span> runif(len)
|
||||
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(len, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
|
||||
ds <span style="color: #666666">=</span> <span style="color: #B00040">data.frame</span>(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
|
||||
str(ds)
|
||||
plot( y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span><span style="color: #BA2121">"Known cubic with noise"</span>)
|
||||
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
|
||||
s <span style="color: #666666">=</span> <span style="color: #008000">seq</span>(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
|
||||
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=2</span>, col <span style="color: #666666">=</span><span style="color: #BA2121">"green"</span>)
|
||||
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> I(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #008000">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> T)
|
||||
class(m)
|
||||
summary(m)
|
||||
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
|
||||
power<span style="color: #666666">.</span>se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
|
||||
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> <span style="color: #008000">I</span>(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #B00040">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> <span style="color: #008000">T</span>)
|
||||
<span style="color: #008000">class</span>(m)
|
||||
<span style="color: #008000">summary</span>(m)
|
||||
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(<span style="color: #008000">summary</span>(m)<span style="color: #666666">$</span>coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
|
||||
power.se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(<span style="color: #008000">summary</span>(m)<span style="color: #666666">$</span>coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
|
||||
plot(y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span> <span style="color: #BA2121">"Fitted power model"</span>, sub <span style="color: #666666">=</span> <span style="color: #BA2121">"Blue: fit; green: known"</span>)
|
||||
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
|
||||
s <span style="color: #666666">=</span> <span style="color: #008000">seq</span>(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
|
||||
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=</span> <span style="color: #666666">2</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">"green"</span>)
|
||||
lines(s, predict(m, <span style="color: #008000">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">"blue"</span>)
|
||||
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, paste(<span style="color: #BA2121">"y =x^ ("</span>, power, <span style="color: #BA2121">" +/- "</span>, power<span style="color: #666666">.</span>se, <span style="color: #BA2121">")"</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">""</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
|
||||
lines(s, predict(m, <span style="color: #B00040">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">"blue"</span>)
|
||||
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, <span style="color: #008000">paste</span>(<span style="color: #BA2121">"y =x^ ("</span>, power, <span style="color: #BA2121">" +/- "</span>, power.se, <span style="color: #BA2121">")"</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">""</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"cells": [],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"cells": [],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"cells": [],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
"<!-- Author: --> \n",
|
||||
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
|
||||
"\n",
|
||||
"Date: **Dec 6, 2017**\n",
|
||||
"Date: **Dec 8, 2017**\n",
|
||||
"\n",
|
||||
"Copyright 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
|
||||
"\n",
|
||||
@@ -125,9 +125,24 @@
|
||||
"To add more entropy, **cython** can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook \n",
|
||||
"setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility, \n",
|
||||
"including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook \n",
|
||||
"can easily be converted into a nicely rendered **PDF** file or a Latex file for further processing.\n",
|
||||
"\n",
|
||||
"This never ends.\n",
|
||||
"can easily be converted into a nicely rendered **PDF** file or a Latex file for further processing. For example, convert to latex as"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"jupyter nbconvert filename.ipynb --to latex"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If you use the light mark-up language **doconce** you can convert a standard ascii text file into various HTML \n",
|
||||
"formats, ipython notebooks, latex files, pdf files etc. \n",
|
||||
"\n",
|
||||
@@ -138,7 +153,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -173,7 +188,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -283,7 +298,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -540,7 +555,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -614,7 +629,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 6,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -648,32 +663,28 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"HudsonBay = read.csv(\"src/Hudson_Bay.csv\",header=T)\n",
|
||||
"fix(HudsonBay)\n",
|
||||
"dim(HudsonBay)\n",
|
||||
"names(HudsonBay)\n",
|
||||
"plot(HudsonBay$Year, HudsonBay$Hares..x1000.)\n",
|
||||
"attach(HudsonBay)\n",
|
||||
"plot(Year, Hares..x1000.)\n",
|
||||
"plot(Year, Hares..x1000., col=\"red\", varwidth=T, xlab=\"Years\", ylab=\"Haresx 1000\")\n",
|
||||
"summary(HudsonBay)\n",
|
||||
"summary(Hares..x1000.)\n",
|
||||
"library(MASS)\n",
|
||||
"library(ISLR)\n",
|
||||
"scatter.smooth(x=Year, y = Hares..x1000.)\n",
|
||||
"linearMod = lm(Hares..x1000. ~ Year)\n",
|
||||
"print(linearMod)\n",
|
||||
"summary(linearMod)\n",
|
||||
"plot(linearMod)\n",
|
||||
"confint(linearMod)\n",
|
||||
"predict(linearMod,data.frame(Year=c(1910,1914,1920)),interval=\"confidence\")"
|
||||
" HudsonBay = read.csv(\"src/Hudson_Bay.csv\",header=T)\n",
|
||||
" fix(HudsonBay)\n",
|
||||
" dim(HudsonBay)\n",
|
||||
" names(HudsonBay)\n",
|
||||
" plot(HudsonBay$Year, HudsonBay$Hares..x1000.)\n",
|
||||
" attach(HudsonBay)\n",
|
||||
" plot(Year, Hares..x1000.)\n",
|
||||
" plot(Year, Hares..x1000., col=\"red\", varwidth=T, xlab=\"Years\", ylab=\"Haresx 1000\")\n",
|
||||
" summary(HudsonBay)\n",
|
||||
" summary(Hares..x1000.)\n",
|
||||
" library(MASS)\n",
|
||||
" library(ISLR)\n",
|
||||
" scatter.smooth(x=Year, y = Hares..x1000.)\n",
|
||||
" linearMod = lm(Hares..x1000. ~ Year)\n",
|
||||
" print(linearMod)\n",
|
||||
" summary(linearMod)\n",
|
||||
" plot(linearMod)\n",
|
||||
" confint(linearMod)\n",
|
||||
" predict(linearMod,data.frame(Year=c(1910,1914,1920)),interval=\"confidence\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -684,32 +695,28 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"set.seed(1485)\n",
|
||||
"len = 24\n",
|
||||
"x = runif(len)\n",
|
||||
"y = x^3+rnorm(len, 0,0.06)\n",
|
||||
"ds = data.frame(x = x, y = y)\n",
|
||||
"str(ds)\n",
|
||||
"plot( y ~ x, main =\"Known cubic with noise\")\n",
|
||||
"s = seq(0,1,length =100)\n",
|
||||
"lines(s, s^3, lty =2, col =\"green\")\n",
|
||||
"m = nls(y ~ I(x^power), data = ds, start = list(power=1), trace = T)\n",
|
||||
"class(m)\n",
|
||||
"summary(m)\n",
|
||||
"power = round(summary(m)$coefficients[1], 3)\n",
|
||||
"power.se = round(summary(m)$coefficients[2], 3)\n",
|
||||
"plot(y ~ x, main = \"Fitted power model\", sub = \"Blue: fit; green: known\")\n",
|
||||
"s = seq(0, 1, length = 100)\n",
|
||||
"lines(s, s^3, lty = 2, col = \"green\")\n",
|
||||
"lines(s, predict(m, list(x = s)), lty = 1, col = \"blue\")\n",
|
||||
"text(0, 0.5, paste(\"y =x^ (\", power, \" +/- \", power.se, \")\", sep = \"\"), pos = 4)"
|
||||
" set.seed(1485)\n",
|
||||
" len = 24\n",
|
||||
" x = runif(len)\n",
|
||||
" y = x^3+rnorm(len, 0,0.06)\n",
|
||||
" ds = data.frame(x = x, y = y)\n",
|
||||
" str(ds)\n",
|
||||
" plot( y ~ x, main =\"Known cubic with noise\")\n",
|
||||
" s = seq(0,1,length =100)\n",
|
||||
" lines(s, s^3, lty =2, col =\"green\")\n",
|
||||
" m = nls(y ~ I(x^power), data = ds, start = list(power=1), trace = T)\n",
|
||||
" class(m)\n",
|
||||
" summary(m)\n",
|
||||
" power = round(summary(m)$coefficients[1], 3)\n",
|
||||
" power.se = round(summary(m)$coefficients[2], 3)\n",
|
||||
" plot(y ~ x, main = \"Fitted power model\", sub = \"Blue: fit; green: known\")\n",
|
||||
" s = seq(0, 1, length = 100)\n",
|
||||
" lines(s, s^3, lty = 2, col = \"green\")\n",
|
||||
" lines(s, predict(m, list(x = s)), lty = 1, col = \"blue\")\n",
|
||||
" text(0, 0.5, paste(\"y =x^ (\", power, \" +/- \", power.se, \")\", sep = \"\"), pos = 4)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 32 KiB |
@@ -112,9 +112,11 @@ either Python or C++ as programming languages.
|
||||
To add more entropy, _cython_ can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
|
||||
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
|
||||
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
|
||||
can easily be converted into a nicely rendered _PDF_ file or a Latex file for further processing.
|
||||
can easily be converted into a nicely rendered _PDF_ file or a Latex file for further processing. For example, convert to latex as
|
||||
!bc pycod
|
||||
jupyter nbconvert filename.ipynb --to latex
|
||||
!ec
|
||||
|
||||
This never ends.
|
||||
If you use the light mark-up language _doconce_ you can convert a standard ascii text file into various HTML
|
||||
formats, ipython notebooks, latex files, pdf files etc.
|
||||
|
||||
@@ -445,7 +447,7 @@ plt.show()
|
||||
!split
|
||||
===== Linear Least squares in R =====
|
||||
!bblock
|
||||
!bc pycod
|
||||
!bc r
|
||||
HudsonBay = read.csv("src/Hudson_Bay.csv",header=T)
|
||||
fix(HudsonBay)
|
||||
dim(HudsonBay)
|
||||
@@ -471,7 +473,7 @@ predict(linearMod,data.frame(Year=c(1910,1914,1920)),interval="confidence")
|
||||
!split
|
||||
===== Non-Linear Least squares in R =====
|
||||
!bblock
|
||||
!bc pycod
|
||||
!bc r
|
||||
set.seed(1485)
|
||||
len = 24
|
||||
x = runif(len)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from IPython.display import display
|
||||
import sklearn
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.tree import DecisionTreeRegressor
|
||||
from sklearn.model_selection import train_test_split
|
||||
import mglearn
|
||||
X, y = mglearn.datasets.make_forge()
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
|
||||
from sklearn.neighbors import KNeighborsClassifier
|
||||
clf = KNeighborsClassifier(n_neighbors=3)
|
||||
clf.fit(X_train, y_train)
|
||||
KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',metric_params=None, n_jobs=1, n_neighbors=3, p=2,weights='uniform')
|
||||
|
||||
clf.predict(X_test)
|
||||
|
||||
clf.score(X_test, y_test)
|
||||
fig, axes = plt.subplots(1, 3, figsize=(10, 3))
|
||||
for n_neighbors, ax in zip([1, 3, 9], axes):
|
||||
clf = KNeighborsClassifier(n_neighbors=n_neighbors).fit(X, y)
|
||||
mglearn.plots.plot_2d_separator(clf, X, fill=True, eps=0.5, ax=ax, alpha=.4)
|
||||
ax.scatter(X[:, 0], X[:, 1], c=y, s=60, cmap=mglearn.cm2)
|
||||
ax.set_title("%d neighbor(s)" % n_neighbors)
|
||||
|
||||
|
||||
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
|
||||
x = data[:,0]
|
||||
y = data[:,1]
|
||||
#x_train, y_train = train_test_split(x, y, random_state=0)
|
||||
line = np.linspace(1900,1930,1000,endpoint=False).reshape(-1,1)
|
||||
reg = DecisionTreeRegressor(min_samples_split=3).fit(x.reshape(-1,1),y.reshape(-1,1))
|
||||
plt.plot(line, reg.predict(line), label="decision tree")
|
||||
regline = LinearRegression().fit(x.reshape(-1,1),y.reshape(-1,1))
|
||||
plt.plot(line, regline.predict(line), label= "Linear Regression")
|
||||
plt.plot(x, y, label= "Linear Regression")
|
||||
plt.show()
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from IPython.display import display
|
||||
import pandas as pd
|
||||
|
||||
data = pd.read_csv('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
|
||||
|
||||
|
||||
data_pandas = pd.DataFrame(data)
|
||||
display(data_pandas)
|
||||
@@ -5,12 +5,29 @@ import sklearn
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.tree import DecisionTreeRegressor
|
||||
from sklearn.model_selection import train_test_split
|
||||
X_train, X_test, y_train, y_test = train_test_split(x, y, random_state=0)
|
||||
import mglearn
|
||||
X, y = mglearn.datasets.make_forge()
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
|
||||
from sklearn.neighbors import KNeighborsClassifier
|
||||
clf = KNeighborsClassifier(n_neighbors=3)
|
||||
clf.fit(X_train, y_train)
|
||||
KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',metric_params=None, n_jobs=1, n_neighbors=3, p=2,weights='uniform')
|
||||
|
||||
clf.predict(X_test)
|
||||
|
||||
clf.score(X_test, y_test)
|
||||
fig, axes = plt.subplots(1, 3, figsize=(10, 3))
|
||||
for n_neighbors, ax in zip([1, 3, 9], axes):
|
||||
clf = KNeighborsClassifier(n_neighbors=n_neighbors).fit(X, y)
|
||||
mglearn.plots.plot_2d_separator(clf, X, fill=True, eps=0.5, ax=ax, alpha=.4)
|
||||
ax.scatter(X[:, 0], X[:, 1], c=y, s=60, cmap=mglearn.cm2)
|
||||
ax.set_title("%d neighbor(s)" % n_neighbors)
|
||||
|
||||
|
||||
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
|
||||
x = data[:,0]
|
||||
y = data[:,1]
|
||||
x_train, y_train = train_test_split(x, y, random_state=0)
|
||||
#x_train, y_train = train_test_split(x, y, random_state=0)
|
||||
line = np.linspace(1900,1930,1000,endpoint=False).reshape(-1,1)
|
||||
reg = DecisionTreeRegressor(min_samples_split=3).fit(x.reshape(-1,1),y.reshape(-1,1))
|
||||
plt.plot(line, reg.predict(line), label="decision tree")
|
||||
|
||||