|
Simbody
3.6
|
This is a feedback-controlled force that uses Nose'-Hoover chains to maintain a particular temperature Tb, as though the system were immersed in an infinite heat bath at that temperature. More...
Public Member Functions | |
| Thermostat (GeneralForceSubsystem &forces, const SimbodyMatterSubsystem &matter, Real boltzmannsConstant, Real bathTemperature, Real relaxationTime, int numExcludedDofs=6) | |
| Define a global thermostat (one that affects all degrees of freedom) at a given default temperature and relaxation time. More... | |
| Thermostat () | |
| Default constructor creates an empty handle. More... | |
| Thermostat & | excludeMobilizedBody (MobilizedBodyIndex) |
| TODO: not implemented yet. More... | |
| Thermostat & | setDefaultNumChains (int numChains) |
| Set the default (state independent) number of Nose'-Hoover chains. More... | |
| Thermostat & | setDefaultBathTemperature (Real bathTemperature) |
| Set the default (state independent) bath temperature. More... | |
| Thermostat & | setDefaultRelaxationTime (Real relaxationTime) |
| Set the default (state independent) relaxation time. More... | |
| Thermostat & | setDefaultNumExcludedDofs (int numExcludedDofs) |
| Set the default number of system rigid body degrees of freedom (0-6) to be excluded from the calculation of the number of thermal degrees of freedom N; if you don't call this it is assumed that 6 dofs should be excluded. More... | |
| int | getDefaultNumChains () const |
| Get the initial value for the number of chains that will be used for the "number of chains" State variable. More... | |
| Real | getDefaultBathTemperature () const |
| Get the initial value for the bath temperature that will be use for the "bath temperature" State variable. More... | |
| Real | getDefaultRelaxationTime () const |
| Get the initial value for the bath temperature that will be use for the "bath temperature" State variable. More... | |
| int | getDefaultNumExcludedDofs () const |
| Get the initial value for the number of system rigid body degrees of freedom (0-6) to be excluded from the calculation of the number of thermal degrees of freedom N. More... | |
| Real | getBoltzmannsConstant () const |
| Can't change the value of Boltzmann's constant after construction; this is the value being used. More... | |
| const Thermostat & | setNumChains (State &, int numChains) const |
| Set the actual number of Nose'-Hoover chains to be used. More... | |
| const Thermostat & | setBathTemperature (State &, Real Tb) const |
| Set the bath temperature which serves as the target temperature for the thermostat. More... | |
| const Thermostat & | setRelaxationTime (State &, Real t) const |
| Set the relaxation time which determines how long the system will take to equilibrate to the bath temperature. More... | |
| const Thermostat & | setNumExcludedDofs (State &, int numExcludedDofs) const |
| Set the actual number of system rigid body degrees of freedom (0-6) to be excluded from the calculation of the number of thermal degrees of freedom N. More... | |
| int | getNumChains (const State &) const |
| Obtain the current number of Nose'-Hoover chains in use. More... | |
| Real | getBathTemperature (const State &) const |
| Obtain the current bath temperature, in units which are determined by the value of Boltzmann's constant that was supplied on construction of this Thermostat force element. More... | |
| Real | getRelaxationTime (const State &) const |
| Obtain the current relaxation time. More... | |
| int | getNumExcludedDofs (const State &) const |
| Get the current value for the number of system rigid body degrees of freedom (0-6) to be excluded from the calculation of the number of thermal degrees of freedom N. More... | |
| int | getNumThermalDofs (const State &) const |
| Return the number of thermal degrees of freedom being used in the definition of temperature for this thermostat. More... | |
| Real | getCurrentTemperature (const State &) const |
| Return the temperature of the controlled degrees of freedom via the definition T = 2*ke / (N*Kb) where N is the number of thermal degrees of freedom. More... | |
| void | initializeChainState (State &) const |
| This is a solver that initializes thermostat state variables to zero. More... | |
| void | setChainState (State &, const Vector &) const |
| Set the thermostat state variables to particular values. More... | |
| Vector | getChainState (const State &) const |
| Return the current values of the thermostat chain variables. More... | |
| Real | calcBathEnergy (const State &state) const |
| Calculate the total "bath energy" which, when added to the system energy, should yield a conserved quantity (assuming all other forces are conservative). More... | |
| Real | getExternalPower (const State &state) const |
| Get the amount of power being applied by the thermostat to the system; sign is positive when energy is coming from the bath. More... | |
| Real | getExternalWork (const State &state) const |
| Get the amount of work that has been done by the bath on the system since an arbitrary start time. More... | |
| void | setExternalWork (State &state, Real work) const |
| Set the current value of the work done by the bath to an arbitrary value; normally zero for initialization. More... | |
| void | initializeSystemToBathTemperature (State &) const |
| Set the controlled system to a set of randomized velocities which yields the bath temperature. More... | |
| void | setSystemToTemperature (State &, Real T) const |
| Set the controlled system to a set of randomized velocities which yields a particular temperature. More... | |
| Public Member Functions inherited from SimTK::Force | |
| void | disable (State &) const |
| Disable this force element, effectively removing it from the System for computational purposes (it is still using its ForceIndex, however). More... | |
| void | enable (State &) const |
| Enable this force element if it was previously disabled. More... | |
| bool | isDisabled (const State &) const |
| Test whether this force element is currently disabled in the supplied State. More... | |
| void | setDisabledByDefault (bool shouldBeDisabled) |
| Normally force elements are enabled when defined and can be disabled later. More... | |
| bool | isDisabledByDefault () const |
| Test whether this force element is disabled by default in which case it must be explicitly enabled before it will take effect. More... | |
| void | calcForceContribution (const State &state, Vector_< SpatialVec > &bodyForces, Vector_< Vec3 > &particleForces, Vector &mobilityForces) const |
| Calculate the force that would be applied by this force element if the given state were realized to Dynamics stage. More... | |
| Real | calcPotentialEnergyContribution (const State &state) const |
| Calculate the potential energy contribution that is made by this force element at the given state. More... | |
| Force () | |
| Default constructor for Force handle base class does nothing. More... | |
| operator ForceIndex () const | |
| Implicit conversion to ForceIndex when needed. More... | |
| const GeneralForceSubsystem & | getForceSubsystem () const |
| Get the GeneralForceSubsystem of which this Force is an element. More... | |
| ForceIndex | getForceIndex () const |
| Get the index of this force element within its parent force subsystem. More... | |
| Public Member Functions inherited from SimTK::PIMPLHandle< Force, ForceImpl, true > | |
| bool | isEmptyHandle () const |
| Returns true if this handle is empty, that is, does not refer to any implementation object. More... | |
| bool | isOwnerHandle () const |
| Returns true if this handle is the owner of the implementation object to which it refers. More... | |
| bool | isSameHandle (const Force &other) const |
| Determine whether the supplied handle is the same object as "this" PIMPLHandle. More... | |
| void | disown (Force &newOwner) |
| Give up ownership of the implementation to an empty handle. More... | |
| PIMPLHandle & | referenceAssign (const Force &source) |
| "Copy" assignment but with shallow (pointer) semantics. More... | |
| PIMPLHandle & | copyAssign (const Force &source) |
| This is real copy assignment, with ordinary C++ object ("value") semantics. More... | |
| void | clearHandle () |
| Make this an empty handle, deleting the implementation object if this handle is the owner of it. More... | |
| const ForceImpl & | getImpl () const |
| Get a const reference to the implementation associated with this Handle. More... | |
| ForceImpl & | updImpl () |
| Get a writable reference to the implementation associated with this Handle. More... | |
| int | getImplHandleCount () const |
| Return the number of handles the implementation believes are referencing it. More... | |
Additional Inherited Members | |
| Public Types inherited from SimTK::PIMPLHandle< Force, ForceImpl, true > | |
| typedef PIMPLHandle< Force, ForceImpl, PTR > | HandleBase |
| typedef HandleBase | ParentHandle |
| Protected Member Functions inherited from SimTK::Force | |
| Force (ForceImpl *r) | |
| Use this in a derived Force handle class constructor to supply the concrete implementation object to be stored in the handle base. More... | |
| Protected Member Functions inherited from SimTK::PIMPLHandle< Force, ForceImpl, true > | |
| PIMPLHandle () | |
| The default constructor makes this an empty handle. More... | |
| PIMPLHandle (ForceImpl *p) | |
| This provides consruction of a handle referencing an existing implementation object. More... | |
| PIMPLHandle (const PIMPLHandle &source) | |
| The copy constructor makes either a deep (value) or shallow (reference) copy of the supplied source PIMPL object, based on whether this is a "pointer
semantics" (PTR=true) or "object (value) semantics" (PTR=false, default) class. More... | |
| ~PIMPLHandle () | |
| Note that the destructor is non-virtual. More... | |
| PIMPLHandle & | operator= (const PIMPLHandle &source) |
| Copy assignment makes the current handle either a deep (value) or shallow (reference) copy of the supplied source PIMPL object, based on whether this is a "pointer sematics" (PTR=true) or "object (value) semantics" (PTR=false, default) class. More... | |
| void | setImpl (ForceImpl *p) |
| Set the implementation for this empty handle. More... | |
| bool | hasSameImplementation (const Force &other) const |
| Determine whether the supplied handle is a reference to the same implementation object as is referenced by "this" PIMPLHandle. More... | |
This is a feedback-controlled force that uses Nose'-Hoover chains to maintain a particular temperature Tb, as though the system were immersed in an infinite heat bath at that temperature.
There are two parameters, the temperature Tb and a "relaxation time" t which controls how tightly the temperature is maintained. This thermostat is particularly useful in molecular simulations but can be applied to any mechanical system also.
Temperature is defined here as T = (2*KE) / (N*kB) where KE is the system kinetic energy, N is the number of coupled degrees of freedom (mobilities minus active, nonredundant constraints, minus up to 6 rigid body dofs for the system as a whole), and kB is Boltzmann's constant in appropriate units.
We use a Nose'-Hoover chain to achieve excellent statistical mechanics properties with a continuous force. At equilibrium the temperature will have a Boltzmann distribution; the relaxation time controls how long it takes the system to reach equilibrium with the bath. Smaller values of relaxation time produce faster response but can make the system stiff and will normally require smaller step sizes; larger values will take longer to equilibrate but will run faster.
This Force does not produce any potential energy. However, there is a "bath energy" available through a separate call which can be used in combination with the system energy to construct a conserved quantity; this is described further below.
The current system temperature is defined
T = (2*KE) / (N*kB)
where KE is the kinetic energy of the moving bodies whose N degrees of freedom are being controlled (not necessarily all the bodies in the system), and kB is Boltzmann's constant. Our goal here is to control T so that it follows a Boltzmann distribution around the specified bath temperature Tb.
For an m-chain Nose'-Hoover chain, we will define m auxiliary "thermostat" state variables c[i], 0<=i<m, with units of 1/time. The 0'th thermostat variable c[0] is used to generate a generalized force f applied to the system mobilities u:
f = -c[0] * M * u
where M is the system mass matrix and u is the vector of generalized speeds. (Note that in Simbody the M*u product is formed in O(n) time; M itself is never formed.) The c variables should be initialized to zero at the start of a simulation. Ideally, you should initialize the u's so that they are already at the right temperature, but if not you should still make them non-zero – you can see above that if you have no velocities you will get no Nose'-Hoover forces.
If m==1, we have the standard Nose'-Hoover method except with a relaxation time specified instead of the thermal mass parameter, as in reference [2]:
cdot[0] = (T/Tb - 1)/t^2
Otherwise, for m > 1 we have:
cdot[0] = (T/Tb - 1)/t^2 - c[0]*c[1] cdot[1] = N*c[0]^2 - 1/t^2 - c[1]*c[2] cdot[i] = c[i-1]^2 - 1/t^2 - c[i]*c[i+1] (2<=i<m-1) cdot[m-1] = c[m-2]^2 - 1/t^2
For comparison with the literature where thermal mass parameters Qi are used, we use Q0 = N kB Tb t^2 and Qi = kB Tb t^2, i > 0. That is, the first thermostat that controls the N thermal degrees of freedom is N times "heavier" than the subsequent ones, each of which controls only the one dof of its next-lower thermostat. See refs [1] and [2].
In addition there is a set of state variables si given by sdot[i]=c[i]. Together these permit us to define a "bath energy" which can be combined with system energy to produce a conserved quantity. Bath energy is KEb+PEb where
KEb = 1/2 kB Tb t^2 (N c[0]^2 + sum(c[i]^2)) PEb = kB Tb (N s[0] + sum(s[i]))
where kB is Boltzmann's constant, Tb the bath temperature, N the number of thermal degrees of freedom in the temperature definition, and the sums run from 1 to m-1. Note that you must request the bath energy separately; we do not return any potential energy for this force otherwise.
[1] Martyna, GJ; Klien, ML; Tuckerman, M. Nose'-Hoover chains: The canonical ensemble via continuous dynamics. J. Chem. Phys. 97(4):2635-2643 (1992).
[2] Vaidehi, N; Jain, A; Goddard, WA. Constant Temperature Constrained Molecular Dynamics: The Newton-Euler Inverse Mass Operator Method. J. Phys. Chem. 100:10508-10517 (1996).
| SimTK::Force::Thermostat::Thermostat | ( | GeneralForceSubsystem & | forces, |
| const SimbodyMatterSubsystem & | matter, | ||
| Real | boltzmannsConstant, | ||
| Real | bathTemperature, | ||
| Real | relaxationTime, | ||
| int | numExcludedDofs = 6 |
||
| ) |
Define a global thermostat (one that affects all degrees of freedom) at a given default temperature and relaxation time.
The number of Nose'-Hoover chains is given a default value.
|
inline |
Default constructor creates an empty handle.
| Thermostat& SimTK::Force::Thermostat::excludeMobilizedBody | ( | MobilizedBodyIndex | ) |
TODO: not implemented yet.
Remove a body from consideration in the thermostat. Typically this would be the system base body so that overall rigid body translation and orientation is not counted as part of the temperature.
| Thermostat& SimTK::Force::Thermostat::setDefaultNumChains | ( | int | numChains | ) |
Set the default (state independent) number of Nose'-Hoover chains.
This is a Topology-stage change.
| Thermostat& SimTK::Force::Thermostat::setDefaultBathTemperature | ( | Real | bathTemperature | ) |
Set the default (state independent) bath temperature.
This will be interpreted using the value of Boltzmann's constant Kb provided on construction. The units will be Kb/energy, typically Kelvins.
| Thermostat& SimTK::Force::Thermostat::setDefaultRelaxationTime | ( | Real | relaxationTime | ) |
Set the default (state independent) relaxation time.
| Thermostat& SimTK::Force::Thermostat::setDefaultNumExcludedDofs | ( | int | numExcludedDofs | ) |
Set the default number of system rigid body degrees of freedom (0-6) to be excluded from the calculation of the number of thermal degrees of freedom N; if you don't call this it is assumed that 6 dofs should be excluded.
| int SimTK::Force::Thermostat::getDefaultNumChains | ( | ) | const |
| Real SimTK::Force::Thermostat::getDefaultBathTemperature | ( | ) | const |
| Real SimTK::Force::Thermostat::getDefaultRelaxationTime | ( | ) | const |
Get the initial value for the bath temperature that will be use for the "bath temperature" State variable.
| int SimTK::Force::Thermostat::getDefaultNumExcludedDofs | ( | ) | const |
Get the initial value for the number of system rigid body degrees of freedom (0-6) to be excluded from the calculation of the number of thermal degrees of freedom N.
A new value may be set in a particular State.
| Real SimTK::Force::Thermostat::getBoltzmannsConstant | ( | ) | const |
Can't change the value of Boltzmann's constant after construction; this is the value being used.
| const Thermostat& SimTK::Force::Thermostat::setNumChains | ( | State & | , |
| int | numChains | ||
| ) | const |
Set the actual number of Nose'-Hoover chains to be used.
This variable controls the number of auxiliary state variables allocated by the Thermostat so invalidates Model stage.
| const Thermostat& SimTK::Force::Thermostat::setBathTemperature | ( | State & | , |
| Real | Tb | ||
| ) | const |
Set the bath temperature which serves as the target temperature for the thermostat.
This is given in units defined by the value of Boltzmann's constant (which has units of energy/temperature) that was set on construction. This sets an Instance-stage state variable so invalidates Instance and higher stages in the given State.
| const Thermostat& SimTK::Force::Thermostat::setRelaxationTime | ( | State & | , |
| Real | t | ||
| ) | const |
Set the relaxation time which determines how long the system will take to equilibrate to the bath temperature.
This sets an Instance-stage state variable so invalidates Instance and higher stages in the given State.
| const Thermostat& SimTK::Force::Thermostat::setNumExcludedDofs | ( | State & | , |
| int | numExcludedDofs | ||
| ) | const |
Set the actual number of system rigid body degrees of freedom (0-6) to be excluded from the calculation of the number of thermal degrees of freedom N.
This sets an Instance-stage state variable so invalidates Instance and higher stages in the given State.
| int SimTK::Force::Thermostat::getNumChains | ( | const State & | ) | const |
Obtain the current number of Nose'-Hoover chains in use.
This is a state variable so can be obtained any time after realization of the Model stage.
Obtain the current bath temperature, in units which are determined by the value of Boltzmann's constant that was supplied on construction of this Thermostat force element.
This is a state variable so can be obtained any time after realization of the Model stage.
Obtain the current relaxation time.
This is a state variable so can be obtained any time after realization of the Model stage.
| int SimTK::Force::Thermostat::getNumExcludedDofs | ( | const State & | ) | const |
Get the current value for the number of system rigid body degrees of freedom (0-6) to be excluded from the calculation of the number of thermal degrees of freedom N.
This is a state variable so can be obtained any time after realization of the Model stage.
| int SimTK::Force::Thermostat::getNumThermalDofs | ( | const State & | ) | const |
Return the number of thermal degrees of freedom being used in the definition of temperature for this thermostat.
This is the net of the total number of mobilities minus nonredundant constraints minus the number of excluded system rigid body degrees of freedom (0-6).
Return the temperature of the controlled degrees of freedom via the definition T = 2*ke / (N*Kb) where N is the number of thermal degrees of freedom.
You can call this after Stage::Velocity has been realized.
| void SimTK::Force::Thermostat::initializeChainState | ( | State & | ) | const |
This is a solver that initializes thermostat state variables to zero.
Set the thermostat state variables to particular values.
The Vector's length must be the same as twice the current number of chains called for by the State.
Return the current values of the thermostat chain variables.
The returned vector will have twice the length that getNumChains() would return if called on this same State.
Calculate the total "bath energy" which, when added to the system energy, should yield a conserved quantity (assuming all other forces are conservative).
Get the amount of power being applied by the thermostat to the system; sign is positive when energy is coming from the bath.
Get the amount of work that has been done by the bath on the system since an arbitrary start time.
Set the current value of the work done by the bath to an arbitrary value; normally zero for initialization.
| void SimTK::Force::Thermostat::initializeSystemToBathTemperature | ( | State & | ) | const |
Set the controlled system to a set of randomized velocities which yields the bath temperature.
This ignores the current system velocities. TODO: not implemented yet.
Set the controlled system to a set of randomized velocities which yields a particular temperature.
This ignores the current system velocities. The temperature is interpreted using the value of Boltzmann's constant that was provided on construction of this Thermostat. TODO: not implemented yet.


Decision trees, overarching aims
Contents
9. Decision trees, overarching aims¶
We start here with the most basic algorithm, the so-called decision tree. With this basic algorithm we can in turn build more complex networks, spanning from homogeneous and heterogenous forests (bagging, random forests and more) to one of the most popular supervised algorithms nowadays, the extreme gradient boosting, or just XGBoost. But let us start with the simplest possible ingredient.
Decision trees are supervised learning algorithms used for both, classification and regression tasks.
The main idea of decision trees is to find those descriptive features which contain the most information regarding the target feature and then split the dataset along the values of these features such that the target feature values for the resulting underlying datasets are as pure as possible.
The descriptive features which reproduce best the target/output features are normally said to be the most informative ones. The process of finding the most informative feature is done until we accomplish a stopping criteria where we then finally end up in so called leaf nodes.
9.1. Basics of a tree¶
A decision tree is typically divided into a root node, the interior nodes, and the final leaf nodes or just leaves. These entities are then connected by so-called branches.
The leaf nodes contain the predictions we will make for new query instances presented to our trained model. This is possible since the model has learned the underlying structure of the training data and hence can, given some assumptions, make predictions about the target feature value (class) of unseen query instances.
9.2. General Features¶
The overarching approach to decision trees is a top-down approach.
A leaf provides the classification of a given instance.
A node specifies a test of some attribute of the instance.
A branch corresponds to a possible values of an attribute.
An instance is classified by starting at the root node of the tree, testing the attribute specified by this node, then moving down the tree branch corresponding to the value of the attribute in the given example.
This process is then repeated for the subtree rooted at the new node.
In simplified terms, the process of training a decision tree and predicting the target features of query instances is as follows:
Present a dataset containing of a number of training instances characterized by a number of descriptive features and a target feature
Train the decision tree model by continuously splitting the target feature along the values of the descriptive features using a measure of information gain during the training process
Grow the tree until we accomplish a stopping criteria create leaf nodes which represent the predictions we want to make for new query instances
Show query instances to the tree and run down the tree until we arrive at leaf nodes
Then we are essentially done!
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
steps=250
distance=0
x=0
distance_list=[]
steps_list=[]
while x<steps:
distance+=np.random.randint(-1,2)
distance_list.append(distance)
x+=1
steps_list.append(x)
plt.plot(steps_list,distance_list, color='green', label="Random Walk Data")
steps_list=np.asarray(steps_list)
distance_list=np.asarray(distance_list)
X=steps_list[:,np.newaxis]
#Polynomial fits
#Degree 2
poly_features=PolynomialFeatures(degree=2, include_bias=False)
X_poly=poly_features.fit_transform(X)
lin_reg=LinearRegression()
poly_fit=lin_reg.fit(X_poly,distance_list)
b=lin_reg.coef_
c=lin_reg.intercept_
print ("2nd degree coefficients:")
print ("zero power: ",c)
print ("first power: ", b[0])
print ("second power: ",b[1])
z = np.arange(0, steps, .01)
z_mod=b[1]*z**2+b[0]*z+c
fit_mod=b[1]*X**2+b[0]*X+c
plt.plot(z, z_mod, color='r', label="2nd Degree Fit")
plt.title("Polynomial Regression")
plt.xlabel("Steps")
plt.ylabel("Distance")
#Degree 10
poly_features10=PolynomialFeatures(degree=10, include_bias=False)
X_poly10=poly_features10.fit_transform(X)
poly_fit10=lin_reg.fit(X_poly10,distance_list)
y_plot=poly_fit10.predict(X_poly10)
plt.plot(X, y_plot, color='black', label="10th Degree Fit")
plt.legend()
plt.show()
#Decision Tree Regression
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(X, distance_list)
regr_2.fit(X, distance_list)
regr_3.fit(X, distance_list)
X_test = np.arange(0.0, steps, 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)
# Plot the results
plt.figure()
plt.scatter(X, distance_list, s=2.5, c="black", label="data")
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.xlabel("Data")
plt.ylabel("Darget")
plt.title("Decision Tree Regression")
plt.legend()
plt.show()
2nd degree coefficients:
zero power: -6.548110376991839
first power: 0.2232822462117919
second power: -0.0007480407244119591
9.3. Building a tree, regression¶
There are mainly two steps
We split the predictor space (the set of possible values \(x_1,x_2,\dots, x_p\)) into \(J\) distinct and non-non-overlapping regions, \(R_1,R_2,\dots,R_J\).
For every observation that falls into the region \(R_j\) , we make the same prediction, which is simply the mean of the response values for the training observations in \(R_j\).
How do we construct the regions \(R_1,\dots,R_J\)? In theory, the regions could have any shape. However, we choose to divide the predictor space into high-dimensional rectangles, or boxes, for simplicity and for ease of interpretation of the resulting predictive model. The goal is to find boxes \(R_1,\dots,R_J\) that minimize the MSE, given by
where \(\overline{y}_{R_j}\) is the mean response for the training observations within box \(j\).
Unfortunately, it is computationally infeasible to consider every possible partition of the feature space into \(J\) boxes. The common strategy is to take a top-down approach
The approach is top-down because it begins at the top of the tree (all observations belong to a single region) and then successively splits the predictor space; each split is indicated via two new branches further down on the tree. It is greedy because at each step of the tree-building process, the best split is made at that particular step, rather than looking ahead and picking a split that will lead to a better tree in some future step.
9.3.1. Making a tree¶
In order to implement the recursive binary splitting we start by selecting the predictor \(x_j\) and a cutpoint \(s\) that splits the predictor space into two regions \(R_1\) and \(R_2\)
and
so that we obtain the lowest MSE, that is
which we want to minimize by considering all predictors \(x_1,x_2,\dots,x_p\). We consider also all possible values of \(s\) for each predictor. These values could be determined by randomly assigned numbers or by starting at the midpoint and then proceed till we find an optimal value.
For any \(j\) and \(s\), we define the pair of half-planes where \(\overline{y}_{R_1}\) is the mean response for the training observations in \(R_1(j,s)\), and \(\overline{y}_{R_2}\) is the mean response for the training observations in \(R_2(j,s)\).
Finding the values of \(j\) and \(s\) that minimize the above equation can be done quite quickly, especially when the number of features \(p\) is not too large.
Next, we repeat the process, looking for the best predictor and best cutpoint in order to split the data further so as to minimize the MSE within each of the resulting regions. However, this time, instead of splitting the entire predictor space, we split one of the two previously identified regions. We now have three regions. Again, we look to split one of these three regions further, so as to minimize the MSE. The process continues until a stopping criterion is reached; for instance, we may continue until no region contains more than five observations.
The above procedure is rather straightforward, but leads often to overfitting and unnecessarily large and complicated trees. The basic idea is to grow a large tree \(T_0\) and then prune it back in order to obtain a subtree. A smaller tree with fewer splits (fewer regions) can lead to smaller variance and better interpretation at the cost of a little more bias.
The so-called Cost complexity pruning algorithm gives us a way to do just this. Rather than considering every possible subtree, we consider a sequence of trees indexed by a nonnegative tuning parameter \(\alpha\).
Read more at the following Scikit-Learn link on pruning.
For each value of \(\alpha\) there corresponds a subtree \(T \in T_0\) such that
is as small as possible. Here \(\overline{T}\) is the number of terminal nodes of the tree \(T\) , \(R_m\) is the rectangle (i.e. the subset of predictor space) corresponding to the \(m\)-th terminal node.
The tuning parameter \(\alpha\) controls a trade-off between the subtree’s complexity and its fit to the training data. When \(\alpha = 0\), then the subtree \(T\) will simply equal \(T_0\), because then the above equation just measures the training error. However, as \(\alpha\) increases, there is a price to pay for having a tree with many terminal nodes. The above equation will tend to be minimized for a smaller subtree.
It turns out that as we increase \(\alpha\) from zero branches get pruned from the tree in a nested and predictable fashion, so obtaining the whole sequence of subtrees as a function of \(\alpha\) is easy. We can select a value of \(\alpha\) using a validation set or using cross-validation. We then return to the full data set and obtain the subtree corresponding to \(\alpha\).
9.3.2. Schematic Regression Procedure¶
Building a Regression Tree
Use recursive binary splitting to grow a large tree on the training data, stopping only when each terminal node has fewer than some minimum number of observations.
Apply cost complexity pruning to the large tree in order to obtain a sequence of best subtrees, as a function of \(\alpha\).
Use for example \(K\)-fold cross-validation to choose \(\alpha\). Divide the training observations into \(K\) folds. For each \(k=1,2,\dots,K\) we:
repeat steps 1 and 2 on all but the \(k\)-th fold of the training data.
Then we valuate the mean squared prediction error on the data in the left-out \(k\)-th fold, as a function of \(\alpha\).
Finally we average the results for each value of \(\alpha\), and pick \(\alpha\) to minimize the average error.
Return the subtree from Step 2 that corresponds to the chosen value of \(\alpha\).
!eblock
9.4. A Classification Tree¶
A classification tree is very similar to a regression tree, except that it is used to predict a qualitative response rather than a quantitative one. Recall that for a regression tree, the predicted response for an observation is given by the mean response of the training observations that belong to the same terminal node. In contrast, for a classification tree, we predict that each observation belongs to the most commonly occurring class of training observations in the region to which it belongs. In interpreting the results of a classification tree, we are often interested not only in the class prediction corresponding to a particular terminal node region, but also in the class proportions among the training observations that fall into that region.
The task of growing a classification tree is quite similar to the task of growing a regression tree. Just as in the regression setting, we use recursive binary splitting to grow a classification tree. However, in the classification setting, the MSE cannot be used as a criterion for making the binary splits. A natural alternative to MSE is the classification error rate. Since we plan to assign an observation in a given region to the most commonly occurring error rate class of training observations in that region, the classification error rate is simply the fraction of the training observations in that region that do not belong to the most common class.
When building a classification tree, either the Gini index or the entropy are typically used to evaluate the quality of a particular split, since these two approaches are more sensitive to node purity than is the classification error rate.
If our targets are the outcome of a classification process that takes for example \(k=1,2,\dots,K\) values, the only thing we need to think of is to set up the splitting criteria for each node.
We define a PDF \(p_{mk}\) that represents the number of observations of a class \(k\) in a region \(R_m\) with \(N_m\) observations. We represent this likelihood function in terms of the proportion \(I(y_i=k)\) of observations of this class in the region \(R_m\) as
We let \(p_{mk}\) represent the majority class of observations in region \(m\). The three most common ways of splitting a node are given by
Misclassification error
Gini index \(g\)
Information entropy or just entropy \(s\)
9.4.1. Visualizing the Tree, Classification¶
import os
from sklearn.datasets import load_breast_cancer
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.tree import export_graphviz
from IPython.display import Image
from pydot import graph_from_dot_data
import pandas as pd
import numpy as np
cancer = load_breast_cancer()
X = pd.DataFrame(cancer.data, columns=cancer.feature_names)
print(X)
y = pd.Categorical.from_codes(cancer.target, cancer.target_names)
y = pd.get_dummies(y)
print(y)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
tree_clf = DecisionTreeClassifier(max_depth=5)
tree_clf.fit(X_train, y_train)
export_graphviz(
tree_clf,
out_file="DataFiles/cancer.dot",
feature_names=cancer.feature_names,
class_names=cancer.target_names,
rounded=True,
filled=True
)
cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'
os.system(cmd)
mean radius mean texture mean perimeter mean area mean smoothness \
0 17.99 10.38 122.80 1001.0 0.11840
1 20.57 17.77 132.90 1326.0 0.08474
2 19.69 21.25 130.00 1203.0 0.10960
3 11.42 20.38 77.58 386.1 0.14250
4 20.29 14.34 135.10 1297.0 0.10030
.. ... ... ... ... ...
564 21.56 22.39 142.00 1479.0 0.11100
565 20.13 28.25 131.20 1261.0 0.09780
566 16.60 28.08 108.30 858.1 0.08455
567 20.60 29.33 140.10 1265.0 0.11780
568 7.76 24.54 47.92 181.0 0.05263
mean compactness mean concavity mean concave points mean symmetry \
0 0.27760 0.30010 0.14710 0.2419
1 0.07864 0.08690 0.07017 0.1812
2 0.15990 0.19740 0.12790 0.2069
3 0.28390 0.24140 0.10520 0.2597
4 0.13280 0.19800 0.10430 0.1809
.. ... ... ... ...
564 0.11590 0.24390 0.13890 0.1726
565 0.10340 0.14400 0.09791 0.1752
566 0.10230 0.09251 0.05302 0.1590
567 0.27700 0.35140 0.15200 0.2397
568 0.04362 0.00000 0.00000 0.1587
mean fractal dimension ... worst radius worst texture \
0 0.07871 ... 25.380 17.33
1 0.05667 ... 24.990 23.41
2 0.05999 ... 23.570 25.53
3 0.09744 ... 14.910 26.50
4 0.05883 ... 22.540 16.67
.. ... ... ... ...
564 0.05623 ... 25.450 26.40
565 0.05533 ... 23.690 38.25
566 0.05648 ... 18.980 34.12
567 0.07016 ... 25.740 39.42
568 0.05884 ... 9.456 30.37
worst perimeter worst area worst smoothness worst compactness \
0 184.60 2019.0 0.16220 0.66560
1 158.80 1956.0 0.12380 0.18660
2 152.50 1709.0 0.14440 0.42450
3 98.87 567.7 0.20980 0.86630
4 152.20 1575.0 0.13740 0.20500
.. ... ... ... ...
564 166.10 2027.0 0.14100 0.21130
565 155.00 1731.0 0.11660 0.19220
566 126.70 1124.0 0.11390 0.30940
567 184.60 1821.0 0.16500 0.86810
568 59.16 268.6 0.08996 0.06444
worst concavity worst concave points worst symmetry \
0 0.7119 0.2654 0.4601
1 0.2416 0.1860 0.2750
2 0.4504 0.2430 0.3613
3 0.6869 0.2575 0.6638
4 0.4000 0.1625 0.2364
.. ... ... ...
564 0.4107 0.2216 0.2060
565 0.3215 0.1628 0.2572
566 0.3403 0.1418 0.2218
567 0.9387 0.2650 0.4087
568 0.0000 0.0000 0.2871
worst fractal dimension
0 0.11890
1 0.08902
2 0.08758
3 0.17300
4 0.07678
.. ...
564 0.07115
565 0.06637
566 0.07820
567 0.12400
568 0.07039
[569 rows x 30 columns]
malignant benign
0 1 0
1 1 0
2 1 0
3 1 0
4 1 0
.. ... ...
564 1 0
565 1 0
566 1 0
567 1 0
568 0 1
[569 rows x 2 columns]
0
# Common imports
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import make_moons
from sklearn.tree import export_graphviz
from pydot import graph_from_dot_data
import pandas as pd
import os
np.random.seed(42)
X, y = make_moons(n_samples=100, noise=0.25, random_state=53)
X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=0)
tree_clf = DecisionTreeClassifier(max_depth=5)
tree_clf.fit(X_train, y_train)
export_graphviz(
tree_clf,
out_file="DataFiles/moons.dot",
rounded=True,
filled=True
)
cmd = 'dot -Tpng DataFiles/moons.dot -o DataFiles/moons.png'
os.system(cmd)
0
9.4.2. Other ways of visualizing the trees¶
Scikit-Learn has also another way to visualize the trees which is very useful, here with the Iris data.
from sklearn.datasets import load_iris
from sklearn import tree
X, y = load_iris(return_X_y=True)
tree_clf = tree.DecisionTreeClassifier()
tree_clf = tree_clf.fit(X, y)
# and then plot the tree
tree.plot_tree(tree_clf)
[Text(0.5, 0.9166666666666666, 'X[2] <= 2.45\ngini = 0.667\nsamples = 150\nvalue = [50, 50, 50]'),
Text(0.4230769230769231, 0.75, 'gini = 0.0\nsamples = 50\nvalue = [50, 0, 0]'),
Text(0.5769230769230769, 0.75, 'X[3] <= 1.75\ngini = 0.5\nsamples = 100\nvalue = [0, 50, 50]'),
Text(0.3076923076923077, 0.5833333333333334, 'X[2] <= 4.95\ngini = 0.168\nsamples = 54\nvalue = [0, 49, 5]'),
Text(0.15384615384615385, 0.4166666666666667, 'X[3] <= 1.65\ngini = 0.041\nsamples = 48\nvalue = [0, 47, 1]'),
Text(0.07692307692307693, 0.25, 'gini = 0.0\nsamples = 47\nvalue = [0, 47, 0]'),
Text(0.23076923076923078, 0.25, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 1]'),
Text(0.46153846153846156, 0.4166666666666667, 'X[3] <= 1.55\ngini = 0.444\nsamples = 6\nvalue = [0, 2, 4]'),
Text(0.38461538461538464, 0.25, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 3]'),
Text(0.5384615384615384, 0.25, 'X[2] <= 5.45\ngini = 0.444\nsamples = 3\nvalue = [0, 2, 1]'),
Text(0.46153846153846156, 0.08333333333333333, 'gini = 0.0\nsamples = 2\nvalue = [0, 2, 0]'),
Text(0.6153846153846154, 0.08333333333333333, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 1]'),
Text(0.8461538461538461, 0.5833333333333334, 'X[2] <= 4.85\ngini = 0.043\nsamples = 46\nvalue = [0, 1, 45]'),
Text(0.7692307692307693, 0.4166666666666667, 'X[1] <= 3.1\ngini = 0.444\nsamples = 3\nvalue = [0, 1, 2]'),
Text(0.6923076923076923, 0.25, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 2]'),
Text(0.8461538461538461, 0.25, 'gini = 0.0\nsamples = 1\nvalue = [0, 1, 0]'),
Text(0.9230769230769231, 0.4166666666666667, 'gini = 0.0\nsamples = 43\nvalue = [0, 0, 43]')]
Alternatively, the tree can also be exported in textual format with the function exporttext. This method doesn’t require the installation of external libraries and is more compact:
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import export_text
iris = load_iris()
decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)
decision_tree = decision_tree.fit(iris.data, iris.target)
r = export_text(decision_tree, feature_names=iris['feature_names'])
print(r)
|--- petal width (cm) <= 0.80
| |--- class: 0
|--- petal width (cm) > 0.80
| |--- petal width (cm) <= 1.75
| | |--- class: 1
| |--- petal width (cm) > 1.75
| | |--- class: 2
9.5. Algorithms for Setting up Decision Trees¶
Two algorithms stand out in the set up of decision trees:
The CART (Classification And Regression Tree) algorithm for both classification and regression
The ID3 algorithm based on the computation of the information gain for classification
We discuss both algorithms with applications here. The popular library Scikit-Learn uses the CART algorithm. For classification problems you can use either the gini index or the entropy to split a tree in two branches.
9.5.1. The CART algorithm for Classification¶
For classification, the CART algorithm splits the data set in two subsets using a single feature \(k\) and a threshold \(t_k\). This could be for example a threshold set by a number below a certain circumference of a malign tumor.
How do we find these two quantities? We search for the pair \((k,t_k)\) that produces the purest subset using for example the gini factor \(G\). The cost function it tries to minimize is then
where \(G_{\mathrm{left/right}}\) measures the impurity of the left/right subset and \(m_{\mathrm{left/right}}\) is the number of instances in the left/right subset
Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the \(max\_depth\) hyperparameter), or if it cannot find a split that will reduce impurity. A few other hyperparameters control additional stopping conditions such as the \(min\_samples\_split\), \(min\_samples\_leaf\), \(min\_weight\_fraction\_leaf\), and \(max\_leaf\_nodes\).
9.5.2. The CART algorithm for Regression¶
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the training set in a way that minimizes say the gini or entropy impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now
Here the MSE for a specific node is defined as
with
the mean value of all observations in a specific node.
Without any regularization, the regression task for decision trees, just like for classification tasks, is prone to overfitting.
9.5.3. Computing the Gini index¶
The example we will look at is a classical one in many Machine Learning applications. Based on various meteorological features, we have several so-called attributes which decide whether we at the end will do some outdoor activity like skiing, going for a bike ride etc etc. The table here contains the feautures outlook, temperature, humidity and wind. The target or output is whether we ride (True=1) or whether we do something else that day (False=0). The attributes for each feature are then sunny, overcast and rain for the outlook, hot, cold and mild for temperature, high and normal for humidity and weak and strong for wind.
The table here summarizes the various attributes and
| Day | Outlook | Temperature | Humidity | Wind | Ride |
|---|---|---|---|---|---|
| 1 | Sunny | Hot | High | Weak | 0 |
| 2 | Sunny | Hot | High | Strong | 1 |
| 3 | Overcast | Hot | High | Weak | 1 |
| 4 | Rain | Mild | High | Weak | 1 |
| 5 | Rain | Cool | Normal | Weak | 1 |
| 6 | Rain | Cool | Normal | Strong | 0 |
| 7 | Overcast | Cool | Normal | Strong | 1 |
| 8 | Sunny | Mild | High | Weak | 0 |
| 9 | Sunny | Cool | Normal | Weak | 1 |
| 10 | Rain | Mild | Normal | Weak | 1 |
| 11 | Sunny | Mild | Normal | Strong | 1 |
| 12 | Overcast | Mild | High | Strong | 1 |
| 13 | Overcast | Hot | Normal | Weak | 1 |
| 14 | Rain | Mild | High | Strong | 0 |
9.5.4. Simple Python Code to read in Data and perform Classification¶
# Common imports
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.tree import export_graphviz
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from IPython.display import Image
from pydot import graph_from_dot_data
import os
# Where to save the figures and data files
PROJECT_ROOT_DIR = "Results"
FIGURE_ID = "Results/FigureFiles"
DATA_ID = "DataFiles/"
if not os.path.exists(PROJECT_ROOT_DIR):
os.mkdir(PROJECT_ROOT_DIR)
if not os.path.exists(FIGURE_ID):
os.makedirs(FIGURE_ID)
if not os.path.exists(DATA_ID):
os.makedirs(DATA_ID)
def image_path(fig_id):
return os.path.join(FIGURE_ID, fig_id)
def data_path(dat_id):
return os.path.join(DATA_ID, dat_id)
def save_fig(fig_id):
plt.savefig(image_path(fig_id) + ".png", format='png')
infile = open(data_path("rideclass.csv"),'r')
# Read the experimental data with Pandas
from IPython.display import display
ridedata = pd.read_csv(infile,names = ('Outlook','Temperature','Humidity','Wind','Ride'))
ridedata = pd.DataFrame(ridedata)
# Features and targets
X = ridedata.loc[:, ridedata.columns != 'Ride'].values
y = ridedata.loc[:, ridedata.columns == 'Ride'].values
# Create the encoder.
encoder = OneHotEncoder(handle_unknown="ignore")
# Assume for simplicity all features are categorical.
encoder.fit(X)
# Apply the encoder.
X = encoder.transform(X)
print(X)
# Then do a Classification tree
tree_clf = DecisionTreeClassifier(max_depth=2)
tree_clf.fit(X, y)
print("Train set accuracy with Decision Tree: {:.2f}".format(tree_clf.score(X,y)))
#transfer to a decision tree graph
export_graphviz(
tree_clf,
out_file="DataFiles/ride.dot",
rounded=True,
filled=True
)
cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'
os.system(cmd)
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
Input In [6], in <cell line: 37>()
34 def save_fig(fig_id):
35 plt.savefig(image_path(fig_id) + ".png", format='png')
---> 37 infile = open(data_path("rideclass.csv"),'r')
39 # Read the experimental data with Pandas
40 from IPython.display import display
FileNotFoundError: [Errno 2] No such file or directory: 'DataFiles/rideclass.csv'
The above functions (gini, entropy and misclassification error) are important components of the so-called CART algorithm. We will discuss this algorithm below after we have discussed the information gain algorithm ID3.
In the example here we have converted all our attributes into numerical values \(0,1,2\) etc.
# Split a dataset based on an attribute and an attribute value
def test_split(index, value, dataset):
left, right = list(), list()
for row in dataset:
if row[index] < value:
left.append(row)
else:
right.append(row)
return left, right
# Calculate the Gini index for a split dataset
def gini_index(groups, classes):
# count all samples at split point
n_instances = float(sum([len(group) for group in groups]))
# sum weighted Gini index for each group
gini = 0.0
for group in groups:
size = float(len(group))
# avoid divide by zero
if size == 0:
continue
score = 0.0
# score the group based on the score for each class
for class_val in classes:
p = [row[-1] for row in group].count(class_val) / size
score += p * p
# weight the group score by its relative size
gini += (1.0 - score) * (size / n_instances)
return gini
# Select the best split point for a dataset
def get_split(dataset):
class_values = list(set(row[-1] for row in dataset))
b_index, b_value, b_score, b_groups = 999, 999, 999, None
for index in range(len(dataset[0])-1):
for row in dataset:
groups = test_split(index, row[index], dataset)
gini = gini_index(groups, class_values)
print('X%d < %.3f Gini=%.3f' % ((index+1), row[index], gini))
if gini < b_score:
b_index, b_value, b_score, b_groups = index, row[index], gini, groups
return {'index':b_index, 'value':b_value, 'groups':b_groups}
dataset = [[0,0,0,0,0],
[0,0,0,1,1],
[1,0,0,0,1],
[2,1,0,0,1],
[2,2,1,0,1],
[2,2,1,1,0],
[1,2,1,1,1],
[0,1,0,0,0],
[0,2,1,0,1],
[2,1,1,0,1],
[0,1,1,1,1],
[1,1,0,1,1],
[1,0,1,0,1],
[2,1,0,1,0]]
split = get_split(dataset)
print('Split: [X%d < %.3f]' % ((split['index']+1), split['value']))
9.6. Entropy and the ID3 algorithm¶
The ID3 algorithm learns decision trees by constructing them in a top down way, beginning with the question which attribute should be tested at the root of the tree?
Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.
The best attribute is selected and used as the test at the root node of the tree.
A descendant of the root node is then created for each possible value of this attribute.
Training examples are sorted to the appropriate descendant node.
The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.
This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.
The ID3 algorithm selects which attribute to test at each node in the tree.
We would like to select the attribute that is most useful for classifying examples.
What is a good quantitative measure of the worth of an attribute?
Information gain measures how well a given attribute separates the training examples according to their target classification.
The ID3 algorithm uses this information gain measure to select among the candidate attributes at each step while growing the tree.
9.6.1. Cancer Data again now with Decision Trees and other Methods¶
import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
# Load the data
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
print(X_train.shape)
print(X_test.shape)
# Logistic Regression
logreg = LogisticRegression(solver='lbfgs')
logreg.fit(X_train, y_train)
print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
# Support vector machine
svm = SVC(gamma='auto', C=100)
svm.fit(X_train, y_train)
print("Test set accuracy with SVM: {:.2f}".format(svm.score(X_test,y_test)))
# Decision Trees
deep_tree_clf = DecisionTreeClassifier(max_depth=None)
deep_tree_clf.fit(X_train, y_train)
print("Test set accuracy with Decision Trees: {:.2f}".format(deep_tree_clf.score(X_test,y_test)))
#now scale the data
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Logistic Regression
logreg.fit(X_train_scaled, y_train)
print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
# Support Vector Machine
svm.fit(X_train_scaled, y_train)
print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
# Decision Trees
deep_tree_clf.fit(X_train_scaled, y_train)
print("Test set accuracy with Decision Trees and scaled data: {:.2f}".format(deep_tree_clf.score(X_test_scaled,y_test)))
9.6.2. Another example, the moons again¶
from __future__ import division, print_function, unicode_literals
# Common imports
import numpy as np
import os
# to make this notebook's output stable across runs
np.random.seed(42)
# To plot pretty figures
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
plt.rcParams['axes.labelsize'] = 14
plt.rcParams['xtick.labelsize'] = 12
plt.rcParams['ytick.labelsize'] = 12
from sklearn.svm import SVC
from sklearn import datasets
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import make_moons
from sklearn.tree import export_graphviz
Xm, ym = make_moons(n_samples=100, noise=0.25, random_state=53)
deep_tree_clf1 = DecisionTreeClassifier(random_state=42)
deep_tree_clf2 = DecisionTreeClassifier(min_samples_leaf=4, random_state=42)
deep_tree_clf1.fit(Xm, ym)
deep_tree_clf2.fit(Xm, ym)
def plot_decision_boundary(clf, X, y, axes=[0, 7.5, 0, 3], iris=True, legend=False, plot_training=True):
x1s = np.linspace(axes[0], axes[1], 100)
x2s = np.linspace(axes[2], axes[3], 100)
x1, x2 = np.meshgrid(x1s, x2s)
X_new = np.c_[x1.ravel(), x2.ravel()]
y_pred = clf.predict(X_new).reshape(x1.shape)
custom_cmap = ListedColormap(['#fafab0','#9898ff','#a0faa0'])
plt.contourf(x1, x2, y_pred, alpha=0.3, cmap=custom_cmap)
if not iris:
custom_cmap2 = ListedColormap(['#7d7d58','#4c4c7f','#507d50'])
plt.contour(x1, x2, y_pred, cmap=custom_cmap2, alpha=0.8)
if plot_training:
plt.plot(X[:, 0][y==0], X[:, 1][y==0], "yo", label="Iris-Setosa")
plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs", label="Iris-Versicolor")
plt.plot(X[:, 0][y==2], X[:, 1][y==2], "g^", label="Iris-Virginica")
plt.axis(axes)
if iris:
plt.xlabel("Petal length", fontsize=14)
plt.ylabel("Petal width", fontsize=14)
else:
plt.xlabel(r"$x_1$", fontsize=18)
plt.ylabel(r"$x_2$", fontsize=18, rotation=0)
if legend:
plt.legend(loc="lower right", fontsize=14)
plt.figure(figsize=(11, 4))
plt.subplot(121)
plot_decision_boundary(deep_tree_clf1, Xm, ym, axes=[-1.5, 2.5, -1, 1.5], iris=False)
plt.title("No restrictions", fontsize=16)
plt.subplot(122)
plot_decision_boundary(deep_tree_clf2, Xm, ym, axes=[-1.5, 2.5, -1, 1.5], iris=False)
plt.title("min_samples_leaf = {}".format(deep_tree_clf2.min_samples_leaf), fontsize=14)
plt.show()
np.random.seed(6)
Xs = np.random.rand(100, 2) - 0.5
ys = (Xs[:, 0] > 0).astype(np.float32) * 2
angle = np.pi/4
rotation_matrix = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
Xsr = Xs.dot(rotation_matrix)
tree_clf_s = DecisionTreeClassifier(random_state=42)
tree_clf_s.fit(Xs, ys)
tree_clf_sr = DecisionTreeClassifier(random_state=42)
tree_clf_sr.fit(Xsr, ys)
plt.figure(figsize=(11, 4))
plt.subplot(121)
plot_decision_boundary(tree_clf_s, Xs, ys, axes=[-0.7, 0.7, -0.7, 0.7], iris=False)
plt.subplot(122)
plot_decision_boundary(tree_clf_sr, Xsr, ys, axes=[-0.7, 0.7, -0.7, 0.7], iris=False)
plt.show()
# Quadratic training set + noise
np.random.seed(42)
m = 200
X = np.random.rand(m, 1)
y = 4 * (X - 0.5) ** 2
y = y + np.random.randn(m, 1) / 10
from sklearn.tree import DecisionTreeRegressor
tree_reg = DecisionTreeRegressor(max_depth=2, random_state=42)
tree_reg.fit(X, y)
from sklearn.tree import DecisionTreeRegressor
tree_reg1 = DecisionTreeRegressor(random_state=42, max_depth=2)
tree_reg2 = DecisionTreeRegressor(random_state=42, max_depth=3)
tree_reg1.fit(X, y)
tree_reg2.fit(X, y)
def plot_regression_predictions(tree_reg, X, y, axes=[0, 1, -0.2, 1], ylabel="$y$"):
x1 = np.linspace(axes[0], axes[1], 500).reshape(-1, 1)
y_pred = tree_reg.predict(x1)
plt.axis(axes)
plt.xlabel("$x_1$", fontsize=18)
if ylabel:
plt.ylabel(ylabel, fontsize=18, rotation=0)
plt.plot(X, y, "b.")
plt.plot(x1, y_pred, "r.-", linewidth=2, label=r"$\hat{y}$")
plt.figure(figsize=(11, 4))
plt.subplot(121)
plot_regression_predictions(tree_reg1, X, y)
for split, style in ((0.1973, "k-"), (0.0917, "k--"), (0.7718, "k--")):
plt.plot([split, split], [-0.2, 1], style, linewidth=2)
plt.text(0.21, 0.65, "Depth=0", fontsize=15)
plt.text(0.01, 0.2, "Depth=1", fontsize=13)
plt.text(0.65, 0.8, "Depth=1", fontsize=13)
plt.legend(loc="upper center", fontsize=18)
plt.title("max_depth=2", fontsize=14)
plt.subplot(122)
plot_regression_predictions(tree_reg2, X, y, ylabel=None)
for split, style in ((0.1973, "k-"), (0.0917, "k--"), (0.7718, "k--")):
plt.plot([split, split], [-0.2, 1], style, linewidth=2)
for split in (0.0458, 0.1298, 0.2873, 0.9040):
plt.plot([split, split], [-0.2, 1], "k:", linewidth=1)
plt.text(0.3, 0.5, "Depth=2", fontsize=13)
plt.title("max_depth=3", fontsize=14)
plt.show()
tree_reg1 = DecisionTreeRegressor(random_state=42)
tree_reg2 = DecisionTreeRegressor(random_state=42, min_samples_leaf=10)
tree_reg1.fit(X, y)
tree_reg2.fit(X, y)
x1 = np.linspace(0, 1, 500).reshape(-1, 1)
y_pred1 = tree_reg1.predict(x1)
y_pred2 = tree_reg2.predict(x1)
plt.figure(figsize=(11, 4))
plt.subplot(121)
plt.plot(X, y, "b.")
plt.plot(x1, y_pred1, "r.-", linewidth=2, label=r"$\hat{y}$")
plt.axis([0, 1, -0.2, 1.1])
plt.xlabel("$x_1$", fontsize=18)
plt.ylabel("$y$", fontsize=18, rotation=0)
plt.legend(loc="upper center", fontsize=18)
plt.title("No restrictions", fontsize=14)
plt.subplot(122)
plt.plot(X, y, "b.")
plt.plot(x1, y_pred2, "r.-", linewidth=2, label=r"$\hat{y}$")
plt.axis([0, 1, -0.2, 1.1])
plt.xlabel("$x_1$", fontsize=18)
plt.title("min_samples_leaf={}".format(tree_reg2.min_samples_leaf), fontsize=14)
plt.show()
9.7. Pros and cons of trees, pros¶
White box, easy to interpret model. Some people believe that decision trees more closely mirror human decision-making than do the regression and classification approaches discussed earlier (think of support vector machines)
Trees are very easy to explain to people. In fact, they are even easier to explain than linear regression!
No feature normalization needed
Tree models can handle both continuous and categorical data (Classification and Regression Trees)
Can model nonlinear relationships
Can model interactions between the different descriptive features
Trees can be displayed graphically, and are easily interpreted even by a non-expert (especially if they are small)
9.7.1. Disadvantages¶
Unfortunately, trees generally do not have the same level of predictive accuracy as some of the other regression and classification approaches
If continuous features are used the tree may become quite large and hence less interpretable
Decision trees are prone to overfit the training data and hence do not well generalize the data if no stopping criteria or improvements like pruning, boosting or bagging are implemented
Small changes in the data may lead to a completely different tree. This issue can be addressed by using ensemble methods like bagging, boosting or random forests
Unbalanced datasets where some target feature values occur much more frequently than others may lead to biased trees since the frequently occurring feature values are preferred over the less frequently occurring ones.
If the number of features is relatively large (high dimensional) and the number of instances is relatively low, the tree might overfit the data
Features with many levels may be preferred over features with less levels since for them it is more easy to split the dataset such that the sub datasets only contain pure target feature values. This issue can be addressed by preferring for instance the information gain ratio as splitting criteria over information gain
However, by aggregating many decision trees, using methods like bagging, random forests, and boosting, the predictive performance of trees can be substantially improved.


Any contributions to the core Astropy package, whether bug fixes, improvements to the documentation, or new functionality, can be done via pull requests on GitHub. The workflow for this is described below.
However, substantial contributions, such as whole new sub-packages, can first be developed as affiliated packages then submitted to the Astropy core via pull requests once ready (as described in Vision for a Common Astronomy Python Package). Teams working on affiliated packages are free to choose whatever version control system they wish, but ultimately the affiliated package should be merged into a fork of the Astropy repository in order to be submitted as a pull request (this merging can be done either by the team or by one of the core maintainers).
The only absolutely necessary configuration step is identifying yourself and your contact info:
git config --global user.name "Your Name"
git config --global user.email<EMAIL_ADDRESS>The following sections cover the installation of the git software, the basic configuration, and links to resources to learn more about using git. However, you can also directly go to the GitHub help pages which offer a great introduction to git and GitHub.
The following two sections describe the workflow for the Astropy core package, but teams working on affiliated packages that have chosen to use git are encouraged to also follow these guidelines internally.
If for any reason developers do not wish to or cannot contribute via pull requests, they can submit a patch as described in Creating patches.


Home
Beta!
Architect
Calendar
City Planner
About
Beta!
Architect
Calendar
City Planner
About
Palladio runs on Web3
Please view consultations from a desktop computer
All
Upcoming
In Progress
Completed
Contract Overview
Duration
Site Plan Control Category
Consultation


{% load static %}
Do you want your meal service to feature on this list? Click here to enter details
We kindly request you to forward this portal to all those you know who are currently providing this service.


--------- India's Biggest Blood Donation Organisation ----------
BLOOD DONATION
Login
Register
Home
Blood Banks
Doctors Available
Donation
Discussion Forum
ContactUs
Contact Us
Got any idea or need to ask something?
Feel free to contact us anytime.Fill the following form and we will respond to you as soon as possible.
Name
Email
Mobile
Suggestion


The Metal Brand
Origami metal sheet designs.
More than 40 different DIY products for home and office
Our strong expertise in Product Design has given us a unique value when it comes to prototyping and modeling the experimental phases of a product.
You craft it
Each piece is delivered as a DIY metal sheet facilitating transport and shipping while allowing the user to experience the art of the making by providing them with the opportunity to give the product its final form. The user becomes an essential part of the process and design itself.
Innovation
This project is created with the goal to conceive a series of pieces that require a minimum industrialized process – it’s narrowed down to only laser cut and paint, which avoids any further assembly and operations saving a significant amount of cost and time.
"Metalbrand is not only a product, it's an experience."


39+ Log To Ln Calculator PNG. It is often used in mathematical analysis, physics, chemistry, statistics. This free log calculator solves for the unknown portions of a logarithmic expression using base e, 2, 10, or any other desired base.
Ln calculator is used to determine the natural logarithm of a number. Your results will be displayed in the bottom platform of the calculator. The natural logarithm of x is the base e logarithm of x:
Graph functions, plot points, visualize algebraic equations, add sliders, animate graphs, and more.
Your results will be displayed in the bottom platform of the calculator. A logarithm can have any positive value as its base. Well, this is where ln 2 comes into play: Online ln (x) calculator to find its natural log, which has special base in it.


