Skip to content
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

Adding online learning to lds model #10

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python"
xmlns:p1="clr-namespace:Bonsai.ML.LinearDynamicalSystems;assembly=Bonsai.ML.LinearDynamicalSystems"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="py:ObserveOnGIL" />
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" DisplayName="Name" Category="ModelReference" />
</Expression>
<Expression xsi:type="SubscribeSubject" TypeArguments="p1:ModelReference">
<Name>model</Name>
</Expression>
<Expression xsi:type="MemberSelector">
<Selector>Name</Selector>
</Expression>
<Expression xsi:type="Format">
<Format>{0}.get_optimization_finished()</Format>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:WithLatestFrom" />
</Expression>
<Expression xsi:type="InputMapping">
<PropertyMappings>
<Property Name="Expression" Selector="it.Item2" />
</PropertyMappings>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>LDSModule</Name>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Module" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="py:Eval">
<py:Expression>model1.get_optimization_finished()</py:Expression>
</Combinator>
</Expression>
<Expression xsi:type="rx:Condition">
<Name>OptimizationFinished?</Name>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Expression>it.ToString() == "True"</scr:Expression>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
</Edges>
</Workflow>
</Expression>
<Expression xsi:type="SubscribeSubject" TypeArguments="p1:ModelReference">
<Name>model</Name>
</Expression>
<Expression xsi:type="MemberSelector">
<Selector>Name</Selector>
</Expression>
<Expression xsi:type="Format">
<Format>{0}.reset_optimization_loop()</Format>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:WithLatestFrom" />
</Expression>
<Expression xsi:type="InputMapping">
<PropertyMappings>
<Property Name="Expression" Selector="it.Item2" />
</PropertyMappings>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>LDSModule</Name>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Module" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="py:Eval">
<py:Expression>model1.reset_optimization_loop()</py:Expression>
</Combinator>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="6" Label="Source1" />
<Edge From="2" To="3" Label="Source1" />
<Edge From="2" To="12" Label="Source1" />
<Edge From="3" To="4" Label="Source1" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="5" To="6" Label="Source2" />
<Edge From="6" To="7" Label="Source1" />
<Edge From="7" To="10" Label="Source1" />
<Edge From="8" To="9" Label="Source1" />
<Edge From="9" To="10" Label="Source2" />
<Edge From="10" To="11" Label="Source1" />
<Edge From="11" To="15" Label="Source1" />
<Edge From="12" To="13" Label="Source1" />
<Edge From="13" To="14" Label="Source1" />
<Edge From="14" To="15" Label="Source2" />
<Edge From="15" To="16" Label="Source1" />
<Edge From="16" To="19" Label="Source1" />
<Edge From="17" To="18" Label="Source1" />
<Edge From="18" To="19" Label="Source2" />
<Edge From="19" To="20" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python"
xmlns:p1="clr-namespace:Bonsai.ML.LinearDynamicalSystems;assembly=Bonsai.ML.LinearDynamicalSystems"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="BatchSize" Category="TrainingData" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="IntProperty">
<Value>200</Value>
</Combinator>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Count" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="IntProperty">
<Value>200</Value>
</Combinator>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Skip" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:BufferCount">
<rx:Count>200</rx:Count>
<rx:Skip>200</rx:Skip>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Concat" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="py:ObserveOnGIL" />
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" DisplayName="Name" Category="ModelReference" />
</Expression>
<Expression xsi:type="SubscribeSubject" TypeArguments="p1:ModelReference">
<Name>model</Name>
</Expression>
<Expression xsi:type="MemberSelector">
<Selector>Name</Selector>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:WithLatestFrom" />
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="sigma_a" Category="ParametersToOptimize" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
<Value>true</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="sigma_x, sigma_y" Category="ParametersToOptimize" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
<Value>true</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="m0" Category="ParametersToOptimize" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
<Value>true</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="sqrt_diag_V0_value" Category="ParametersToOptimize" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
<Value>true</Value>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="IntProperty">
<Value>200</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="NumIterations" Category="Hyperparameters" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="IntProperty">
<Value>50</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="PrintConvergenceMessages" Category="Verbosity" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
<Value>true</Value>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:CombineLatest" />
</Expression>
<Expression xsi:type="Format">
<Format>vars_to_estimate = {{"sigma_a": {0}, "sqrt_diag_R": {1}, "R": {1}, "m0": {2}, "sqrt_diag_V0": {3}, "V0": {3}}}, batch_size = {4}, max_iter = {5}, disp = {6}</Format>
<Selector>it.Item1, it.Item2, it.Item3, it.Item4, it.Item5, it.Item6, it.Item7</Selector>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:WithLatestFrom" />
</Expression>
<Expression xsi:type="Format">
<Format>{0}.run_optimization_async({1}, {2})</Format>
<Selector>it.Item1.Item2,it.Item1.Item1, it.Item2</Selector>
</Expression>
<Expression xsi:type="InputMapping">
<PropertyMappings>
<Property Name="Expression" Selector="it" />
</PropertyMappings>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>LDSModule</Name>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Module" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="py:Eval">
<py:Expression>model1.run_optimization_async(x=372.270477294922,y=149.264526367188, vars_to_estimate = {"sigma_a": True, "sqrt_diag_R": True, "R": True, "m0": True, "sqrt_diag_V0": True, "V0": True}, batch_size = 200)</py:Expression>
</Combinator>
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Expression>it.ToString() == "True"</scr:Expression>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:DistinctUntilChanged" />
</Expression>
<Expression xsi:type="rx:Condition">
<Name>IsRunningOptimization?</Name>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
</Edges>
</Workflow>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="6" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
<Edge From="1" To="4" Label="Source1" />
<Edge From="1" To="21" Label="Source1" />
<Edge From="2" To="3" Label="Source1" />
<Edge From="3" To="6" Label="Source2" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="5" To="6" Label="Source3" />
<Edge From="6" To="7" Label="Source1" />
<Edge From="7" To="8" Label="Source1" />
<Edge From="8" To="12" Label="Source1" />
<Edge From="9" To="10" Label="Source1" />
<Edge From="10" To="11" Label="Source1" />
<Edge From="11" To="12" Label="Source2" />
<Edge From="12" To="28" Label="Source1" />
<Edge From="13" To="14" Label="Source1" />
<Edge From="14" To="26" Label="Source1" />
<Edge From="15" To="16" Label="Source1" />
<Edge From="16" To="26" Label="Source2" />
<Edge From="17" To="18" Label="Source1" />
<Edge From="18" To="26" Label="Source3" />
<Edge From="19" To="20" Label="Source1" />
<Edge From="20" To="26" Label="Source4" />
<Edge From="21" To="26" Label="Source5" />
<Edge From="22" To="23" Label="Source1" />
<Edge From="23" To="26" Label="Source6" />
<Edge From="24" To="25" Label="Source1" />
<Edge From="25" To="26" Label="Source7" />
<Edge From="26" To="27" Label="Source1" />
<Edge From="27" To="28" Label="Source2" />
<Edge From="28" To="29" Label="Source1" />
<Edge From="29" To="30" Label="Source1" />
<Edge From="30" To="33" Label="Source1" />
<Edge From="31" To="32" Label="Source1" />
<Edge From="32" To="33" Label="Source2" />
<Edge From="33" To="34" Label="Source1" />
<Edge From="34" To="35" Label="Source1" />
<Edge From="35" To="36" Label="Source1" />
<Edge From="36" To="37" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
Loading