-
Notifications
You must be signed in to change notification settings - Fork 5
Add new deep learning functionality #78
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
base: main
Are you sure you want to change the base?
Changes from all commits
912049d
7261825
eefefea
7aecc5d
20d4cea
96e5611
bc1e4bb
7457b0b
a7d3a62
8c0a1b2
f11a427
6c4fe96
349b4f5
d84c277
de16d5d
1b3fa2a
a5f5d80
32ad837
2d2a1a5
0a22aaa
b3da5e7
8d3b49f
cfd257e
5c8904f
e9f4d09
aa457e5
18d8107
291d6a1
f2cc9bf
a11b3de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Reactive.Linq; | ||
| using static TorchSharp.torch; | ||
| using static TorchSharp.torch.nn; | ||
|
|
||
| namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction; | ||
|
|
||
| /// <summary> | ||
| /// Represents an operator that creates a continuously differentiable exponential linear unit (CELU) activation function. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.CELU.html"/> for more information. | ||
| /// </remarks> | ||
| [Description("Creates a continuously differentiable exponential linear unit (CELU) activation function.")] | ||
| [DisplayName("CELU")] | ||
| public class Celu | ||
| { | ||
| /// <summary> | ||
| /// The alpha value for the CELU activation function. | ||
| /// </summary> | ||
| [Description("The alpha value for the CELU activation function.")] | ||
| public double Alpha { get; set; } = 1D; | ||
|
|
||
| /// <summary> | ||
| /// If set to true, will do this operation in-place. | ||
| /// </summary> | ||
| [Description("If set to true, will do this operation in-place.")] | ||
| public bool Inplace { get; set; } = false; | ||
|
|
||
| /// <summary> | ||
| /// Creates a continuously differentiable exponential linear unit (CELU) module. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.CELU> Process() | ||
| { | ||
| return Observable.Return(CELU(Alpha, Inplace)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a continuously differentiable exponential linear unit (CELU) module. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="source"></param> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.CELU> Process<T>(IObservable<T> source) | ||
| { | ||
| return source.Select(_ => CELU(Alpha, Inplace)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Reactive.Linq; | ||
| using static TorchSharp.torch; | ||
| using static TorchSharp.torch.nn; | ||
|
|
||
| namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction; | ||
|
|
||
| /// <summary> | ||
| /// Represents an operator that creates an exponential linear unit (ELU) activation function. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.ELU.html"/> for more information. | ||
| /// </remarks> | ||
| [Description("Creates an exponential linear unit (ELU) activation function.")] | ||
| [DisplayName("ELU")] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
| public class Elu | ||
| { | ||
| /// <summary> | ||
| /// The alpha value for the ELU activation function. | ||
| /// </summary> | ||
| [Description("The alpha value for the ELU activation function")] | ||
| public double Alpha { get; set; } = 1D; | ||
|
|
||
| /// <summary> | ||
| /// If set to true, will do this operation in-place. | ||
| /// </summary> | ||
| [Description("If set to true, will do this operation in-place")] | ||
| public bool Inplace { get; set; } = false; | ||
|
|
||
| /// <summary> | ||
| /// Creates an exponential linear unit (ELU) module. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.ELU> Process() | ||
| { | ||
| return Observable.Return(ELU(Alpha, Inplace)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates an exponential linear unit (ELU) module. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="source"></param> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.ELU> Process<T>(IObservable<T> source) | ||
| { | ||
| return source.Select(_ => ELU(Alpha, Inplace)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Reactive.Linq; | ||
| using static TorchSharp.torch; | ||
| using static TorchSharp.torch.nn; | ||
|
|
||
| namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction; | ||
|
|
||
| /// <summary> | ||
| /// Represents an operator that creates a gaussian error linear unit (GELU) activation function. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.GELU.html"/> for more information. | ||
| /// </remarks> | ||
| [Description("Creates a gaussian error linear unit (GELU) activation function.")] | ||
| [DisplayName("GELU")] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| public class Gelu | ||
| { | ||
| /// <summary> | ||
| /// If set to true, will do this operation in-place. | ||
| /// </summary> | ||
| [Description("If set to true, will do this operation in-place.")] | ||
| public bool InPlace { get; set; } = false; | ||
|
|
||
| /// <summary> | ||
| /// Creates a gaussian error linear unit (GELU) module. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.GELU> Process() | ||
| { | ||
| return Observable.Return(GELU(InPlace)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a gaussian error linear unit (GELU) module. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="source"></param> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.GELU> Process<T>(IObservable<T> source) | ||
| { | ||
| return source.Select(_ => GELU(InPlace)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Reactive.Linq; | ||
| using static TorchSharp.torch; | ||
| using static TorchSharp.torch.nn; | ||
|
|
||
| namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction; | ||
|
|
||
| /// <summary> | ||
| /// Represents an operator that creates a gated linear unit (GLU) module. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.GLU.html"/> for more information. | ||
| /// </remarks> | ||
| [Description("Creates a gated linear unit (GLU) module.")] | ||
| [DisplayName("GLU")] | ||
| public class Glu | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. Alternatively, we could emulate our decision in the Torch package and simply expand all acronyms into their full long names to favor readability, as these acronyms are impenetrable to cursory reading, and easily confused with each other. |
||
| { | ||
| /// <summary> | ||
| /// The dimension on which to split the input tensor. | ||
| /// </summary> | ||
| [Description("The dimension on which to split the input tensor.")] | ||
| public long Dim { get; set; } = -1; | ||
|
|
||
| /// <summary> | ||
| /// Creates a gated linear unit (GLU) module. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.GLU> Process() | ||
| { | ||
| return Observable.Return(GLU(Dim)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a gated linear unit (GLU) module. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="source"></param> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.GLU> Process<T>(IObservable<T> source) | ||
| { | ||
| return source.Select(_ => GLU(Dim)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Reactive.Linq; | ||
| using static TorchSharp.torch; | ||
| using static TorchSharp.torch.nn; | ||
|
|
||
| namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction; | ||
|
|
||
| /// <summary> | ||
| /// Represents an operator that creates a Hardshrink module. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.Hardshrink.html"/> for more information. | ||
| /// </remarks> | ||
| [Description("Creates a Hardshrink module.")] | ||
| public class Hardshrink | ||
| { | ||
| /// <summary> | ||
| /// The lambda parameter for the Hardshrink function. | ||
| /// </summary> | ||
| [Description("The lambda parameter for the Hardshrink function")] | ||
| public double Lambda { get; set; } = 0.5D; | ||
|
|
||
| /// <summary> | ||
| /// Creates a Hardshrink module. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.Hardshrink> Process() | ||
| { | ||
| return Observable.Return(Hardshrink(Lambda)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a Hardshrink module. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="source"></param> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.Hardshrink> Process<T>(IObservable<T> source) | ||
| { | ||
| return source.Select(_ => Hardshrink(Lambda)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Reactive.Linq; | ||
| using static TorchSharp.torch; | ||
| using static TorchSharp.torch.nn; | ||
|
|
||
| namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction; | ||
|
|
||
| /// <summary> | ||
| /// Represents an operator that creates a Hardsigmoid module. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.Hardsigmoid.html"/> for more information. | ||
| /// </remarks> | ||
| [Description("Creates a Hardsigmoid module.")] | ||
| public class Hardsigmoid | ||
| { | ||
| /// <summary> | ||
| /// If set to true, will do this operation in-place. | ||
| /// </summary> | ||
| [Description("If set to true, will do this operation in-place")] | ||
| public bool Inplace { get; set; } = false; | ||
|
|
||
| /// <summary> | ||
| /// Creates a Hardsigmoid module. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.Hardsigmoid> Process() | ||
| { | ||
| return Observable.Return(Hardsigmoid(Inplace)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a Hardsigmoid module. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="source"></param> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.Hardsigmoid> Process<T>(IObservable<T> source) | ||
| { | ||
| return source.Select(_ => Hardsigmoid(Inplace)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Reactive.Linq; | ||
| using static TorchSharp.torch; | ||
| using static TorchSharp.torch.nn; | ||
|
|
||
| namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction; | ||
|
|
||
| /// <summary> | ||
| /// Represents an operator that creates a Hardswish module. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.Hardswish.html"/> for more information. | ||
| /// </remarks> | ||
| [Description("Creates a Hardswish module.")] | ||
| public class Hardswish | ||
| { | ||
| /// <summary> | ||
| /// If set to true, will do this operation in-place. | ||
| /// </summary> | ||
| [Description("If set to true, will do this operation in-place")] | ||
| public bool Inplace { get; set; } = false; | ||
|
|
||
| /// <summary> | ||
| /// Creates a Hardswish module. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.Hardswish> Process() | ||
| { | ||
| return Observable.Return(Hardswish(Inplace)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a Hardswish module. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="source"></param> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.Hardswish> Process<T>(IObservable<T> source) | ||
| { | ||
| return source.Select(_ => Hardswish(Inplace)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Reactive.Linq; | ||
| using static TorchSharp.torch; | ||
| using static TorchSharp.torch.nn; | ||
|
|
||
| namespace Bonsai.ML.Torch.NeuralNets.ActivationFunction; | ||
|
|
||
| /// <summary> | ||
| /// Represents an operator that creates a Hardtanh module. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// See <see href="https://pytorch.org/docs/stable/generated/torch.nn.Hardtanh.html"/> for more information. | ||
| /// </remarks> | ||
| [Description("Creates a Hardtanh module.")] | ||
| public class Hardtanh | ||
| { | ||
| /// <summary> | ||
| /// The minimum value of the linear region range. | ||
| /// </summary> | ||
| [Description("The minimum value of the linear region range.")] | ||
| public double MinVal { get; set; } = -1D; | ||
|
|
||
| /// <summary> | ||
| /// The maximum value of the linear region range. | ||
| /// </summary> | ||
| [Description("The maximum value of the linear region range.")] | ||
| public double MaxVal { get; set; } = 1D; | ||
|
|
||
| /// <summary> | ||
| /// If set to true, will do this operation in-place. | ||
| /// </summary> | ||
| [Description("If set to true, will do this operation in-place")] | ||
| public bool Inplace { get; set; } = false; | ||
|
|
||
| /// <summary> | ||
| /// Creates a Hardtanh module. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.Hardtanh> Process() | ||
| { | ||
| return Observable.Return(Hardtanh(MinVal, MaxVal, Inplace)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a Hardtanh module. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="source"></param> | ||
| /// <returns></returns> | ||
| public IObservable<TorchSharp.Modules.Hardtanh> Process<T>(IObservable<T> source) | ||
| { | ||
| return source.Select(_ => Hardtanh(MinVal, MaxVal, Inplace)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have on occasion changed the display name for dynamic operators, but usually I try to avoid doing it for casing reasons, since on XML the actual class name will persist, and may create confusion between diffs and the visual editor.
I do agree this is a strange acronym, I looked elsewhere and couldn't find a better name, but would still keep the C# naming conventions.