Skip to main content

Softmax

Struct Softmax 

Source
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

Source

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
Hide additional 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§

Source§

impl Default for Softmax

Source§

fn default() -> Self

Creates a new Softmax activation function Softmax weight initialization factor is set to Xavier initialization.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V