diff --git a/doc/pub/DecisionTrees/html/DecisionTrees-bs.html b/doc/pub/DecisionTrees/html/DecisionTrees-bs.html index 1e27744ca..1f17cb1bd 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees-bs.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees-bs.html @@ -100,7 +100,7 @@ end of tocinfo -->
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

-

May 30, 2018

+

Nov 1, 2018


@@ -113,6 +113,15 @@ end of tocinfo -->

+

+Decision trees are supervised learning algorithms used for both, +classification and regression tasks where we will concentrate on +classification in this first part of our decision tree tutorial. +Decision trees are assigned to the information based learning +algorithms which use different measures of information gain for +learning. We can use decision trees for issues where we have +continuous but also categorical input and target features. +

@@ -279,6 +288,105 @@ plt.show()

+ +

# Program to test the Metropolis algorithm with one particle at given temp in
+# one dimension
+#!/usr/bin/env python
+import numpy as np
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
+import random
+from math import sqrt, exp, log
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.linear_model import LinearRegression
+# initialize the rng with a seed
+random.seed()
+# Hard coding of input parameters
+MCcycles = 100000
+Temperature = 2.0
+beta = 1./Temperature
+InitialVelocity = -2.0
+CurrentVelocity = InitialVelocity
+Energy = 0.5*InitialVelocity*InitialVelocity
+VelocityRange = 10*sqrt(Temperature)
+VelocityStep = 2*VelocityRange/10.
+AverageEnergy = Energy
+AverageEnergy2 = Energy*Energy
+VelocityValues = np.zeros(MCcycles)
+# The Monte Carlo sampling with Metropolis starts here
+for i in range (1, MCcycles, 1):
+    TrialVelocity = CurrentVelocity + (2.0*random.random() - 1.0)*VelocityStep
+    EnergyChange = 0.5*(TrialVelocity*TrialVelocity -CurrentVelocity*CurrentVelocity);
+    if random.random() <= exp(-beta*EnergyChange):
+        CurrentVelocity = TrialVelocity
+        Energy += EnergyChange
+        VelocityValues[i] = CurrentVelocity
+    AverageEnergy += Energy
+    AverageEnergy2 += Energy*Energy
+#Final averages
+AverageEnergy = AverageEnergy/MCcycles
+AverageEnergy2 = AverageEnergy2/MCcycles
+Variance = AverageEnergy2 - AverageEnergy*AverageEnergy
+print(AverageEnergy, Variance)
+n, bins, patches = plt.hist(VelocityValues, 400, facecolor='green')
+
+plt.xlabel('$v$')
+plt.ylabel('Velocity distribution P(v)')
+plt.title(r'Velocity histogram at $k_BT=2$')
+plt.axis([-5, 5, 0, 600])
+plt.grid(True)
+from collections import Counter
+
+#print (Counter(VelocityValues))
+
+print (VelocityValues[:20])
+VelocityValues=list(Counter(VelocityValues).keys())
+d=list(Counter(VelocityValues).values())
+
+VelocityValues=np.asarray(VelocityValues)[:, np.newaxis]
+d=np.asarray(d)
+print (VelocityValues.shape, d.shape)
+
+plt.scatter(VelocityValues, d)
+plt.show()
+
+#2nd Degree Polynomial
+poly_feat=PolynomialFeatures(degree=20, include_bias=False)
+X_poly=poly_feat.fit_transform(VelocityValues)
+lin_reg=LinearRegression()
+poly_fit=lin_reg.fit(X_poly,d)
+
+y_plot=poly_fit.predict(X_poly)
+plt.title("Polynomial Fit")
+plt.plot(VelocityValues, y_plot, color='black', label="Fit")
+plt.show()
+
+#Decision Trees
+
+from sklearn.tree import DecisionTreeRegressor
+regr_1=DecisionTreeRegressor(max_depth=2)
+regr_2=DecisionTreeRegressor(max_depth=5)
+regr_3=DecisionTreeRegressor(max_depth=7)
+regr_1.fit(VelocityValues, d)
+regr_2.fit(VelocityValues, d)
+regr_3.fit(VelocityValues, d)
+
+X_test = np.arange(0.0, MCcycles, 0.01)[:, np.newaxis]
+y_1=regr_1.predict(X_test)
+y_2=regr_2.predict(X_test)
+y_3=regr_3.predict(X_test)
+
+plt.title("Decision Tree")
+plt.plot(X_test, y_1, color="red", label="max_depth=2", linewidth=2)
+plt.plot(X_test, y_2, color="green", label="max_depth=5", linewidth=2)
+plt.plot(X_test, y_3, color="m", label="max_depth=7", linewidth=2)
+plt.show()
+
+#Separate each frequency not in one specific velocity, but in a range of values,
+#i.e. frequency of all velocities in range -5 to -4.9, -4.9 to -4.8, etc...
+
+

