Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
RoberLopez committed Dec 18, 2024
1 parent bf7523e commit d06a0e0
Show file tree
Hide file tree
Showing 29 changed files with 420 additions and 481 deletions.
85 changes: 48 additions & 37 deletions opennn/addition_layer_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,78 @@
namespace opennn
{

AdditionLayer3D::AdditionLayer3D(const Index& new_inputs_number, const Index& new_inputs_depth) : Layer()
AdditionLayer3D::AdditionLayer3D(const Index& new_inputs_number,
const Index& new_inputs_depth,
const string& new_name) : Layer()
{
set(new_inputs_number, new_inputs_depth);
set(new_inputs_number, new_inputs_depth, new_name);
}


Index AdditionLayer3D::get_inputs_number_xxx() const
Index AdditionLayer3D::get_sequence_length() const
{
return inputs_number_xxx;
return sequence_length;
}


Index AdditionLayer3D::get_inputs_depth() const
Index AdditionLayer3D::get_embedding_length() const
{
return inputs_depth;
return embedding_length;
}


dimensions AdditionLayer3D::get_input_dimensions() const
{
return { sequence_length, embedding_length };
}


dimensions AdditionLayer3D::get_output_dimensions() const
{
return { inputs_number_xxx, inputs_depth };
return { sequence_length, embedding_length };
}


void AdditionLayer3D::set(const Index& new_inputs_number, const Index& new_inputs_depth)
void AdditionLayer3D::set(const Index& new_sequence_length,
const Index& new_embedding_length,
const string& new_name)
{
inputs_number_xxx = new_inputs_number;
sequence_length = new_sequence_length;

inputs_depth = new_inputs_depth;
embedding_length = new_embedding_length;

name = "addition_layer_3d";
name = new_name;

layer_type = Type::Addition3D;
}


void AdditionLayer3D::set_inputs_number(const Index& new_inputs_number)
void AdditionLayer3D::set_sequence_length(const Index& new_sequence_length)
{
inputs_number_xxx = new_inputs_number;
sequence_length = new_sequence_length;
}


void AdditionLayer3D::set_inputs_depth(const Index& new_inputs_depth)
void AdditionLayer3D::set_embedding_length(const Index& new_embedding_length)
{
inputs_depth = new_inputs_depth;
embedding_length = new_embedding_length;
}


void AdditionLayer3D::forward_propagate(const vector<pair<type*, dimensions>>& input_pairs,
unique_ptr<LayerForwardPropagation>& layer_forward_propagation,
const bool&)
{
const TensorMap<Tensor<type, 3>> input_1 = tensor_map_3(input_pairs[0]);
const TensorMap<Tensor<type, 3>> positional_encodings = tensor_map_3(input_pairs[0]);

const TensorMap<Tensor<type, 3>> input_2 = tensor_map_3(input_pairs[1]);
const TensorMap<Tensor<type, 3>> input_embeddings = tensor_map_3(input_pairs[1]);

AdditionLayer3DForwardPropagation* addition_layer_3d_forward_propagation =
static_cast<AdditionLayer3DForwardPropagation*>(layer_forward_propagation.get());

Tensor<type, 3>& outputs = addition_layer_3d_forward_propagation->outputs;

outputs.device(*thread_pool_device) = input_1 + input_2;
outputs.device(*thread_pool_device) = positional_encodings + input_embeddings;

}

Expand Down Expand Up @@ -107,8 +117,8 @@ void AdditionLayer3D::from_XML(const XMLDocument& document)
throw runtime_error("Addition3D element is nullptr.\n");

set_name(read_xml_string(addition_layer_element, "Name"));
set_inputs_number(read_xml_index(addition_layer_element, "InputsNumber"));
set_inputs_depth(read_xml_index(addition_layer_element, "InputsDepth"));
set_sequence_length(read_xml_index(addition_layer_element, "SequenceLength"));
set_embedding_length(read_xml_index(addition_layer_element, "EmbeddingLength"));
}


Expand All @@ -117,14 +127,15 @@ void AdditionLayer3D::to_XML(XMLPrinter& printer) const
printer.OpenElement("Addition3D");

add_xml_element(printer, "Name", name);
add_xml_element(printer, "InputsNumber", to_string(get_inputs_number_xxx()));
add_xml_element(printer, "InputsDepth", to_string(get_inputs_depth()));
add_xml_element(printer, "SequenceLength", to_string(get_sequence_length()));
add_xml_element(printer, "EmbeddingLength", to_string(get_embedding_length()));

