Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
neural_chunking::Layer< T > Class Template Reference

Neural network layer implementation. More...

#include <neural_chunking.hpp>

Public Member Functions

 Layer (size_t input_size, size_t output_size)
 
std::vector< T > forward (const std::vector< T > &input)
 

Private Member Functions

void initialize_weights ()
 

Private Attributes

std::vector< T > biases_
 
size_t input_size_
 
size_t output_size_
 
std::vector< T > weights_
 

Detailed Description

template<typename T>
class neural_chunking::Layer< T >

Neural network layer implementation.

Template Parameters
TData type for layer computations

Definition at line 23 of file neural_chunking.hpp.

Constructor & Destructor Documentation

◆ Layer()

template<typename T >
neural_chunking::Layer< T >::Layer ( size_t  input_size,
size_t  output_size 
)
inline

Definition at line 25 of file neural_chunking.hpp.

26 : input_size_(input_size), output_size_(output_size) {
27 weights_.resize(input_size * output_size);
28 biases_.resize(output_size);
30 }
std::vector< T > weights_

Member Function Documentation

◆ forward()

template<typename T >
std::vector< T > neural_chunking::Layer< T >::forward ( const std::vector< T > &  input)
inline

Definition at line 32 of file neural_chunking.hpp.

32 {
33 if (input.size() != input_size_) {
34 throw std::invalid_argument("Invalid input size");
35 }
36 std::vector<T> output(output_size_);
37 // Simple forward pass implementation
38 for (size_t i = 0; i < output_size_; ++i) {
39 output[i] = biases_[i];
40 for (size_t j = 0; j < input_size_; ++j) {
41 output[i] += input[j] * weights_[i * input_size_ + j];
42 }
43 }
44 return output;
45 }

Referenced by neural_chunking::NeuralChunking< T >::train().

◆ initialize_weights()

template<typename T >
void neural_chunking::Layer< T >::initialize_weights ( )
inlineprivate

Definition at line 53 of file neural_chunking.hpp.

53 {
54 // Simple Xavier initialization
55 T scale = std::sqrt(2.0 / (input_size_ + output_size_));
56 for (auto& w : weights_) {
57 w = (static_cast<T>(rand()) / RAND_MAX * 2 - 1) * scale;
58 }
59 for (auto& b : biases_) {
60 b = 0;
61 }
62 }

Member Data Documentation

◆ biases_

template<typename T >
std::vector<T> neural_chunking::Layer< T >::biases_
private

Definition at line 51 of file neural_chunking.hpp.

◆ input_size_

template<typename T >
size_t neural_chunking::Layer< T >::input_size_
private

Definition at line 48 of file neural_chunking.hpp.

◆ output_size_

template<typename T >
size_t neural_chunking::Layer< T >::output_size_
private

Definition at line 49 of file neural_chunking.hpp.

◆ weights_

template<typename T >
std::vector<T> neural_chunking::Layer< T >::weights_
private

Definition at line 50 of file neural_chunking.hpp.


The documentation for this class was generated from the following file: