Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasPhilippi committed Oct 14, 2021
1 parent 6deb7e2 commit d309169
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ The installation requires the following dependencies:
- numpy==1.18.2
- scipy==1.4.1
- pandas==1.1.4
- statsmodels==0.12.1
- statsmodels==0.11.1
- scikit-learn==0.23.0
- tensorflow==2.1.0
- keras==2.3.1
- tensorflow==2.4.1
- pulp==2.0
- lightgbm==2.3.1
- mpmath

Note: The package is actively developed and conflicts with other packages may occur during
installation. To avoid any installation conflicts we therefore recommend to install the
Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/tutorial_modules/tutorial.ipynb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"id": "NCdRffbpKh_C"
},
"source": [
"pip install ddop==0.7.4 seaborn==0.11.0 matplotlib"
"pip install ddop==0.7.5 seaborn==0.11.0 matplotlib"
],
"execution_count": null,
"outputs": []
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial_modules/tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h2>Getting started<a class="headerlink" href="#Getting-started" title="Permalin
</pre></div>
</div>
<div class="input_area highlight-none notranslate"><div class="highlight"><pre>
<span></span>pip install ddop==0.7.4 seaborn==0.11.0 matplotlib
<span></span>pip install ddop==0.7.5 seaborn==0.11.0 matplotlib
</pre></div>
</div>
</div>
Expand Down Expand Up @@ -2362,7 +2362,7 @@ <h3>Weighted Sample Average Approximation<a class="headerlink" href="#Weighted-S
</tbody>
</table>
<p>First, we train a regression tree to predict the demand given the features weekend and temperature. The resulting tree looks like this:</p>
<p><img alt="c6ed14b033e44fd2969ad3bdc48897ec" class="no-scaled-link" src="https://drive.google.com/uc?export=view&amp;id=1fXW6PV2bUcnZSNByTde39k8hEgRB_5aV" style="width: 450px;" /></p>
<p><img alt="fe4bec31f74940fda04370bebcc8b744" class="no-scaled-link" src="https://drive.google.com/uc?export=view&amp;id=1fXW6PV2bUcnZSNByTde39k8hEgRB_5aV" style="width: 450px;" /></p>
<p>The regression tree splits our data into four leafs based on the two features. To determine the sample weights, we look to which leaf the new instance <span class="math notranslate nohighlight">\(x=(0,18)\)</span> belongs. In the first level of the tree we follow the left path since it is no weekend. Then, given the temperature forecast of <span class="math notranslate nohighlight">\(18°C\)</span>, we end up in leaf 1 together with sample 1, 6, 7. This means that these observations are most similar to <span class="math notranslate nohighlight">\(x\)</span>. Using this information, we assign a weight of <span class="math notranslate nohighlight">\(\frac{1}{3}\)</span> to each
of the three samples falling into the same leaf. The sample weights are then given by:</p>
<p><span class="math">\begin{equation}
Expand Down Expand Up @@ -2498,7 +2498,7 @@ <h4>Linear Regression<a class="headerlink" href="#Linear-Regression" title="Perm
</table>
<p>We plot the data and it looks like there is a linear relationship between temperature and demand (see figure below). Consequently, to solve our problem the first thing that comes into mind is linear regression. For this reason, we construct a linear function <span class="math notranslate nohighlight">\(q(x)=b+w*x\)</span>, where <span class="math notranslate nohighlight">\(b\)</span> is the intercept term, and <span class="math notranslate nohighlight">\(w\)</span> is a weight. We can think of the intercept as a base demand to which we add or subtract a certain amount depending on the temperature <span class="math notranslate nohighlight">\(x\)</span> and weight <span class="math notranslate nohighlight">\(w\)</span>. To
find the optimal mapping from temperature to demand, we now have to learn the best fitting values for <span class="math notranslate nohighlight">\(b\)</span> and <span class="math notranslate nohighlight">\(w\)</span>. We start by setting <span class="math notranslate nohighlight">\(b=16\)</span> and <span class="math notranslate nohighlight">\(w=-0,4\)</span>, which gives us function <span class="math notranslate nohighlight">\(q(x)=16-0,4*x\)</span> that already fits the data quite well. Still, for each sample <span class="math notranslate nohighlight">\(i\)</span> we obtain an error representing the difference between the actual demand <span class="math notranslate nohighlight">\(d_i\)</span> and the estimated decision of <span class="math notranslate nohighlight">\(q(x_i)\)</span>. In the figure below these errors are illustrated as dotted lines.</p>
<p><img alt="be8492a841874ced871aef4cd8b3e7dc" class="no-scaled-link" src="https://drive.google.com/uc?export=view&amp;id=1IbPX_WRmSURbEypcyYdwwcvSo7aUjfDZ" style="width: 600px;" /></p>
<p><img alt="779bf542e42a4eeba9739eef021ca6a5" class="no-scaled-link" src="https://drive.google.com/uc?export=view&amp;id=1IbPX_WRmSURbEypcyYdwwcvSo7aUjfDZ" style="width: 600px;" /></p>
<p>According to linear regression, the goal would be to adjust the values for <span class="math notranslate nohighlight">\(b\)</span> and <span class="math notranslate nohighlight">\(w\)</span> in a way that minimizes the mean difference (error) between the actual demand and the estimated decision. Formally speaking: <span class="math">\begin{equation}
\min_{b,w} \frac{1}{n}\sum_{i=1}^{n}\bigl\vert d_i-(b+w*x)\bigl\vert
\end{equation}</span></p>
Expand Down Expand Up @@ -2633,7 +2633,7 @@ <h4>Linear Regression<a class="headerlink" href="#Linear-Regression" title="Perm
<section id="Deep-Learning">
<h4>Deep Learning<a class="headerlink" href="#Deep-Learning" title="Permalink to this headline"></a></h4>
<p>In the previous section, we assumed that the demand is a linear combination of features. To find the perfect mapping from features <span class="math notranslate nohighlight">\(x\)</span> to decision <span class="math notranslate nohighlight">\(q\)</span> we therefore specified that <span class="math notranslate nohighlight">\(q(\cdot)\)</span> belongs to the class of linear decision functions. However, sometimes there is no linear relationship, so we need a nonlinear function to describe our data. One way to obtain such a function is by using a deep neural network (DNN).</p>
<p><img alt="136a6046ace044b39766e882aad0e0ff" src="https://drive.google.com/uc?export=view&amp;id=1rmgdo9urd4Qx5MQrPu4sO9sto8_ogCm1" /></p>
<p><img alt="d10b8cc0b0ff4ad8b6344ad61fa619d7" src="https://drive.google.com/uc?export=view&amp;id=1rmgdo9urd4Qx5MQrPu4sO9sto8_ogCm1" /></p>
<p>A DNN uses a cascade of many layers to obtain an output given some input data. In general, it can be distinguished between input-, hidden-, and output-layer, each consisting of a number of neurons. In the first layer the number of neurons corresponds to the number of inputs. In other words, each neuron takes the value of a single feature as input, e.g. the temperature or the weekday. The input-layer is followed by a number of hidden-layers, each presented by an arbitrary number of neurons. In
the output-layer the number of neurons corresponds to the number of outputs. In our example, we only have a single neuron that outputs the decision <span class="math notranslate nohighlight">\(q\)</span> conditional on the features temperature and weekday. The individual neurons of a layer are each connected to the neurons of the layer before and behind. In a graph, the neurons can be represented as nodes and their connections as weighted edges. A neuron takes the outputs of the neurons from the previous layer as inputs. Subsequently, it
computes the weighted sum of its inputs and adds a bias to it. Formally speaking:</p>
Expand All @@ -2643,7 +2643,7 @@ <h4>Deep Learning<a class="headerlink" href="#Deep-Learning" title="Permalink to
\end{equation}</span></p>
<p>where <span class="math notranslate nohighlight">\(x_l\)</span> is the <span class="math notranslate nohighlight">\(l\)</span>-th input of a neuron and <span class="math notranslate nohighlight">\(w_l\)</span> the corresponding weight. Does this look familiar? This is the exactly the decision function <span class="math notranslate nohighlight">\((7)\)</span> that we used in the regression based approach before. The only difference is that we use the term “bias” for the constant value instead of “intercept”. But what does this mean? If we were just to combine a set of linear functions, we would get a single linear function as a result. In other words, there would be no
difference to the previous approach. This is where the activation function comes into play. The activation function is a non-linear function that transforms the computed value of equation (9) and then outputs the final result of a neuron. For example, the Rectified Linear Unit (ReLU) activation function outputs <span class="math notranslate nohighlight">\(0\)</span> if the input value is negative and its input otherwise. Thus, the DNN models a piecewise linear function, which may looks like this:</p>
<p><img alt="05bc90dd2ce24683bcdc8ca62b605803" class="no-scaled-link" src="https://drive.google.com/uc?export=view&amp;id=18YRxB6jYlqV97FaEPXf-IcRuJt1nWkWI" style="width: 350px;" /></p>
<p><img alt="b1c1d6c73b474bae995b7c66911d6964" class="no-scaled-link" src="https://drive.google.com/uc?export=view&amp;id=18YRxB6jYlqV97FaEPXf-IcRuJt1nWkWI" style="width: 350px;" /></p>
<p>The goal of the network is then to find the function that fits the data best. To find such a function in the linear regression based model, we had to determine the optimal values for the feature weights and the intercept term. This is basically the same here. We just have a lot more weights and intercept terms (biases). Since we are trying to obtain cost-optimal decisions, the network tries to determine the unknown parameters in a way that minimizes the average costs on our data. Thus, the
problem can be stated as follows:</p>
<p><span class="math">\begin{equation}
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial_modules/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"outputs": [],
"source": [
"pip install ddop==0.7.4 seaborn==0.11.0 matplotlib"
"pip install ddop==0.7.5 seaborn==0.11.0 matplotlib"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docsrc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The installation requires the following dependencies:
- numpy==1.18.2
- scipy==1.4.1
- pandas==1.1.4
- statsmodels==0.12.1
- statsmodels==0.11.1
- scikit-learn==0.23.0
- tensorflow==2.4.1
- pulp==2.0
Expand Down
2 changes: 1 addition & 1 deletion docsrc/tutorial_modules/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"id": "NCdRffbpKh_C"
},
"source": [
"pip install ddop==0.7.4 seaborn==0.11.0 matplotlib"
"pip install ddop==0.7.5 seaborn==0.11.0 matplotlib"
],
"execution_count": null,
"outputs": []
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='ddop',
version='v0.7.4',
version='v0.7.5',
url='https://andreasphilippi.github.io/ddop/',
license='MIT',
author='Andreas Philippi',
Expand Down

0 comments on commit d309169

Please sign in to comment.