Skip to content

Commit

Permalink
code updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasgerstenberg committed Jun 9, 2024
1 parent a7b82c7 commit 06466f4
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 409 deletions.
259 changes: 127 additions & 132 deletions code/R/experiments/Experiment.Rmd

Large diffs are not rendered by default.

252 changes: 126 additions & 126 deletions code/R/experiments/Experiment.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ write.csv(df.prediction_explanation_truth_only, file = "../../../data/model/expl
```



# Session info

```{r, echo=F}
Expand Down
24 changes: 12 additions & 12 deletions code/R/optimal_intervention_model/optimal_intervention_model.html
Original file line number Diff line number Diff line change
Expand Up @@ -1591,12 +1591,12 @@ <h1><span class="header-section-number">3</span> Functions</h1>
<div id="data" class="section level1" number="4">
<h1><span class="header-section-number">4</span> DATA</h1>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a>df.data <span class="ot">=</span> <span class="fu">bind_rows</span>(</span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/hardint_pos.csv&quot;</span>),</span>
<span id="cb4-3"><a href="#cb4-3" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/hardint_neg.csv&quot;</span>),</span>
<span id="cb4-4"><a href="#cb4-4" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/softint_pos.csv&quot;</span>),</span>
<span id="cb4-5"><a href="#cb4-5" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/softint_neg.csv&quot;</span>),</span>
<span id="cb4-6"><a href="#cb4-6" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/fixedint_pos.csv&quot;</span>),</span>
<span id="cb4-7"><a href="#cb4-7" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/fixedint_neg.csv&quot;</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/aggregate/hardint_pos.csv&quot;</span>),</span>
<span id="cb4-3"><a href="#cb4-3" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/aggregate/hardint_neg.csv&quot;</span>),</span>
<span id="cb4-4"><a href="#cb4-4" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/aggregate/softint_pos.csv&quot;</span>),</span>
<span id="cb4-5"><a href="#cb4-5" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/aggregate/softint_neg.csv&quot;</span>),</span>
<span id="cb4-6"><a href="#cb4-6" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/aggregate/fixedint_pos.csv&quot;</span>),</span>
<span id="cb4-7"><a href="#cb4-7" tabindex="-1"></a> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">&quot;../../../data/aggregate/fixedint_neg.csv&quot;</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb4-8"><a href="#cb4-8" tabindex="-1"></a> <span class="fu">clean_names</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb4-9"><a href="#cb4-9" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">causal_structure =</span> <span class="fu">str_to_lower</span>(causal_structure),</span>
<span id="cb4-10"><a href="#cb4-10" tabindex="-1"></a> <span class="at">experiment =</span> <span class="fu">str_remove</span>(experiment, <span class="st">&quot;int&quot;</span>)) <span class="sc">%&gt;%</span> </span>
Expand Down Expand Up @@ -1728,10 +1728,10 @@ <h3><span class="header-section-number">5.1.3</span> Fit softmax parameter</h3>
<span id="cb8-9"><a href="#cb8-9" tabindex="-1"></a> <span class="fu">pull</span>(loss)</span>
<span id="cb8-10"><a href="#cb8-10" tabindex="-1"></a>}</span>
<span id="cb8-11"><a href="#cb8-11" tabindex="-1"></a></span>
<span id="cb8-12"><a href="#cb8-12" tabindex="-1"></a>fit.temperature <span class="ot">=</span> <span class="fu">optim</span>(<span class="at">par =</span> <span class="dv">10</span>, </span>
<span id="cb8-12"><a href="#cb8-12" tabindex="-1"></a>fit.temperature <span class="ot">=</span> <span class="fu">optim</span>(<span class="at">par =</span> <span class="dv">10</span>,</span>
<span id="cb8-13"><a href="#cb8-13" tabindex="-1"></a> <span class="at">fn =</span> fun.fit_temperature,</span>
<span id="cb8-14"><a href="#cb8-14" tabindex="-1"></a> <span class="at">method =</span> <span class="st">&quot;L-BFGS-B&quot;</span>,</span>
<span id="cb8-15"><a href="#cb8-15" tabindex="-1"></a> <span class="at">lower =</span> <span class="dv">0</span>, </span>
<span id="cb8-15"><a href="#cb8-15" tabindex="-1"></a> <span class="at">lower =</span> <span class="dv">0</span>,</span>
<span id="cb8-16"><a href="#cb8-16" tabindex="-1"></a> <span class="at">upper =</span> <span class="dv">100</span>,</span>
<span id="cb8-17"><a href="#cb8-17" tabindex="-1"></a> <span class="at">df_data =</span> df.intervention,</span>
<span id="cb8-18"><a href="#cb8-18" tabindex="-1"></a> <span class="at">df_prediction =</span> df.choice)</span>
Expand Down Expand Up @@ -1874,8 +1874,8 @@ <h4><span class="header-section-number">5.2.4.1</span> Combined model</h4>
<span id="cb21-3"><a href="#cb21-3" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">prediction =</span> <span class="fu">fun.softmax</span>(fit.params<span class="sc">$</span>par[<span class="dv">1</span>] <span class="sc">*</span> value <span class="sc">+</span> (<span class="dv">1</span> <span class="sc">-</span> fit.params<span class="sc">$</span>par[<span class="dv">1</span>]) <span class="sc">*</span> truth, <span class="at">temp =</span> fit.params<span class="sc">$</span>par[<span class="dv">2</span>])) <span class="sc">%&gt;%</span></span>
<span id="cb21-4"><a href="#cb21-4" tabindex="-1"></a> <span class="fu">ungroup</span>()</span>
<span id="cb21-5"><a href="#cb21-5" tabindex="-1"></a></span>
<span id="cb21-6"><a href="#cb21-6" tabindex="-1"></a><span class="co"># write.csv(df.prediction_explanation, file = &quot;explanation_predictions.csv&quot;, row.names = FALSE)</span></span>
<span id="cb21-7"><a href="#cb21-7" tabindex="-1"></a><span class="co"># write.csv(df.prediction_intervention, file = &quot;intervention_predictions.csv&quot;, row.names = FALSE)</span></span></code></pre></div>
<span id="cb21-6"><a href="#cb21-6" tabindex="-1"></a><span class="fu">write.csv</span>(df.prediction_explanation, <span class="at">file =</span> <span class="st">&quot;../../../data/model/explanation_predictions.csv&quot;</span>, <span class="at">row.names =</span> <span class="cn">FALSE</span>)</span>
<span id="cb21-7"><a href="#cb21-7" tabindex="-1"></a><span class="fu">write.csv</span>(df.prediction_intervention, <span class="at">file =</span> <span class="st">&quot;../../../data/model/intervention_predictions.csv&quot;</span>, <span class="at">row.names =</span> <span class="cn">FALSE</span>)</span></code></pre></div>
</div>
<div id="intervention-only-model-2" class="section level4" number="5.2.4.2">
<h4><span class="header-section-number">5.2.4.2</span> Intervention only model</h4>
Expand All @@ -1884,7 +1884,7 @@ <h4><span class="header-section-number">5.2.4.2</span> Intervention only model</
<span id="cb22-3"><a href="#cb22-3" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">prediction =</span> <span class="fu">fun.softmax</span>(value, <span class="at">temp =</span> fit.params_intervention_only<span class="sc">$</span>par[<span class="dv">1</span>])) <span class="sc">%&gt;%</span></span>
<span id="cb22-4"><a href="#cb22-4" tabindex="-1"></a> <span class="fu">ungroup</span>()</span>
<span id="cb22-5"><a href="#cb22-5" tabindex="-1"></a></span>
<span id="cb22-6"><a href="#cb22-6" tabindex="-1"></a><span class="co"># write.csv(df.prediction_explanation_intervention_only, file = &quot;explanation_predictions_intervention_only.csv&quot;, row.names = FALSE)</span></span></code></pre></div>
<span id="cb22-6"><a href="#cb22-6" tabindex="-1"></a><span class="fu">write.csv</span>(df.prediction_explanation_intervention_only, <span class="at">file =</span> <span class="st">&quot;../../../data/model/explanation_predictions_intervention_only.csv&quot;</span>, <span class="at">row.names =</span> <span class="cn">FALSE</span>)</span></code></pre></div>
</div>
<div id="truth-only-model-2" class="section level4" number="5.2.4.3">
<h4><span class="header-section-number">5.2.4.3</span> Truth only model</h4>
Expand All @@ -1893,7 +1893,7 @@ <h4><span class="header-section-number">5.2.4.3</span> Truth only model</h4>
<span id="cb23-3"><a href="#cb23-3" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">prediction =</span> <span class="fu">fun.softmax</span>(truth, <span class="at">temp =</span> fit.params_truth_only<span class="sc">$</span>par[<span class="dv">1</span>])) <span class="sc">%&gt;%</span></span>
<span id="cb23-4"><a href="#cb23-4" tabindex="-1"></a> <span class="fu">ungroup</span>()</span>
<span id="cb23-5"><a href="#cb23-5" tabindex="-1"></a></span>
<span id="cb23-6"><a href="#cb23-6" tabindex="-1"></a><span class="co"># write.csv(df.prediction_explanation_truth_only, file = &quot;explanation_predictions_truth_only.csv&quot;, row.names = FALSE)</span></span></code></pre></div>
<span id="cb23-6"><a href="#cb23-6" tabindex="-1"></a><span class="fu">write.csv</span>(df.prediction_explanation_truth_only, <span class="at">file =</span> <span class="st">&quot;../../../data/model/explanation_predictions_truth_only.csv&quot;</span>, <span class="at">row.names =</span> <span class="cn">FALSE</span>)</span></code></pre></div>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 06466f4

Please sign in to comment.