Company Name
Home
About
Services
Contact
Contact us
ABC Company
22, Def Street,
Near DLF Square,
XYZ.
+12-123123123
For further enquiries write to us at: abc@xyz.com


My Team
John
Manager
ID: 1
Email:
<EMAIL_ADDRESS>Office Number: 1
Cody
Engineer
ID: 2
Email:
<EMAIL_ADDRESS>GitHub: lewisoutdoorllc
James
Engineer
ID: 3
Email:
<EMAIL_ADDRESS>GitHub: githubjohn
Kevin
Engineer
ID: 4
Email:
<EMAIL_ADDRESS>GitHub: githubkevin
George
Intern
ID: 5
Email:
<EMAIL_ADDRESS>School: UCF


{% extends 'base.html' %} {% block nav-home-class %}active{% endblock %} {% block title %}top{% endblock %} {% block page_header %}Demo Site{% endblock %} {% block content %}
This is demo website of django-static-site.
django-static-site is static site generator for django. You can make a static website so simply with django-static-site.
Please refer to Getting Started.


- seeAction(ActionUtility[][]) - Static method in class policysearch.PolicySearchApp
-
seeAction Method
Displays the Action of the States on the console in Grid format (Policy)
- seeStateGrid() - Method in class policysearch.StateGrid
-
Displays the StateGrid with their respective States on the console
- seeUtil(ActionUtility[][]) - Static method in class policysearch.PolicySearchApp
-
seeUtil Method
Displays the Utility of the States on the console in List format
- seeUtilGrid(ActionUtility[][]) - Static method in class policysearch.PolicySearchApp
-
seeUtilGrid Method
Displays the Utility of the States on the console in Grid format
- seeUtilityIterationsPolicy() - Static method in class policysearch.PolicySearchApp
-
seeUtilityIterationsPolicy method
Displays the Number of Iterations and the estimated utilities of the State for the following state:
(0,0) (0,5) (1,5) (3,3) (4,5) for Policy Iteration
- seeUtilityIterationsValue() - Static method in class policysearch.PolicySearchApp
-
seeUtilityIterationsValue method
Displays the Number of Iterations and the estimated utilities of the State for the following state:
(0,0) (0,5) (1,5) (3,3) (4,5) for Value Iteration
- setAct(Action) - Method in class policysearch.ActionUtility
-
Set method for Action
- setType(StateType) - Method in class policysearch.State
-
Set method for type
- setUtil(double) - Method in class policysearch.ActionUtility
-
Set method for Utility
- State - Class in policysearch
-
State Class
Class that stores the information of the State in the Markovian Decision Process
- State(StateType) - Constructor for class policysearch.State
-
Class Constructor
- StateGrid - Class in policysearch
-
StateGrid Class
Class that stores the State Grid and the methods used to generate and display the State Grid of the object
- StateGrid(int, int) - Constructor for class policysearch.StateGrid
-
Class Constructor
Creates a new State in the grid with the default StateType White
- states - Variable in class policysearch.StateGrid
-
states[][]: The States in the StateGrid of the form SIZE*SIZE
- StateType - Enum in policysearch
-
StateType Enum
Enum that stores the StateType of the State.
- StateType(double, boolean, String) - Constructor for enum policysearch.StateType
-
Class constructor with parameters reward, wall and string
- string - Variable in enum policysearch.Action
-
string: A string that is shown when it is printed on the console
- string - Variable in enum policysearch.StateType
-


