-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add tutorial on obtaining information about distributiosn
- Loading branch information
1 parent
58f5bd6
commit cb669f1
Showing
10 changed files
with
390 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"# Analysing Distributions\n", | ||
"\n", | ||
"The equation tree can be used to extract information from existing distributions of equations (e.g., for example by scraping priors: https://autoresearch.github.io/equation-scraper/tutorials/equation_scraper_tutorial/)\n", | ||
"\n", | ||
"## Installation" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install equation-tree" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"## Equation Database\n", | ||
"\n", | ||
"Here, we use a list of sympy equation to demonstrate the functionality" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"outputs": [], | ||
"source": [ | ||
"# import functionality from sympy\n", | ||
"from sympy import sympify\n", | ||
"\n", | ||
"eq_1 = sympify('x_1 + x_2')\n", | ||
"eq_2 = sympify('exp(x_1) * 2.5')\n", | ||
"eq_3 = sympify('sin(x_1) + 2 * cos(x_2)')\n", | ||
"equation_list = [eq_1, eq_2, eq_3]" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"## Analyse the List\n", | ||
"\n", | ||
"We can obtain informations about equations and lists of equations:" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": "{'max_depth': {3: 0.3333333333333333,\n 4: 0.3333333333333333,\n 7: 0.3333333333333333},\n 'depth': {1: 0.3333333333333333,\n 2: 0.3333333333333333,\n 3: 0.3333333333333333},\n 'structures': {'[0, 1, 1]': 0.3333333333333333,\n '[0, 1, 1, 2]': 0.3333333333333333,\n '[0, 1, 2, 1, 2, 2, 3]': 0.3333333333333333},\n 'features': {'constants': 0.2857142857142857,\n 'variables': 0.7142857142857143},\n 'functions': {'exp': 0.3333333333333333,\n 'sin': 0.3333333333333333,\n 'cos': 0.3333333333333333},\n 'operators': {'+': 0.5, '*': 0.5},\n 'function_conditionals': {'exp': {'features': {'constants': 0.0,\n 'variables': 1.0},\n 'functions': {},\n 'operators': {}},\n 'sin': {'features': {'constants': 0.0, 'variables': 1.0},\n 'functions': {},\n 'operators': {}},\n 'cos': {'features': {'constants': 0.0, 'variables': 1.0},\n 'functions': {},\n 'operators': {}}},\n 'operator_conditionals': {'+': {'features': {'constants': 0.0,\n 'variables': 1.0},\n 'functions': {'sin': 1.0},\n 'operators': {'*': 1.0}},\n '*': {'features': {'constants': 1.0, 'variables': 0.0},\n 'functions': {'exp': 0.5, 'cos': 0.5},\n 'operators': {}}}}" | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from equation_tree import get_frequencies\n", | ||
"\n", | ||
"# Show the frequencies of\n", | ||
"frequencies = get_frequencies(equation_list)\n", | ||
"frequencies" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Instead of frequencies, we can also obtain absolute values:" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": "{'max_depth': {3: 1, 4: 1, 7: 1},\n 'depth': {1: 1, 2: 1, 3: 1},\n 'structures': {'[0, 1, 1]': 1, '[0, 1, 1, 2]': 1, '[0, 1, 2, 1, 2, 2, 3]': 1},\n 'features': {'constants': 2, 'variables': 5},\n 'functions': {'exp': 1, 'sin': 1, 'cos': 1},\n 'operators': {'+': 2, '*': 2},\n 'function_conditionals': {'exp': {'features': {'constants': 0,\n 'variables': 1},\n 'functions': {},\n 'operators': {}},\n 'sin': {'features': {'constants': 0, 'variables': 1},\n 'functions': {},\n 'operators': {}},\n 'cos': {'features': {'constants': 0, 'variables': 1},\n 'functions': {},\n 'operators': {}}},\n 'operator_conditionals': {'+': {'features': {'constants': 0, 'variables': 2},\n 'functions': {'sin': 1},\n 'operators': {'*': 1}},\n '*': {'features': {'constants': 2, 'variables': 0},\n 'functions': {'exp': 1, 'cos': 1},\n 'operators': {}}}}" | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from src.equation_tree import get_counts\n", | ||
"\n", | ||
"counts = get_counts(equation_list)\n", | ||
"counts" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Note: We can directly use the obtained frequencies to sample new functions:" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/Users/younesstrittmatter/Documents/GitHub/AutoRA/equation-tree/src/equation_tree/util/io.py:27: UserWarning: No hashed prior found. Sample frequencies may diverge from the prior. Consider burning this prior first.\n", | ||
" warnings.warn(\n", | ||
"Processing: 100%|██████████| 10/10 [00:00<00:00, 90.79iteration/s]" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[c_1*cos(x_1), 2*x_1, 2*x_1, 2*x_1, 2*x_1, x_1 + sin(x_1), c_1*cos(x_1), c_1*cos(x_1), x_1 + sin(x_1), x_1 + sin(x_1)]\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from equation_tree import sample\n", | ||
"\n", | ||
"# sample equations\n", | ||
"equations = sample(10, frequencies)\n", | ||
"print(equations)" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"{'max_depth': {4: 0.6, 3: 0.4}, 'depth': {2: 0.6, 1: 0.4}, 'structures': {'[0, 1, 1, 2]': 0.6, '[0, 1, 1]': 0.4}, 'features': {'constants': 0.35, 'variables': 0.65}, 'functions': {'cos': 0.5, 'sin': 0.5}, 'operators': {'*': 0.7, '+': 0.3}, 'function_conditionals': {'cos': {'features': {'constants': 0.0, 'variables': 1.0}, 'functions': {}, 'operators': {}}, 'sin': {'features': {'constants': 0.0, 'variables': 1.0}, 'functions': {}, 'operators': {}}}, 'operator_conditionals': {'*': {'features': {'constants': 0.6363636363636364, 'variables': 0.36363636363636365}, 'functions': {'cos': 1.0}, 'operators': {}}, '+': {'features': {'constants': 0.0, 'variables': 1.0}, 'functions': {'sin': 1.0}, 'operators': {}}}}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# check the frequencies\n", | ||
"print(get_frequencies(equations))" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.