printer.CloseElement();
}


AdditionLayer3DForwardPropagation::AdditionLayer3DForwardPropagation(const Index& new_batch_samples_number, Layer* new_layer)
AdditionLayer3DForwardPropagation::AdditionLayer3DForwardPropagation(const Index& new_batch_samples_number,
Layer* new_layer)
: LayerForwardPropagation()
{
set(new_batch_samples_number, new_layer);
Expand All @@ -135,10 +146,10 @@ pair<type*, dimensions> AdditionLayer3DForwardPropagation::get_outputs_pair() co
{
AdditionLayer3D* addition_layer_3d = static_cast<AdditionLayer3D*>(layer);

const Index inputs_number = addition_layer_3d->get_inputs_number_xxx();
const Index inputs_depth = addition_layer_3d->get_inputs_depth();
const Index sequence_length = addition_layer_3d->get_sequence_length();
const Index embedding_length = addition_layer_3d->get_embedding_length();

return {(type*)outputs.data(), {batch_samples_number, inputs_number, inputs_depth}};
return {(type*)outputs.data(), {batch_samples_number, sequence_length, embedding_length}};
}


Expand All @@ -150,10 +161,10 @@ void AdditionLayer3DForwardPropagation::set(const Index& new_batch_samples_numbe

batch_samples_number = new_batch_samples_number;

const Index inputs_number = addition_layer_3d->get_inputs_number_xxx();
const Index inputs_depth = addition_layer_3d->get_inputs_depth();
const Index sequence_length = addition_layer_3d->get_sequence_length();
const Index embedding_length = addition_layer_3d->get_embedding_length();

outputs.resize(batch_samples_number, inputs_number, inputs_depth);
outputs.resize(batch_samples_number, sequence_length, embedding_length);
}


Expand All @@ -172,11 +183,11 @@ void AdditionLayer3DBackPropagation::set(const Index& new_batch_samples_number,

batch_samples_number = new_batch_samples_number;

const Index inputs_number = addition_layer_3d->get_inputs_number_xxx();
const Index inputs_depth = addition_layer_3d->get_inputs_depth();
const Index sequence_length = addition_layer_3d->get_sequence_length();
const Index embedding_length = addition_layer_3d->get_embedding_length();

input_1_derivatives.resize(batch_samples_number, inputs_number, inputs_depth);
input_2_derivatives.resize(batch_samples_number, inputs_number, inputs_depth);
input_1_derivatives.resize(batch_samples_number, sequence_length, embedding_length);
input_2_derivatives.resize(batch_samples_number, sequence_length, embedding_length);
}


Expand All @@ -196,12 +207,12 @@ vector<pair<type*, dimensions>> AdditionLayer3DBackPropagation::get_input_deriva
{
AdditionLayer3D* addition_layer_3d = static_cast<AdditionLayer3D*>(layer);

const Index inputs_number = addition_layer_3d->get_inputs_number_xxx();
const Index inputs_depth = addition_layer_3d->get_inputs_depth();
const Index sequence_length = addition_layer_3d->get_sequence_length();
const Index embedding_length = addition_layer_3d->get_embedding_length();

return
{{(type*)input_1_derivatives.data(), {batch_samples_number, inputs_number, inputs_depth}},
{(type*)input_2_derivatives.data(), {batch_samples_number, inputs_number, inputs_depth}}};
{{(type*)input_1_derivatives.data(), {batch_samples_number, sequence_length, embedding_length}},
{(type*)input_2_derivatives.data(), {batch_samples_number, sequence_length, embedding_length}}};
}

}
Expand Down
24 changes: 9 additions & 15 deletions opennn/addition_layer_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,18 @@ class AdditionLayer3D : public Layer

public:

AdditionLayer3D(const Index& = 0, const Index& = 0);
AdditionLayer3D(const Index& = 0, const Index& = 0, const string& = "addition_layer_3d");

Index get_inputs_number_xxx() const;
Index get_inputs_depth() const;

// @todo

dimensions get_input_dimensions() const override
{
throw runtime_error("XXX");
}
Index get_sequence_length() const;
Index get_embedding_length() const;

dimensions get_input_dimensions() const override;
dimensions get_output_dimensions() const override;

void set(const Index& = 0, const Index& = 0);
void set(const Index& = 0, const Index& = 0, const string & = "addition_layer_3d");

