-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from bonsai-rx/linear-regression
Linear regression subpackage added to linear dynamical systems
- Loading branch information
Showing
20 changed files
with
1,723 additions
and
66 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
112 changes: 112 additions & 0 deletions
112
src/Bonsai.ML.LinearDynamicalSystems/LinearRegression/CreateKFModel.bonsai
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,112 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<WorkflowBuilder Version="2.8.1" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:p1="clr-namespace:Bonsai.ML.LinearDynamicalSystems.LinearRegression;assembly=Bonsai.ML.LinearDynamicalSystems" | ||
xmlns:p2="clr-namespace:Bonsai.ML.LinearDynamicalSystems;assembly=Bonsai.ML.LinearDynamicalSystems" | ||
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core" | ||
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python" | ||
xmlns="https://bonsai-rx.org/2018/workflow"> | ||
<Workflow> | ||
<Nodes> | ||
<Expression xsi:type="WorkflowInput"> | ||
<Name>Source1</Name> | ||
</Expression> | ||
<Expression xsi:type="ExternalizedMapping"> | ||
<Property Name="LikelihoodPrecisionCoefficient" Category="Parameters" /> | ||
<Property Name="PriorPrecisionCoefficient" Category="Parameters" /> | ||
<Property Name="NumFeatures" Category="Parameters" /> | ||
</Expression> | ||
<Expression xsi:type="ExternalizedMapping"> | ||
<Property Name="X" Category="ModelState" /> | ||
<Property Name="P" Category="ModelState" /> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="p1:KFModelParameters"> | ||
<p1:LikelihoodPrecisionCoefficient>25</p1:LikelihoodPrecisionCoefficient> | ||
<p1:PriorPrecisionCoefficient>2</p1:PriorPrecisionCoefficient> | ||
<p1:NumFeatures>2</p1:NumFeatures> | ||
</Combinator> | ||
</Expression> | ||
<Expression xsi:type="ExternalizedMapping"> | ||
<Property Name="Name" Category="ModelReference" /> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="p2:CreateModelReference"> | ||
<p2:Name>model</p2:Name> | ||
</Combinator> | ||
</Expression> | ||
<Expression xsi:type="rx:BehaviorSubject"> | ||
<Name>model</Name> | ||
</Expression> | ||
<Expression xsi:type="MemberSelector"> | ||
<Selector>Name</Selector> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="rx:Zip" /> | ||
</Expression> | ||
<Expression xsi:type="rx:Sink"> | ||
<Name>InitModel</Name> | ||
<Workflow> | ||
<Nodes> | ||
<Expression xsi:type="WorkflowInput"> | ||
<Name>Source1</Name> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="py:ObserveOnGIL" /> | ||
</Expression> | ||
<Expression xsi:type="Format"> | ||
<Format>{0} = KalmanFilterLinearRegression({1})</Format> | ||
<Selector>it.Item2, it.Item1</Selector> | ||
</Expression> | ||
<Expression xsi:type="InputMapping"> | ||
<PropertyMappings> | ||
<Property Name="Script" 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:Exec"> | ||
<py:Script>model = KalmanFilterLinearRegression(likelihood_precision_coef=25, prior_precision_coef=2, n_features=2, x=None, P=None)</py:Script> | ||
</Combinator> | ||
</Expression> | ||
<Expression xsi:type="WorkflowOutput" /> | ||
</Nodes> | ||
<Edges> | ||
<Edge From="0" To="1" Label="Source1" /> | ||
<Edge From="1" To="2" Label="Source1" /> | ||
<Edge From="2" To="3" Label="Source1" /> | ||
<Edge From="3" To="6" Label="Source1" /> | ||
<Edge From="4" To="5" Label="Source1" /> | ||
<Edge From="5" To="6" Label="Source2" /> | ||
<Edge From="6" To="7" Label="Source1" /> | ||
</Edges> | ||
</Workflow> | ||
</Expression> | ||
<Expression xsi:type="MemberSelector"> | ||
<Selector>Item1</Selector> | ||
</Expression> | ||
<Expression xsi:type="WorkflowOutput" /> | ||
</Nodes> | ||
<Edges> | ||
<Edge From="0" To="3" Label="Source1" /> | ||
<Edge From="1" To="3" Label="Source2" /> | ||
<Edge From="2" To="3" Label="Source3" /> | ||
<Edge From="3" To="8" Label="Source1" /> | ||
<Edge From="4" To="5" Label="Source1" /> | ||
<Edge From="4" To="6" Label="Source2" /> | ||
<Edge From="5" To="6" Label="Source1" /> | ||
<Edge From="6" To="7" Label="Source1" /> | ||
<Edge From="7" To="8" Label="Source2" /> | ||
<Edge From="8" To="9" Label="Source1" /> | ||
<Edge From="9" To="10" Label="Source1" /> | ||
<Edge From="10" To="11" Label="Source1" /> | ||
</Edges> | ||
</Workflow> | ||
</WorkflowBuilder> |
136 changes: 136 additions & 0 deletions
136
src/Bonsai.ML.LinearDynamicalSystems/LinearRegression/CreateMultivariatePDF.bonsai
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,136 @@ | ||
<?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:p2="clr-namespace:Bonsai.ML.LinearDynamicalSystems.LinearRegression;assembly=Bonsai.ML.LinearDynamicalSystems" | ||
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="Combinator"> | ||
<Combinator xsi:type="rx:WithLatestFrom" /> | ||
</Expression> | ||
<Expression xsi:type="MemberSelector"> | ||
<Selector>Item2</Selector> | ||
</Expression> | ||
<Expression xsi:type="ExternalizedMapping"> | ||
<Property Name="X0" Category="GridParameters" /> | ||
<Property Name="X1" Category="GridParameters" /> | ||
<Property Name="XSteps" Category="GridParameters" /> | ||
<Property Name="Y0" Category="GridParameters" /> | ||
<Property Name="Y1" Category="GridParameters" /> | ||
<Property Name="YSteps" Category="GridParameters" /> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="p2:GridParameters"> | ||
<p2:X0>-1</p2:X0> | ||
<p2:X1>1</p2:X1> | ||
<p2:XSteps>100</p2:XSteps> | ||
<p2:Y0>-1</p2:Y0> | ||
<p2:Y1>1</p2:Y1> | ||
<p2:YSteps>100</p2:YSteps> | ||
</Combinator> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="rx:WithLatestFrom" /> | ||
</Expression> | ||
<Expression xsi:type="rx:Sink"> | ||
<Name>PDF</Name> | ||
<Workflow> | ||
<Nodes> | ||
<Expression xsi:type="WorkflowInput"> | ||
<Name>Source1</Name> | ||
</Expression> | ||
<Expression xsi:type="Format"> | ||
<Format>{0}.pdf({1})</Format> | ||
<Selector>it.Item1, it.Item2</Selector> | ||
</Expression> | ||
<Expression xsi:type="InputMapping"> | ||
<PropertyMappings> | ||
<Property Name="Script" 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:Exec"> | ||
<py:Script>model.pdf(x0=-1, x1=1, xsteps=100, y0=-1, y1=1, ysteps=100)</py:Script> | ||
</Combinator> | ||
</Expression> | ||
<Expression xsi:type="WorkflowOutput" /> | ||
</Nodes> | ||
<Edges> | ||
<Edge From="0" To="1" Label="Source1" /> | ||
<Edge From="1" To="2" Label="Source1" /> | ||
<Edge From="2" To="5" Label="Source1" /> | ||
<Edge From="3" To="4" Label="Source1" /> | ||
<Edge From="4" To="5" Label="Source2" /> | ||
<Edge From="5" To="6" Label="Source1" /> | ||
</Edges> | ||
</Workflow> | ||
</Expression> | ||
<Expression xsi:type="InputMapping"> | ||
<PropertyMappings> | ||
<Property Name="VariableName" Selector="it.Item1" /> | ||
</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:Get"> | ||
<py:VariableName>model</py:VariableName> | ||
</Combinator> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="p2:MultivariatePDF" /> | ||
</Expression> | ||
<Expression xsi:type="WorkflowOutput" /> | ||
</Nodes> | ||
<Edges> | ||
<Edge From="0" To="1" Label="Source1" /> | ||
<Edge From="1" To="5" Label="Source1" /> | ||
<Edge From="2" To="3" Label="Source1" /> | ||
<Edge From="3" To="4" Label="Source1" /> | ||
<Edge From="4" To="5" Label="Source2" /> | ||
<Edge From="5" To="6" Label="Source1" /> | ||
<Edge From="6" To="9" Label="Source1" /> | ||
<Edge From="7" To="8" Label="Source1" /> | ||
<Edge From="8" To="9" Label="Source2" /> | ||
<Edge From="9" To="10" Label="Source1" /> | ||
<Edge From="10" To="11" Label="Source1" /> | ||
<Edge From="11" To="14" Label="Source1" /> | ||
<Edge From="12" To="13" Label="Source1" /> | ||
<Edge From="13" To="14" Label="Source2" /> | ||
<Edge From="14" To="15" Label="Source1" /> | ||
<Edge From="15" To="16" Label="Source1" /> | ||
</Edges> | ||
</Workflow> | ||
</WorkflowBuilder> |
Oops, something went wrong.