| Top |
ExampleCatExampleCat — Generated C code for the org.gtk.GDBus.Example.ObjectManager.Cat D-Bus interface |
| ExampleCat | |
| struct | ExampleCatIface |
| struct | ExampleCatProxy |
| struct | ExampleCatProxyClass |
| struct | ExampleCatSkeleton |
| struct | ExampleCatSkeletonClass |
GInterface ╰── ExampleCat GObject ├── GDBusInterfaceSkeleton │ ╰── ExampleCatSkeleton ╰── GDBusProxy ╰── ExampleCatProxy
ExampleCatProxy implements GDBusInterface, GInitable, GAsyncInitable and ExampleCat.
ExampleCatSkeleton implements GDBusInterface and ExampleCat.
This section contains code for working with the org.gtk.GDBus.Example.ObjectManager.Cat D-Bus interface in C.
GDBusInterfaceInfo *
example_cat_interface_info (void
);
Gets a machine-readable description of the org.gtk.GDBus.Example.ObjectManager.Cat D-Bus interface.
guint example_cat_override_properties (GObjectClass *klass
,guint property_id_begin
);
Overrides all GObject properties in the ExampleCat interface for a concrete class. The properties are overridden in the order they are defined.
klass |
The class structure for a GObject-derived class. |
|
property_id_begin |
The property id to assign to the first overridden property. |
void example_cat_proxy_new (GDBusConnection *connection
,GDBusProxyFlags flags
,const gchar *name
,const gchar *object_path
,GCancellable *cancellable
,GAsyncReadyCallback callback
,gpointer user_data
);
Asynchronously creates a proxy for the D-Bus interface org.gtk.GDBus.Example.ObjectManager.Cat. See g_dbus_proxy_new()
for more details.
When the operation is finished, callback
will be invoked in the thread-default main loop of the thread you are calling this method from.
You can then call example_cat_proxy_new_finish()
to get the result of the operation.
See example_cat_proxy_new_sync()
for the synchronous, blocking version of this constructor.
connection |
||
flags |
Flags from the GDBusProxyFlags enumeration. |
|
name |
A bus name (well-known or unique) or |
[allow-none] |
object_path |
An object path. |
|
cancellable |
A GCancellable or |
[allow-none] |
callback |
A GAsyncReadyCallback to call when the request is satisfied. |
|
user_data |
User data to pass to |
ExampleCat * example_cat_proxy_new_finish (GAsyncResult *res
,GError **error
);
Finishes an operation started with example_cat_proxy_new()
.
res |
The GAsyncResult obtained from the GAsyncReadyCallback passed to |
|
error |
Return location for error or |
ExampleCat * example_cat_proxy_new_sync (GDBusConnection *connection
,GDBusProxyFlags flags
,const gchar *name
,const gchar *object_path
,GCancellable *cancellable
,GError **error
);
Synchronously creates a proxy for the D-Bus interface org.gtk.GDBus.Example.ObjectManager.Cat. See g_dbus_proxy_new_sync()
for more details.
The calling thread is blocked until a reply is received.
See example_cat_proxy_new()
for the asynchronous version of this constructor.
connection |
||
flags |
Flags from the GDBusProxyFlags enumeration. |
|
name |
A bus name (well-known or unique) or |
[allow-none] |
object_path |
An object path. |
|
cancellable |
A GCancellable or |
[allow-none] |
error |
Return location for error or |
void example_cat_proxy_new_for_bus (GBusType bus_type
,GDBusProxyFlags flags
,const gchar *name
,const gchar *object_path
,GCancellable *cancellable
,GAsyncReadyCallback callback
,gpointer user_data
);
Like example_cat_proxy_new()
but takes a GBusType instead of a GDBusConnection.
When the operation is finished, callback
will be invoked in the thread-default main loop of the thread you are calling this method from.
You can then call example_cat_proxy_new_for_bus_finish()
to get the result of the operation.
See example_cat_proxy_new_for_bus_sync()
for the synchronous, blocking version of this constructor.
bus_type |
A GBusType. |
|
flags |
Flags from the GDBusProxyFlags enumeration. |
|
name |
A bus name (well-known or unique). |
|
object_path |
An object path. |
|
cancellable |
A GCancellable or |
[allow-none] |
callback |
A GAsyncReadyCallback to call when the request is satisfied. |
|
user_data |
User data to pass to |
ExampleCat * example_cat_proxy_new_for_bus_finish (GAsyncResult *res
,GError **error
);
Finishes an operation started with example_cat_proxy_new_for_bus()
.
res |
The GAsyncResult obtained from the GAsyncReadyCallback passed to |
|
error |
Return location for error or |
ExampleCat * example_cat_proxy_new_for_bus_sync (GBusType bus_type
,GDBusProxyFlags flags
,const gchar *name
,const gchar *object_path
,GCancellable *cancellable
,GError **error
);
Like example_cat_proxy_new_sync()
but takes a GBusType instead of a GDBusConnection.
The calling thread is blocked until a reply is received.
See example_cat_proxy_new_for_bus()
for the asynchronous version of this constructor.
bus_type |
A GBusType. |
|
flags |
Flags from the GDBusProxyFlags enumeration. |
|
name |
A bus name (well-known or unique). |
|
object_path |
An object path. |
|
cancellable |
A GCancellable or |
[allow-none] |
error |
Return location for error or |
ExampleCat *
example_cat_skeleton_new (void
);
Creates a skeleton object for the D-Bus interface org.gtk.GDBus.Example.ObjectManager.Cat.
typedef struct _ExampleCat ExampleCat;
Abstract interface type for the D-Bus interface org.gtk.GDBus.Example.ObjectManager.Cat.
struct ExampleCatIface { GTypeInterface parent_iface; };
Virtual table for the D-Bus interface org.gtk.GDBus.Example.ObjectManager.Cat.
struct ExampleCatProxy;
The ExampleCatProxy structure contains only private data and should only be accessed using the provided API.
struct ExampleCatProxyClass { GDBusProxyClass parent_class; };
Class structure for ExampleCatProxy.
struct ExampleCatSkeleton;
The ExampleCatSkeleton structure contains only private data and should only be accessed using the provided API.
struct ExampleCatSkeletonClass { GDBusInterfaceSkeletonClass parent_class; };
Class structure for ExampleCatSkeleton.