+ diff --git a/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html b/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html index fc637f3eb..d9029b31d 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html @@ -132,7 +132,7 @@ td.padding {

[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

 
-

May 30, 2018

+

Nov 1, 2018


@@ -147,6 +147,15 @@ td.padding {

+Decision trees are supervised learning algorithms used for both, +classification and regression tasks where we will concentrate on +classification in this first part of our decision tree tutorial. +Decision trees are assigned to the information based learning +algorithms which use different measures of information gain for +learning. We can use decision trees for issues where we have +continuous but also categorical input and target features. + +

@@ -309,6 +318,105 @@ plt.title("Decision Tree Regression" +

+ + +

# Program to test the Metropolis algorithm with one particle at given temp in
+# one dimension
+#!/usr/bin/env python
+import numpy as np
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
+import random
+from math import sqrt, exp, log
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.linear_model import LinearRegression
+# initialize the rng with a seed
+random.seed()
+# Hard coding of input parameters
+MCcycles = 100000
+Temperature = 2.0
+beta = 1./Temperature
+InitialVelocity = -2.0
+CurrentVelocity = InitialVelocity
+Energy = 0.5*InitialVelocity*InitialVelocity
+VelocityRange = 10*sqrt(Temperature)
+VelocityStep = 2*VelocityRange/10.
+AverageEnergy = Energy
+AverageEnergy2 = Energy*Energy
+VelocityValues = np.zeros(MCcycles)
+# The Monte Carlo sampling with Metropolis starts here
+for i in range (1, MCcycles, 1):
+    TrialVelocity = CurrentVelocity + (2.0*random.random() - 1.0)*VelocityStep
+    EnergyChange = 0.5*(TrialVelocity*TrialVelocity -CurrentVelocity*CurrentVelocity);
+    if random.random() <= exp(-beta*EnergyChange):
+        CurrentVelocity = TrialVelocity
+        Energy += EnergyChange
+        VelocityValues[i] = CurrentVelocity
+    AverageEnergy += Energy
+    AverageEnergy2 += Energy*Energy
+#Final averages
+AverageEnergy = AverageEnergy/MCcycles
+AverageEnergy2 = AverageEnergy2/MCcycles
+Variance = AverageEnergy2 - AverageEnergy*AverageEnergy
+print(AverageEnergy, Variance)
+n, bins, patches = plt.hist(VelocityValues, 400, facecolor='green')
+
+plt.xlabel('$v$')
+plt.ylabel('Velocity distribution P(v)')
+plt.title(r'Velocity histogram at $k_BT=2$')
+plt.axis([-5, 5, 0, 600])
+plt.grid(True)
+from collections import Counter
+
+#print (Counter(VelocityValues))
+
+print (VelocityValues[:20])
+VelocityValues=list(Counter(VelocityValues).keys())
+d=list(Counter(VelocityValues).values())
+
+VelocityValues=np.asarray(VelocityValues)[:, np.newaxis]
+d=np.asarray(d)
+print (VelocityValues.shape, d.shape)
+
+plt.scatter(VelocityValues, d)
+plt.show()
+
+#2nd Degree Polynomial
+poly_feat=PolynomialFeatures(degree=20, include_bias=False)
+X_poly=poly_feat.fit_transform(VelocityValues)
+lin_reg=LinearRegression()
+poly_fit=lin_reg.fit(X_poly,d)
+
+y_plot=poly_fit.predict(X_poly)
+plt.title("Polynomial Fit")
+plt.plot(VelocityValues, y_plot, color='black', label="Fit")
+plt.show()
+
+#Decision Trees
+
+from sklearn.tree import DecisionTreeRegressor
+regr_1=DecisionTreeRegressor(max_depth=2)
+regr_2=DecisionTreeRegressor(max_depth=5)
+regr_3=DecisionTreeRegressor(max_depth=7)
+regr_1.fit(VelocityValues, d)
+regr_2.fit(VelocityValues, d)
+regr_3.fit(VelocityValues, d)
+
+X_test = np.arange(0.0, MCcycles, 0.01)[:, np.newaxis]
+y_1=regr_1.predict(X_test)
+y_2=regr_2.predict(X_test)
+y_3=regr_3.predict(X_test)
+
+plt.title("Decision Tree")
+plt.plot(X_test, y_1, color="red", label="max_depth=2", linewidth=2)
+plt.plot(X_test, y_2, color="green", label="max_depth=5", linewidth=2)
+plt.plot(X_test, y_3, color="m", label="max_depth=7", linewidth=2)
+plt.show()
+
+#Separate each frequency not in one specific velocity, but in a range of values,
+#i.e. frequency of all velocities in range -5 to -4.9, -4.9 to -4.8, etc...
+
diff --git a/doc/pub/DecisionTrees/html/DecisionTrees-solarized.html b/doc/pub/DecisionTrees/html/DecisionTrees-solarized.html index 126e10ec0..3bf90a5e3 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees-solarized.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees-solarized.html @@ -88,7 +88,7 @@ end of tocinfo -->
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

-

May 30, 2018

+

Nov 1, 2018












@@ -98,6 +98,15 @@ end of tocinfo -->

+

+Decision trees are supervised learning algorithms used for both, +classification and regression tasks where we will concentrate on +classification in this first part of our decision tree tutorial. +Decision trees are assigned to the information based learning +algorithms which use different measures of information gain for +learning. We can use decision trees for issues where we have +continuous but also categorical input and target features. + @@ -263,6 +272,105 @@ plt.show()

+ +

# Program to test the Metropolis algorithm with one particle at given temp in
+# one dimension
+#!/usr/bin/env python
+import numpy as np
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
+import random
+from math import sqrt, exp, log
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.linear_model import LinearRegression
+# initialize the rng with a seed
+random.seed()
+# Hard coding of input parameters
+MCcycles = 100000
+Temperature = 2.0
+beta = 1./Temperature
+InitialVelocity = -2.0
+CurrentVelocity = InitialVelocity
+Energy = 0.5*InitialVelocity*InitialVelocity
+VelocityRange = 10*sqrt(Temperature)
+VelocityStep = 2*VelocityRange/10.
+AverageEnergy = Energy
+AverageEnergy2 = Energy*Energy
+VelocityValues = np.zeros(MCcycles)
+# The Monte Carlo sampling with Metropolis starts here
+for i in range (1, MCcycles, 1):
+    TrialVelocity = CurrentVelocity + (2.0*random.random() - 1.0)*VelocityStep
+    EnergyChange = 0.5*(TrialVelocity*TrialVelocity -CurrentVelocity*CurrentVelocity);
+    if random.random() <= exp(-beta*EnergyChange):
+        CurrentVelocity = TrialVelocity
+        Energy += EnergyChange
+        VelocityValues[i] = CurrentVelocity
+    AverageEnergy += Energy
+    AverageEnergy2 += Energy*Energy
+#Final averages
+AverageEnergy = AverageEnergy/MCcycles
+AverageEnergy2 = AverageEnergy2/MCcycles
+Variance = AverageEnergy2 - AverageEnergy*AverageEnergy
+print(AverageEnergy, Variance)
+n, bins, patches = plt.hist(VelocityValues, 400, facecolor='green')
+
+plt.xlabel('$v$')
+plt.ylabel('Velocity distribution P(v)')
+plt.title(r'Velocity histogram at $k_BT=2$')
+plt.axis([-5, 5, 0, 600])
+plt.grid(True)
+from collections import Counter
+
+#print (Counter(VelocityValues))
+
+print (VelocityValues[:20])
+VelocityValues=list(Counter(VelocityValues).keys())
+d=list(Counter(VelocityValues).values())
+
+VelocityValues=np.asarray(VelocityValues)[:, np.newaxis]
+d=np.asarray(d)
+print (VelocityValues.shape, d.shape)
+
+plt.scatter(VelocityValues, d)
+plt.show()
+
+#2nd Degree Polynomial
+poly_feat=PolynomialFeatures(degree=20, include_bias=False)
+X_poly=poly_feat.fit_transform(VelocityValues)
+lin_reg=LinearRegression()
+poly_fit=lin_reg.fit(X_poly,d)
+
+y_plot=poly_fit.predict(X_poly)
+plt.title("Polynomial Fit")
+plt.plot(VelocityValues, y_plot, color='black', label="Fit")
+plt.show()
+
+#Decision Trees
+
+from sklearn.tree import DecisionTreeRegressor
+regr_1=DecisionTreeRegressor(max_depth=2)
+regr_2=DecisionTreeRegressor(max_depth=5)
+regr_3=DecisionTreeRegressor(max_depth=7)
+regr_1.fit(VelocityValues, d)
+regr_2.fit(VelocityValues, d)
+regr_3.fit(VelocityValues, d)
+
+X_test = np.arange(0.0, MCcycles, 0.01)[:, np.newaxis]
+y_1=regr_1.predict(X_test)
+y_2=regr_2.predict(X_test)
+y_3=regr_3.predict(X_test)
+
+plt.title("Decision Tree")
+plt.plot(X_test, y_1, color="red", label="max_depth=2", linewidth=2)
+plt.plot(X_test, y_2, color="green", label="max_depth=5", linewidth=2)
+plt.plot(X_test, y_3, color="m", label="max_depth=7", linewidth=2)
+plt.show()
+
+#Separate each frequency not in one specific velocity, but in a range of values,
+#i.e. frequency of all velocities in range -5 to -4.9, -4.9 to -4.8, etc...
+
+

+ diff --git a/doc/pub/DecisionTrees/html/DecisionTrees.html b/doc/pub/DecisionTrees/html/DecisionTrees.html index caf1002f0..9b5a02915 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees.html @@ -93,7 +93,7 @@ end of tocinfo -->

[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

-

May 30, 2018

+

Nov 1, 2018












@@ -103,6 +103,15 @@ end of tocinfo -->

+

+Decision trees are supervised learning algorithms used for both, +classification and regression tasks where we will concentrate on +classification in this first part of our decision tree tutorial. +Decision trees are assigned to the information based learning +algorithms which use different measures of information gain for +learning. We can use decision trees for issues where we have +continuous but also categorical input and target features. + @@ -268,6 +277,105 @@ plt.show()

+ +

# Program to test the Metropolis algorithm with one particle at given temp in
+# one dimension
+#!/usr/bin/env python
+import numpy as np
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
+import random
+from math import sqrt, exp, log
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.linear_model import LinearRegression
+# initialize the rng with a seed
+random.seed()
+# Hard coding of input parameters
+MCcycles = 100000
+Temperature = 2.0
+beta = 1./Temperature
+InitialVelocity = -2.0
+CurrentVelocity = InitialVelocity
+Energy = 0.5*InitialVelocity*InitialVelocity
+VelocityRange = 10*sqrt(Temperature)
+VelocityStep = 2*VelocityRange/10.
+AverageEnergy = Energy
+AverageEnergy2 = Energy*Energy
+VelocityValues = np.zeros(MCcycles)
+# The Monte Carlo sampling with Metropolis starts here
+for i in range (1, MCcycles, 1):
+    TrialVelocity = CurrentVelocity + (2.0*random.random() - 1.0)*VelocityStep
+    EnergyChange = 0.5*(TrialVelocity*TrialVelocity -CurrentVelocity*CurrentVelocity);
+    if random.random() <= exp(-beta*EnergyChange):
+        CurrentVelocity = TrialVelocity
+        Energy += EnergyChange
+        VelocityValues[i] = CurrentVelocity
+    AverageEnergy += Energy
+    AverageEnergy2 += Energy*Energy
+#Final averages
+AverageEnergy = AverageEnergy/MCcycles
+AverageEnergy2 = AverageEnergy2/MCcycles
+Variance = AverageEnergy2 - AverageEnergy*AverageEnergy
+print(AverageEnergy, Variance)
+n, bins, patches = plt.hist(VelocityValues, 400, facecolor='green')
+
+plt.xlabel('$v$')
+plt.ylabel('Velocity distribution P(v)')
+plt.title(r'Velocity histogram at $k_BT=2$')
+plt.axis([-5, 5, 0, 600])
+plt.grid(True)
+from collections import Counter
+
+#print (Counter(VelocityValues))
+
+print (VelocityValues[:20])
+VelocityValues=list(Counter(VelocityValues).keys())
+d=list(Counter(VelocityValues).values())
+
+VelocityValues=np.asarray(VelocityValues)[:, np.newaxis]
+d=np.asarray(d)
+print (VelocityValues.shape, d.shape)
+
+plt.scatter(VelocityValues, d)
+plt.show()
+
+#2nd Degree Polynomial
+poly_feat=PolynomialFeatures(degree=20, include_bias=False)
+X_poly=poly_feat.fit_transform(VelocityValues)
+lin_reg=LinearRegression()
+poly_fit=lin_reg.fit(X_poly,d)
+
+y_plot=poly_fit.predict(X_poly)
+plt.title("Polynomial Fit")
+plt.plot(VelocityValues, y_plot, color='black', label="Fit")
+plt.show()
+
+#Decision Trees
+
+from sklearn.tree import DecisionTreeRegressor
+regr_1=DecisionTreeRegressor(max_depth=2)
+regr_2=DecisionTreeRegressor(max_depth=5)
+regr_3=DecisionTreeRegressor(max_depth=7)
+regr_1.fit(VelocityValues, d)
+regr_2.fit(VelocityValues, d)
+regr_3.fit(VelocityValues, d)
+
+X_test = np.arange(0.0, MCcycles, 0.01)[:, np.newaxis]
+y_1=regr_1.predict(X_test)
+y_2=regr_2.predict(X_test)
+y_3=regr_3.predict(X_test)
+
+plt.title("Decision Tree")
+plt.plot(X_test, y_1, color="red", label="max_depth=2", linewidth=2)
+plt.plot(X_test, y_2, color="green", label="max_depth=5", linewidth=2)
+plt.plot(X_test, y_3, color="m", label="max_depth=7", linewidth=2)
+plt.show()
+
+#Separate each frequency not in one specific velocity, but in a range of values,
+#i.e. frequency of all velocities in range -5 to -4.9, -4.9 to -4.8, etc...
+
+

+ diff --git a/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz b/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz index 4a60dfe94..26722ba50 100644 Binary files a/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz and b/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz differ diff --git a/doc/pub/DecisionTrees/pdf/DecisionTrees-beamer-handouts2x3.pdf b/doc/pub/DecisionTrees/pdf/DecisionTrees-beamer-handouts2x3.pdf index f880c1005..3a063fa2c 100644 Binary files a/doc/pub/DecisionTrees/pdf/DecisionTrees-beamer-handouts2x3.pdf and b/doc/pub/DecisionTrees/pdf/DecisionTrees-beamer-handouts2x3.pdf differ diff --git a/doc/pub/DecisionTrees/pdf/DecisionTrees-beamer.pdf b/doc/pub/DecisionTrees/pdf/DecisionTrees-beamer.pdf index a474ffa50..d596f1eb8 100644 Binary files a/doc/pub/DecisionTrees/pdf/DecisionTrees-beamer.pdf and b/doc/pub/DecisionTrees/pdf/DecisionTrees-beamer.pdf differ diff --git a/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf b/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf index 60824fabe..7372d84b4 100644 Binary files a/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf and b/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf differ