-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Do deterministic inference #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6e7a101
Do deterministic inference
carlosgjs 2329f66
expose do_sample param
carlosgjs 93922a9
fix param
carlosgjs 9105f98
unit test
carlosgjs 70e4031
use float arg
carlosgjs bf38d27
CR feesdback
carlosgjs 81fb31f
format
carlosgjs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,69 @@ | ||
| import numpy as np | ||
| import pandas as pd | ||
| import sympy as sp | ||
| from autora.experiment_runner.synthetic.abstract.equation import equation_experiment | ||
| from autora.experimentalist.random import random_pool | ||
| from autora.state import StandardState, estimator_on_state, on_state | ||
| from autora.theorist.bms import BMSRegressor | ||
| from autora.variable import ValueType, Variable, VariableCollection | ||
|
|
||
| #################################################################################### | ||
| ## Define initial data | ||
| #################################################################################### | ||
|
|
||
| #### Define variable data #### | ||
| iv = Variable(name="x", value_range=(0, 2 * np.pi), allowed_values=np.linspace(0, 2 * np.pi, 30)) | ||
| dv = Variable(name="y", type=ValueType.REAL) | ||
| variables = VariableCollection(independent_variables=[iv], dependent_variables=[dv]) | ||
|
|
||
| #### Define seed condition data #### | ||
| conditions = random_pool(variables, num_samples=10, random_state=0) | ||
|
|
||
| #################################################################################### | ||
| ## Define experimentalist | ||
| #################################################################################### | ||
|
|
||
| experimentalist = on_state(random_pool, output=["conditions"]) | ||
|
|
||
| #################################################################################### | ||
| ## Define experiment runner | ||
| #################################################################################### | ||
|
|
||
| sin_experiment = equation_experiment( | ||
| sp.simplify("sin(x)"), variables.independent_variables, variables.dependent_variables[0] | ||
| ) | ||
| sin_runner = sin_experiment.experiment_runner | ||
|
|
||
| experiment_runner = on_state(sin_runner, output=["experiment_data"]) | ||
|
|
||
| #################################################################################### | ||
| ## Define theorist | ||
| #################################################################################### | ||
|
|
||
| theorist = estimator_on_state(BMSRegressor(epochs=100)) | ||
|
|
||
| #################################################################################### | ||
| ## Define state | ||
| #################################################################################### | ||
|
|
||
| s = StandardState( | ||
| variables=variables, conditions=conditions, experiment_data=pd.DataFrame(columns=["x", "y"]) | ||
| ) | ||
|
|
||
| #################################################################################### | ||
| ## Cycle through the state | ||
| #################################################################################### | ||
|
|
||
| print("Pre-Defined State:") | ||
| print(f"Number of datapoints collected: {len(s['experiment_data'])}") | ||
| print(f"Derived models: {s['models']}") | ||
| print("\n") | ||
|
|
||
| for i in range(5): | ||
| s = experimentalist(s, num_samples=10, random_state=42) | ||
| s = experiment_runner(s, added_noise=1.0, random_state=42) | ||
| s = theorist(s) | ||
| print(f"\nCycle {i+1} Results:") | ||
| print(f"Number of datapoints collected: {len(s['experiment_data'])}") | ||
| print(f"Derived models: {s['models']}") | ||
| print("\n") |
This file contains hidden or 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 @@ | ||
| {"instruction": "import numpy as np\nimport pandas as pd\nimport sympy as sp\nfrom autora.experiment_runner.synthetic.abstract.equation import equation_experiment\nfrom autora.experimentalist.random import random_pool\nfrom autora.state import StandardState, estimator_on_state, on_state\nfrom autora.theorist.bms import BMSRegressor\nfrom autora.variable import ValueType, Variable, VariableCollection\n\n####################################################################################\n## Define initial data\n####################################################################################\n\n#### Define variable data ####\niv = Variable(name=\"x\", value_range=(0, 2 * np.pi), allowed_values=np.linspace(0, 2 * np.pi, 30))\ndv = Variable(name=\"y\", type=ValueType.REAL)\nvariables = VariableCollection(independent_variables=[iv], dependent_variables=[dv])\n\n#### Define seed condition data ####\nconditions = random_pool(variables, num_samples=10, random_state=0)\n\n####################################################################################\n## Define experimentalist\n####################################################################################\n\nexperimentalist = on_state(random_pool, output=[\"conditions\"])\n\n####################################################################################\n## Define experiment runner\n####################################################################################\n\nsin_experiment = equation_experiment(\n sp.simplify(\"sin(x)\"), variables.independent_variables, variables.dependent_variables[0]\n)\nsin_runner = sin_experiment.experiment_runner\n\nexperiment_runner = on_state(sin_runner, output=[\"experiment_data\"])\n\n####################################################################################\n## Define theorist\n####################################################################################\n\ntheorist = estimator_on_state(BMSRegressor(epochs=100))\n\n####################################################################################\n## Define state\n####################################################################################\n\ns = StandardState(\n variables=variables, conditions=conditions, experiment_data=pd.DataFrame(columns=[\"x\", \"y\"])\n)\n\n####################################################################################\n## Cycle through the state\n####################################################################################\n\nprint(\"Pre-Defined State:\")\nprint(f\"Number of datapoints collected: {len(s['experiment_data'])}\")\nprint(f\"Derived models: {s['models']}\")\nprint(\"\\n\")\n\nfor i in range(5):\n s = experimentalist(s, num_samples=10, random_state=42)\n s = experiment_runner(s, added_noise=1.0, random_state=42)\n s = theorist(s)\n print(f\"\\nCycle {i+1} Results:\")\n print(f\"Number of datapoints collected: {len(s['experiment_data'])}\")\n print(f\"Derived models: {s['models']}\")\n print(\"\\n\")\n", "output": "The following example demonstrates how to use AutoRA to automate the process of model discovery, experimental design, and data collection. \n\nThe discovery problem is defined by a single independent variable $x \\in [0, 2 \\pi]$ and dependent variable $y$.\nThe experiment amounts to a simple sine wave, $y = \\sin(x)$, which is the model we are trying to discover.\n\nThe discovery cycle iterates between the experimentalist, experiment runner, and theorist. Here, we us a \"random\" experimentalist, which samples novel experimental conditions for $x$ every cycle. \nThe experiment runner then collects data for the corresponding $y$ values. Finally, the theorist uses a [Bayesian Machine Scientist](https://autoresearch.github.io/autora/user-guide/theorists/bms/) (BMS; Guimerà et al., in Science Advances) to identify a scientific model that explains the data. "} |
This file contains hidden or 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,7 @@ | ||
| The following example demonstrates how to use AutoRA to automate the process of model discovery, experimental design, and data collection. | ||
|
|
||
| The discovery problem is defined by a single independent variable $x \in [0, 2 \pi]$ and dependent variable $y$. | ||
| The experiment amounts to a simple sine wave, $y = \sin(x)$, which is the model we are trying to discover. | ||
|
|
||
| The discovery cycle iterates between the experimentalist, experiment runner, and theorist. Here, we us a "random" experimentalist, which samples novel experimental conditions for $x$ every cycle. | ||
| The experiment runner then collects data for the corresponding $y$ values. Finally, the theorist uses a [Bayesian Machine Scientist](https://autoresearch.github.io/autora/user-guide/theorists/bms/) (BMS; Guimerà et al., in Science Advances) to identify a scientific model that explains the data. |
File renamed without changes.
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.