--- layout: doco title: "MicroView Arduino Library - MicroViewWidget Class Reference" category: API description: "MicroView Arduino Library Documentation" tags: [microview, library, functions, documentation] comments: true ---
Public Member Functions | |
| MicroViewWidget (uint8_t newx, uint8_t newy, int16_t min, int16_t max) | |
| MicroView widget parent class. More... | |
| uint8_t | getX () |
| Get widget x position. | |
| uint8_t | getY () |
| Get widget y position. | |
| void | setX (uint8_t newx) |
| Set widget x position. | |
| void | setY (uint8_t newy) |
| Set widget y position. | |
| int16_t | getMinValue () |
| Get minimum value. More... | |
| int16_t | getMaxValue () |
| Get maximum value. More... | |
| int16_t | getValue () |
| Get current value. More... | |
| void | setMinValue (int16_t min) |
| Set minimum value. More... | |
| void | setMaxValue (int16_t max) |
| Set maximum value. More... | |
| void | setValue (int16_t val) |
| Set current value and update widget. More... | |
| void | setValue (int16_t val, boolean doDraw) |
| Set current value with optional update. More... | |
| uint8_t | getValLen () |
| Get the print length of the value. More... | |
| uint8_t | getMaxValLen () |
| Get the maximum possible print length of the value. More... | |
| virtual void | draw () |
| Draw widget value overridden by child class. | |
| virtual void | drawFace () |
| Draw widget face overridden by child class. | |
| void | reDraw () |
| MicroView Widget reDraw routine. More... | |
| void | drawNumValue (int16_t value) |
| Draw a signed decimal numeric value at the current cursor location. More... | |
Protected Attributes | |
| uint8_t | posX |
| uint8_t | posY |
| int16_t | minValue |
| int16_t | maxValue |
| int16_t | value |
| uint8_t | valLen |
| uint8_t | maxValLen |
| MicroViewWidget::MicroViewWidget | ( | uint8_t | newx, |
| uint8_t | newy, | ||
| int16_t | min, | ||
| int16_t | max | ||
| ) |
MicroView widget parent class.
The MicroViewWidget class is the parent class for child widget like MicroViewSlider and MicroViewGauge.
| void MicroViewWidget::drawNumValue | ( | int16_t | value | ) |
Draw a signed decimal numeric value at the current cursor location.
The value is right justified with leading spaces, within a field the length of the maximum posible for the widget's value range.
| uint8_t MicroViewWidget::getMaxValLen | ( | ) |
Get the maximum possible print length of the value.
Return the maximum number of characters that would be printed using uView.print(value) for the current value range.
| int16_t MicroViewWidget::getMaxValue | ( | ) |
Get maximum value.
Return the maximum value of the widget.
| int16_t MicroViewWidget::getMinValue | ( | ) |
Get minimum value.
Return the minimum value of the widget.
| uint8_t MicroViewWidget::getValLen | ( | ) |
Get the print length of the value.
Return the number of characters that would be printed using uView.print(value) for the current value.
| int16_t MicroViewWidget::getValue | ( | ) |
Get current value.
Return the current value of the widget.
| void MicroViewWidget::reDraw | ( | ) |
MicroView Widget reDraw routine.
Redraws the widget.
| void MicroViewWidget::setMaxValue | ( | int16_t | max | ) |
Set maximum value.
The maximum value of the widget is set to the variable passed in.
| void MicroViewWidget::setMinValue | ( | int16_t | min | ) |
Set minimum value.
The minimum value of the widget is set to the variable passed in.
| void MicroViewWidget::setValue | ( | int16_t | val | ) |
Set current value and update widget.
The current value of the widget is set to the variable passed in and the widget is drawn with the new value.
| void MicroViewWidget::setValue | ( | int16_t | val, |
| boolean | doDraw | ||
| ) |
Set current value with optional update.
The current value of the widget is set to the variable passed in. The widget is drawn with the new value if the doDraw argument is true.


Args:
i_lowerColor: HSV values of the lower threshold used to identify the puck
i_upperColor: HSV values of the Upper threshold used to identify the puck
i_radius: Radius of the puck in pixels
i_camera: pointer to a concrete implementation of the abstract base class Camera
i_broadcaster : pointer to a concrete implementation of the abstract base class Broadcaster
Reimplemented from src.VisionPuckDetector.PuckDetectorCore.PuckDetectorCore.
◆ autoConfiguration()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.autoConfiguration |
( |
|
self | ) |
|
This method check the HSV value of the puck region and applies these values to the settings. This should be used
as a first step, before the user does fine tunning through the SetConfiguration() method.
◆ DisplayRadius()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.DisplayRadius |
( |
|
self | ) |
|
This method iterates until the camera fails or until the user is satisfied with the settings.
It displays the current frame with a circle of specified radius drawn on top of it.
This method is designed to be launched in a thread, while another thread changes
the configuration values (radius).
◆ getHSVOfPuck()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.getHSVOfPuck |
( |
|
self, |
|
|
|
i_frame |
|
) |
| |
Returns the average HSV values of the puck region
Args:
i_frame: The frame to analyse
Returns:
The average HSV values of the puck region
◆ GetHValue()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.GetHValue |
( |
|
self | ) |
|
Get the mid range value of the H value
Returns:
The mid range value of the H value
◆ GetSValue()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.GetSValue |
( |
|
self | ) |
|
Get the mid range value of the S value
Returns:
The mid range value of the S value
◆ GetVValue()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.GetVValue |
( |
|
self | ) |
|
Get the mid range value of the V value
Returns:
The mid range value of the V value
◆ setColorValue()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.setColorValue |
( |
|
self, |
|
|
|
i_value, |
|
|
|
i_color |
|
) |
| |
Sets the mid range value of one of the 3 HSV values
Args:
i_value: The new mid range value of the specified HSV value
i_color: Used to specify which HSV parameter should be changed
◆ SetConfiguration()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.SetConfiguration |
( |
|
self | ) |
|
This is the main method of the PuckDetectorConfiguration class. This method iterates until the camera fails or until
the user is satisfied with the settings. It displays the ProcessedFrame as calculated with the current
settings at every loop. This method is designed to be launched in a thread, while another thread changes
the configuration values (HSV values).
◆ SetHValue()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.SetHValue |
( |
|
self, |
|
|
|
i_value |
|
) |
| |
Sets the mid range value of the H value
Args:
i_value: The new mid range value of the H value
◆ SetRadiusValue()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.SetRadiusValue |
( |
|
self, |
|
|
|
i_radius |
|
) |
| |
Sets the value of the radius
Args:
i_radius: The new value of self.m_radius
◆ SetSValue()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.SetSValue |
( |
|
self, |
|
|
|
i_value |
|
) |
| |
Sets the mid range value of the S value
Args:
i_value: The new mid range value of the S value
◆ SetVValue()
| def src.VisionPuckDetector.PuckDetectorConfiguration.PuckDetectorConfiguration.SetVValue |
( |
|
self, |
|
|
|
i_value |
|
) |
| |
Sets the mid range value of the V value
Args:
i_value: The new mid range value of the V value
The documentation for this class was generated from the following file:
- D:/école/Université/UDES/Session 4/PROJET/HockusPockus/Vision/src/VisionPuckDetector/PuckDetectorConfiguration.py


SELENA A film review by Walter Frith Copyright 1997 Walter Frith
Jennifer Lopez gives a star making performance in the biopic 'Selena'. This energizing look at the life of a blossoming music superstar whose life ended in tragic fashion in 1995 at the hands of her fan club manager at a hotel in Corpus Christi, Texas is an in-depth, creative and fascinating look at a life based not only on talent and decication to one's craft but also to the bonds of family life which is so splendidly played out by the entire cast.
In 1987, 'La Bamba' starring Lou Diamond Phillips had a similar look as it too was the story of a Mexican-American music legend whose life ended too soon in a plane crash on February 3, 1959 that also took the lives of Buddy Holly and The Big Bopper. As well as documenting the final three years of Valens' life, that film characterized the rivalry between Valens and his older brother while 'Selena' chooses to focus on her family struggling and working hard as children from the time Selena is nine until her death at age twenty three.
Led by the belief of their father (Edward James Olmos) that they can make it big in show business, the family's other children aside from Selena learn to play musical instruments and are by Selena's side as she climbs the ladder of success. Lopez looks astonishingly similar to the real life Selena and the movie is an indication that her career can go far because of her dedication to this role.
Director/writer Gregory Nava ('El Norte') brings a hard edged and straight laced look to this film and makes Edward James Olmos as Selena's father the pillar of strength as his towering performance as the family's bonding elder is the best one in the film.
For movie lovers interested in knowing something about the life of this talented superstar, 'Selena' takes the time to also be a sweet, tender and caring film about family, success, disappointment and tragic circumstance juggled for a perfect balance.
OUT OF 5> * * *
The review above was posted to the
rec.arts.movies.reviews newsgroup (de.rec.film.kritiken for German reviews).
The Internet Movie Database accepts no responsibility for the contents of the
review and has no editorial control. Unless stated otherwise, the copyright
belongs to the author.
Please direct comments/criticisms of the review to relevant newsgroups.
Broken URLs inthe reviews are the responsibility of the author.
The formatting of the review is likely to differ from the original due
to ASCII to HTML conversion.
Related links: index of all rec.arts.movies.reviews reviews


Title: Streaming on Twitch
Description: A registered user wants to start a stream on their account.
Name and Role of Persona: Joesph Biggs, registered user
Preconditions: An account on Twitch, equipment needed to stream, and applications on his computer to stream with.
Postconditions: Registered user is streaming on his account.
Interaction Flow:


Navigation
My devBootcamp cohort is the SF Bobolinks of 2016. We started doing the bare essentials of Web development on July 11, 2016. This page is intended for my ongoing training in Web development. As you can see from this, I am going to be honest and admit that I know very little of Web page formatting. This page looks terrible, but we all have to start somewhere. Thank you for your visit and feel free to check the "Phase 0" section.
An amateur's analysis of the Business Insider web page:


About
I'm a Full-Stack Developer leveraging a background in entrepreneurial start-ups and hospitality to build a strong rapport between the technical aspect and client relations. I earned a certificate in Full Stack Development from the University of North Carolina- Charlotte, with newly developed skills in JavaScript, CSS, React.js and responsive web design. Known as a creative problem-solver passionate about developing apps, with a focus on mobile-first design and development.
For 25 years I've either worked for a spa as a licensed massage therapist and/or I've worked for myself owning a spa staffing company along with owning an antique event planning business and real estate brokerage. I love what I do, but I've always had an interest in the technical aspect that has grown into a passion.
Some may think, "Wow! What a drastic change!", but really it isn't. I decided to switch gears into software development because as a business owner and massage therapist, I have had to problem solve my client's issues and have had a creative and responsive approach depending on their needs and what the situation demanded.
More about what makes me tick is that I'm also detail and protocol oriented as an individual. As I looked at software development, I saw the similarities and dug a little deeper to understand that not only is this a good fit for me but it's been an underlying passion all along.


