diff --git a/doc/pub/How2ReadData/html/How2ReadData-bs.html b/doc/pub/How2ReadData/html/How2ReadData-bs.html index 77c33d5d6..412777604 100644 --- a/doc/pub/How2ReadData/html/How2ReadData-bs.html +++ b/doc/pub/How2ReadData/html/How2ReadData-bs.html @@ -142,7 +142,7 @@ MathJax.Hub.Config({
-
@@ -481,7 +481,7 @@ example of the functionality of scikit-learn. from sklearn.metrics import mean_squared_error, r2_score, mean_squared_log_error, mean_absolute_error x = np.random.rand(100,1) -y = 2.0+ 5*x+0.5np.random.randn(100,1) +y = 2.0+ 5*x+0.5*np.random.randn(100,1) linreg = LinearRegression() linreg.fit(x,y) ypredict = linreg.predict(x) @@ -594,6 +594,7 @@ plt.show()
Similarly, using R, we can perform similar studies. The following R code illustrates this. +(more details on R will be inserted later).
We present here several examples, with pertinent Python codes that we -will us to illustrate various machine learning methods and ways to +will use to illustrate various machine learning methods and ways to analyze, from simple to complex, various data sets. Many of these examples allow us to generate the data we want to analyze, following much of the same philosophy we discussed above when @@ -678,7 +679,7 @@ Here we will construct a model for cell growth based on a simple difference equa interval \( \Delta t \) as \( N \) cells would: \( \Delta N \propto N \)
-The difference equation can be programmed in a simple was, and in order to get started we +The difference equation can be programmed in a simple way, and in order to get started we set \( r=1.5 \), \( N^0=1 \), \( \Delta t=0.5 \). The program reads
@@ -702,13 +703,12 @@ set \( r=1.5 \), \( N^0=1 \), \( \Delta t=0.5 \). The program reads t = np.linspace(0, 10, 21) # 20 intervals in [0, 10] dt = t[1] - t[0] N = np.zeros(t.size) - N[0] = 1 r = 0.5 for n in range(0, N.size-1, 1): N[n+1] = N[n] + r*dt*N[n] - print 'N[%d]=%.1f' % (n+1, N[n+1]) + print('N[%d]=%.1f' % (n+1, N[n+1]))
and it generates the following output @@ -739,7 +739,7 @@ N[20]=86.7
This forms our data which later will define our training set. In this case we defined the value of the parameter \( r \). We could alternatively assume that we just received the -above data file and where asked to use find \( r \). How can we estimate \( r \) from data? +above data file and where asked to find \( r \). How can we estimate \( r \) from data? This will be one of our tasks later.
We can use the difference equation with the experimental data @@ -749,12 +749,13 @@ Suppose now that \( N^{n+1} \) and \( N^n \) are known from data. Then we could $$ r = \frac{N^{n+1}-N^n}{N^n\Delta t} $$ Suppose we set \( t_1=600 \), \( t_2=1200 \), -\( N^1=140 \) and \( N^2=250 \). We obtain then \( r=0.0013 \). The exact value is \( r = 0.000694 \) -The following code plot +\( N^1=140 \) and \( N^2=250 \). +The following code plots the data
import numpy as np
+import matplotlib.pyplot as plt
# Estimate r
data = np.loadtxt('ecoli.csv', delimiter=',')
@@ -762,10 +763,9 @@ t_e = data[:,0<
N_e = data[:,1]
i = 2 # Data point (i,i+1) used to estimate r
r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i]))
-print 'Estimated r=%.5f' % r
+print('Estimated r=%.5f' % r)
# Can experiment with r values and see if the model can
# match the data better
-
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, 1000)
@@ -776,7 +776,6 @@ N[0] = <
for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
-import matplotlib.pyplot as plt
plt.plot(t, N, 'r-', t_e, N_e, 'bo')
plt.xlabel('time [s]'); plt.ylabel('N')
plt.legend(['model', 'experiment'], loc='upper left')
@@ -1038,7 +1037,7 @@ parameters result in a slightly modified initial conditions, namely
\( H(0) = 34.91 \) and \( L(0)=3.857 \).
-The following Python demonstrates how we can use linear regression to fit for example the population of lynx.
+The following Python code demonstrates how we can use linear regression to fit for example the population of lynx.
Similarly, we have also used a decision tree algorithm to fit the lynx population data. As expected, the linear regression is not exactly impressive
@@ -1063,7 +1062,7 @@ plt.plot(x, y, label.show()
-The similar code for linear regression in R reads +The similar code for linear regression in R reads (more details to come)
@@ -1172,7 +1171,6 @@ Our task is to first set up an algorithm which simulates the above transactions \( w_m\Delta m \). You will need to set up a value for the interval \( \Delta m \) (typically \( 0.01-0.05 \)). That means you need to account for the number of times you register an income in the interval \( m,m+\Delta m \). The number of times you register this income, represents the value that enters the histogram. - You will also need to find a criterion for when the equilibrium situation has been reached.
diff --git a/doc/pub/How2ReadData/html/How2ReadData-reveal.html b/doc/pub/How2ReadData/html/How2ReadData-reveal.html index 34e634731..f6744726e 100644 --- a/doc/pub/How2ReadData/html/How2ReadData-reveal.html +++ b/doc/pub/How2ReadData/html/How2ReadData-reveal.html @@ -148,7 +148,7 @@ MathJax.Hub.Config({
-
Similarly, using R, we can perform similar studies. The following R code illustrates this. +(more details on R will be inserted later).
We present here several examples, with pertinent Python codes that we -will us to illustrate various machine learning methods and ways to +will use to illustrate various machine learning methods and ways to analyze, from simple to complex, various data sets. Many of these examples allow us to generate the data we want to analyze, following much of the same philosophy we discussed above when @@ -700,7 +701,7 @@ Here we will construct a model for cell growth based on a simple difference equa interval \( \Delta t \) as \( N \) cells would: \( \Delta N \propto N \)
-The difference equation can be programmed in a simple was, and in order to get started we +The difference equation can be programmed in a simple way, and in order to get started we set \( r=1.5 \), \( N^0=1 \), \( \Delta t=0.5 \). The program reads
@@ -722,13 +723,12 @@ set \( r=1.5 \), \( N^0=1 \), \( \Delta t=0.5 \). The program reads t = np.linspace(0, 10, 21) # 20 intervals in [0, 10] dt = t[1] - t[0] N = np.zeros(t.size) - N[0] = 1 r = 0.5 for n in range(0, N.size-1, 1): N[n+1] = N[n] + r*dt*N[n] - print 'N[%d]=%.1f' % (n+1, N[n+1]) + print('N[%d]=%.1f' % (n+1, N[n+1]))
and it generates the following output @@ -759,7 +759,7 @@ N[20]=86.7
This forms our data which later will define our training set. In this case we defined the value of the parameter \( r \). We could alternatively assume that we just received the -above data file and where asked to use find \( r \). How can we estimate \( r \) from data? +above data file and where asked to find \( r \). How can we estimate \( r \) from data? This will be one of our tasks later.
We can use the difference equation with the experimental data @@ -773,12 +773,13 @@ $$ r = \frac{N^{n+1}-N^n}{N^n\Delta t} $$
Suppose we set \( t_1=600 \), \( t_2=1200 \),
-\( N^1=140 \) and \( N^2=250 \). We obtain then \( r=0.0013 \). The exact value is \( r = 0.000694 \)
-The following code plot
+\( N^1=140 \) and \( N^2=250 \).
+The following code plots the data
import numpy as np
+import matplotlib.pyplot as plt
# Estimate r
data = np.loadtxt('ecoli.csv', delimiter=',')
@@ -786,10 +787,9 @@ t_e = data[:,0]
N_e = data[:,1]
i = 2 # Data point (i,i+1) used to estimate r
r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i]))
-print 'Estimated r=%.5f' % r
+print('Estimated r=%.5f' % r)
# Can experiment with r values and see if the model can
# match the data better
-
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, 1000)
@@ -800,7 +800,6 @@ N[0] = 100for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
-import matplotlib.pyplot as plt
plt.plot(t, N, 'r-', t_e, N_e, 'bo')
plt.xlabel('time [s]'); plt.ylabel('N')
plt.legend(['model', 'experiment'], loc='upper left')
@@ -1070,7 +1069,7 @@ parameters result in a slightly modified initial conditions, namely
\( H(0) = 34.91 \) and \( L(0)=3.857 \).
-The following Python demonstrates how we can use linear regression to fit for example the population of lynx.
+The following Python code demonstrates how we can use linear regression to fit for example the population of lynx.
Similarly, we have also used a decision tree algorithm to fit the lynx population data. As expected, the linear regression is not exactly impressive
@@ -1095,7 +1094,7 @@ plt.plot(x, y, label= "Linear Regression"
plt.show()
-The similar code for linear regression in R reads +The similar code for linear regression in R reads (more details to come)
@@ -1216,7 +1215,6 @@ Our task is to first set up an algorithm which simulates the above transactions \( w_m\Delta m \). You will need to set up a value for the interval \( \Delta m \) (typically \( 0.01-0.05 \)). That means you need to account for the number of times you register an income in the interval \( m,m+\Delta m \). The number of times you register this income, represents the value that enters the histogram. - You will also need to find a criterion for when the equilibrium situation has been reached.
diff --git a/doc/pub/How2ReadData/html/How2ReadData-solarized.html b/doc/pub/How2ReadData/html/How2ReadData-solarized.html index a84d765ae..b81301af6 100644 --- a/doc/pub/How2ReadData/html/How2ReadData-solarized.html +++ b/doc/pub/How2ReadData/html/How2ReadData-solarized.html @@ -120,7 +120,7 @@ MathJax.Hub.Config({
-
Similarly, using R, we can perform similar studies. The following R code illustrates this. +(more details on R will be inserted later).
We present here several examples, with pertinent Python codes that we -will us to illustrate various machine learning methods and ways to +will use to illustrate various machine learning methods and ways to analyze, from simple to complex, various data sets. Many of these examples allow us to generate the data we want to analyze, following much of the same philosophy we discussed above when @@ -653,7 +654,7 @@ Here we will construct a model for cell growth based on a simple difference equa interval \( \Delta t \) as \( N \) cells would: \( \Delta N \propto N \)
-The difference equation can be programmed in a simple was, and in order to get started we +The difference equation can be programmed in a simple way, and in order to get started we set \( r=1.5 \), \( N^0=1 \), \( \Delta t=0.5 \). The program reads
@@ -676,13 +677,12 @@ set \( r=1.5 \), \( N^0=1 \), \( \Delta t=0.5 \). The program reads t = np.linspace(0, 10, 21) # 20 intervals in [0, 10] dt = t[1] - t[0] N = np.zeros(t.size) - N[0] = 1 r = 0.5 for n in range(0, N.size-1, 1): N[n+1] = N[n] + r*dt*N[n] - print 'N[%d]=%.1f' % (n+1, N[n+1]) + print('N[%d]=%.1f' % (n+1, N[n+1]))
and it generates the following output @@ -713,7 +713,7 @@ N[20]=86.7
This forms our data which later will define our training set. In this case we defined the value of the parameter \( r \). We could alternatively assume that we just received the -above data file and where asked to use find \( r \). How can we estimate \( r \) from data? +above data file and where asked to find \( r \). How can we estimate \( r \) from data? This will be one of our tasks later.
We can use the difference equation with the experimental data @@ -723,12 +723,13 @@ Suppose now that \( N^{n+1} \) and \( N^n \) are known from data. Then we could $$ r = \frac{N^{n+1}-N^n}{N^n\Delta t} $$ Suppose we set \( t_1=600 \), \( t_2=1200 \), -\( N^1=140 \) and \( N^2=250 \). We obtain then \( r=0.0013 \). The exact value is \( r = 0.000694 \) -The following code plot +\( N^1=140 \) and \( N^2=250 \). +The following code plots the data
import numpy as np
+import matplotlib.pyplot as plt
# Estimate r
data = np.loadtxt('ecoli.csv', delimiter=',')
@@ -736,10 +737,9 @@ t_e = data[:,0]
N_e = data[:,1]
i = 2 # Data point (i,i+1) used to estimate r
r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i]))
-print 'Estimated r=%.5f' % r
+print('Estimated r=%.5f' % r)
# Can experiment with r values and see if the model can
# match the data better
-
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, 1000)
@@ -750,7 +750,6 @@ N[0] = 100for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
-import matplotlib.pyplot as plt
plt.plot(t, N, 'r-', t_e, N_e, 'bo')
plt.xlabel('time [s]'); plt.ylabel('N')
plt.legend(['model', 'experiment'], loc='upper left')
@@ -1006,7 +1005,7 @@ parameters result in a slightly modified initial conditions, namely
\( H(0) = 34.91 \) and \( L(0)=3.857 \).
-The following Python demonstrates how we can use linear regression to fit for example the population of lynx.
+The following Python code demonstrates how we can use linear regression to fit for example the population of lynx.
Similarly, we have also used a decision tree algorithm to fit the lynx population data. As expected, the linear regression is not exactly impressive
@@ -1031,7 +1030,7 @@ plt.plot(x, y, label= "Linear Regression"
plt.show()
-The similar code for linear regression in R reads +The similar code for linear regression in R reads (more details to come)
@@ -1140,7 +1139,6 @@ Our task is to first set up an algorithm which simulates the above transactions \( w_m\Delta m \). You will need to set up a value for the interval \( \Delta m \) (typically \( 0.01-0.05 \)). That means you need to account for the number of times you register an income in the interval \( m,m+\Delta m \). The number of times you register this income, represents the value that enters the histogram. - You will also need to find a criterion for when the equilibrium situation has been reached.
diff --git a/doc/pub/How2ReadData/html/How2ReadData.html b/doc/pub/How2ReadData/html/How2ReadData.html index ee631f1c0..28d565b93 100644 --- a/doc/pub/How2ReadData/html/How2ReadData.html +++ b/doc/pub/How2ReadData/html/How2ReadData.html @@ -125,7 +125,7 @@ MathJax.Hub.Config({
-
Similarly, using R, we can perform similar studies. The following R code illustrates this. +(more details on R will be inserted later).
We present here several examples, with pertinent Python codes that we -will us to illustrate various machine learning methods and ways to +will use to illustrate various machine learning methods and ways to analyze, from simple to complex, various data sets. Many of these examples allow us to generate the data we want to analyze, following much of the same philosophy we discussed above when @@ -658,7 +659,7 @@ Here we will construct a model for cell growth based on a simple difference equa interval \( \Delta t \) as \( N \) cells would: \( \Delta N \propto N \)
-The difference equation can be programmed in a simple was, and in order to get started we +The difference equation can be programmed in a simple way, and in order to get started we set \( r=1.5 \), \( N^0=1 \), \( \Delta t=0.5 \). The program reads
@@ -681,13 +682,12 @@ set \( r=1.5 \), \( N^0=1 \), \( \Delta t=0.5 \). The program reads t = np.linspace(0, 10, 21) # 20 intervals in [0, 10] dt = t[1] - t[0] N = np.zeros(t.size) - N[0] = 1 r = 0.5 for n in range(0, N.size-1, 1): N[n+1] = N[n] + r*dt*N[n] - print 'N[%d]=%.1f' % (n+1, N[n+1]) + print('N[%d]=%.1f' % (n+1, N[n+1]))
and it generates the following output @@ -718,7 +718,7 @@ N[20]=86.7
This forms our data which later will define our training set. In this case we defined the value of the parameter \( r \). We could alternatively assume that we just received the -above data file and where asked to use find \( r \). How can we estimate \( r \) from data? +above data file and where asked to find \( r \). How can we estimate \( r \) from data? This will be one of our tasks later.
We can use the difference equation with the experimental data @@ -728,12 +728,13 @@ Suppose now that \( N^{n+1} \) and \( N^n \) are known from data. Then we could $$ r = \frac{N^{n+1}-N^n}{N^n\Delta t} $$ Suppose we set \( t_1=600 \), \( t_2=1200 \), -\( N^1=140 \) and \( N^2=250 \). We obtain then \( r=0.0013 \). The exact value is \( r = 0.000694 \) -The following code plot +\( N^1=140 \) and \( N^2=250 \). +The following code plots the data
import numpy as np
+import matplotlib.pyplot as plt
# Estimate r
data = np.loadtxt('ecoli.csv', delimiter=',')
@@ -741,10 +742,9 @@ t_e = data[:,0<
N_e = data[:,1]
i = 2 # Data point (i,i+1) used to estimate r
r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i]))
-print 'Estimated r=%.5f' % r
+print('Estimated r=%.5f' % r)
# Can experiment with r values and see if the model can
# match the data better
-
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, 1000)
@@ -755,7 +755,6 @@ N[0] = <
for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
-import matplotlib.pyplot as plt
plt.plot(t, N, 'r-', t_e, N_e, 'bo')
plt.xlabel('time [s]'); plt.ylabel('N')
plt.legend(['model', 'experiment'], loc='upper left')
@@ -1011,7 +1010,7 @@ parameters result in a slightly modified initial conditions, namely
\( H(0) = 34.91 \) and \( L(0)=3.857 \).
-The following Python demonstrates how we can use linear regression to fit for example the population of lynx.
+The following Python code demonstrates how we can use linear regression to fit for example the population of lynx.
Similarly, we have also used a decision tree algorithm to fit the lynx population data. As expected, the linear regression is not exactly impressive
@@ -1036,7 +1035,7 @@ plt.plot(x, y, label.show()
-The similar code for linear regression in R reads +The similar code for linear regression in R reads (more details to come)
@@ -1145,7 +1144,6 @@ Our task is to first set up an algorithm which simulates the above transactions \( w_m\Delta m \). You will need to set up a value for the interval \( \Delta m \) (typically \( 0.01-0.05 \)). That means you need to account for the number of times you register an income in the interval \( m,m+\Delta m \). The number of times you register this income, represents the value that enters the histogram. - You will also need to find a criterion for when the equilibrium situation has been reached.
diff --git a/doc/pub/How2ReadData/ipynb/How2ReadData.ipynb b/doc/pub/How2ReadData/ipynb/How2ReadData.ipynb index 95954d7ff..00b3d6745 100644 --- a/doc/pub/How2ReadData/ipynb/How2ReadData.ipynb +++ b/doc/pub/How2ReadData/ipynb/How2ReadData.ipynb @@ -10,7 +10,7 @@ " \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: **May 29, 2018**\n", + "Date: **May 30, 2018**\n", "\n", "Copyright 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", "\n", @@ -410,7 +410,7 @@ "from sklearn.metrics import mean_squared_error, r2_score, mean_squared_log_error, mean_absolute_error\n", "\n", "x = np.random.rand(100,1)\n", - "y = 2.0+ 5*x+0.5np.random.randn(100,1)\n", + "y = 2.0+ 5*x+0.5*np.random.randn(100,1)\n", "linreg = LinearRegression()\n", "linreg.fit(x,y)\n", "ypredict = linreg.predict(x)\n", @@ -588,7 +588,7 @@ "metadata": {}, "source": [ "Similarly, using **R**, we can perform similar studies. The following **R** code illustrates this.\n", - "\n", + "(more details on **R** will be inserted later).\n", "\n", "## Non-Linear Least squares in R" ] @@ -653,7 +653,7 @@ "## Examples\n", "\n", "We present here several examples, with pertinent Python codes that we\n", - "will us to illustrate various machine learning methods and ways to\n", + "will use to illustrate various machine learning methods and ways to\n", "analyze, from simple to complex, various data sets. Many of these\n", "examples allow us to generate the data we want to analyze, following\n", "much of the same philosophy we discussed above when\n", @@ -678,7 +678,7 @@ "3. $N$ cells result in twice as many new individuals $\\Delta N$ in\n", " time $2\\Delta t$ as in time $\\Delta t$: $\\Delta N \\propto\\Delta t$\n", "\n", - "4. Same proportionality wrt death \n", + "4. Same proportionality with respect to death \n", "\n", "5. Proposed model: $\\Delta N = b\\Delta t N - d\\Delta tN$ for some unknown\n", " constants $b$ (births) and $d$ (deaths)\n", @@ -693,7 +693,7 @@ "\n", "\n", "\n", - "The difference equation can be programmed in a simple was, and in order to get started we\n", + "The difference equation can be programmed in a simple way, and in order to get started we\n", "set $r=1.5$, $N^0=1$, $\\Delta t=0.5$. The program reads" ] }, @@ -710,13 +710,12 @@ "t = np.linspace(0, 10, 21) # 20 intervals in [0, 10]\n", "dt = t[1] - t[0]\n", "N = np.zeros(t.size)\n", - "\n", "N[0] = 1\n", "r = 0.5\n", "\n", "for n in range(0, N.size-1, 1):\n", " N[n+1] = N[n] + r*dt*N[n]\n", - " print 'N[%d]=%.1f' % (n+1, N[n+1])" + " print('N[%d]=%.1f' % (n+1, N[n+1]))" ] }, { @@ -758,7 +757,7 @@ "source": [ "This forms our data which later will define our training set. \n", "In this case we defined the value of the parameter $r$. We could alternatively assume that we just received the \n", - "above data file and where asked to use find $r$. How can we estimate $r$ from data?\n", + "above data file and where asked to find $r$. How can we estimate $r$ from data? This will be one of our tasks later.\n", "\n", "We can use the difference equation with the experimental data" ] @@ -793,8 +792,8 @@ "metadata": {}, "source": [ "Suppose we set $t_1=600$, $t_2=1200$,\n", - "$N^1=140$ and $N^2=250$. We obtain then $r=0.0013$. The exact value is $r = 0.000694$\n", - "The following code plot" + "$N^1=140$ and $N^2=250$. \n", + "The following code plots the data" ] }, { @@ -806,6 +805,7 @@ "outputs": [], "source": [ "import numpy as np\n", + "import matplotlib.pyplot as plt\n", "\n", "# Estimate r\n", "data = np.loadtxt('ecoli.csv', delimiter=',')\n", @@ -813,10 +813,9 @@ "N_e = data[:,1]\n", "i = 2 # Data point (i,i+1) used to estimate r\n", "r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i]))\n", - "print 'Estimated r=%.5f' % r\n", + "print('Estimated r=%.5f' % r)\n", "# Can experiment with r values and see if the model can\n", "# match the data better\n", - "\n", "T = 1200 # cell can divide after T sec\n", "t_max = 5*T # 5 generations in experiment\n", "t = np.linspace(0, t_max, 1000)\n", @@ -827,7 +826,6 @@ "for n in range(0, len(t)-1, 1):\n", " N[n+1] = N[n] + r*dt*N[n]\n", "\n", - "import matplotlib.pyplot as plt\n", "plt.plot(t, N, 'r-', t_e, N_e, 'bo')\n", "plt.xlabel('time [s]'); plt.ylabel('N')\n", "plt.legend(['model', 'experiment'], loc='upper left')\n", @@ -1180,7 +1178,7 @@ "$H(0) = 34.91$ and $L(0)=3.857$. \n", "\n", "\n", - "The following Python demonstrates how we can use linear regression to fit for example the population of lynx.\n", + "The following Python code demonstrates how we can use linear regression to fit for example the population of lynx.\n", "Similarly, we have also used a decision tree algorithm to fit the lynx population data. As expected, the linear regression is not exactly impressive" ] }, @@ -1216,7 +1214,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The similar code for linear regression in **R** reads" + "The similar code for linear regression in **R** reads (more details to come)" ] }, { @@ -1383,8 +1381,7 @@ " This histogram contains the number of times a value $m$ is registered and represents\n", " $w_m\\Delta m$. You will need to set up a value for the interval $\\Delta m$ (typically $0.01-0.05$).\n", " That means you need to account for the number of times you register an income in the interval\n", - " $m,m+\\Delta m$. The number of times you register this income, represents the value that enters the histogram.\n", - " You will also need to find a criterion for when the equilibrium situation has been reached." + " $m,m+\\Delta m$. The number of times you register this income, represents the value that enters the histogram." ] }, { diff --git a/doc/pub/How2ReadData/ipynb/ipynb-How2ReadData-src.tar.gz b/doc/pub/How2ReadData/ipynb/ipynb-How2ReadData-src.tar.gz index b5cdbf950..e3418a6a2 100644 Binary files a/doc/pub/How2ReadData/ipynb/ipynb-How2ReadData-src.tar.gz and b/doc/pub/How2ReadData/ipynb/ipynb-How2ReadData-src.tar.gz differ diff --git a/doc/pub/How2ReadData/pdf/How2ReadData-minted.pdf b/doc/pub/How2ReadData/pdf/How2ReadData-minted.pdf index 1bed17b1b..4fe4e6db7 100644 Binary files a/doc/pub/How2ReadData/pdf/How2ReadData-minted.pdf and b/doc/pub/How2ReadData/pdf/How2ReadData-minted.pdf differ diff --git a/doc/src/How2ReadData/How2ReadData.do.txt b/doc/src/How2ReadData/How2ReadData.do.txt index 863759c34..6df53fe52 100644 --- a/doc/src/How2ReadData/How2ReadData.do.txt +++ b/doc/src/How2ReadData/How2ReadData.do.txt @@ -317,7 +317,7 @@ from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_squared_error, r2_score, mean_squared_log_error, mean_absolute_error x = np.random.rand(100,1) -y = 2.0+ 5*x+0.5np.random.randn(100,1) +y = 2.0+ 5*x+0.5*np.random.randn(100,1) linreg = LinearRegression() linreg.fit(x,y) ypredict = linreg.predict(x) @@ -430,7 +430,7 @@ print (error(y)) !ec Similarly, using _R_, we can perform similar studies. The following _R_ code illustrates this. - +(more details on _R_ will be inserted later). ===== Non-Linear Least squares in R ===== !bblock @@ -478,7 +478,7 @@ display(data_pandas) ===== Examples ===== We present here several examples, with pertinent Python codes that we -will us to illustrate various machine learning methods and ways to +will use to illustrate various machine learning methods and ways to analyze, from simple to complex, various data sets. Many of these examples allow us to generate the data we want to analyze, following much of the same philosophy we discussed above when @@ -502,7 +502,7 @@ Here we will construct a model for cell growth based on a simple difference equa interval $\Delta t$ as $N$ cells would: $\Delta N \propto N$ o $N$ cells result in twice as many new individuals $\Delta N$ in time $2\Delta t$ as in time $\Delta t$: $\Delta N \propto\Delta t$ - o Same proportionality wrt death + o Same proportionality with respect to death o Proposed model: $\Delta N = b\Delta t N - d\Delta tN$ for some unknown constants $b$ (births) and $d$ (deaths) o Describe evolution in discrete time: $t_n=n\Delta t$ @@ -511,7 +511,7 @@ Here we will construct a model for cell growth based on a simple difference equa o Program model: `N[n+1] = N[n] + r*dt*N[n]` !eblock -The difference equation can be programmed in a simple was, and in order to get started we +The difference equation can be programmed in a simple way, and in order to get started we set $r=1.5$, $N^0=1$, $\Delta t=0.5$. The program reads !bc pycod @@ -520,13 +520,12 @@ import numpy as np t = np.linspace(0, 10, 21) # 20 intervals in [0, 10] dt = t[1] - t[0] N = np.zeros(t.size) - N[0] = 1 r = 0.5 for n in range(0, N.size-1, 1): N[n+1] = N[n] + r*dt*N[n] - print 'N[%d]=%.1f' % (n+1, N[n+1]) + print('N[%d]=%.1f' % (n+1, N[n+1])) !ec and it generates the following output !bc @@ -553,7 +552,7 @@ N[20]=86.7 !ec This forms our data which later will define our training set. In this case we defined the value of the parameter $r$. We could alternatively assume that we just received the -above data file and where asked to use find $r$. How can we estimate $r$ from data? +above data file and where asked to find $r$. How can we estimate $r$ from data? This will be one of our tasks later. We can use the difference equation with the experimental data !bt @@ -564,10 +563,11 @@ Suppose now that $N^{n+1}$ and $N^n$ are known from data. Then we could solve w \[ r = \frac{N^{n+1}-N^n}{N^n\Delta t} \] !et Suppose we set $t_1=600$, $t_2=1200$, -$N^1=140$ and $N^2=250$. We obtain then $r=0.0013$. The exact value is $r = 0.000694$ -The following code plot +$N^1=140$ and $N^2=250$. +The following code plots the data !bc pycod import numpy as np +import matplotlib.pyplot as plt # Estimate r data = np.loadtxt('ecoli.csv', delimiter=',') @@ -575,10 +575,9 @@ t_e = data[:,0] N_e = data[:,1] i = 2 # Data point (i,i+1) used to estimate r r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i])) -print 'Estimated r=%.5f' % r +print('Estimated r=%.5f' % r) # Can experiment with r values and see if the model can # match the data better - T = 1200 # cell can divide after T sec t_max = 5*T # 5 generations in experiment t = np.linspace(0, t_max, 1000) @@ -589,7 +588,6 @@ N[0] = 100 for n in range(0, len(t)-1, 1): N[n+1] = N[n] + r*dt*N[n] -import matplotlib.pyplot as plt plt.plot(t, N, 'r-', t_e, N_e, 'bo') plt.xlabel('time [s]'); plt.ylabel('N') plt.legend(['model', 'experiment'], loc='upper left') @@ -767,7 +765,7 @@ parameters result in a slightly modified initial conditions, namely $H(0) = 34.91$ and $L(0)=3.857$. -The following Python demonstrates how we can use linear regression to fit for example the population of lynx. +The following Python code demonstrates how we can use linear regression to fit for example the population of lynx. Similarly, we have also used a decision tree algorithm to fit the lynx population data. As expected, the linear regression is not exactly impressive !bc pycod import numpy as np @@ -792,7 +790,7 @@ plt.show() -The similar code for linear regression in _R_ reads +The similar code for linear regression in _R_ reads (more details to come) !bc r HudsonBay = read.csv("src/Hudson_Bay.csv",header=T) fix(HudsonBay) @@ -890,7 +888,6 @@ Our task is to first set up an algorithm which simulates the above transactions $w_m\Delta m$. You will need to set up a value for the interval $\Delta m$ (typically $0.01-0.05$). That means you need to account for the number of times you register an income in the interval $m,m+\Delta m$. The number of times you register this income, represents the value that enters the histogram. - You will also need to find a criterion for when the equilibrium situation has been reached. !bc pycod #!/usr/bin/env python