void set_inputs_number(const Index&);
void set_inputs_depth(const Index&);
void set_sequence_length(const Index&);
void set_embedding_length(const Index&);

void forward_propagate(const vector<pair<type*, dimensions>>&,
unique_ptr<LayerForwardPropagation>&,
Expand All @@ -61,9 +55,9 @@ class AdditionLayer3D : public Layer

private:

Index inputs_number_xxx = 0;
Index sequence_length = 0;

Index inputs_depth = 0;
Index embedding_length = 0;
};


Expand Down
14 changes: 7 additions & 7 deletions opennn/auto_associative_neural_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ void AutoAssociativeNeuralNetwork::distance_descriptives_from_XML(const XMLDocum
if(standard_deviation_element->GetText())
new_standard_deviation = type(stod(standard_deviation_element->GetText()));

const Descriptives distance_descriptives(new_minimum, new_maximum, new_mean, new_standard_deviation);
const Descriptives new_distance_descriptives(new_minimum, new_maximum, new_mean, new_standard_deviation);

set_distance_descriptives(distance_descriptives);
set_distance_descriptives(new_distance_descriptives);

}

Expand Down Expand Up @@ -435,7 +435,7 @@ void AutoAssociativeNeuralNetwork::save_autoassociation_outputs(const Tensor<typ
{
ofstream file(file_name);

if(distances_vector.size() != types_vector.size())
if(distances_vector.size() != Index(types_vector.size()))
throw runtime_error("Distances and types vectors must have the same dimensions.\n");

if(!file.is_open())
Expand Down Expand Up @@ -481,11 +481,13 @@ void AutoAssociativeNeuralNetwork::to_XML(XMLPrinter& printer) const

buffer.str("");

for(Index i = 0; i < Index(layers.size()); i++)
const Index layers_number = get_layers_number();

for(Index i = 0; i < layers_number; i++)
{
buffer << layers[i]->get_type_string();

if(i != layers.size()-1)
if(i != layers_number - 1)
buffer << " ";
}

Expand Down Expand Up @@ -554,8 +556,6 @@ void AutoAssociativeNeuralNetwork::to_XML(XMLPrinter& printer) const

// DistancesDescriptives

const Descriptives distance_descriptives = get_distance_descriptives();

printer.OpenElement("DistancesDescriptives");
add_xml_element(printer, "Minimum", to_string(distance_descriptives.minimum));
add_xml_element(printer, "Maximum", to_string(distance_descriptives.maximum));
Expand Down
12 changes: 6 additions & 6 deletions opennn/data_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ vector<vector<string>> DataSet::get_data_file_preview() const


void DataSet::set(const filesystem::path& new_data_path,
const string& separator,
const string& new_separator,
const bool& new_has_header,
const bool& new_has_ids,
const DataSet::Codification& new_codification)
Expand All @@ -1713,7 +1713,7 @@ void DataSet::set(const filesystem::path& new_data_path,

set_data_path(new_data_path);

set_separator_string(separator);
set_separator_string(new_separator);

set_has_header(new_has_header);

Expand Down Expand Up @@ -2088,7 +2088,7 @@ vector<Histogram> DataSet::calculate_raw_variable_distributions(const Index& bin
const Index used_samples_number = used_sample_indices.size();

vector<Histogram> histograms(used_raw_variables_number);

/*
Index variable_index = 0;
Index used_raw_variable_index = 0;
Expand Down Expand Up @@ -2173,7 +2173,7 @@ vector<Histogram> DataSet::calculate_raw_variable_distributions(const Index& bin
throw runtime_error("Unknown raw variable type.");
}
}

*/
return histograms;
}

Expand Down Expand Up @@ -2496,7 +2496,7 @@ bool DataSet::has_nan_row(const Index& row_index) const

void DataSet::print_missing_values_information() const
{
const Index missing_values_number = count_nan();
//const Index missing_values_number = count_nan();

const Tensor<Index, 0> raw_variables_with_missing_values = count_raw_variables_with_nan().sum();

Expand Down Expand Up @@ -4648,7 +4648,7 @@ Tensor<type, 2> DataSet::read_input_csv(const filesystem::path& input_data_file_

// Scrub missing values

const MissingValuesMethod missing_values_method = get_missing_values_method();
//const MissingValuesMethod missing_values_method = get_missing_values_method();

const Index samples_number = input_data.dimension(0);
const Index variables_number = input_data.dimension(1);
Expand Down
Loading

0 comments on commit d06a0e0

Please sign in to comment.