@import java.util.Date @(approveSessionInfo: UpdateApproveSessionInfo)
Hi,
A session is requested by @approveSessionInfo.email with following details
Please review session details and take the required action.


@Handle is too long
@Handle required
Email is too long
Email required
Password is too long
You must enter a password to sign up
Please confirm your password
Already have an account? Sign In


Cranial Osteopathy
Adults as well as children and babies can benefit from cranial treatment and it can be used alone or with a combination of other osteopathic techniques. Cranial osteopathy is a type of osteopathic treatment that encourages the release of stresses and strains in the body.
Although, often known as 'cranial osteopathy' as many of the techniques are performed on the face and head it is a technique that can be used anywhere on the body.
At Kane and Ross Clinics the experienced osteopaths have very finely developed sense of touch to feel subtle movements or stresses or stains in the body. During treatment patients feel relaxed and may feel a slight sensation of tissues moving or heat.
Patients often present at the clinic with the following symptoms:
- Back and neck pain
- Headaches
- Face pain and jaw problems
- Low back pain
- Complicated structural problems such as scoliosis
- Pain in pregnancy or post-natal
Babies often present at the clinic with the following symptoms:
- Colicky babies – wind, constipation, reflux
- Lactation problems – weak suckling or tongue tie
- Poor sleep
- Chronic coughs and colds
- Sinus problems
- Ear infections/glue ear
- Flat heads
- Sticky eyes


See: Description
| Package | Description |
|---|---|
| edu.richmond.adminsys.conduit | |
| edu.richmond.adminsys.conduit.monitors | |
| edu.richmond.adminsys.conduit.sinks | |
| edu.richmond.adminsys.conduit.sources |
Conduit is a Groovy application framework that performs data transformation jobs by reading data from data sources and writing them to data sinks. Data sources and data sinks send messages during this process that are collected by monitors. Data sources are classes that implement the ICSource interface. Data Sinks are classes that implement the ICSink interface. A class that implements the ICMessagePump interface collects events from the sources and sinks and distributes them to one or more monitors, which are classes that implement the ICMonitor interface.
Each transformation job is a single conduit and is described in an XML configuration file. A configuration file consists of a conduit root element with one source child node, one sink child node, and one or more monitor child nodes. When the Conduit application starts it looks for one or more XML configuration files and executes the jobs that they describe.
The Main class is the entry point for the application and is responsible for initializing the source, sink, and monitor components from the information in the XML configuration file and executing the data transformation job. It parses the XML configuration file for the conduit using the XMLSlurper parser and passes the configuration element for each component as a GPathResult object into its setUp method. It then instantiates the message pump and adds each monitor to the list of components that will receive events sent by the sources and sinks. After initializing the source, sink, and montiors it calls the get method from the source component to retrieve a list of rows representing the data from the source. It passes this list into the set method of the sink component which performs a transformation on the data and writes them to the data sink. When the transformation is complete, it calss the tearDown method for each source, sink, and monitor component.
Conduit expects the path of its XML configuration file to be passed as the first parameter on the command line:
java -jar Conduit.jar configuration.xml
Conduit will run through the transformation described in the XML configuration file and exit. If it does not detect an error during the transformation it will exit with a code of 0, otherwise it will exit with a code of -1.
If Conduit does not find any command line parameters it expects to run in batch mode. In batch mode, conduit looks for a file named conduits.xml on the path in which it was started. It expects this file to contain a root element named conduits with one or more child elements each named conduit. The text of each of these elements contains a path to a single XML configuration file. Conduit will load each configuration and process them in the order in which they appear in the file. Conduit will exit with code of 0 if it does not detect an error in any of the transformations, otherwise it will exit with a code of -1.


[gecode-users] Gecode 3.6.0 released
Guido Tack
tack at gecode.org
Fri Jul 15 08:12:47 CEST 2011
Dear all,
we are releasing a new version of Gecode:
Gecode 3.6.0
http://www.gecode.org
This release adds new constraints (value precedence constraints for integer and set variables, no-overlap constraints for rectangles, constraints for Hamiltonian paths), improves and cleans up a number of existing constraints (scheduling, channeling, relation, bin-packing, lexicographic relations), and adds new functionality (support for externalization of choices for distributed search, support for incremental propagation).
Some models might have to be changed as the graph and scheduling modules have been incorporated into the integer module (removing the respective include directives is sufficient).
On top, there are many small fixes, in particular for FlatZinc.
On our web site, you find source packages, binary packages for Windows and Mac OS, and the full documentation.
Cheers,
Guido
More information about the users
mailing list


Responsive gallery
Simple proof of concept for responsive image gallery that works regardless of the image size.


RobotOpenDS
Joy #1
Joy #2
Joy #3
Joy #4
Enable Robot
Connect
Spacebar to Disable
RobotOpen Dashboard
Network Latency
Robot Feedback
Name
Value
Type
Display
Waiting for connection...
Console/Debug
Robot Must Be Disabled To Update or Modify
Load from Robot
Commit All
Parameters
Name
Address
Type
Value
No parameters loaded
RobotOpen Setup
Your browser does not appear to support Gamepad API.
Joy #1
Joy #2
Joy #3
Joy #4
Robot
Joystick #1
No Joystick
Identifier
Mapped Button/Axis
Joystick #2
No Joystick
Identifier
Mapped Button/Axis
Joystick #3
No Joystick
Identifier
Mapped Button/Axis
Joystick #4
No Joystick
Identifier
Mapped Button/Axis
Robot Connection
IP Address
Port
No Joystick Enable


NOTE: This tutorial is under development. We will have it done shortly.
There's a lot more to making JavaScript apps than writing JavaScript. StealJS is a collection of command and browser based JavaScript utilities that make building, packaging, sharing, and consuming JavaScript applications easy.
This tutorial will cover building a basic tabs widget with only StealJS.
[javascriptmvc.com/builder.html Download StealJS] or install JavaScriptMVC and unzip it in a public folder.
Note: StealJS requires Java 1.6 or greater.
Steal organizes your application's content in an application folder. Generate an application.
In a page, add the script tag.
Load other scripts
This should be about steal.get. It should have someone install the steal'ed version of jQueryUI.
Our scripts are ugly, we can clean them ... or JS lint them ...
Covered in Searchable Ajax Apps


high-level, feature-rich, reliable
precise and concise
powerful
looks gorgeous on the screen
no fluff, just stuff
beautiful
open classes and meta-programming
no type or var declarations
freedom!


--- layout: post title: dinner taken with instagram date: '2011-03-18T01:02:22+08:00' tags: [] tumblr_url: http://blog.jln.co/post/3919759840/dinner-taken-with-instagram ---
Dinner (Taken with instagram)


Signing Up...
I agree to the User Agreement, and acknowledged the Privacy Policy
We sent a verification email to email_here.
Click the link in the email to verify your email.
If the email didn't arrive, please contact new.user@tnmservices.co.uk


OpenLayers 3 Examples
Simple example
Example of a simple map.
See the
simple.js source
to see how this is done.
simple, openstreetmap


## this is the skeleton of all pages on our site - it defines the basic structure with our menus, sidebars, etc.
## by naming this file with .htm, it can't be viewed directly (urls.py only allows full .html)
## set up a StaticRenderer object to enable the CSS/JS automatic inclusion magic.
<%! from base_app import static_files %>
<% static_renderer = static_files.StaticRenderer(self) %>
MyStuff Digital Life My Way
## global files
<%! from base_app import global_static %>
${ global_static.SITE_WIDE_CSS }
${ global_static.SITE_WIDE_JS }
## render the css
${ static_renderer.get_template_css(request, context) }
<%
from base_app.user_util import manager_check, employee_check
isEmployee = employee_check(request.user)
isManager = manager_check(request.user)
%>
<%block name="top">
%block>
<%block name="main">
Site content goes here in sub-templates.
%block>
<% %>
## render the JS for this page (placed here at the end because browsers apparently load faster when JS is at the end)
${ static_renderer.get_template_js(request, context) }


|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.yahoo.ycsb.Workload
public abstract class Workload
One experiment scenario. One object of this type will be instantiated and shared among all client threads. This class should be constructed using a no-argument constructor, so we can load it dynamically. Any argument-based initialization should be done by init(). If you extend this class, you should support the "insertstart" property. This allows the load phase to proceed from multiple clients on different machines, in case the client is the bottleneck. For example, if we want to load 1 million records from 2 machines, the first machine should have insertstart=0 and the second insertstart=500000. Additionally, the "insertcount" property, which is interpreted by Client, can be used to tell each instance of the client how many inserts to do. In the example above, both clients should have insertcount=500000.
| Field Summary | |
|---|---|
static java.lang.String |
INSERT_START_PROPERTY
|
static java.lang.String |
INSERT_START_PROPERTY_DEFAULT
|
| Constructor Summary | |
|---|---|
Workload()
|
| Method Summary | |
|---|---|
void |
cleanup()
Cleanup the scenario. |
abstract boolean |
doInsert(DataStore db,
java.lang.Object threadstate)
Do one insert operation. |
abstract boolean |
doTransaction(DataStore db,
java.lang.Object threadstate)
Do one transaction operation. |
void |
init(java.util.Properties p)
Initialize the scenario. |
java.lang.Object |
initThread(java.util.Properties p,
int mythreadid,
int threadcount)
Initialize any state for a particular client thread. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String INSERT_START_PROPERTY
public static final java.lang.String INSERT_START_PROPERTY_DEFAULT
| Constructor Detail |
|---|
public Workload()
| Method Detail |
|---|
public void init(java.util.Properties p) throws WorkloadException
WorkloadException
public java.lang.Object initThread(java.util.Properties p, int mythreadid, int threadcount) throws WorkloadException
WorkloadException
public void cleanup() throws WorkloadException
WorkloadException
public abstract boolean doInsert(DataStore db, java.lang.Object threadstate)
public abstract boolean doTransaction(DataStore db, java.lang.Object threadstate)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |


About Us
David
David graduated in 2015 with a B.S. in Chemistry and a B.A. in Biochemistry. Instead of pursuing a Ph.D., he decided to pursue a a career in the wild world of coding. When not coding, he enjoys vacations, playing guitar, brewing beer, video games, and fantasy football.
Erica
Erica's life is a weird dichotomy between the old and the modern. When she's not creating one of mankind's oldest pieces of technology, she spends a lot of time playing games of all different kinds. Also, there is no kind of pie that Erica does not like (except peach, which was awkward when she lived in the South.)
Logan
Heyo! When not watching anime or playing video games, you can probably find Logan cooking! Food is a passion of his, so finding good food to eat is a big deal! He's excited that we are able to contribute to Code Fellows in some way, and help people find the food they want to eat!
Val
A former Project Manager, Val has been working in tech since the 80s. Started out with a company that did CGI for the original Tron movie. Her next career will be about solving problems in Healthcare IT. Off hours are spent volunteer-working and raising a frenzied young hound dog. Food preferences: gluten-free, no shellfish, and extra cheese.