pub struct Softmax;Expand description
Softmax is a builder for Softmax Activation Function
It converts a vector of values into a normalized probability distribution, where each element is in the range (0, 1) and all elements sum to 1. It is typically used in the output layer of a classification model to represent confidence scores across multiple classes.
Range: (0, 1) for each output element Best for: Output layers of multi-class classification models.
Implementations§
Source§impl Softmax
impl Softmax
Sourcepub fn build() -> Result<Box<dyn ActivationFunction>, NetworkError>
pub fn build() -> Result<Box<dyn ActivationFunction>, NetworkError>
Examples found in repository?
examples/triplets/triplets.rs (line 182)
179fn triplets_network(inp_size: usize, targ_size: usize) -> Network {
180 let network = NetworkBuilder::new(inp_size, targ_size)
181 .layer(Dense::default().size(24).activation(ReLU::build()).build())
182 .layer(Dense::default().size(targ_size).activation(Softmax::build()).build())
183 .loss_function(CrossEntropy::default().epsilon(1e-8).build())
184 .optimizer(Adam::default().beta1(0.99).beta2(0.999).learning_rate(0.0035).build())
185 .batch_size(8)
186 .batch_group_size(2)
187 .parallelize(2)
188 .epochs(1000)
189 .seed(55)
190 .build();
191
192 match network {
193 Ok(net) => net,
194 Err(e) => {
195 eprintln!("Failed to build network: {}", e);
196 std::process::exit(1);
197 }
198 }
199}More examples
examples/wine/wine.rs (line 119)
115fn one_hot_encode_network(inp_size: usize, targ_size: usize) -> Network {
116 let network = NetworkBuilder::new(inp_size, targ_size)
117 .layer(Dense::default().size(7).activation(ReLU::build()).build())
118 .layer(Dense::default().size(5).activation(ReLU::build()).build())
119 .layer(Dense::default().size(targ_size).activation(Softmax::build()).build())
120 .optimizer(Adam::default().beta1(0.99).beta2(0.999).learning_rate(0.0035).build())
121 .loss_function(CrossEntropy::default().epsilon(1e-8).build())
122 .batch_size(4)
123 .normalize_input(MinMax::default())
124 .epochs(500)
125 .seed(55)
126 .build();
127
128 match network {
129 Ok(net) => net,
130 Err(e) => {
131 error!("Failed to build network: {}", e);
132 std::process::exit(1);
133 }
134 }
135}examples/iris/iris.rs (line 112)
108fn iris_network(inp_size: usize, targ_size: usize) -> Network {
109 let network = NetworkBuilder::new(inp_size, targ_size)
110 .layer(Dense::default().size(12).activation(ReLU::build()).build())
111 .layer(Dense::default().size(12).activation(ReLU::build()).build())
112 .layer(Dense::default().size(targ_size).activation(Softmax::build()).build())
113 .loss_function(CrossEntropy::default().epsilon(1e-8).build())
114 .optimizer(Adam::default().beta1(0.99).beta2(0.999).learning_rate(0.0035).build())
115 .batch_size(9)
116 .batch_group_size(2)
117 .parallelize(2)
118 .epochs(3000)
119 .seed(55)
120 .build();
121
122 match network {
123 Ok(net) => net,
124 Err(e) => {
125 eprintln!("Failed to build network: {}", e);
126 std::process::exit(1);
127 }
128 }
129}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Softmax
impl RefUnwindSafe for Softmax
impl Send for Softmax
impl Sync for Softmax
impl Unpin for Softmax
impl UnsafeUnpin for Softmax
impl UnwindSafe for Softmax
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.