Skip to content

Commit

Permalink
Merge branch 'graph_improvment' into mkdocs-work
Browse files Browse the repository at this point in the history
  • Loading branch information
Vihtoriaaa authored Nov 30, 2023
2 parents 803f118 + f01c12f commit 230cdd0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 16 deletions.
1 change: 1 addition & 0 deletions private_gsd
Submodule private_gsd added at e64df3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
setup(
name="SynRD",
version="0.1",
python_requires='== 3.7.*', # Unfortunately, need specific python version for rpy2
python_requires='== 3.9.*', # Unfortunately, need specific python version for rpy2
description="Benchmark for differentially private synthetic data.",
long_description=long_description,
author="Lucas Rosenblatt",
Expand Down
2 changes: 1 addition & 1 deletion web/formatted_data.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"data": [[0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.6799999999999998, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 0.6399999999999999, 0.5999999999999999, 0.5999999999999999, 0.6399999999999999, 1.0, 1.0, 1.0, 1.0, 1.0]], "columns": ["iverson22football-0", "iverson22football-1", "iverson22football-2", "iverson22football-3", "iverson22football-4", "iverson22football-5", "iverson22football-6", "lee2021ability-0", "lee2021ability-1", "lee2021ability-2", "lee2021ability-3", "lee2021ability-4"], "index": ["privbayes - 0.37", "privbayes - 1.0"]}
{"data": [[0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.6799999999999998, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 0.6399999999999999, 0.5999999999999999, 0.5999999999999999, 0.6399999999999999, 1.0, 1.0, 1.0, 1.0, 1.0]], "columns": ["iverson22football-0", "iverson22football-1", "iverson22football-2", "iverson22football-3", "iverson22football-4", "iverson22football-5", "iverson22football-6", "lee2021ability-0", "lee2021ability-1", "lee2021ability-2", "lee2021ability-3", "lee2021ability-4"], "index": ["privbayes - 0.37", "privbayes - 1.0"], "findings": [["The sample was, on average, 38 years old<br>at the Wave V assessment.", "During the Wave V assessment, 307<br>(17.4%) men reported being diagnosed<br>with depression at some point in their<br>life, 275 (15.6%) being diagnosed with<br>an anxiety disorder or panic disorder at<br>some point in their life, 211 (12.0%)<br>having received psychological or<br>emotional counseling in the past 12<br>months, 125 (7.1%) reported seriously<br>thinking about suicide in the past year,<br>and 101 (5.8%) reported feeling<br>depressed in the previous week (i.e., \u201ca<br>lot of the time\u201d or \u201cmost of the time or<br>all of the time\u201d over the past 7 days).", "Examining responses the participants<br>gave during the Wave I assessment when<br>they were adolescents, 369 (20.9%)<br>reported playing (or intending to play)<br>football in high school and 952 (54.0%)<br>reported not intending to play football<br>in high school. Of note, 441<br>participants (25% of the sample) did not<br>answer this question and were excluded<br>from analyses pertaining to football<br>participation.", "During Wave I, there were 174 boys<br>(9.9%) who reported undergoing<br>psychological counseling in the past<br>year while in high school. During the<br>Wave V interview, ~24 years later, those<br>individuals who underwent psychological<br>counseling during adolescence were much<br>more likely to report (i) a lifetime<br>history of depression [37.4 vs. 15.3%,<br>\u03c72 ((11)) = 53.17, p &lt; 0.001, OR=<br>3.31, 95% CI = 2.37-4.64],", "(ii) a lifetime history of an anxiety<br>disorder or panic disorder [31.0 vs.<br>14.9%, \u03c72 ((11)) = 41.12, p &lt; 0.001,<br>OR= 2.61, 95% CI = 1.94-3.50],", "(iii) having received psychological<br>counseling in the past 12 months [31.0<br>vs. 12.0%, \u03c72 ((11)) = 36.00, p &lt;<br>0.001, OR= 2.70, 95% CI = 1.98-3.67],", "(iv) suicidal ideation in the past year<br>[12.6 vs. 6.4%, \u03c72(1) = 9.24 , 95%CI =<br>1.29\u20133.44], , p = 0.002, OR = 2.11", "As predicted, a negative correlation was<br>found between perceived low math teacher<br>support and 11thgrade math achievement<br>(r = -0.11).", "Ability self-concepts and parental<br>supportin 9th grade were positively<br>correlated with students'11th grade<br>achievement (r = 0.30 and r = 0.12<br>respectively).", "A strong positive correlation was found<br>between9th and 11th grade math<br>achievement (r = 0.74).", "perceived low math teacher support in<br>11th gradenegatively predicted students'<br>11th grade math achievement(B = -1.51, p<br>&lt; .001) while controlling for<br>students'demographics, 9th grade math<br>achievement score, and mathcourse.", "Second, as shown under Model 2, math<br>ability self-conceptspositively and<br>directly predicted 11th grade math<br>achievement(B = 2.51, p &lt; .001)."], ["The sample was, on average, 38 years old<br>at the Wave V assessment.", "During the Wave V assessment, 307<br>(17.4%) men reported being diagnosed<br>with depression at some point in their<br>life, 275 (15.6%) being diagnosed with<br>an anxiety disorder or panic disorder at<br>some point in their life, 211 (12.0%)<br>having received psychological or<br>emotional counseling in the past 12<br>months, 125 (7.1%) reported seriously<br>thinking about suicide in the past year,<br>and 101 (5.8%) reported feeling<br>depressed in the previous week (i.e., \u201ca<br>lot of the time\u201d or \u201cmost of the time or<br>all of the time\u201d over the past 7 days).", "Examining responses the participants<br>gave during the Wave I assessment when<br>they were adolescents, 369 (20.9%)<br>reported playing (or intending to play)<br>football in high school and 952 (54.0%)<br>reported not intending to play football<br>in high school. Of note, 441<br>participants (25% of the sample) did not<br>answer this question and were excluded<br>from analyses pertaining to football<br>participation.", "During Wave I, there were 174 boys<br>(9.9%) who reported undergoing<br>psychological counseling in the past<br>year while in high school. During the<br>Wave V interview, ~24 years later, those<br>individuals who underwent psychological<br>counseling during adolescence were much<br>more likely to report (i) a lifetime<br>history of depression [37.4 vs. 15.3%,<br>\u03c72 ((11)) = 53.17, p &lt; 0.001, OR=<br>3.31, 95% CI = 2.37-4.64],", "(ii) a lifetime history of an anxiety<br>disorder or panic disorder [31.0 vs.<br>14.9%, \u03c72 ((11)) = 41.12, p &lt; 0.001,<br>OR= 2.61, 95% CI = 1.94-3.50],", "(iii) having received psychological<br>counseling in the past 12 months [31.0<br>vs. 12.0%, \u03c72 ((11)) = 36.00, p &lt;<br>0.001, OR= 2.70, 95% CI = 1.98-3.67],", "(iv) suicidal ideation in the past year<br>[12.6 vs. 6.4%, \u03c72(1) = 9.24 , 95%CI =<br>1.29\u20133.44], , p = 0.002, OR = 2.11", "As predicted, a negative correlation was<br>found between perceived low math teacher<br>support and 11thgrade math achievement<br>(r = -0.11).", "Ability self-concepts and parental<br>supportin 9th grade were positively<br>correlated with students'11th grade<br>achievement (r = 0.30 and r = 0.12<br>respectively).", "A strong positive correlation was found<br>between9th and 11th grade math<br>achievement (r = 0.74).", "perceived low math teacher support in<br>11th gradenegatively predicted students'<br>11th grade math achievement(B = -1.51, p<br>&lt; .001) while controlling for<br>students'demographics, 9th grade math<br>achievement score, and mathcourse.", "Second, as shown under Model 2, math<br>ability self-conceptspositively and<br>directly predicted 11th grade math<br>achievement(B = 2.51, p &lt; .001)."]]}
22 changes: 14 additions & 8 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
fetch('formatted_data.json')
.then(response => response.json())
.then(data => {
console.log(data.columns.length)
console.log( Array.from({ length: data.columns.length }, (_, i) => i + 1))
// Prepare data for Plotly
const trace = {
z: data.data,
x: Array.from({ length: data.columns.length }, (_, i) => i + 1),
x: [data.columns.map(col => col.split('-')[0]), data.columns.map(col => parseInt(col.split('-')[1]) + 1)],
y: data.index,
type: 'heatmap',
hoverinfo: 'z+x+y',
colorscale: [[0, 'black'], [1, 'white']],
hovertext: data.findings,
hoverinfo: 'text',
colorscale: [[0, 'FD7900'], [1, '80FB35']],
showscale: true,
xgap: 1,
ygap: 1,
Expand Down Expand Up @@ -58,11 +61,14 @@
// Layout configuration
const layout = {
title: 'Epistemic Parity',
xaxis: {
tickvals: Array.from({ length: data.columns.length }, (_, i) => i),
ticktext: Array.from({ length: data.columns.length }, (_, i) => i + 1),
},
annotations: annotations,
yaxis:{
tickangle:270
}
// xaxis: {
// tickvals: Array.from({ length: data.columns.length }, (_, i) => i),
// ticktext: Array.from({ length: data.columns.length }, (_, i) => i + 1),
// },
// annotations: annotations,
};

const config = {
Expand Down
45 changes: 39 additions & 6 deletions web/preprocess.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 27,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'iverson22football': <class 'SynRD.papers.iverson22football.Iverson22Football'>, 'lee2021ability': <class 'SynRD.papers.lee2021ability.Lee2021Ability'>}\n",
"Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dtype='int64')\n",
"Index([12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], dtype='int64')\n",
"{'data': [[0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.6799999999999998, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 0.6399999999999999, 0.5999999999999999, 0.5999999999999999, 0.6399999999999999, 1.0, 1.0, 1.0, 1.0, 1.0]], 'columns': ['iverson22football-0', 'iverson22football-1', 'iverson22football-2', 'iverson22football-3', 'iverson22football-4', 'iverson22football-5', 'iverson22football-6', 'lee2021ability-0', 'lee2021ability-1', 'lee2021ability-2', 'lee2021ability-3', 'lee2021ability-4'], 'index': ['privbayes - 0.37', 'privbayes - 1.0'], 'findings': [['The sample was, on average, 38 years old<br>at the Wave V assessment.', 'During the Wave V assessment, 307<br>(17.4%) men reported being diagnosed<br>with depression at some point in their<br>life, 275 (15.6%) being diagnosed with<br>an anxiety disorder or panic disorder at<br>some point in their life, 211 (12.0%)<br>having received psychological or<br>emotional counseling in the past 12<br>months, 125 (7.1%) reported seriously<br>thinking about suicide in the past year,<br>and 101 (5.8%) reported feeling<br>depressed in the previous week (i.e., “a<br>lot of the time” or “most of the time or<br>all of the time” over the past 7 days).', 'Examining responses the participants<br>gave during the Wave I assessment when<br>they were adolescents, 369 (20.9%)<br>reported playing (or intending to play)<br>football in high school and 952 (54.0%)<br>reported not intending to play football<br>in high school. Of note, 441<br>participants (25% of the sample) did not<br>answer this question and were excluded<br>from analyses pertaining to football<br>participation.', 'During Wave I, there were 174 boys<br>(9.9%) who reported undergoing<br>psychological counseling in the past<br>year while in high school. During the<br>Wave V interview, ~24 years later, those<br>individuals who underwent psychological<br>counseling during adolescence were much<br>more likely to report (i) a lifetime<br>history of depression [37.4 vs. 15.3%,<br>χ2 ((11)) = 53.17, p &lt; 0.001, OR=<br>3.31, 95% CI = 2.37-4.64],', '(ii) a lifetime history of an anxiety<br>disorder or panic disorder [31.0 vs.<br>14.9%, χ2 ((11)) = 41.12, p &lt; 0.001,<br>OR= 2.61, 95% CI = 1.94-3.50],', '(iii) having received psychological<br>counseling in the past 12 months [31.0<br>vs. 12.0%, χ2 ((11)) = 36.00, p &lt;<br>0.001, OR= 2.70, 95% CI = 1.98-3.67],', '(iv) suicidal ideation in the past year<br>[12.6 vs. 6.4%, χ2(1) = 9.24 , 95%CI =<br>1.29–3.44], , p = 0.002, OR = 2.11', 'As predicted, a negative correlation was<br>found between perceived low math teacher<br>support and 11thgrade math achievement<br>(r = -0.11).', \"Ability self-concepts and parental<br>supportin 9th grade were positively<br>correlated with students'11th grade<br>achievement (r = 0.30 and r = 0.12<br>respectively).\", 'A strong positive correlation was found<br>between9th and 11th grade math<br>achievement (r = 0.74).', \"perceived low math teacher support in<br>11th gradenegatively predicted students'<br>11th grade math achievement(B = -1.51, p<br>&lt; .001) while controlling for<br>students'demographics, 9th grade math<br>achievement score, and mathcourse.\", 'Second, as shown under Model 2, math<br>ability self-conceptspositively and<br>directly predicted 11th grade math<br>achievement(B = 2.51, p &lt; .001).'], ['The sample was, on average, 38 years old<br>at the Wave V assessment.', 'During the Wave V assessment, 307<br>(17.4%) men reported being diagnosed<br>with depression at some point in their<br>life, 275 (15.6%) being diagnosed with<br>an anxiety disorder or panic disorder at<br>some point in their life, 211 (12.0%)<br>having received psychological or<br>emotional counseling in the past 12<br>months, 125 (7.1%) reported seriously<br>thinking about suicide in the past year,<br>and 101 (5.8%) reported feeling<br>depressed in the previous week (i.e., “a<br>lot of the time” or “most of the time or<br>all of the time” over the past 7 days).', 'Examining responses the participants<br>gave during the Wave I assessment when<br>they were adolescents, 369 (20.9%)<br>reported playing (or intending to play)<br>football in high school and 952 (54.0%)<br>reported not intending to play football<br>in high school. Of note, 441<br>participants (25% of the sample) did not<br>answer this question and were excluded<br>from analyses pertaining to football<br>participation.', 'During Wave I, there were 174 boys<br>(9.9%) who reported undergoing<br>psychological counseling in the past<br>year while in high school. During the<br>Wave V interview, ~24 years later, those<br>individuals who underwent psychological<br>counseling during adolescence were much<br>more likely to report (i) a lifetime<br>history of depression [37.4 vs. 15.3%,<br>χ2 ((11)) = 53.17, p &lt; 0.001, OR=<br>3.31, 95% CI = 2.37-4.64],', '(ii) a lifetime history of an anxiety<br>disorder or panic disorder [31.0 vs.<br>14.9%, χ2 ((11)) = 41.12, p &lt; 0.001,<br>OR= 2.61, 95% CI = 1.94-3.50],', '(iii) having received psychological<br>counseling in the past 12 months [31.0<br>vs. 12.0%, χ2 ((11)) = 36.00, p &lt;<br>0.001, OR= 2.70, 95% CI = 1.98-3.67],', '(iv) suicidal ideation in the past year<br>[12.6 vs. 6.4%, χ2(1) = 9.24 , 95%CI =<br>1.29–3.44], , p = 0.002, OR = 2.11', 'As predicted, a negative correlation was<br>found between perceived low math teacher<br>support and 11thgrade math achievement<br>(r = -0.11).', \"Ability self-concepts and parental<br>supportin 9th grade were positively<br>correlated with students'11th grade<br>achievement (r = 0.30 and r = 0.12<br>respectively).\", 'A strong positive correlation was found<br>between9th and 11th grade math<br>achievement (r = 0.74).', \"perceived low math teacher support in<br>11th gradenegatively predicted students'<br>11th grade math achievement(B = -1.51, p<br>&lt; .001) while controlling for<br>students'demographics, 9th grade math<br>achievement score, and mathcourse.\", 'Second, as shown under Model 2, math<br>ability self-conceptspositively and<br>directly predicted 11th grade math<br>achievement(B = 2.51, p &lt; .001).']]}\n"
]
}
],
"source": [
"import pandas as pd\n",
"import json\n",
"from SynRD.papers import Iverson22Football, Lee2021Ability\n",
"import pandas as pd\n",
"import textwrap\n",
"\n",
"# needed to create the instance of publication class\n",
"silly_df = pd.DataFrame.from_dict({\"silly\":[1]})\n",
"\n",
"names_to_papers = {Iverson22Football.DEFAULT_PAPER_ATTRIBUTES['id']:Iverson22Football,\n",
" Lee2021Ability.DEFAULT_PAPER_ATTRIBUTES['id']: Lee2021Ability}\n",
"\n",
"df = pd.read_csv('data.csv')\n",
"\n",
Expand All @@ -17,23 +37,36 @@
"data = []\n",
"columns = []\n",
"index = []\n",
"findings = []\n",
"\n",
"# wrap hovertext function, a line has at most width characters long.\n",
"def wrap_hovertext(hovertext, width=40):\n",
" wrapped_hovertext = [\"<br>\".join(textwrap.wrap(text,width=width)) for text in hovertext]\n",
" return wrapped_hovertext\n",
"\n",
"for (synthesizer, epsilon), group in grouped:\n",
" # sort based on 'paper' and 'finding_number'\n",
" group = group.sort_values(['paper', 'finding_number'])\n",
" \n",
" if not columns:\n",
" columns = list(group['paper'] + '-' + group['finding_number'].astype(str))\n",
" \n",
" findings_in_group = []\n",
" for i in group.index:\n",
" paper_name = group['paper'][i]\n",
" paper_class=names_to_papers[paper_name]\n",
" finding = paper_class(silly_df).FINDINGS[group['finding_number'][i]].text.replace('\\n', ' ').replace(2*' ',\"\")\n",
" findings_in_group.append(finding)\n",
"\n",
" findings.append(wrap_hovertext(findings_in_group))\n",
" index.append(f\"{synthesizer} - {epsilon}\")\n",
" data.append(group['parity'].tolist())\n",
"\n",
"result = {\n",
" 'data': data,\n",
" 'columns': columns,\n",
" 'index': index\n",
" 'index': index,\n",
" 'findings': findings\n",
"}\n",
"\n",
"with open('formatted_data.json', 'w') as f:\n",
" json.dump(result, f)"
]
Expand Down Expand Up @@ -294,7 +327,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.16"
"version": "3.9.18"
},
"orig_nbformat": 4,
"vscode": {
Expand Down

0 comments on commit 230cdd0

Please sign in to comment.